馬達控制器 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.