Victor 883 發動機#
介紹#
motor_victor 類別用於控制連接到三線連接埠的 Victor 883 馬達控制器。 Victor 883 馬達控制器從 V5 主控模組發送 PWM 訊號,以控制無法直接連接到智慧型連接埠的相容 VEXpro 或 VEX EDR 直流馬達。
Victor 883 馬達控制器無法在 VEXcode 中進行配置,必須手動在程式碼中建置才能使用。
類別建構函數#
1 — 為連接到指定 3 線連接埠的 Victor 883 馬達控制器建立一個
motor_victor物件。motor_victor( triport::port& port );
2 — 在指定的 3 線連接埠上建立一個
motor_victor對象,並可選擇反轉其方向。motor_victor( triport::port& port, bool reverse );
類別析構函數#
銷毀 motor_victor 物件並釋放相關資源。
~motor_victor();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
Victor 883 馬達連接的 3 線端口,寫成 |
|
|
Sets whether the motor’s spin direction is reversed:
|
例子#
// Create the motor_victor instance on 3-Wire Port A
motor_victor victor = motor_victor(Brain.ThreeWirePort.A);
// Create the motor_victor instance with reversed direction
motor_victor victor2 = motor_victor(Brain.ThreeWirePort.B, true);
成員功能#
motor_victor motor_victor 函數:
spin— 使馬達沿指定方向旋轉。stop— 停止馬達。setVelocity— 告訴馬達旋轉的速度。setReversed— 設定馬達方向是否反轉。
在呼叫 motor_victor 函式之前,必須先建立 motor_victor 實例,如下所示:
/* This constructor is required to use a
Victor 883 Motor. Replace the values
as needed. */
// Create the motor_victor instance on 3-Wire Port A
motor_victor victor = motor_victor(Brain.ThreeWirePort.A);
spin#
使馬達沿指定方向無限旋轉。
Available Functions1 — 使用目前配置的馬達速度旋轉馬達。
void spin( directionType dir );
Parameters2 — 使馬達以指定速度旋轉。
void spin( directionType dir, double velocity, velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
馬達旋轉方向: |
|
|
當使用 |
|
|
速度單位:
|
此函數不傳回值。
Notes馬達將繼續旋轉,直到呼叫
stop或執行另一個運動函數。
// Spin forward, then stop
victor.spin(forward);
wait(1, seconds);
victor.stop();
// Spin forward at 100 rpm
victor.spin(forward, 100, rpm);
wait(1, seconds);
victor.stop();
stop#
停止馬達旋轉。
Available Functionsvoid stop();
此函數不接受任何參數。
Return Values此函數不傳回值。
Notes呼叫
stop會立即停止任何目前的馬達運動。
// Spin and then stop
victor.spin(forward);
wait(1, seconds);
victor.stop();
setVelocity#
控制馬達轉速。百分比越高,馬達轉速越快;百分比越低,馬達轉速越慢。
每個項目開始時,每個連接的馬達預設以 50% 的速度旋轉。
Available Functionsvoid setVelocity(
double velocity,
percentUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
當使用 |
|
|
速度單位: |
此函數不傳回值。
Notes任何後續的 Victor 883 馬達運動函數(例如
spin)如果未明確指定速度,則將使用此值。
// Set velocity to 50%, then spin
victor.setVelocity(50, percent);
victor.spin(forward);
setReversed#
設定馬達是否反轉。
Available Functionsvoid setReversed( bool value );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
Whether the motor’s direction is reversed:
|
此函數不傳回值。
Notes這與在建構子中更改
reverse參數相同。
// Reverse the motor direction
victor.setReversed(true);
victor.spin(forward); // Will actually spin in reverse