发动机#
初始化电机类#
使用以下构造函数创建 EXP Motor 对象:
电机(左舷,齿轮,倒车)
此构造函数最多接受三个参数。
范围 |
描述 |
---|---|
|
电机连接到 EXP Brain 上的 端口。 |
|
**可选。**设置电机中安装的 齿轮设置,默认为 |
|
**可选。**设置电机的旋转是否应该反转,默认为“False”。 |
# Construct a Motor object named motor_1 in Port 1 on
# the EXP Brain which has the reverse flag set to True.
motor_1 = Motor(Ports.PORT1, True)
当引用 Motor 类方法时,此“motor_1”对象将在本 API 文档的所有后续示例中使用。
类方法#
spin()#
spin(direction, speed, units)
方法用于使电机沿指定方向旋转,直到使用旋转或停止命令,或者项目停止。
这是一个非等待功能,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
方向 |
有效的 DirectionType。 |
速度 |
**可选。**电机旋转的速度。将使用 |
单位 |
**可选。**有效的 VelocityUnit 或 |
**返回:**无。
# Spin motor_1 forward.
motor_1.spin(FORWARD)
spin_to_position()#
spin_to_position(rotation, units, speed, units_v, wait)
方法用于使用提供的参数将电机旋转到绝对位置。
该函数可以是等待或非等待命令,具体取决于wait
参数是否设置为True
。
参数 |
描述 |
---|---|
旋转 |
电机旋转的位置。 |
单位 |
**可选。**有效的 RotationUnit。默认值为 |
速度 |
**可选。**电机旋转的速度。将使用 |
单位 |
**可选。**有效的 VelocityUnit 或 |
等待 |
可选。 确定命令是否阻止后续命令( |
**返回:**无。
# Spin motor_1 to the position 90 degrees at 100 RPM.
motor_1.spin_to_position(90, DEGREES, 100, RPM)
spin_for()#
spin_for(direction, value, units, speed, units_v, wait)
方法用于使电机旋转特定时长、圈数或直至达到特定的编码器值。该位置相对于电机的当前位置。
这可以是等待或非等待命令,取决于是否使用了“wait”参数。
参数 |
描述 |
---|---|
方向 |
有效的 DirectionType。 |
价值 |
电机旋转的值。 |
单位 |
**可选。**有效的 RotationUnit。默认值为 |
速度 |
**可选。**电机旋转的速度。将使用 |
单位 |
**可选。**有效的 VelocityUnit 或 |
等待 |
可选。 确定命令是否阻止后续命令( |
**返回:**无。
# Spin motor_1 forward for 10 turns at 100 percent velocity.
motor_1.spin_for(FORWARD, 10, TURNS, 100, PERCENT)
stop()#
stop(mode)
方法用于停止电机,将其速度设置为 0 并配置当前停止模式。
参数 |
描述 |
---|---|
模式 |
**可选。**有效的 BrakeType。默认值为“COAST”,除非之前使用“motor_1.set_stopping()”命令进行了更改。 |
**返回:**无。
# Spin motor_1 forward for 2.5 seconds.
motor_1.spin(FORWARD)
wait(2.5, SECONDS)
# Stop motor_1 using the HOLD brake type.
motor_1.stop(HOLD)
set_velocity()#
set_velocity(velocity, units)
方法用于设置电机的默认速度。如果未提供具体速度,则此速度设置将用于后续调用任何运动函数。
参数 |
描述 |
---|---|
速度 |
为电机设置的新速度。 |
单位 |
有效的 VelocityUnit 或 |
**返回:**无。
# Spin motor_1 forward at 75 percent velocity
motor_1.set_velocity(75, PERCENT)
motor_1.spin(FORWARD)
set_reversed()#
set_reversed(value)
方法将电机方向设置为反转。此命令的作用与构造电机时将 reverse
参数设置为 True
相同。
参数 |
描述 |
---|---|
价值 |
布尔值来设置方向是否反转。 |
**返回:**无。
set_stopping()#
set_stopping(mode)
方法用于设置电机的停止模式。
参数 |
描述 |
---|---|
模式 |
有效的 BrakeType。 |
**返回:**无。
reset_position()#
reset_position()
方法将电机位置重置为 0。motor_1.position()
函数返回的位置将更新为 0。
**返回:**无。
set_position()#
set_position(value, units)
方法用于设置电机的位置。motor_1.position()
函数返回的位置将更新为该新值。
参数 |
描述 |
---|---|
价值 |
为电机设置的新位置。 |
单位 |
有效的 RotationUnit。 |
**返回:**无。
set_timeout()#
set_timeout(value, units)
方法用于设置电机的超时时间。motor_1.get_timeout()
函数返回的位置将更新为该新值。
参数 |
描述 |
---|---|
价值 |
为电机设置的新超时。 |
单位 |
**可选。**有效的 TimeUnit。默认值为 |
**返回:**无。
get_timeout()#
get_timeout()
方法返回 Motor 的当前超时时间。
**返回:**当前超时值(以毫秒为单位)。
is_spinning()#
is_spinning()
方法返回 motor_1.spin_to_position()
或 motor_1.spin_for()
命令的当前状态。当任一命令中的 wait 参数为 False
时,使用此函数。
返回: 如果电机仍在旋转,则返回 True
。如果电机已完成移动或发生超时,则返回 False
。
is_done()#
is_done()
方法返回 motor_1.spin_to_position()
或 motor_1.spin_for()
命令的当前状态。当任一命令中的 wait 参数为 False
时,使用此函数。
返回: 如果电机仍在旋转,则返回 True
。如果电机已完成移动或发生超时,则返回 False
。
set_max_torque()#
set_max_torque(value, units)
方法用于设置电机的最大扭矩。扭矩可以设置为扭矩、电流或最大扭矩的百分比。
参数 |
描述 |
---|---|
价值 |
电机的新最大扭矩。 |
单位 |
有效的 TorqueUnit、 |
**返回:**无。
direction()#
direction()
方法返回电机当前旋转的方向。
返回: 电机当前旋转的 DirectionType。
position()#
position(units)
方法返回电机的当前位置。
参数 |
描述 |
---|---|
单位 |
**可选。**有效的 RotationUnit。默认值为 |
返回: 以指定单位表示的电机当前位置。
velocity()#
velocity(units)
方法返回电机的当前速度。
参数 |
描述 |
---|---|
单位 |
**可选。**有效的 VelocityUnit。默认值为 |
**返回:**以指定单位表示的电机当前速度。
current()#
current(units)
方法返回电机正在使用的电流。
参数 |
描述 |
---|---|
单位 |
**可选。**电流的唯一有效单位是“AMP”或“PERCENT”。 |
返回: 电机以指定单位吸收的电流。
power()#
power(units)
方法返回电机消耗的功率。
参数 |
描述 |
---|---|
单位 |
可选。 功率的唯一有效单位是“瓦特”或“百分比”。 |
**返回:**电机以指定单位消耗的功率。
torque()#
torque(units)
方法返回电机产生的扭矩。
参数 |
描述 |
---|---|
单位 |
**可选。**有效的 TorqueUnit。默认值为 |
返回: 电机以指定单位产生的扭矩。
efficiency()#
efficiency(units)
方法返回电机的效率。
参数 |
描述 |
---|---|
单位 |
**可选。**效率的唯一有效单位是“百分比”。 |
**返回:**电机效率的百分比。
temperature()#
temp(units)
方法返回电机的温度。
参数 |
描述 |
---|---|
单位 |
**可选。**有效的 TemperatureUnit。默认值为 |
**返回:**以指定单位表示的电机温度。
command()#
command(units)
方法返回发送给电机的最后速度。
参数 |
描述 |
---|---|
单位 |
**可选。**有效的 VelocityUnit。默认值为 |
**返回:**以指定单位表示的电机指令速度。
installed()#
如果电机已连接到 EXP Brain,则 installed()
方法返回。
返回: 如果电机已连接,则返回 True
。如果未连接,则返回 False
。
timestamp()#
timestamp()
方法返回从电机接收到的最后一个状态包的时间戳。
**返回:**最后接收的状态包的时间戳(以毫秒为单位)。