エンコーダー#

導入#

encoder クラスは、シャフトの回転位置と速度を測定する光学式シャフトエンコーダで使用されます。内部の光学センサーを使用してシャフトの回転距離と速度を検出するため、ホイールの回転、アームの位置、その他の機構の追跡に役立ちます。

VEX光学式シャフトエンコーダー。

クラスコンストラクタ#

encoder(
  triport::port &port );

クラスデストラクタ#

Destroys the encoder object and releases associated resources.

virtual ~encoder();

パラメータ#

パラメータ

タイプ

説明

port

triport::port &

光軸エンコーダで使用される必須の 2 ポート グループの最初の 3 線ポート。エンコーダは、ブレインまたは 3 線エキスパンダのいずれかで、隣接する 2 つのポート (A–B、C–D、E–F、または G–H) を占有します。ペアの最初のポート (A、C、E、または G) を、 Brain.ThreeWirePort.X または ExpanderName.X のように記述して指定します。ここで X はポート文字です (例: Brain.ThreeWirePort.A または Expander1.C)。

例#

// Create an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

メンバーの機能#

encoder クラスには、以下のメンバ関数が含まれています。

  • setPosition — エンコーダの現在位置を指定された値に設定します。

  • position — エンコーダが回転した距離を返します。

  • velocity — エンコーダの現在の回転速度を返します。

エンコーダー encoder メンバ関数を呼び出す前に、以下に示すように encoder インスタンスを作成する必要があります。

/* This constructor is required when using VS Code.
Encoder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

setPosition#

エンコーダの現在位置を指定した値に設定します。これにより、モーターやその他の機構を回転させることなく、トラッキング位置を手動で設定できます。

Available Functions
void setPosition(
  double        value,
  rotationUnits units);

Parameters

パラメータ

タイプ

説明

value

double

設定する回転位置。

units

rotationUnits

The unit that represents the position:

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

Return Values

この関数は値を返しません。

position#

エンコーダに接続されたシャフトがどれだけ回転したかを返します。

Available Functions
double position(
  rotationUnits units );

Parameters

パラメータ

タイプ

説明

units

rotationUnits

The unit that represents the position:

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

Return Values

指定された単位での回転を表す、 double 倍精度浮動小数点数を返します。

velocity#

エンコーダの回転速度を返します。

Available Functions
double velocity(
  velocityUnits units );

Parameters

パラメータ

タイプ

説明

units

velocityUnits

速度を表す単位:

  • percent / pct — パーセント
  • rpm — 毎分回転数
  • dps — 毎秒角度

Return Values

指定された単位での速度を表す、 double を返します。