electromagnet#

Initializing the electromagnet Class#

An electromagnet object is created by using the following constructor:

The electromagnet constructor creates an electromagnet object in the specified Port:

Parameter

Description

port

A valid Smart Port that the Electromagnet is connected to.

// Construct an Electromagnet "magnet" with the
// electromagnet class.
electromagnet magnet = electromagnet(PORT1);

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

Class Methods#

setPower()#

The setPower(power) method sets the power level of the electromagnet used to pickup and drop.

Parameters

Description

power

The power level to set in the range 0 - 100.

Returns: None.

// Set the default power to 80%.
magnet.setPower(80);

pickup()#

This method is called in the following ways:

The pickup() method activates the electromagnet to pickup an object for the default duration and at the default power specified by the setPower() method.

// Set the magnet to pickup.
magnet.pickup();

The pickup(time, units) method activates the electromagnet to pickup an object for a specified duration and at the default power specified by the setPower() method.

Parameters

Description

time

The duration to activate the Electromagnet.

units

A valid TimeUnit. The default is msec.

// Set the magnet to pickup for 10 seconds.
magnet.pickup(10, seconds);

The pickup(time, units, power) method activates the electromagnet to pick up an object for a specified duration at a specified power.

Parameters

Description

time

The duration to activate the Electromagnet.

units

A valid TimeUnit. The default is msec.

power

The power level to set.

// Set the magnet to pickup for 10 seconds at 90% power.
magnet.pickup(10, seconds, 90);

Returns: None.

drop()#

This method is called in the following ways:

The drop() method activates the electromagnet to pickup an object for the default duration and at the default power specified by the setPower() method.

Returns: None.

// Set the magnet to drop.
magnet.drop();

The drop(time, units) method deactivates the electromagnet to drop an object for a specified duration and at the default power specified by the setPower() method.

Parameters

Description

time

The duration to deactivate the Electromagnet.

units

A valid TimeUnit. The default is msec.

Returns: None.

// Set the magnet to drop for 10 seconds.
magnet.drop(10, seconds);

The drop(time, units, power) method deactivates the electromagnet to drop an object for a specified duration at a specified power.

Parameters

Description

time

The duration to deactivate the Electromagnet.

units

A valid TimeUnit. The default is msec.

power

The power level to set.

Returns: None.

// Set the magnet to drop for 10 seconds at 90 percent power.
magnet.drop(10, seconds, 90);

temperature()#

The temperature(units) method returns the temperature of the electromagnet.

Parameters

Description

units

A valid TemperatureUnit. The default is celsius.

Returns: A double representing the temperature of the electromagnet.

timestamp()#

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

Returns: Timestamp of the last status packet as an unsigned 32-bit integer in milliseconds.

installed()#

The installed() method returns if the electromagnet is connected.

Returns: true if the electromagnet is installed. false if it is not.