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

參數#

範圍

類型

描述

port

triport::port&

Victor 883 馬達連接的 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 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 Functions

1 — 使用目前配置的馬達速度旋轉馬達。

void spin(
 directionType dir );

2 — 使馬達以指定速度旋轉。

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

Parameters

範圍

類型

描述

dir

directionType

馬達旋轉方向: forward 或 reverse。

velocity

double

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

units

velocityUnits

速度單位:

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

Return Values

此函數不傳回值。

Notes
  • 馬達將繼續旋轉,直到呼叫 stop 或執行另一個運動函數。

Examples
// 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 Functions
void stop();

Parameters

此函數不接受任何參數。

Return Values

此函數不傳回值。

Notes
  • 呼叫 stop 會立即停止任何目前的馬達運動。

Examples
// Spin and then stop
victor.spin(forward);
wait(1, seconds);
victor.stop();

setVelocity#

控制馬達轉速。百分比越高,馬達轉速越快;百分比越低,馬達轉速越慢。

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

Available Functions
void setVelocity(
    double       velocity,
    percentUnits units );

Parameters

範圍

類型

描述

velocity

double

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

units

percentUnits

速度單位:percent / pct%

Return Values

此函數不傳回值。

Notes
  • 任何後續的 Victor 883 馬達運動函數(例如 spin)如果未明確指定速度,則將使用此值。

Examples
// Set velocity to 50%, then spin
victor.setVelocity(50, percent);
victor.spin(forward);

setReversed#

設定馬達是否反轉。

Available Functions
void setReversed( bool value );

Parameters

範圍

類型

描述

value

bool

Whether the motor’s direction is reversed:

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

Return Values

此函數不傳回值。

Notes
  • 這與在建構子中更改 reverse 參數相同。

Examples
// Reverse the motor direction
victor.setReversed(true);
victor.spin(forward); // Will actually spin in reverse