Electromagnet#

Initializing the Electromagnet Class#

An Electromagnet is created by using the following constructor:

Electromagnet(port)

This constructor use one parameter:

Parameter

Description

port

A valid Smart Port that the Electromagnet is connected to.

# Construct an Electromagnet "magnet" with the
# Electromagnet class.
magnet = Electromagnet(Ports.PORT1)

This magnet object will be used in all subsequent examples throughout this API documentation when referring to Electromagnet class methods.

Class Methods#

set_power()#

The set_power(value) method sets the power level of the Electromagnet used to pickup and drop.

Parameters

Description

value

The power level to set (0 - 100).

Returns: None.

# Set the default power to 80%. 
magnet.set_power(80)

pickup()#

The pickup(duration, units, power) method activates the Electromagnet to pick up an object.

Parameters

Description

duration

Optional. The duration to activate the Electromagnet.

units

Optional. A valid TimeUnits type. The default is MSEC.

power

Optional. The power level to set (0 - 100).

Returns: None.

# Set the Electromagnet to pickup.
magnet.pickup()

# Set the Electromagnet to pickup for 250 milliseconds at
# 90% power.
magnet.pickup(250, MSEC, 90)

drop()#

The drop() method deactivates the Electromagnet to drop an object.

Parameters

Description

duration

Optional. The duration to deactivate the Electromagnet.

units

Optional. A valid TimeUnits type. The default is MSEC.

power

Optional. The power level to set (0 - 100).

Returns: None.

# Set the Electromagnet to drop.
magnet.drop()

# Set the Electromagnet to drop for 250 milliseconds at
# 90% power.
magnet.drop(250, MSEC, 90)

temperature()#

The temperature() method returns the temperature of the Electromagnet.

Parameters

Description

units

Optional. A valid TemperatureUnits type. The default is CELSIUS.

Returns: The temperature of the Electromagnet.

installed()#

The installed() method checks if the Electromagnet is connected.

Returns: True if the Electromagnet is installed. False if it is not.

timestamp()#

The timestamp() method returns the timestamp of the last received status packet from the Electromagnet.

Returns: The timestamp of the last received status packet in milliseconds.