电磁铁#

初始化电磁铁类#

使用以下构造函数创建电磁铁:

Electromagnet(port)

此构造函数使用一个参数:

范围

描述

port

电磁铁所连接的有效 智能端口

# 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.

类方法#

set_power()#

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

参数

描述

价值

要设置的功率级别(0 - 100)。

**返回:**无。

# 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.

参数

描述

期间

**可选。**激活电磁铁的持续时间。

单位

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

力量

**可选。**要设置的功率级别(0 - 100)。

**返回:**无。

# 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.

参数

描述

期间

可选。 停用电磁铁的持续时间。

单位

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

力量

**可选。**要设置的功率级别(0 - 100)。

**返回:**无。

# 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.

参数

描述

单位

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

**返回:**电磁铁的温度。

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.

**返回:**最后接收的状态包的时间戳(以毫秒为单位)。