电机控制器 55#

介绍#

motor55 类用于控制连接到 V5 主控模块的 VEX 电机控制器 55。电机控制器 55 是一款传统的电机控制器,设计用于驱动两线直流电机。

VEX电机控制器55.

类构造函数#

1 — 在指定的智能端口上创建一个 motor55 对象。

motor55(
  int32_t index );

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

motor55(
  int32_t index,
  bool    reverse );

3 — 在指定的智能端口上创建一个 motor55 对象,设置最大驱动电压,并改变正转方向。

motor55(
  int32_t index,
  double  maxv,
  bool    reverse );

类析构函数#

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

~motor55();

参数#

范围

类型

描述

index

int32_t

电机控制器 55 连接的智能端口,记为 PORTx,其中 x 是端口号(例如, PORT1)。

reverse

bool

Determines whether the motor’s direction is reversed:

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

maxv

double

电机控制器 55 可以施加到电机的最大电压。

例子#

// Create the motor55 instance in Smart Port 1
motor55 Motor1 = motor55(PORT1);

成员功能#

motor55 类包含以下成员函数:

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

  • stop — 停止电机。

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

  • setStopping — 设置停止行为(滑行或制动)。

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

  • current — 返回电机的电流。

  • voltage — 返回电机的电压。

  • temperature — 返回电机温度。

  • getMotorType — 返回检测到的电机/控制器类型。

  • installed — 返回是否在指定的智能端口上检测到电机控制器 55。

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

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

// Create the motor55 instance in Smart Port 1
motor55 MC55_1 = motor55(PORT1);

spin#

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

可用功能

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

void spin(
  directionType dir );

2 — 在指定电压下旋转。

void spin(
  directionType dir,
  double        voltage,
  voltageUnits  units );

参数

范围

类型

描述

dir

directionType

电机旋转方向: forward 或 reverse。

voltage

double

施加到电机上的电压值。负值表示电机旋转方向与给定的 dir

units

voltageUnits

电压单位:

  • volt — 伏特
  • voltageUnits::mV — 毫伏特

返回值

此函数不返回值。

条笔记

  • 该函数不等待,调用后程序立即继续执行。

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

stop#

使用当前配置的制动模式 停止电机旋转。

可用功能

void stop();

参数

此函数不接受任何参数。

返回值

此函数不返回值。

条笔记

  • 使用 setStopping 设置的当前配置的停止模式停止电机。

setVelocity#

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

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

可用功能

void setVelocity(
    double       velocity,
    percentUnits units = percent );

参数

范围

类型

描述

velocity

double

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

units

percentUnits

The velocity unit:

  • percent / pct (default) — percent

返回值

此函数不返回值。

条笔记

  • 任何后续对 spin 的调用,如果没有指定电压,将使用此值。

setStopping#

设置电机停止时的行为方式。

可用功能

void setStopping(
    brakeType mode );

参数

范围

类型

描述

mode

brakeType

调用 stop 时采用的停止模式:

  • coast — 电机滑行停止
  • brake — 电机通过制动快速停止

返回值

此函数不返回值。

条笔记

  • 任何后续对 stop 的调用都将使用此停止模式。

  • 电机控制器 55 仅支持 coast 和 brake 不支持 hold。

setReversed#

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

可用功能

void setReversed(
    bool value );

参数

范围

类型

描述

value

bool

Whether the motor’s direction is reversed:

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

返回值

此函数不返回值。

条笔记

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

current#

current 返回直流电机当前消耗的电流大小。电流是指流过直流电机的电量。以安培为单位返回时,电流值范围为 0.0 至 1.2 A。

电流值越高,意味着直流电机消耗的电流越大。这种情况可能发生在直流电机提升重物、推动物体或试图在卡住时移动时。

这可以用来检查直流电机在运动过程中是否运转吃力。如果电流持续过高,电机可能会发热或功率利用率降低。

Available Functions

1 — 返回直流电机的电流(单位为安培)。

double current(
  currentUnits units = amp );

2 — 返回直流电机电流占最大额定电流的百分比。

double current(
  percentUnits units );

Parameters

范围

类型

描述

units

currentUnits

电流单位:amp (默认)— 安培

units

percentUnits

表示当前电流占电机最大额定电流的百分比:percent / pct%

Return Values

返回一个 double 的 double 值,表示直流电机在指定单位下使用的电流大小。

voltage#

返回提供给电机的电压。

Available Functions
double voltage(
  voltageUnits units = volt );

参数

范围

类型

描述

units

voltageUnits

电压单位:

  • volt (默认)
  • voltageUnits::mV — 毫伏特

返回值

返回一个 double ,表示电机的电压,单位为指定值。

temperature#

temperature 返回直流电机的温度。

电机温度显示直流电机的温度。温度越高,说明直流电机在工作过程中温度越高。为了保持最佳性能,电机温度应保持在 55°C 以下。

如果直流电机过热,它会降低最大电流以保护自身。当温度达到 70°C 时,电机将停止运转,直到冷却下来。

这可以用来检查直流电机在重复运动、长时间运行或推动物体时是否过热。

Available Functions

1 — 返回直流电机温度占最大工作温度的百分比。

double temperature(
  percentUnits units = percent );

2 — 返回以物理温度单位表示的直流电机温度。

double temperature(
  temperatureUnits units );

参数

范围

类型

描述

units

percentUnits

The unit used to represent DC motor temperature as a percentage:

  • percent / pct (default) — percent

units

temperatureUnits

直流电机温度的单位(以摄氏度为单位):

  • celsius — 摄氏度
  • fahrenheit — 华氏度

返回值

返回一个 double ,表示直流电机的温度,单位为指定单位。

条笔记

  • 电机的工作温度范围约为 20°C (68°F) 至 70°C (158°F)。

getMotorType#

返回检测到的电机/控制器类型。

可用功能

int32_t getMotorType();

参数

此函数不接受任何参数。

返回值

返回 int32_t ,表示检测到的电机/控制器类型:

  • 0 — 11W Motor
  • 1 — 5.5W Motor
  • 2 — Motor Controller 55

installed#

返回电机控制器 55 是否连接到 V5 大脑。

Available Functions
bool installed();

参数

此函数不接受任何参数。

返回值

返回 bool 布尔值,指示电机控制器 55 是否已连接。

  • true — The Motor Controller 55 is connected.
  • false — The Motor Controller 55 is not connected.