电机组#

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

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

初始化 motor_group 类#

使用以下构造函数创建 EXP 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. 
Motor1 = motor(PORT1);
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.

MotorGroup.spin()#

The MotorGroup.spin(direction, velocity, units) command is used to spin a motor group in the specified direction forever, until another motion command is used, or the project is stopped.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.spin(direction, velocity, units).

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

参数

描述

方向

有效的 directionType

速度

Optional. The velocity at which the motor group will spin. If unspecified, the default velocity set by the MotorGroup.setVelocity() command will be used.

单位

Optional. A valid velocityUnit. The default is rpm.

**返回:**无。

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

电机组.spinToPosition()#

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

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.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 degrees.

速度

Optional. The velocity at which the motor group will spin. If unspecified, the default velocity set by the MotorGroup.setVelocity() command will be used.

单位

Optional. A valid velocityUnit. 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 group to 180 degrees.
MotorGroup1.spinToPosition(180);

MotorGroup.spinFor()#

The MotorGroup.spinFor(direction, value, units, velocity, units_v, wait) command is used to spin the motor group for a specific duration, rotations, or until a specific encoder value is reached. The position is relative to the current position of the motor group.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.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 degrees.

速度

Optional. The velocity at which the motor group will spin. If unspecified, the default velocity set by the MotorGroup.setVelocity() command will be used.

单位

Optional. A valid velocityUnit. 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 180 degrees from the current position.
MotorGroup1.spinFor(forward, 180);

MotorGroup.停止()#

The MotorGroup.stop(mode) command is used to stop a motor group, setting them to 0 velocity and configuring the current stopping mode.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.stop(mode).

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

参数

描述

模式

A valid brakeType. The default is coast, unless previously changed using the MotorGroup.setStopping() command.

**返回:**无。

// Stop the motor group.
MotorGroup1.stop()

MotorGroup.count()#

The MotorGroup.count() command returns the number of motors in the group.

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

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

电机组.setVelocity()#

The MotorGroup.setVelocity(velocity, units) command is used to set the default velocity for a motor group. 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 MotorGroup with the desired motor group, for example: ArmMotorGroup.setVelocity(velocity, units).

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

参数

描述

速度

为电机组设置的新速度。

单位

Optional. A valid velocityUnit. The default is rpm, unless previously changed using the MotorGroup.setVelocity() command.

**返回:**无。

MotorGroup.setStopping()#

The MotorGroup.setStopping(mode) command is used to set the stopping mode for a motor group.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.setStopping(mode).

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

参数

描述

模式

A valid brakeType. The default is coast, unless previously changed using the MotorGroup.setStopping() command.

**返回:**无。

电机组.重置位置()#

The MotorGroup.resetPosition() command resets the motor group position to 0.

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

**返回:**无。

电机组.setPosition()#

The MotorGroup.setPosition(value, units) command is used to set the position of a motor group. The position that is returned by the MotorGroup.position() function will be updated to this new value.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.setPosition(value, units).

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

参数

描述

价值

为电机组设置的新位置。

单位

Optional. A valid rotationUnit. The default is degrees.

**返回:**无。

MotorGroup.setTimeout()#

The MotorGroup.setTimeout(value, units) command is used to set the timeout for a motor group.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.setTimeout(value, units).

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

参数

描述

价值

为电机组设置的新超时。

单位

Optional. A valid timeUnit. The default is msec.

**返回:**无。

MotorGroup.isSpinning()#

The MotorGroup.isSpinning() command returns if the motor group is currently spinning.

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

返回: 如果电机组当前正在旋转,则返回 True。否则,返回 False。

MotorGroup.isDone()#

The MotorGroup.isDone() command returns if the motor group has completed its movement.

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

返回: 如果电机组已完成运动,则返回 True。如果尚未完成运动,则返回 False。

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

The MotorGroup.setMaxTorque(value, units) command is used to set the maximum torque for a motor group. The torque can be set as torque, current, or a percent of maximum torque.

To use this command, replace MotorGroup with the desired motor group, for example: ArmMotorGroup.setMaxTorque(value, units).

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

参数

描述

价值

电机组的新最大扭矩。

单位

A valid torqueUnit, amp, or percent.

**返回:**无。

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

MotorGroup.方向()#

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

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

**返回:**电机组当前旋转的 directionType

MotorGroup.位置()#

The MotorGroup.position(units) command returns the current position of the motor group.

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

参数

描述

单位

Optional. A valid rotationUnit. The default is dergees.

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

MotorGroup.速度()#

The MotorGroup.velocity(units) command returns the current velocity of the motor group.

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

参数

描述

单位

Optional. A valid velocityUnit. The default is rpm.

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

MotorGroup.current()#

The MotorGroup.current(units) command returns the current being used by the motor group.

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

参数

描述

单位

Optional. The only valid unit for current is amp.

返回: 电机组以指定单位吸收的电流。

电机组.功率()#

The MotorGroup.power(units) command returns the power being consumed by the motor group.

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

参数

描述

单位

Optional. The only valid unit for power is watt.

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

电机组.扭矩()#

The MotorGroup.torque(units) command returns the torque being generated by the motor group.

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

参数

描述

单位

Optional. A valid torqueUnit. The default is Nm.

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

MotorGroup.效率()#

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

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

参数

描述

单位

Optional. The only valid unit for efficiency is percent.

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

电机组.温度()#

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

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

参数

描述

单位

Optional. A valid temperatureUnit. The default is celsius.

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