伺服馬達#

介紹#

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

EDR VEX伺服馬達

類別建構函數#

servo( triport::port& port );

類別析構函數#

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

~servo();

參數#

範圍

類型

描述

port

triport::port&

伺服馬達連接的 3 線端口,寫成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

例子#

// Create the servo instance on 3-Wire Port A
servo myServo = servo(Brain.ThreeWirePort.A);

成員功能#

servo 類別包含以下成員函數:

在呼叫任何 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#

將伺服馬達移到指定位置。

伺服电机示意图,显示其旋转角度,从 100 度到 0 度。

Available Functions

1 — 使用百分比值設定伺服位置。

void setPosition(
 int32_t value,
 percentUnits units );

2 — 使用旋轉單位設定伺服位置。

void setPosition(
 double value,
 rotationUnits units );

Parameters

範圍

類型

描述

value

int32_t

使用百分比單位表示的伺服位置值。

value

double

使用旋轉單元時的伺服位置值。

units

percentUnits

位置單位: percent / pct%

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

此函數不傳回值。

Notes
  • 使用百分比單位時,有效範圍為 0 – 100%。

  • 伺服馬達在開始每個項目之前,都會自動將自身調整到 50 度中心位置,然後再進行任何運動。

  • 使用旋轉單元時,伺服馬達將會移動到指定的絕對位置。

Examples
// 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);