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

介绍#

The motor29 class is used to control a Motor Controller 29 connected to a 3-Wire Port. The Motor Controller 29 sends a PWM signal from the V5 Brain to operate a VEX Motor 393.

类构造函数#

1 Creates a motor29 object on the specified 3-Wire Port.

motor29(
    triport::port &port );

2 Creates a motor29 object on the specified 3-Wire Port and changes the positive turning direction.

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

类析构函数#

Destroys the motor29 object and releases associated resources.

~motor29();

参数#

范围

类型

描述

port

triport::port&

The 3-Wire Port that the Motor Controller 29 is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

reverse

bool

Sets the positive direction of motor rotation:

  • false (default) — Clockwise rotation is treated as forward (positive direction).
  • true — Counterclockwise rotation is treated as forward (positive direction).

例子#

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

成员功能#

The motor29 class includes the following member functions:

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

  • 停止 — 停止电机。

  • setVelocity — 设置后续运动命令使用的默认电机速度。

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

Before calling any motor29 member functions, an instance must be created, as shown below:

/* 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

The direction in which the motor spins:

  • forward
  • reverse

velocity

double

施加于电机的速度值。

units

velocityUnits

The unit used to represent velocity:

  • percent / pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

返回值

此函数不返回值。

条笔记

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

  • The Motor 393 will continue spinning until stop is called or another spin is used.

stop#

停止电机运转。

可用功能

void stop();

参数

此函数不接受任何参数。

返回值

此函数不返回值。

setVelocity#

Sets the default velocity for a Motor 393. This velocity setting will be used for subsequent calls to spin if a specific velocity is not provided.

可用功能

void setVelocity(
    double velocity,
    percentUnits units );

参数

范围

类型

描述

velocity

double

施加于电机 393 的速度值。

units

percentUnits

The unit used to represent velocity:

  • percent / pct — percent

返回值

此函数不返回值。

setReversed#

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

可用功能

void setReversed(
    bool value );

参数

范围

类型

描述

value

bool

Sets the motor’s direction behavior:

  • true — The Motor 393’s positive direction is reversed.
  • false — The Motor 393’s positive direction remains normal.

返回值

此函数不返回值。

条笔记

  • Calling setReversed is the same as changing the reverse parameter in the constructor.