汽车和汽车集团#

介绍#

Motors and motor groups control how parts of a robot move. A motor object controls one configured IQ Smart Motor, while a motor_group object controls multiple configured IQ Smart Motors together so they move in tandem. Motors and motor groups can be used to raise an arm, turn a claw, spin a wheel, or move another part of a build. Two motors can work together as a drivetrain to move and turn the whole robot.

Each motor or motor group is configured in the Devices window. Depending on the build, motor and motor group names can change. This page uses Motor1 and MotorGroup1 as example names. Replace them with your own configured names as needed.

VEX IQ(第二代)电机,前进方向用加号表示,箭头表示向左(或逆时针)旋转。 VEX IQ(第二代)电机显示反向旋转,用减号和箭头表示其向右(顺时针)旋转。

By default, forward spins a motor counterclockwise, and reverse spins a motor clockwise. If a motor is set to reverse, those directions will be switched.

发动机#

Class Constructors#

1 Creates a motor object for the IQ Smart Motor connected to the specified Smart Port. The motor automatically uses the detected internal gearSetting.

motor(
  int32_t index );

2 Creates a motor object on the specified Smart Port and optionally reverses its direction. The motor automatically uses the detected internal gearSetting.

motor(
 int32_t index,
 bool    reverse );

3 Creates a motor object on the specified Smart Port with the specified gearSetting.

motor(
 int32_t     index,
 gearSetting gears );

4 Creates a motor object on the specified Smart Port with the specified gearSetting and optional reversed direction.

motor(
 int32_t     index,
 gearSetting gears,
 bool        reverse );

Class Destructor#

Destroys the motor object and releases associated resources.

~motor();

Parameters#

范围

类型

描述

index

int32_t

The Smart Port that the motor is connected to, written as PORTx, where x is the port number (for example, PORT1).

reverse

bool

Sets whether the motor’s spin direction is reversed:

  • false (default) — Does not reverse the motor’s direction.
  • true — Reverses the motor’s direction.

gears

gearSetting

Specifies the internal gear cartridge ratio.

  • ratio1_1 — A 1:1 gear ratio
  • ratio2_1 — A 2:1 gear ratio
  • ratio3_1 — A 3:1 gear ratio

Notes#

  • 齿轮设置应与电机中安装的物理卡盘相匹配。

Example#

// Create the motor instance in Smart Port 1
motor LeftMotor = motor(PORT1);

// Creates the motor instance with different settings
motor RightMotor = motor(
  PORT2,      // Smart Port 2
  ratio2_1,  // Gear ratio is 2:1
  true);

汽车集团#

Class Constructors#

motor_group( motor &m1, Args&... m2 );

Class Destructor#

Destroys the motor_group object and releases associated resources.

~motor_group();

Parameters#

范围

类型

描述

m1

motor &

集团新增的第一台电机。

m2

motor &

该电机组新增了电机。一个电机组最多可包含四个电机。

Example#

// Create individual motor instances
motor LeftMotor  = motor(PORT1);
motor RightMotor = motor(PORT2);

// Create a motor group with both motors
motor_group DriveMotors = motor_group(LeftMotor, RightMotor);

成员功能#

There are many ways to code motors and motor groups. Below is a list of all motor and motor_group member functions:

操作——停止和旋转电机及电机组。

  • spin — Spins a motor or motor group forward or reverse forever.

  • spinFor — Spins a motor or motor group for a specific distance or amount of time.

  • spinToPosition — Spins a motor or motor group to a specific position.

  • stop — Stops a motor or motor group from spinning.

变异器 — 调整电机和电机组设置。

  • setVelocity — Tells a motor or motor group how fast to spin.

  • setMaxTorque — Sets how hard a motor or motor group is allowed to push while spinning.

  • setPosition — Changes the motor or motor group’s current position to a new value.

  • setStopping — Sets how a motor or motor group will stop moving: by braking, coasting, or holding.

  • setTimeout — Sets how much time a motor or motor group will try to finish a movement.

Getters — 检查电机和电机组状态。

  • isDone — Returns whether the motor or motor group is finished moving, as a Boolean value.

  • isSpinning — Returns whether the motor or motor group is spinning, as a Boolean value.

  • position — Returns the motor or motor group’s current position.

  • velocity — Returns how fast the motor or motor group is spinning.

  • current — Returns how much electrical current the motor or motor group is using.

  • power — Returns how much power the motor or motor group is using.

  • torque — Returns how much torque the motor or motor group is using.

  • efficiency — Returns how efficiently the motor or motor group is using power.

  • temperature — Returns the temperature of the motor or motor group.

  • voltage — Returns the electrical voltage supplied to the motor or motor group.

  • direction — Returns the direction the motor or motor group is spinning.

  • installed — Returns whether the motor or motor group is connected to the Brain.

  • count — Returns the number of motors in a motor group.

Before calling any motor or motor_group member functions, an instance must be created, as shown below:

/* This constructor is required when using VS Code.
Motor and Motor Group configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create the motor instance in Smart Port 1
motor Motor1 = motor(PORT1);

行动#

spin#

spin spins a motor or motor group forward or reverse forever. The motor or motor group will continue to spin until it is given another action, like spinning in a different direction or stopping.

Available Functions

1 使用当前配置的电机速度旋转电机或电机组。

void spin(
 directionType dir );

2 使电机或电机组以指定的速度旋转。

void spin(
 directionType dir,
 double        velocity,
 velocityUnits units );

3 使用指定的电压驱动电机或电机组旋转。

void spin(
 directionType dir,
 double        voltage,
 voltageUnits  units );

Parameters

范围

类型

描述

dir

directionType

The direction the motor or motor group spins: forward or reverse.

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units

velocityUnits

The unit used to represent velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

voltage

double

The voltage to spin with. A negative value spins opposite the given dir.

units

voltageUnits

The unit used to represent voltage:

  • volt — volts
  • voltageUnits::mV — millivolts

Return Values

此函数不返回值。

Notes
  • 该函数不等待,调用后项目将立即继续执行。

  • The motor or motor group will continue spinning until stop is called or another movement function is executed.

  • Functions such as isDone and isSpinning are not applicable to spin, since it does not use target-based movement (doesn’t have a rotation or time parameter).

Examples
// Spin forward, then stop
Motor1.spin(forward);
wait(1, seconds);
Motor1.stop();

spinFor#

spinFor spins a motor or motor group for a specific distance or amount of time. A rotation-based spin is relative to the current position of the motor or motor group. By default, the project will wait until the motor or motor group is done spinning before the next line of code runs.

Available Functions

1 以函数调用中提供的速度旋转特定距离。

bool spinFor(
 double        rotation,
 rotationUnits units,
 double        velocity,
 velocityUnits units_v,
 bool          waitForCompletion = true );

2 接受一个方向参数,并以函数调用中提供的速度旋转指定的距离。

bool spinFor(
 directionType dir,
 double        rotation,
 rotationUnits units,
 double        velocity,
 velocityUnits units_v,
 bool          waitForCompletion = true );

3 使用 当前配置的电机速度 旋转特定距离。

bool spinFor(
 double        rotation,
 rotationUnits units,
 bool          waitForCompletion = true );

4 接受一个方向参数,并使用当前配置的电机速度旋转特定距离。

bool spinFor(
 directionType dir,
 double        rotation,
 rotationUnits units,
 bool          waitForCompletion = true );

5 以函数调用中提供的速度旋转特定时间。

bool spinFor(
 double        time,
 timeUnits     units,
 double        velocity,
 velocityUnits units_v );

6 接受一个方向参数,并以函数调用中提供的速度旋转特定的时间。

bool spinFor(
 directionType dir,
 double        time,
 timeUnits     units,
 double        velocity,
 velocityUnits units_v );

7 使用当前配置的电机速度旋转特定时间。

bool spinFor(
 double    time,
 timeUnits units );

8 接受一个方向参数,并使用当前配置的电机速度旋转特定的时间。

bool spinFor(
 directionType dir,
 double        time,
 timeUnits     units );

Parameters

范围

类型

描述

dir

directionType

The direction the motor or motor group spins: forward or reverse.

rotation

double

电机或电机组的旋转距离。

units

rotationUnits

The rotation unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

time

double

电机或电机组旋转的时间长度。

units

timeUnits

The unit of time:

  • seconds / sec — seconds
  • msec — milliseconds

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units_v

velocityUnits

The unit used to represent velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

waitForCompletion

bool

  • true (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • false — Makes the next line of code run right away.

Return Values

返回一个布尔值,表示电机或电机组是否达到目标值。

  • true — The motor or motor group reached the target value.
  • false — The motor or motor group was not able to reach the target value or waitForCompletion is set to false.
Notes
  • Executing another motor movement function (such as spin or stop) while spinFor is in progress will interrupt the current movement.

  • Because spinFor is target-based (uses a rotation or time parameter), functions such as isDone and isSpinning work with spinFor.

Examples
// Spin 1 turn fast, then 1 turn slow
Motor1.spinFor(forward, 1, turns, true);
Motor1.spinFor(reverse, 1, turns, 20, velocityUnits::pct, true);

spinToPosition#

spinToPosition spins a motor or motor group to a specific position.

A motor or motor group’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. At the beginning of a project, the motor or motor group position is set to 0 degrees. The motor or motor group position can also be set using the setPosition function.

位置值是绝对值。这意味着旋转方向取决于电机或电机组的当前位置。

例如,如果电机或电机组从 0 度开始旋转到 720 度,它将正转两圈。如果之后它旋转到 360 度,它将反转一圈,因为 360 小于 720。

Available Functions

1 以函数调用中提供的速度旋转到特定位置。

bool spinToPosition(
 double        rotation,
 rotationUnits units,
 double        velocity,
 velocityUnits units_v,
 bool          waitForCompletion = true );

2 使用 当前配置的电机速度 旋转到特定位置。

bool spinToPosition(
 double        rotation,
 rotationUnits units,
 bool          waitForCompletion = true );

Parameters

范围

类型

描述

rotation

double

电机或电机组将旋转到的位置值。

units

rotationUnits

The rotation unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units_v

velocityUnits

The unit used to represent velocity:

  • pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

waitForCompletion

bool

  • true (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • false — Makes the next line of code run right away.

Return Values

返回一个布尔值,表示电机或电机组是否已开始请求的基于目标的运动。

  • true — The motor or motor group begins the requested target-based movement.
  • false — The call fails or waitForCompletion is set to false.
Notes
  • Executing another motor movement function (such as spin or spinFor) while spinToPosition is in progress will interrupt the current movement.

  • Because spinToPosition is target-based (uses a rotation parameter), functions such as isDone and isSpinning work with spinToPosition.

Examples
// Spin forward, then go to 90°
Motor1.spin(forward);
wait(1, seconds);
Motor1.spinToPosition(90, degrees);

stop#

stop stops a motor or motor group from spinning.

Available Functions

1 使用当前配置的制动模式 停止电机或电机组。

void stop();

2 使用函数调用中提供的制动模式停止电机或电机组。

void stop(
  brakeType mode );

Parameters

范围

类型

描述

mode

brakeType

Optional. How the motor or motor group will stop:

  • coast — Slows to a stop.
  • brake — Stops immediately.
  • hold — Stops immediately and holds the motor or motor group position.

Return Values

此函数不返回值。

Notes
  • Calling stop immediately stops any current motor or motor group movement.

  • 如果没有指定制动模式,则电机或电机组使用当前配置的制动模式

  • stop interrupts any active target-based movement (such as spinFor or spinToPosition).

Examples
// Spin and coast to a stop
Motor1.setVelocity(100, percent);
Motor1.spin(forward);
wait(1, seconds);
Motor1.stop(coast);

修改器#

setVelocity#

setVelocity tells a motor or motor group how fast to spin. A higher percentage makes the motor or motor group spin faster and a lower percentage makes the motor or motor group spin slower.

每个项目开始时,每个电机或电机组默认以 50% 的速度旋转。

**注意:**更高的速度会使电机或电机组旋转得更快,但精度可能会降低。更低的速度会使电机或电机组旋转得更慢,但精度可能会更高。

Available Functions
void setVelocity(
    double        velocity,
    velocityUnits units );

Parameters

范围

类型

描述

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units

velocityUnits

The unit used to represent velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

Return Values

此函数不返回值。

Notes
  • Any subsequent motor movement function (such as spin, spinFor, or spinToPosition) that does not explicitly specify a velocity will use this value.

Examples
// Try default, then slow, then fast
Motor1.spinFor(forward, 180, degrees);
wait(1, seconds);
Motor1.setVelocity(20, percent);
Motor1.spinFor(reverse, 180, degrees);
wait(1, seconds);
Motor1.setVelocity(100, percent);
Motor1.spinFor(forward, 180, degrees);

setMaxTorque#

扭矩表示电机或电机组在旋转时能够产生的推力或拉力的大小。

setMaxTorque sets the most torque a motor or motor group is allowed to use.

较高的百分比可以让电机或电机组施加更大的推力,例如在举起重物时。较低的百分比则会限制电机或电机组的推力。这有助于在电机或电机组卡住或达到其运动极限时保护机器人。

每个项目开始时,每个电机或电机组的扭矩默认设置为 50%。

Available Functions

1 将最大扭矩设置为电机或电机组额定扭矩的百分比。

void setMaxTorque(
 double       value,
 percentUnits units );

2 使用物理扭矩单位设置最大扭矩。

void setMaxTorque(
 double      value,
 torqueUnits units );

3 通过限制电机电流来设定最大扭矩。

void setMaxTorque(
 double       value,
 currentUnits units );

Parameters

范围

类型

描述

value

double

电机或电机组可使用的最大扭矩。

units

percentUnits

Specifies torque as a percentage: percent / pct — percent

units

torqueUnits

Specifies torque in physical units such as:

  • Nm — Newton-meters
  • InLb — inch-pounds

units

currentUnits

Specifies torque by limiting motor current:

  • amp

Return Values

此函数不返回值。

Notes
  • When using currentUnits, torque is limited by restricting how much electrical current the motor or motor group can use.

setPosition#

A motor or motor group’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. setPosition changes the motor or motor group’s current position to a new value.

例如,如果电机或电机组旋转了 180 度,将其位置设置为 0 度会将该位置从 180 度重置为 0 度。然后,电机或电机组可以根据该新值旋转到相应位置。

Available Functions
void setPosition(
    double        value,
    rotationUnits units );

Parameters

范围

类型

描述

value

double

要为电机或电机组设置的位置值。

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

此函数不返回值。

Notes
  • After calling setPosition, subsequent calls to spinToPosition will use the updated position as the reference.

setStopping#

setStopping sets how a motor or motor group will stop moving: by braking, coasting, or holding.

Available Functions
void setStopping(
  brakeType mode );

Parameters

范围

类型

描述

mode

brakeType

How the motor or motor group will stop:

  • brake — Stops immediately.
  • coast — Slows to a stop.
  • hold — Stops immediately and holds the motor or motor group position.

Return Values

此函数不返回值。

Notes
  • Any subsequent call to stop without a specified brake mode will use this value.

setTimeout#

setTimeout sets how much time a motor or motor group will try to finish a movement. If the motor or motor group cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the motor or motor group from getting stuck on a movement.

Available Functions
void setTimeout(
    int32_t   time,
    timeUnits units );

Parameters

范围

类型

描述

time

int32_t

电机或电机组尝试完成一次动作的时间。该值必须为正整数。

units

timeUnits

The unit of time:

  • msec — milliseconds
  • seconds / sec — seconds

返回值

此函数不返回值。

Notes
  • 电机或电机组超时用于防止未到达目标位置的运动停止堆栈中其他命令的执行。

  • 如果电机或电机组在超时时间到期前未到达目标位置,它将停止尝试并继续执行下一行代码。

  • The timeout applies to functions that have a target value such as spinFor and spinToPosition.

Examples
// Stop a long move after 1 second
Motor1.setTimeout(1, seconds);
Motor1.spinFor(forward, 2, turns);
Motor1.spinToPosition(0, degrees);

吸气剂#

isDone#

isDone returns whether the motor or motor group is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.

  • true — The motor or motor group is finished moving.

  • false — The motor or motor group is still moving.

This function works together with the following Motion functions that have the waitForCompletion parameter: spinFor and spinToPosition.

Available Functions
bool isDone();

Parameters

此函数不接受任何参数。

Return Values

返回电机或电机组是否停止运动,以布尔值表示。

  • true — The motor or motor group is finished moving.
  • false — The motor or motor group is still moving.
Notes
  • isDone works together with the following Motion functions that have the waitForCompletion parameter: spinFor and spinToPosition.

Examples
// Spin forward until the motor is done spinning
Motor1.spinFor(forward, 200, degrees, false);
while (true) {
  if (Motor1.isDone()) {
    Drivetrain.stop();
  } else {
    Drivetrain.drive(forward);
  }
}

isSpinning#

isSpinning returns whether the motor or motor group is spinning, as a Boolean value. This can be used to control the timing of other behaviors based on the motor or motor group’s movement.

  • true — The motor or motor group is spinning.

  • false — The motor or motor group is not spinning.

This function works together with Motion movement functions such as spin, spinFor, and spinToPosition.

Available Functions
bool isSpinning();

Parameters

此函数不接受任何参数。

Return Values

返回电机或电机组是否正在旋转,以布尔值表示。

  • true — The motor or motor group is spinning.
  • false — The motor or motor group is not spinning.
Notes Examples
// Spin forward until the motor is done spinning
Motor1.spinFor(forward, 200, degrees, false);
while (true) {
  if (Motor1.isSpinning()) {
    Drivetrain.drive(forward);
  } else {
    Drivetrain.stop();
  }
}

position#

A motor or motor group’s position is how far it has spun, measured in degrees or turns. One turn is equal to 360 degrees. position returns the motor or motor group’s current position.

项目开始时,电机或电机组的位置设置为 0 度。如果电机或电机组正转一圈,则位置为 360 度或 1 圈。如果电机或电机组反向旋转,则位置为负值。

Available Functions
double position(
  rotationUnits units );

Parameters

范围

类型

描述

units

rotationUnits

The unit to return the motor or motor group position in:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the motor or motor group’s current position in the specified units.

Notes
  • Calling setPosition changes the reference point for this value.

  • 返回值反映的是当前编码器读数,并不表示电机或电机组是否正在运行。

  • When called on a motor_group, this function returns the position of the first motor in the group.

Examples
// Spin, then show the final position
Motor1.spin(forward);
wait(1, seconds);
Motor1.stop();
Brain.Screen.print("Pos: %f", Motor1.position(degrees));

velocity#

velocity returns how fast the motor or motor group is spinning.

正值表示电机或电机组正转,负值表示电机或电机组反转。

Available Functions
double velocity(
    velocityUnits units );

Parameters

范围

类型

描述

units

velocityUnits

The unit used to represent velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

Return Values

Returns a double representing how fast the motor or motor group is spinning in the specified units.

条笔记

  • When called on a motor_group, this function returns the velocity of the first motor in the group.

current#

current returns how much electrical current the motor or motor group is using. Current is the amount of electricity flowing through the motor or motor group. When returned in amps, current is reported from 0.0 to 1.2 A.

电流值越高,表示电机或电机组消耗的电流越大。这种情况可能发生在电机或电机组提升重物、推动物体或试图移动卡住的物体时。

这可以用来检查电机或电机组在运动过程中是否运转吃力。如果电流持续过高,电机可能会发热或功率利用率降低。

Available Functions

1 返回电机或电机组的电流(以安培为单位)。

double current(
  currentUnits units = amp );

2 返回电机或电机组的电流占最大额定电流的百分比。

double current(
  percentUnits units );

Parameters

范围

类型

描述

units

currentUnits

The unit used to represent current:amp (default) — amperes

units

percentUnits

Represents the current as a percentage of the motor’s maximum rated current:percent / pct — percent

Return Values

Returns a double representing how much electrical current the motor or motor group is drawing in the specified units.

条笔记

  • When called on a motor_group, this function returns the total electrical current for all motors in the group.

power#

power returns how much power the motor or motor group is using in watts. Power shows how quickly the motor or motor group is using energy.

功率值越高,意味着电机或电机组的能耗速度越快。这种情况可能发生在电机或电机组提升重物、推动物体或试图在卡住时移动时。

这可以用来比较运动情况,或者检查电机或电机组是否运转吃力。如果功率持续偏高,电机可能会发热或能量利用效率降低。

Available Functions
double power(
  powerUnits units = watt );

参数

范围

类型

描述

units

powerUnits

The unit used to represent the motor power:

  • watt (default) — watts

返回值

Returns a double representing how much power the motor or motor group is using in watts.

条笔记

  • When called on a motor_group, this function returns the electrical power of the first motor in the group.

torque#

扭矩表示电机或电机组在旋转时扭转、推动或拉动的力度。

torque returns how much torque the motor or motor group is using.

扭矩值越高,意味着电机或电机组的推拉力越大。这种情况可能发生在电机或电机组提升重物、推动物体或试图移动卡住的物体时。

这可以用来检查运动系统或运动系统是否出现困难,或者比较不同动作需要多少推力。

To set the torque of a motor or motor group, use setMaxTorque.

Available Functions
double torque(
  torqueUnits units = Nm );

参数

范围

类型

描述

units

torqueUnits

The unit used to represent the motor torque:

  • Nm (default) — Newton-meters
  • InLb — inch-pounds

返回值

Returns a double representing how much torque the motor or motor group is using in the specified units.

条笔记

  • When called on a motor_group, this function returns the mechanical output torque of the first motor in the group.

efficiency#

efficiency returns how efficiently the motor or motor group is using power, as a percentage from 0% to 100%.

效率值表示电机或电机组的功率有多少用于运动。效率值越高,意味着电机或电机组用于运动的功率越多。当电机或电机组高负荷运转但运动量很小时,例如被卡住或抵住障碍物时,效率值就会降低。

这可以用来比较运动情况,或者检查电机或电机组是否浪费电力而不是将其用于运动。

Available Functions
double efficiency(
  percentUnits units = percent );

参数

范围

类型

描述

units

percentUnits

The unit used to represent motor efficiency:

  • percent / percentUnits::pct (default) — percent

返回值

Returns a double representing how efficiently the motor or motor group is using power as a percentage.

条笔记

  • When called on a motor_group, this function returns the efficiency of the first motor in the group.

temperature#

temperature returns the temperature of the motor or motor group.

Motor temperature shows how warm the motor or motor group is. A higher temperature means the motor or motor group is getting warmer while it works. The motor should stay below 55°C to keep working at full performance.

If the motor or motor group gets too hot, it will lower its maximum current to protect itself. At 70°C, a motor will stop running until it cools down.

这可以用来检查电机或电机组在重复运动、长时间运行或推动物体时是否过热。

Available Functions

1 返回电机或电机组温度占最大工作温度的百分比。

double temperature(
  percentUnits units = percent );

2 以物理温度单位返回电机或电机组温度。

double temperature(
  temperatureUnits units );

参数

范围

类型

描述

units

percentUnits

The unit used to represent motor or motor group temperature as a percentage:

  • percent / percentUnits::pct (default) — percent

units

temperatureUnits

The unit used to represent motor or motor group temperature in degrees:

  • celsius — degrees Celsius
  • fahrenheit — degrees Fahrenheit

返回值

Returns a double representing the temperature of the motor or motor group in the specified units.

条笔记

  • The operating temperature range for the motor is approximately 20°C (68°F) to 70°C (158°F).

  • When called on a motor_group, this function returns the temperature of the first motor in the group.

voltage#

voltage returns the electrical voltage supplied to the motor or motor group.

Available Functions
double voltage(
  voltageUnits units = volt );

参数

范围

类型

描述

units

voltageUnits

The unit to represent the voltage:

  • volt (default)
  • voltageUnits::mV — millivolts

返回值

Returns a double representing the electrical voltage supplied to the motor or motor group in the specified units.

条笔记

  • When called on a motor_group, this function returns the electrical voltage of the first motor in the group.

direction#

direction returns the direction that the motor or motor group is spinning.

Available Functions
directionType direction();

参数

此函数不接受任何参数。

返回值

Returns a directionType indicating the motor’s or motor group’s current direction:

  • forward — The motor or motor group is spinning forward.
  • reverse — The motor or motor group is spinning in reverse.

installed#

installed returns whether the motor or motor group is connected to the IQ (2nd gen) Brain.

Available Functions
bool installed();

参数

此函数不接受任何参数。

返回值

Returns a bool indicating whether the motor or motor group is connected.

  • true — The motor or motor group is connected.
  • false — The motor or motor group is not connected.

count#

count returns the number of motors in a motor group.

Available Functions
int32_t count();

参数

此函数不接受任何参数。

返回值

Returns an int32_t representing the number of motors in the motor group.