– title: Motor 393 (Motor Controller 29) | VEX EXP - C++ API description: Reference documentation for the motor29 class in VEX EXP C++. Includes constructors, functions, parameters, notes, and usage examples.#

电机 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 EXP Brain to operate a VEX Motor 393.

The VEX Motor Controller 29.

类构造函数#

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

成员功能#

The motor29 class includes the following member functions:

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

  • 停止 — 停止电机。

  • setVelocity — Tells the Motor 393 how fast to spin.

  • 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#

Spins the Motor 393 in the specified direction forever.

可用功能

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

void spin(
 directionType dir );

2 以指定速度旋转。

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

参数

范围

类型

描述

dir

directionType

The direction in which the motor spins: forward or reverse.

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units

velocityUnits

The velocity unit:

  • 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#

Tells a Motor 393 how fast to spin. A higher percentage makes the Motor 393 spin faster and a lower percentage makes the Motor 393 spin slower.

Every project begins with each Motor 393 spinning at 50% velocity by default.

可用功能

void setVelocity(
    double velocity,
    percentUnits units );

参数

范围

类型

描述

velocity

double

The velocity to spin with from 0% to 100% when using percent.

units

percentUnits

The velocity unit:percent / pct — percent

返回值

此函数不返回值。

setReversed#

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

可用功能

void setReversed(
    bool value );

参数

范围

类型

描述

value

bool

Whether the Motor 393’s direction is reversed:

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

返回值

此函数不返回值。

条笔记

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