电机 393(电机控制器 29)#

介绍#

motor29 类用于控制连接到 3 线端口 的电机控制器 29。电机控制器 29 发送来自 V5 主控器的 PWM 信号来驱动 VEX 电机 393。

VEX电机控制器29.

类构造函数#

1 — 在指定的 3 线端口上创建一个 motor29 对象。

motor29(
    triport::port &port );

2 — 在指定的 3 线端口上创建一个 motor29 对象,并改变正向旋转方向。

motor29(
    triport::port &port,
    bool           reverse );

类析构函数#

销毁 motor29 对象并释放相关资源。

~motor29();

参数#

范围

类型

描述

port

triport::port&

电机控制器 29 连接的 3 线端口,写成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

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.

例子#

// Create a Motor Controller 29 instance in 3-Wire Port A
motor29 Motor393_A = motor29(
    Brain.ThreeWirePort.A );

成员功能#

motor29 类包含以下成员函数:

  • 旋转 — 使电机沿指定方向旋转。

  • 停止 — 停止电机。

  • setVelocity — 告诉电机 393 旋转的速度。

  • setReversed — 设置电机的旋转方向是否反转。

在调用 motor29 成员函数之前,必须先创建一个实例,如下所示:

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

// Create a Motor Controller 29 instance in 3-Wire Port A
motor29 Motor393_A = motor29(
    Brain.ThreeWirePort.A );

spin#

使电机 393 沿指定方向无限旋转。

可用功能

1 — 使用 当前配置的速度 旋转。

void spin(
 directionType dir );

2 — 以指定速度旋转。

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

参数

范围

类型

描述

dir

directionType

电机旋转方向: forward 或 reverse。

velocity

double

当使用 percent时,旋转速度从 0% 到 100% 变化。

units

velocityUnits

速度单位:

  • percent 百分比 pct 百分比
  • rpm — 每分钟转数
  • dps — 每秒度数

返回值

此函数不返回值。

条笔记

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

  • 电机 393 将继续旋转,直到调用 stop 或使用另一个 spin。

stop#

停止电机运转。

可用功能

void stop();

参数

此函数不接受任何参数。

返回值

此函数不返回值。

setVelocity#

告诉电机 393 旋转的速度。百分比越高,电机 393 旋转得越快;百分比越低,电机 393 旋转得越慢。

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

可用功能

void setVelocity(
    double velocity,
    percentUnits units );

参数

范围

类型

描述

velocity

double

当使用 percent时,旋转速度从 0% 到 100% 变化。

units

percentUnits

速度单位:percent / pct%

返回值

此函数不返回值。

setReversed#

设置是否反转电机的旋转方向。

可用功能

void setReversed(
    bool value );

参数

范围

类型

描述

value

bool

电机 393 的旋转方向是否反转:

  • true — 反转电机 393 的旋转方向。4
  • false — 将电机 393 的旋转方向恢复为默认值

返回值

此函数不返回值。

条笔记

  • 调用 setReversed 与更改 构造函数 中的 reverse 参数相同。