馬達 393(馬達控制器 29)#

介紹#

motor29 類別用於控制連接到 3 線連接埠 的馬達控制器 29。馬達控制器 29 發送來自 EXP 大腦的 PWM 訊號來驅動 VEX 馬達 393。

VEX馬達控制器29.

類別建構函數#

1 — 在指定的 3 線連接埠上建立一個 motor29 物件。

motor29(
    triport::port &port );

2 — 在指定的 3 線連接埠上建立一個 motor29 對象,並改變正向旋轉方向。

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

類別析構函數#

銷毀 motor29 物件並釋放相關資源。

~motor29();

參數#

範圍

類型

描述

port

triport::port&

馬達控制器 29 連接的 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 a Motor Controller 29 instance in 3-Wire Port A
motor29 Motor393_A = motor29(
    Brain.ThreeWirePort.A );

成員功能#

motor29 類別包含下列成員函數:

  • 旋轉 — 使馬達沿指定方向旋轉。

  • 停止 — 停止馬達。

  • setVelocity — 告訴馬達 393 旋轉的速度。

  • setReversed — 設定馬達的旋轉方向是否反轉。

在呼叫 motor29 成員函數之前,必須先建立一個實例,如下所示:

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

馬達旋轉方向: forward 或 reverse。

velocity

double

當使用 percent時,旋轉速度從 0% 到 100% 變化。

units

velocityUnits

速度單位:

  • percent 百分比 pct 百分比
  • rpm — 每分鐘轉數
  • dps — 每秒度數

傳回值

此函數不傳回值。

條筆記

  • 函數不等待,呼叫後項目將立即繼續執行。

  • 馬達 393 將繼續旋轉,直到呼叫 stop 或使用另一個 spin。

stop#

停止馬達運轉。

可用功能

void stop();

參數

此函數不接受任何參數。

傳回值

此函數不傳回值。

setVelocity#

告訴馬達 393 旋轉的速度。百分比越高,馬達 393 旋轉越快;百分比越低,馬達 393 旋轉越慢。

每個項目開始時,每個馬達 393 預設以 50% 的速度旋轉。

可用功能

void setVelocity(
    double velocity,
    percentUnits units );

參數

範圍

類型

描述

velocity

double

當使用 percent時,旋轉速度從 0% 到 100% 變化。

units

percentUnits

速度單位:percent / pct%

傳回值

此函數不傳回值。

setReversed#

設定是否反轉馬達的旋轉方向。

可用功能

void setReversed(
    bool value );

參數

範圍

類型

描述

value

bool

馬達 393 的旋轉方向是否反轉:

  • true — 反轉馬達 393 的旋轉方向。 4
  • false — 將馬達 393 的旋轉方向恢復為預設值

傳回值

此函數不傳回值。

條筆記

  • 呼叫 setReversed 與更改 建構子 中的 reverse 參數相同。