电机组#

初始化 motor_group 类#

使用以下构造函数创建 IQ(第 1 代)motor_group 对象:

The motor_group constructor creates a motor_group object.

您可以创建具有任意数量电机的 motor_group。

// Create 2 Motors, Motor1 and Motor2 in
// Ports 1 and 2 respectively. 
motor Motor1 = motor(PORT1);
motor Motor1 = motor(PORT2);
// Using the two previously created Motors, create a
// motor_group named MotorGroup1.
motor_group MotorGroup1 = motor_group(Motor1, Motor2);

This MotorGroup1 object will be used in all subsequent examples throughout this API documentation when referring to MotorGroup class methods.

类方法#

spin()#

这是一个非等待功能,允许下一个方法无延迟运行。

该方法通过以下方式调用:

The spin(dir) method is used to spin the Motors in the specified direction forever at the default velocity set by the setVelocity() method, until a spin or stop method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

**返回:**无。

// Spin MotorGroup1 forward.
MotorGroup1.spin(forward);

The spin(dir, velocity, units) method is used to spin the Motors in the specified direction forever at a specified velocity, until a spin or stop method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

速度

电机旋转的速度。

单位

A valid velocityUnit or percent.

**返回:**无。

// Spin MotorGroup1 forward at 100 rpm.
MotorGroup1.spin(forward, 100, rpm);

The spin(dir, voltage, units) method is used to spin the Motors in the specified direction forever at a specified voltage until a spin or stop method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

电压

电机旋转的电压。

单位

有效的 voltUnit

**返回:**无。

// Spin MotorGroup1 forward at 100 volts.
MotorGroup1.spin(forward, 100, volt);

spinToPosition()#

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

该方法通过以下方式调用:

The spinToPosition(rotation, units, waitForCompletion) method is used to spin the Motors to an absolute rotation in the specified units.

参数

描述

旋转

电机旋转的位置。

单位

有效的 rotationUnit

等待完成

Determines whether the method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 to the absolute position 1080 degrees.
MotorGroup1.spinToPosition(1080, degrees);

The spinToPosition(rotation, units, velocity, units_v, waitForCompletion) method is used to spin the Motors to an absolute rotation in the specified units.

参数

描述

旋转

电机旋转的位置。

单位

有效的 rotationUnit

速度

电机旋转的速度。

单位

有效的 velocityUnit

等待完成

Determines whether the method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 to the absolute position 1080 degrees 
// at 100 percent velocity.
MotorGroup1.spinToPosition(1080, degrees, 100,::pct);

spinFor()#

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

该方法通过以下方式调用:

The spinFor(time, units) method is used to spin the Motors for a specified duration.

参数

描述

时间

电机旋转的时间。

单位

有效的 timeUnit

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 for 10 seconds
MotorGroup1.spinFor(10, seconds);

The spinFor(dir, time, units) method is used to spin the Motors for a specified duration in a specified direction.

参数

描述

目录

有效的 directionType

时间

电机旋转的时间。

单位

有效的 timeUnit

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 forward for 10 seconds
MotorGroup1.spinFor(forward, 10, seconds);

The spinFor(time, units, velocity, units_v) method is used to spin the Motors for a specified duration at a specified velocity.

参数

描述

时间

电机旋转的时间。

单位

有效的 timeUnit

速度

电机旋转的速度。

单位

有效的 velocityUnit

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 for 10 seconds at 100 rpm.
MotorGroup1.spinFor(10, seconds, 100, rpm);

The spinFor(dir, time, units, velocity, units_v) method is used to spin the Motors for a specified duration at a specified velocity in a specified direction.

参数

描述

目录

有效的 directionType

时间

电机旋转的时间。

单位

有效的 timeUnit

速度

电机旋转的速度。

单位

有效的 velocityUnit

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 forward for 10 seconds at 100 rpm.
MotorGroup1.spinFor(forward, 10, seconds, 100, rpm);

The spinFor(rotation, units, waitForCompletion) method is used to spin the Motors for a specific rotation. The rotation is relative to the current rotation of the Motor.

参数

描述

旋转

电机旋转的旋转值。

单位

有效的 rotationUnit

等待完成

Determines whether the method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 for 1000 degrees.
MotorGroup1.spinFor(1000, degrees);

The spinFor(dir, rotation, units, waitForCompletion) method is used to spin the Motors for a specific rotation in a specific direction. The rotation is relative to the current rotation of the Motor.

参数

描述

目录

有效的 directionType

旋转

电机旋转的旋转值。

单位

有效的 rotationUnit

等待完成

Determines whether the method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 forward for 1000 degrees.
MotorGroup1.spinFor(forward, 1000, degrees);

The spinFor(rotation, units, velocity, units_v, waitForCompletion) method is used to spin the Motors for a specific rotation. The rotation is relative to the current rotation of the Motor.

参数

描述

旋转

电机旋转的旋转值。

单位

有效的 rotationUnit

速度

电机旋转的速度。

单位

有效的 velocityUnit

等待完成

Determines whether the method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 for 1000 degrees at 25 rpm.
MotorGroup1.spinFor(1000, degrees, 25, rpm);

The spinFor(dir, rotation, units, velocity, units_v, waitForCompletion) method is used to spin the Motors 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 method will block subsequent methods (wait=true) or allow immediate execution (wait=false). If unspecified, the default for the wait parameter is wait=true.

**返回:**一个布尔值,表示电机何时达到目标旋转。

// Spin MotorGroup1 forard for 1000 degrees at 25 rpm.
MotorGroup1.spinFor(forward, 1000, degrees, 25, rpm);

stop()#

这是一种非等待方法,允许下一个方法无延迟运行。

该方法通过以下方式调用:

The stop() method is used to stop the Motors, setting them to 0 velocity and configuring the current stopping mode. The default Brake Type is coast, unless previously changed using the setStopping() method.

**返回:**无。

// Spin MotorGroup1 for 2.5 seconds.
MotorGroup1.spin(forward);

wait(2.5 seconds);

// Stop MotorGroup1.
MotorGroup1.stop();

The stop(mode) method is used to stop the Motors using a specific Brake Type.

参数

描述

模式

有效的 brakeType

**返回:**无。

// Spin MotorGroup1 for 2.5 seconds.
MotorGroup1.spin(forward);

wait(2.5 seconds);

// Stop MotorGroup1 using the hold Brake Type.
MotorGroup1.stop(hold);

count()#

The count() method returns the number of Motors in a Motor Group.

**返回:**电机组中电机的数量。

setVelocity()#

The setVelocity(velocity, units) method is used to set the default velocity for the Motors. This velocity setting will be used for subsequent calls to any motion functions if a specific velocity is not provided.

参数

描述

速度

为电机设置的新速度。

单位

A valid velocityUnit or percent.

**返回:**无。

setStopping()#

The setStopping(mode) method is used to set the stopping mode for the Motors. This will be the stopping mode used when the stop() method is called without specifying a brakeType.

参数

描述

模式

有效的 brakeType

**返回:**无。

resetPosition()#

The resetPosition() method resets the value of all Motor encoders to 0.

**返回:**无。

setPosition()#

The setPosition(value, units) method is used to set the value of all Motor encoders to a specified value. The position that is returned by the position() method will be updated to this new value.

参数

描述

价值

为所有电机编码器设置的新值。

单位

有效的 rotationUnit

**返回:**无。

setTimeout()#

The setTimeout(value, units) method is used to set the timeout for Motor Group methods. If a Motor does not reach its’ methoded position prior to the completion of the timeout, the Motors will stop.

参数

描述

价值

为电机设置的新超时。

单位

有效的 timeUnit

**返回:**无。

isSpinning()#

The isSpinning() method returns if any Motor is currently rotating to a specific target.

Returns: true if any Motor is on and is rotating to a target. false if all Motors are done rotating to a target.

isDone()#

The isDone() method returns if all Motors are done rotating to a specific target.

Returns: true if all Motors are done rotating to a target. false if any Motor is on and rotating to a target.

setMaxTorque()#

该方法通过以下方式调用:

The setMaxTorque(value, units) method is used to set the maximum torque for the Motors in torqueUnits.

参数

描述

价值

电机的新最大扭矩。

单位

有效的 torqueUnit

**返回:**无。

// Set maximum torque to 2 Newton Meters.
MotorGroup1.set_max_torque(2, Nm);

The setMaxTorque(value, units) method is used to set the maximum torque for the Motors in currentUnits.

参数

描述

价值

电机的新最大扭矩。

单位

The only valid unit is amp.

**返回:**无。

// Set maximum torque to ,05 amps.
MotorGroup1.set_max_torque(.05, amp);

The setMaxTorque(value, units) method is used to set the maximum torque for a Motor as a percentage.

参数

描述

价值

电机的新最大扭矩。

单位

The only valid unit is percent.

**返回:**无。

// Set maximum torque to 75 percent.
MotorGroup1.set_max_torque(75, percent);

direction()#

The direction() method returns the current direction the first Motor in the Group is spinning in as a directionType.

返回: directionType 值,表示组中第一个电机当前旋转的方向。

position()#

The position(units) method returns the current rotation of the first Motor in the Group.

参数

描述

单位

有效的 rotationUnit

返回: 一个双精度值,表示组中第一个电机以指定单位的当前旋转速度。

velocity()#

The velocity(units) method returns the current velocity of the first Motor in the Group.

参数

描述

单位

A valid velocityUnit or percent.

**返回:**以指定单位表示组中第一个电机的当前速度的双精度值。

current()#

The current(units) method returns the current being used by the first Motor in the Group.

参数

描述

单位

The only valid units for current are amp or percent.

**返回:**一个双精度数,表示组中第一个电机以指定单位所消耗的电流。

voltage()#

The voltage(units) command returns the voltage being used by the first Motor in the Group.

参数

描述

单位

The only valid unit for voltage is volt.

**返回:**表示组中第一个电机电压的双精度值。

power()#

The power(units) method returns the power being consumed by the first Motor in the Group.

参数

描述

单位

The only valid unit for power is watt.

**返回:**以指定单位表示组中第一个电机的当前功率的双精度值。

torque()#

The torque(units) method returns the torque of the first Motor in the Group.

参数

描述

单位

有效的 torqueUnit

**返回:**组中第一个电机的指定单位的扭矩。

efficiency()#

The efficiency(units) method returns the efficiency of the first Motor in the Group.

参数

描述

单位

The only valid unit for efficiency is percent.

**返回:**组中第一个电机的效率百分比。

temperature()#

The temperature(units) command returns the temperature of the first Motor in the Group.

参数

描述

单位

A valid temperatureUnit or percent.

**返回:**组中第一个电机的温度。