Magnet#

Introduction#

The V5 Magnet is only used with the V5 Workcell.

Below is a list of available methods:

Actions – Interact with the Magnet.

  • pickup – Activates the Magnet to pick up an object.

  • drop – Deactivates the Magnet to drop an object.

  • set_power – Sets the power level of the Magnet used to pickup and drop.

Getters – Return data from the Magnet.

  • temperature – Returns the temperature of the Magnet.

  • installed – Checks if the Magnet is connected.

  • timestamp – Returns the timestamp of the last received status packet from the Magnet.

Constructors – Manually initialize and configure the Magnet.

Actions#

pickup#

pickup(duration, units, power) activates the Magnet to pick up an object.

Usage: magnet.pickup(duration, units, power)

Parameters

Description

duration

Optional. The duration to activate the Magnet as an integer or float.

units

Optional. Units for the duration:

  • MSEC (Default)
  • SECONDS

power

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

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

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

drop#

drop() deactivates the Magnet to drop an object.

Usage: magnet.drop(duration, units, power)

Parameters

Description

duration

Optional. The duration to deactivate the Magnet as an integer or float.

units

Optional. Units for the duration:

  • MSEC (Default)
  • SECONDS

power

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

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

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

set_power#

set_power(value) sets the power level of the Magnet used to pickup and drop.

Usage: magnet.set_power(value)

Parameters

Description

value

The power level to set (0 - 100).

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

Getters#

temperature#

temperature() returns the temperature of the Magnet as a float.

Usage: magnet.temperature(units)

Parameters

Description

units

Optional. Units for the temperature :

  • CELSIUS (Default)
  • FAHRENHEIT

installed#

installed() returns a Boolean if the Magnet is connected.

  • True - The Magnet is connected to the Brain.

  • False - The Magnet is not connected to the Brain.

Usage: magnet.installed()

Parameters

Description

This method has no parameters.

timestamp#

timestamp() returns an integer as the timestamp of the last received status packet from the Magnet.

Usage: magnet.timestamp()

Parameters

Description

This method has no parameters.

Constructors#

Constructors are used to manually create Magnet objects, which are necessary for configuring a Magnet outside of VEXcode.

Electromagnet#

Electromagnet creates a magnet.

Usage: magnet_1 = Electromagnet(port)

Parameter

Description

port

Which Smart Port that the magnet is connected to as Ports.PORT followed by the port number, ranging from 1 to 12.

# Create a Magnet in Port 1.
magnet_1 = Electromagnet(Ports.PORT1)