Victor 883 发动机#
介绍#
motor_victor 类用于控制连接到三线端口的 Victor 883 电机控制器。Victor 883 电机控制器从 V5 主控模块发送 PWM 信号,以控制无法直接连接到智能端口的兼容 VEXpro 或 VEX EDR 直流电机。
Victor 883 电机控制器无法在 VEXcode 中进行配置,必须手动在代码中构建才能使用。
类构造函数#
1 — 为连接到指定 3 线端口的 Victor 883 电机控制器创建一个
motor_victor对象。motor_victor( triport::port& port );
2 — 在指定的 3 线端口上创建一个
motor_victor对象,并可选择反转其方向。motor_victor( triport::port& port, bool reverse );
类析构函数#
销毁 motor_victor 对象并释放相关资源。
~motor_victor();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
Victor 883 电机连接的 3 线端口,写成 |
|
|
Sets whether the motor’s spin direction is reversed:
|
例子#
// Create the motor_victor instance on 3-Wire Port A
motor_victor victor = motor_victor(Brain.ThreeWirePort.A);
// Create the motor_victor instance with reversed direction
motor_victor victor2 = motor_victor(Brain.ThreeWirePort.B, true);
成员功能#
motor_victor motor_victor 函数:
spin— 使电机沿指定方向旋转。stop— 停止电机。setVelocity— 告诉电机旋转的速度。setReversed— 设置电机方向是否反转。
在调用 motor_victor 函数之前,必须先创建 motor_victor 实例,如下所示:
/* This constructor is required to use a
Victor 883 Motor. Replace the values
as needed. */
// Create the motor_victor instance on 3-Wire Port A
motor_victor victor = motor_victor(Brain.ThreeWirePort.A);
spin#
使电机沿指定方向无限旋转。
Available Functions1 — 使用当前配置的电机速度旋转电机。
void spin( directionType dir );
Parameters2 — 使电机以指定速度旋转。
void spin( directionType dir, double velocity, velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
电机旋转方向: |
|
|
当使用 |
|
|
速度单位:
|
此函数不返回值。
Notes电机将继续旋转,直到调用
stop或执行另一个运动函数。
// Spin forward, then stop
victor.spin(forward);
wait(1, seconds);
victor.stop();
// Spin forward at 100 rpm
victor.spin(forward, 100, rpm);
wait(1, seconds);
victor.stop();
stop#
停止电机旋转。
Available Functionsvoid stop();
此函数不接受任何参数。
Return Values此函数不返回值。
Notes调用
stop会立即停止任何当前的电机运动。
// Spin and then stop
victor.spin(forward);
wait(1, seconds);
victor.stop();
setVelocity#
控制电机转速。百分比越高,电机转速越快;百分比越低,电机转速越慢。
每个项目开始时,每个连接的电机默认以 50% 的速度旋转。
Available Functionsvoid setVelocity(
double velocity,
percentUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
当使用 |
|
|
速度单位: |
此函数不返回值。
Notes任何后续的 Victor 883 电机运动函数(例如
spin)如果未明确指定速度,则将使用此值。
// Set velocity to 50%, then spin
victor.setVelocity(50, percent);
victor.spin(forward);
setReversed#
设置电机是否反转。
Available Functionsvoid setReversed( bool value );
范围 |
类型 |
描述 |
|---|---|---|
|
|
Whether the motor’s direction is reversed:
|
此函数不返回值。
Notes这与在构造函数中更改
reverse参数相同。
// Reverse the motor direction
victor.setReversed(true);
victor.spin(forward); // Will actually spin in reverse