Electro Magnet - QuirkyCort/gears GitHub Wiki

This simulates an electro-magnet. While it is not impossible to build an electro-magnet for a robotics set such as the EV3, this cannot be done with official parts.

To control the magnet, just set the speed of the motor that it is simulating. Turning the motor at 100% speed will set the magnet power to 100%. Setting the speed to 0% or stop will turn the magnet power to zero.

Differences from a real actuator

  • A real electro-magnet applies its attractive force to the surface of a magnetic material. The simulator applies its force to the center of the material.

  • Like a real magnet, the power of the simulated magnet follows an inverse square law. However, unlike a real magnet, the simulated magnet uses the distance to the center of the object for its calculations. This means that a large object may be considered too far away, even if the electro-magnet is close to the surface of the object.

  • Setting the speed of the motor to a negative value will cause the electro-magnet to repel magnetic objects. A real electro-magnet would not do that, and this effect is unintentional (ie. a bug)... but it's a cool and useful effect, so I'm officially treating it as a feature.

Configurations

Default values are shown below.

"type": "MagnetActuator",
"options": {
  "maxRange": 8,
  "maxPower": 4000
}

maxRange: If the center of the object is more than this distance (...in cm) away from the electro magnet, it will not be attracted.

maxPower: The attraction force of the electro magnet at a distance of 1cm. If the distance is greater than 1cm, the force will be reduced.