发动机#
要使电机命令出现在 VEXcode V5 中,必须在设备窗口中配置电机。
有关详细信息,请参阅以下文章:
发动机构造器#
可以使用以下构造函数之一以不同的方式实例化 V5 电机:
电机 Motor1 = 电机(int32_t index,bool reverse);
index
= the SmartPort the Motor is connected to.reverse
= a boolean to keep or reverse the direction the motor spins.
电机 Motor1 = 电机(int32_t index, gearSetting 齿轮);
index
= the SmartPort the Motor is connected to.gears
= the gear ratio of the Motor Cartridge.
电机 Motor1 = 电机(int32_t 索引,齿轮设置齿轮,bool 反向);
index
= the SmartPort the Motor is connected to.gears
= the gear ratio of the Motor Cartridge.reverse
= a boolean to keep or reverse the direction the motor spins.
// Construct a V5 Motor that runs in reverse.
motor Motor1 = motor(PORT1, true);
// Construct a V5 Motor with a 6:1 Turbo Gear Cartridge.
motor Motor1 = motor(PORT1, ratio6_1);
// Construct a V5 Motor with a 36:1 Torque Gear Cartridge
// that runs in reverse.
motor Motor1 = motor(PORT1, ratio36_1, true);
电机.旋转()#
The Motor.spin(direction, velocity, units)
command is used to spin a Motor in the specified direction forever, until another motion command is used, or the project is stopped.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spin(direction, velocity, units)
.
这是一个非等待功能,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
方向 |
有效的 directionType。 |
速度 |
Optional. The velocity at which the Motor will spin. The default velocity set by the |
单位 |
Optional. A valid velocityUnit. The default is |
**返回:**无。
// Spin Motor forward.
Motor1.spin(forward);
电机.spinToPosition()#
The Motor.spinToPosition(rotation, units, velocity, units_v, wait)
command is used to spin a Motor to an absolute position using the provided arguments.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spinToPosition(rotation, units, velocity, units_v, wait)
.
This function can be a waiting or non-waiting command depending on if the wait
parameter is used.
参数 |
描述 |
---|---|
旋转 |
电机旋转的位置。 |
单位 |
Optional. A valid rotationUnit. The default is |
速度 |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
单位 |
Optional. A valid velocityUnit. The default is |
等待 |
Optional. Determines whether the command will block subsequent commands ( |
**返回:**无。
// Spin Motor to 180 degrees.
Motor1.spinToPosition(180);
电机.spinFor()#
The Motor.spinFor(direction, value, units, velocity, units_v, wait)
command is used to spin the Motor for a specific duration, rotations, or until a specific encoder value is reached. The position is relative to the current position of the Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spinFor(direction, value, units, velocity, units_v, wait)
.
This can be a waiting or non-waiting command depending on if the wait
parameter is used.
参数 |
描述 |
---|---|
方向 |
有效的 directionType。 |
价值 |
电机旋转的值。 |
单位 |
Optional. A valid rotationUnit. The default is |
速度 |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
单位 |
Optional. A valid velocityUnit. The default is |
等待 |
Optional. Determines whether the command will block subsequent commands ( |
**返回:**无。
// Spin 180 degrees from the current position.
Motor1.spinFor(forward, 180);
电机停止()#
The Motor.stop(mode)
command is used to stop a Motor, setting them to 0 velocity and configuring the current stopping mode.
To use this command, replace Motor
with the desired Motor, for example: armMotor.stop(mode)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
模式 |
Optional. A valid brakeType. The default is |
**返回:**无。
// Stop the Motor.
Motor.stop();
电机.设置速度()#
The Motor.setVelocity(velocity, units)
command is used to set the default velocity for a Motor. This velocity setting will be used for subsequent calls to any motion functions if a specific velocity is not provided.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setVelocity(velocity, units)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
速度 |
为电机设置的新速度。 |
单位 |
Optional. A valid velocityUnit. The default is |
**返回:**无。
电机.setReversed()#
The Motor.setReversed(value)
command sets the Motor direction to be reversed.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
价值 |
布尔值来设置方向是否反转。 |
**返回:**无。
电机.setStopping()#
The Motor.setStopping(mode)
command is used to set the stopping mode for a Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setStopping(mode)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
模式 |
Optional. A valid brakeType. The default is |
**返回:**无。
电机.resetPosition()#
The Motor.resetPosition()
command resets the Motor position to 0.
这是一个非等待命令,允许下一个命令无延迟运行。
**返回:**无。
电机.设置位置()#
The Motor.setPosition(value, units)
command is used to set the position of a Motor. The position that is returned by the Motor.position()
function will be updated to this new value.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setPosition(value, units)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
价值 |
为电机设置的新位置。 |
单位 |
Optional. A valid rotationUnit. The default is |
**返回:**无。
电机.setTimeout()#
The Motor.setTimeout(value, units)
command is used to set the timeout for a Motor. The position that is returned by the Motor.getTimeout()
function will be updated to this new value.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setTimeout(value, units)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
价值 |
为电机设置的新超时。 |
单位 |
Optional. A valid timeUnit. The default is |
**返回:**无。
电机.getTimeout()#
The Motor.getTimeout()
command returns the current timeout for a Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.getTimeout()
.
这是一个非等待命令,允许下一个命令无延迟运行。
**返回:**当前超时值(以毫秒为单位)。
电机是否旋转()#
The Motor.isSpinning()
command returns if the Motor is currently spinning.
这是一个非等待命令,允许下一个命令无延迟运行。
返回: 如果电机当前正在旋转,则返回 True。否则,返回 False。
电机.isDone()#
The Motor.isDone()
command returns if the Motor has completed its movement.
这是一个非等待命令,允许下一个命令无延迟运行。
返回: 如果电机已完成运动,则返回 True。如果尚未完成运动,则返回 False。
电机.设置最大扭矩()#
The Motor.setMaxTorque(value, units)
command is used to set the maximum torque for a Motor. The torque can be set as torque, current, or a percent of maximum torque.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setMaxTorque(value, units)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
价值 |
电机的新最大扭矩。 |
单位 |
A valid torqueUnit, |
**返回:**无。
// Set maximum torque to 2 Newton Meters.
Motor1.set_max_torque(2, Nm);
电机.convertVelocity()#
The Motor.convertVelocity(velocity, units, unitsout)
command converts the velocity in the given units to specified units based on the Motor gearing.
To use this command, replace Motor
with the desired Motor, for example: armMotor.convertVelocity(velocity, units, unitsout)
.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
速度 |
转换的速度。 |
单位 |
速度值的有效 velocityUnit。 |
单位输出 |
Optional. A valid velocityUnit for the returned velocity. The default is |
**返回:**返回转换为指定单位的速度。
电机.获取电机墨盒()#
The Motor.getMotorCartridge()
command returns the gear cartridge setting for the Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.getMotorCartridge()
.
这是一个非等待命令,允许下一个命令无延迟运行。
**返回:**电机的齿轮筒设置。
电机.方向()#
The Motor.direction()
command returns the current direction the Motor is spinning in.
这是一个非等待命令,允许下一个命令无延迟运行。
返回: 电机当前旋转的 directionType。
电机.位置()#
The Motor.position(units)
command returns the current position of the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. A valid rotationUnit. The default is |
返回: 以指定单位表示的电机当前位置。
电机.速度()#
The Motor.velocity(units)
command returns the current velocity of the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. A valid velocityUnit. The default is |
**返回:**以指定单位表示的电机当前速度。
电机电流()#
The Motor.current(units)
command returns the current being used by the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. The only valid unit for current is |
返回: 电机以指定单位吸收的电流。
电机功率()#
The Motor.power(units)
command returns the power being consumed by the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. The only valid unit for power is |
**返回:**电机以指定单位消耗的功率。
电机扭矩()#
The Motor.torque(units)
command returns the torque being generated by the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. A valid torqueUnit. The default is |
返回: 电机以指定单位产生的扭矩。
电机效率()#
The Motor.efficiency(units)
command returns the efficiency of the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. The only valid unit for efficiency is |
**返回:**电机效率的百分比。
电机.温度()#
The Motor.temperature(units)
command returns the temperature of the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. A valid temperatureUnit. The default is |
**返回:**以指定单位表示的电机温度。
电机命令()#
The Motor.command(units)
command returns the last velocity sent to the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
参数 |
描述 |
---|---|
单位 |
Optional. A valid velocityUnit. The default is |
**返回:**以指定单位表示的电机指令速度。
电机.安装()#
The Motor.installed()
command checks if the Motor is connected.
这是一个非等待命令,允许下一个命令无延迟运行。
返回: 如果电机已连接,则返回 True。如果未连接,则返回 False。
电机.值()#
The Motor.value()
command returns the value of the Motor.
这是一个非等待命令,允许下一个命令无延迟运行。
**返回:**表示电机值的整数。