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();

参数#

范围

类型

描述

port

triport::port&

Victor 883 电机连接的 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 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 Functions

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

void spin(
 directionType dir );

2 — 使电机以指定速度旋转。

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

Parameters

范围

类型

描述

dir

directionType

电机旋转方向: forward 或 reverse。

velocity

double

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

units

velocityUnits

速度单位:

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

Return Values

此函数不返回值。

Notes
  • 电机将继续旋转,直到调用 stop 或执行另一个运动函数。

Examples
// 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 Functions
void stop();

Parameters

此函数不接受任何参数。

Return Values

此函数不返回值。

Notes
  • 调用 stop 会立即停止任何当前的电机运动。

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

setVelocity#

控制电机转速。百分比越高,电机转速越快;百分比越低,电机转速越慢。

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

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

Parameters

范围

类型

描述

velocity

double

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

units

percentUnits

速度单位:percent / pct%

Return Values

此函数不返回值。

Notes
  • 任何后续的 Victor 883 电机运动函数(例如 spin)如果未明确指定速度,则将使用此值。

Examples
// Set velocity to 50%, then spin
victor.setVelocity(50, percent);
victor.spin(forward);

setReversed#

设置电机是否反转。

Available Functions
void setReversed( bool value );

Parameters

范围

类型

描述

value

bool

Whether the motor’s direction is reversed:

  • true — Reverses the motor’s direction.
  • false — Returns the motor’s direction to its default.

Return Values

此函数不返回值。

Notes Examples
// Reverse the motor direction
victor.setReversed(true);
victor.spin(forward); // Will actually spin in reverse