发动机#
初始化电机类#
可以使用以下构造函数之一以不同的方式实例化 EXP 电机:
This motor
constructor creates a motor object with gears
defaulting to ratio18_1
.
范围 |
描述 |
---|---|
|
电机所连接的 EXP Brain 上的 端口。 |
|
A boolean value to reverse the direction the Motor spins forward in. The default is |
// Construct a Motor connected to Port 1 which runs
// in reverse.
motor Motor1 = motor(PORT1, true);
This motor
constructor creates a motor object with reverse
defaulting to false
.
范围 |
描述 |
---|---|
|
电机所连接的 EXP Brain 上的 端口。 |
|
插入电机的 gearSetting。 |
// Construct a Motor connected to Port 1 with a 6:1
// High Speed Motor Cartridge.
motor Motor1 = motor(PORT1, ratio6_1);
This motor
constructor creates a motor object with no default parameter values.
范围 |
描述 |
---|---|
|
电机所连接的 EXP Brain 上的 端口。 |
|
插入电机的 gearSetting。 |
|
用于反转电机向前旋转的方向的布尔值。 |
// Construct an EXP Motor with a 36:1 Torque Gear Cartridge
// that runs in reverse.
motor Motor1 = motor(PORT1, ratio36_1, true);
This Motor1
object will be used in all subsequent examples throughout this API documentation when referring to motor class methods.
类方法#
spin()#
这是一个非等待功能,允许下一个命令无延迟运行。
该方法通过以下方式调用:
The spin(dir)
command is used to spin a Motor in the specified direction forever at the default velocity set by the setVelocity()
command, until a spin or stop command is used, or the project is stopped.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
**返回:**无。
// Spin Motor1 forward.
Motor1.spin(forward);
The spin(dir, velocity, units)
command is used to spin a Motor in the specified direction forever at a specified velocity until a spin or stop command is used, or the project is stopped.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
速度 |
电机旋转的速度。 |
单位 |
A valid velocityUnit or |
**返回:**无。
// Spin Motor1 forward at 100 rpm.
Motor1.spin(forward, 100, rpm);
The spin(dir, voltage, units)
command is used to spin a Motor in the specified direction forever at a specified voltage until a spin or stop command is used, or the project is stopped.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
电压 |
电机旋转时的电压。 |
单位 |
有效的 voltUnit。 |
**返回:**无。
// Spin Motor1 forward at 100 millivolts.
Motor1.spin(forward, 100, voltageUnits::mV);
spinToPosition()#
This function can be a waiting or non-waiting command depending on if the waitForCompletion
parameter is used.
该方法通过以下方式调用:
The spinToPosition(rotation, units, waitForCompletion)
command is used to spin a Motor to an absolute rotation in the specified units.
参数 |
描述 |
---|---|
旋转 |
电机旋转的位置。 |
单位 |
有效的 rotationUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 to the absolute position 1080 degrees.
Motor1.spinToPosition(1080, degrees);
The spinToPosition(rotation, units, velocity, units_v, waitForCompletion)
command is used to spin a Motor to an absolute rotation in the specified units.
参数 |
描述 |
---|---|
旋转 |
电机旋转的位置。 |
单位 |
有效的 rotationUnit。 |
速度 |
电机旋转的速度。 |
单位 |
有效的 velocityUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 to the absolute position 1080 degrees
// at 100 percent velocity.
Motor1.spinToPosition(1080, degrees, 100, percent);
spinFor()#
This can be a waiting or non-waiting command depending on if the waitForCompletion
parameter is used.
该方法通过以下方式调用:
The spinFor(time, units)
command is used to spin the Motor for a specified duration.
参数 |
描述 |
---|---|
时间 |
电机旋转的时间。 |
单位 |
有效的 timeUnit。 |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 for 10 seconds
Motor1.spinFor(10, seconds);
The spinFor(dir, time, units)
command is used to spin the Motor for a specified duration in a specified direction.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
时间 |
电机旋转的时间。 |
单位 |
有效的 timeUnit。 |
// Spin Motor1 forward for 10 seconds
Motor1.spinFor(forward, 10, seconds);
The spinFor(time, units, velocity, units_v)
command is used to spin the Motor for a specified duration at a specified velocity.
参数 |
描述 |
---|---|
时间 |
电机旋转的时间。 |
单位 |
有效的 timeUnit。 |
速度 |
电机旋转的速度。 |
单位 |
有效的 velocityUnit。 |
// Spin Motor1 for 10 seconds at 100 rpm.
Motor1.spinFor(10, seconds, 100, rpm);
The spinFor(dir, time, units, velocity, units_v)
command is used to spin the Motor for a specified duration at a specified velocity in a specified direction.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
时间 |
电机旋转的时间。 |
单位 |
有效的 timeUnit。 |
速度 |
电机旋转的速度。 |
单位 |
有效的 velocityUnit。 |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 forward for 10 seconds at 100 rpm.
Motor1.spinFor(forward, 10, seconds, 100, rpm);
The spinFor(rotation, units, waitForCompletion)
command is used to spin the Motor for a specific rotation. The rotation is relative to the current rotation of the Motor.
参数 |
描述 |
---|---|
旋转 |
电机旋转的旋转值。 |
单位 |
有效的 rotationUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 for 1000 degrees.
Motor1.spinFor(1000, degrees);
The spinFor(dir, rotation, units, waitForCompletion)
command is used to spin the Motor for a specific rotation in a specific direction. The rotation is relative to the current rotation of the Motor.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
旋转 |
电机旋转的旋转值。 |
单位 |
有效的 rotationUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 forward for 1000 degrees.
Motor1.spinFor(forward, 1000, degrees);
The spinFor(rotation, units, velocity, units_v, waitForCompletion)
command is used to spin the Motor for a specific rotation. The rotation is relative to the current rotation of the Motor.
参数 |
描述 |
---|---|
旋转 |
电机旋转的旋转值。 |
单位 |
有效的 rotationUnit。 |
速度 |
电机旋转的速度。 |
单位 |
有效的 velocityUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 for 1000 degrees at 25 rpm.
Motor1.spinFor(1000, degrees, 25, rpm);
The spinFor(dir, rotation, units, velocity, units_v, waitForCompletion)
command is used to spin the Motor for a specific rotation in a specific direction. The rotation is relative to the current rotation of the Motor.
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
旋转 |
电机旋转的旋转值。 |
单位 |
有效的 rotationUnit。 |
速度 |
电机旋转的速度。 |
单位 |
有效的 velocityUnit。 |
等待完成 |
Determines whether the command will block subsequent commands ( |
**返回:**一个布尔值,表示电机何时达到目标旋转。
// Spin Motor1 forard for 1000 degrees at 25 rpm.
Motor1.spinFor(forward, 1000, degrees, 25, rpm);
stop()#
这是一个非等待命令,允许下一个命令无延迟运行。
该方法通过以下方式调用:
The stop()
command is used to stop a Motor, setting the Motor to 0 velocity and configuring the current stopping mode. The default Brake Type is coast
, unless previously changed using the setStopping()
command.
**返回:**无。
// Spin Motor1 for 2.5 seconds.
Motor1.spin(forward);
wait(2.5 seconds);
// Stop Motor1.
Motor1.stop();
The stop(mode)
command is used to stop a Motor using a specific Brake Type.
参数 |
描述 |
---|---|
模式 |
有效的 brakeType。 |
**返回:**无。
// Spin Motor1 for 2.5 seconds.
Motor1.spin(forward);
wait(2.5 seconds);
// Stop Motor1 using the hold Brake Type.
Motor1.stop(hold);
setVelocity()#
The 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.
参数 |
描述 |
---|---|
速度 |
为电机设置的新速度。 |
单位 |
A valid velocityUnit or |
**返回:**无。
setReversed()#
The setReversed(value)
command sets the Motor direction to be reversed. Constructing a Motor with the reverse
parameter set to true
has the same result as Motor1.setReversed(true)
.
参数 |
描述 |
---|---|
价值 |
用于设置电机方向是否反转的布尔值。 |
**返回:**无。
setStopping()#
The setStopping(mode)
command is used to set the stopping mode for a Motor. This will be the stopping mode used when the stop()
command is called.
参数 |
描述 |
---|---|
模式 |
有效的 brakeType。 |
**返回:**无。
resetPosition()#
The resetPosition()
command resets the Motor’s encoder value to 0.
**返回:**无。
setPosition()#
The setPosition(value, units)
command is used to set the value of a Motor’s encoder to a specific value. The position that is returned by the position()
command will be updated to this new value.
参数 |
描述 |
---|---|
价值 |
为电机编码器设置的新位置。 |
单位 |
有效的 rotationUnit。 |
**返回:**无。
setTimeout()#
The setTimeout(value, units)
command is used to set the timeout for motor commands. If a Motor does not reach its’ commanded position prior to the completion of the timeout, the Motor will stop.
参数 |
描述 |
---|---|
价值 |
为电机设置的新超时。 |
单位 |
有效的 timeUnit。 |
**返回:**无。
isSpinning()#
The isSpinning()
command returns if the Motor is currently rotating to a specific target.
Returns: true
if the Motor is on and is rotating to a target. false
if it is done rotating to a target.
isDone()#
The isDone()
command returns if the Motor is done rotating to a specific target.
Returns: true
if the Motor is done rotating to a target. false
if it is on and rotating to a target.
setMaxTorque()#
该方法通过以下方式调用:
The setMaxTorque(value, units)
command is used to set the maximum torque for a Motor.
参数 |
描述 |
---|---|
价值 |
电机的新最大扭矩。 |
单位 |
有效的 torqueUnit。 |
**返回:**无。
// Set maximum torque to 2 Newton Meters.
Motor1.set_max_torque(2, Nm);
The setMaxTorque(value, units)
command is used to set the maximum torque for a Motor.
参数 |
描述 |
---|---|
价值 |
电机的新最大扭矩。 |
单位 |
The only valid unit is |
**返回:**无。
// Set maximum torque to ,05 amps.
Motor1.set_max_torque(.05, amp);
The setMaxTorque(value, units)
command is used to set the maximum torque for a Motor as a percentage.
参数 |
描述 |
---|---|
价值 |
电机的新最大扭矩。 |
单位 |
The only valid unit is |
**返回:**无。
// Set maximum torque to 75 percent.
Motor1.set_max_torque(75, percent);
convertVelocity()#
The convertVelocity(velocity, units, unitsout)
command converts the velocity in the given units to the given output units based on the Motor gearing.
参数 |
描述 |
---|---|
速度 |
转换的速度。 |
单位 |
输入速度的有效 velocityUnit。 |
单位输出 |
输出速度的有效 velocityUnit。 |
**返回:**表示转换为指定输出单位的速度的双精度数。
getMotorCartridge()#
The getMotorCartridge()
command returns the gear cartridge setting for the Motor.
**返回:**电机的齿轮筒设置。
direction()#
The direction()
command returns the current direction the Motor is spinning in as a directionType.
**返回:**一个 directionType 值,表示电机当前旋转的方向。
position()#
The position(units)
command returns the current rotation of the Motor.
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。 |
**返回:**以指定单位表示电机当前旋转的双精度值。
velocity()#
The velocity(units)
command returns the current velocity of the Motor.
参数 |
描述 |
---|---|
单位 |
A valid velocityUnit or |
**返回:**以指定单位表示电机当前速度的双精度数。
current()#
The current(units)
command returns the current being used by the Motor.
参数 |
描述 |
---|---|
单位 |
The only valid units for current are |
返回: 以指定单位表示电机所吸收的电流的双精度值。
voltage()#
The voltage(units)
command returns the electrical voltage of the Motor.
参数 |
描述 |
---|---|
单位 |
A valid voltageUnit. The default is |
**返回:**以指定单位表示电机电压的双精度值。
power()#
The power(units)
command returns the power being consumed by the Motor.
参数 |
描述 |
---|---|
单位 |
The only valid unit for power is |
**返回:**以指定单位表示电机当前功率的双精度值。
torque()#
The torque(units)
command returns the torque of the Motor.
参数 |
描述 |
---|---|
单位 |
有效的 torqueUnit。 |
**返回:**指定单位的电机扭矩。
efficiency()#
The efficiency(units)
command returns the efficiency of the Motor.
参数 |
描述 |
---|---|
单位 |
The only valid unit for efficiency is |
**返回:**电机效率的百分比。
temperature()#
The temperature(units)
command returns the current temperature of the Motor.
参数 |
描述 |
---|---|
单位 |
A valid temperatureUnit or |
**返回:**以指定单位表示的电机当前温度。
installed()#
The installed()
command returns if the Motor is connected to the EXP Brain.
Returns: true
if the Motor is connected to the EXP Brain. false
if it is not.