伺服馬達#
介紹#
servo 類用於控制與配置 EXP 三線伺服馬達。 EXP 三線伺服馬達可在固定的運動範圍內提供基於位置的控制。

類別建構函數#
servo( triport::port& port );
類別析構函數#
銷毀 servo 物件並釋放相關資源。
~servo();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
伺服馬達連接的 3 線端口,寫成 |
例子#
// Create the servo instance on 3-Wire Port A
servo myServo = servo(Brain.ThreeWirePort.A);
成員功能#
servo 類別包含以下成員函數:
setPosition— 將伺服馬達移到指定位置。
在呼叫任何 servo 成員函數之前,必須先建立一個 servo 實例,如下所示:
/* This constructor is required when using VS Code.
Servo configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the servo instance on 3-Wire Port A
servo myServo = servo(Brain.ThreeWirePort.A);
setPosition#
將伺服馬達移到指定位置。

1 — 使用百分比值設定伺服位置。
void setPosition( int32_t value, percentUnits units );
Parameters2 — 使用旋轉單位設定伺服位置。
void setPosition( double value, rotationUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
使用百分比單位表示的伺服位置值。 |
|
|
使用旋轉單元時的伺服位置值。 |
|
|
位置單位: |
|
|
The position unit:
|
此函數不傳回值。
Notes使用百分比單位時,有效範圍為 0 – 100%。
伺服馬達在開始每個項目之前,都會自動將自身調整到 50 度中心位置,然後再進行任何運動。
使用旋轉單元時,伺服馬達將會移動到指定的絕對位置。
// Set the servo position to 10 percent
myServo.setPosition(10, percent);
// Set the servo position to 45.5 degrees
myServo.setPosition(45.5, degrees);
// Set the servo position to 90 degrees
myServo.setPosition(90, degrees);