发动机#

要使电机命令出现在 VEXcode V5 中,必须在设备窗口中配置电机。

有关详细信息,请参阅以下文章:

电机.旋转()#

The motor.spin(direction, velocity, units) command spins the motor using the provided arguments.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

方向

有效的 DirectionType

速度

Optional. Spin the motor using this velocity. The default velocity set by set_velocity will be used if not provided.

单位

Optional. A valid VelocityUnit or VOLT. The default is RPM.

**返回:**无。

# Spin motor forward for 2 seconds.
motor1.spin(FORWARD)
wait(2, SECOND)

# Stop spinning.
motor1.stop()

电机.旋转到位置()#

The motor.spin_to_position(rotation, units, velocity, units_v, wait) command is used to spin a motor to an absolute position using the provided arguments.

This function can be a waiting or non-waiting command depending on if the wait parameter is used.

参数

描述

旋转

电机旋转的位置。

单位

Optional. A valid RotationUnits. The default is DEGREES.

速度

Optional. The velocity with which the motor will spin. The default velocity set by set_velocity will be used if not provided.

单位

Optional. A valid VelocityUnits. The default is RPM.

等待

Optional. Determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for The wait parameter is wait=True.

**返回:**无。

# Spin motor to 180 degrees
motor1.spin_to_position(180)

电机.spin_for()#

The motor.spin_for(direction, value, units, velocity, units_v, wait) command spins the motor to a relative position using the provided arguments.

This can be a waiting or non-waiting command depending on if the wait parameter is used.

参数

描述

方向

有效的 DirectionType

价值

电机旋转的值。

单位

Optional. A valid RotationUnits. The default is DEGREES.

速度

Optional. The velocity with which the motor will spin. The default velocity set by set_velocity will be used if not provided.

单位

Optional. A valid VelocityUnits. The default is RPM.

等待

Optional. Determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for The wait parameter is wait=True.

**返回:**无。

电机停止()#

The motor.stop(mode) command is used to stop a motor.

这是一个非等待命令,允许下一个命令无延迟运行。

**返回:**无。

# Spin motor forward for 2 seconds.
motor1.spin(FORWARD)
wait(2, SECOND)

# Stop spinning.
motor1.stop()

电机.设置速度()#

The motor.set_velocity(value, units) command sets the default velocity for the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

价值

新的速度。

单位

Optional. A valid VelocityUnits. The default is RPM.

**返回:**无。

电机.设置反转()#

The motor.set_reversed(value) command sets the motor direction to be reversed.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

价值

布尔值来设置方向是否反转。

**返回:**无。

电机.设置停止()#

The motor.set_stopping(mode) command sets the stopping mode of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

模式

A valid BrakeType. The default is COAST.

**返回:**无。

# Set the motor to stop with a brake.
motor_1.set_stopping(BRAKE)

电机.重置位置()#

The motor.reset_position() command resets the motor position to 0.

这是一个非等待命令,允许下一个命令无延迟运行。

**返回:**无。

电机.设置位置()#

The motor.set_position(value, units) command sets the current position of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

价值

新的职位。

单位

Optional. A valid RotationUnit. The default is DEGREES.

**返回:**无。

电机.设置超时()#

The motor.set_timeout(value, units) command sets the timeout value used by the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

价值

新的超时。

单位

Optional. A valid TimeUnit. The default is MSEC.

**返回:**无。

# Set the motor timeout to 5 seconds.
motor_1.set_timeout(5000, MSEC)

电机.get_timeout()#

The motor.get_timeout() command returns the current value of motor timeout.

这是一个非等待命令,允许下一个命令无延迟运行。

**返回:**当前超时值。

电机正在旋转()#

The motor.is_spinning() command returns if the motor is currently spinning.

这是一个非等待命令,允许下一个命令无延迟运行。

Returns: True if the motor is currently spinning. False if it is not.

电机.is_done()#

The motor.is_done() command returns if the motor has completed its movement.

这是一个非等待命令,允许下一个命令无延迟运行。

Returns: True if the motor has completed its movement. False if it has not.

电机.设置最大扭矩()#

The motor.set_max_torque(value, units) command sets the maximum torque the motor will use.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

价值

新的最大使用扭矩。

单位

A valid TorqueUnit, AMP, or PERCENT.

**返回:**无。

# set maximum torque to 2 Newton Meters
motor1.set_max_torque(2, TorqueUnits.NM)

电机.方向()#

The motor.direction() command returns the current direction the motor is spinning in.

这是一个非等待命令,允许下一个命令无延迟运行。

返回: 电机当前旋转的 DirectionType

电机位置()#

The motor.position(units) command returns the position of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. A valid RotationUnit. The default is DEGREES.

返回: 以指定单位表示的电机当前位置。

电机.速度()#

The motor.velocity(units) command returns the velocity of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. A valid VelocityUnit. The default is RPM.

**返回:**以指定单位表示的电机当前速度。

电机电流()#

The motor.current(units) command returns the current the motor is using.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. The only valid unit for current is AMP.

返回: 以指定单位计算的电机电流。

电机功率()#

The motor.power(units) command returns the power the motor is providing.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. The only valid unit for power is WATT.

返回: 电机以指定单位消耗的功率。

电机扭矩()#

The motor.torque(units) command returns the torque the motor is providing.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. A valid TorqueUnit. The default is NM.

返回: 电机以指定单位产生的扭矩。

电机效率()#

The motor.efficiency(units) command returns the efficiency of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. The only valid unit for efficiency is PERCENT.

**返回:**电机效率的百分比。

电机.温度()#

The motor.temperature(units) command returns the temperature of the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. A valid TemperatureUnits. The default is CELSIUS.

**返回:**以指定单位表示的电机温度。

电机命令()#

The motor.command(units) command returns the last velocity sent to the motor.

这是一个非等待命令,允许下一个命令无延迟运行。

参数

描述

单位

Optional. A valid VelocityUnit. The default is RPM.

**返回:**以指定单位表示的电机指令速度。

电机.安装()#

The motor.installed() command checks for device connection.

这是一个非等待命令,允许下一个命令无延迟运行。

**返回:**真或假。

# Check if the motor is installed.
is_installed = motor_1.installed()

电机.时间戳()#

The motor.timestamp() command requests the timestamp of the last received status packet.

这是一个非等待命令,允许下一个命令无延迟运行。

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

# Get the timestamp of the last received status packet from the motor.
timestamp = motor_1.timestamp()