サーボモーター#

導入#

servo クラスは、V5 3線式サーボモーターの制御と設定に使用されます。V5 3線式サーボモーターは、固定された動作範囲内で位置ベースの制御を提供します。

VEX 3線式サーボモーター

クラスコンストラクタ#

servo( triport::port& port );

クラスデストラクタ#

servo オブジェクトを破棄し、関連するリソースを解放します。

~servo();

パラメータ#

パラメータ

タイプ

説明

port

triport::port&

サーボモーターが接続されている 3 線ポートは、 Brain.ThreeWirePort.X または ExpanderName.Xのように記述され、 X はポート文字です (たとえば、 Brain.ThreeWirePort.A または Expander1.A)。

注記#

  • servo クラス コンストラクタを使用してオブジェクトを作成する前に、Brain または 3-Wire Expander を作成する必要があります。

例#

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

サーボモーターを指定された位置に移動させます。

サーボモーターの回転角度を示す図。左端が100度、中央が50度、右端が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);