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

クラスコンストラクタ#
encoder(
triport::port &port );
クラスデストラクタ#
Destroys the encoder object and releases associated resources.
virtual ~encoder();
パラメータ#
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
光軸エンコーダで使用される必須の 2 ポート グループの最初の 3 線ポート。エンコーダは、ブレインまたは 3 線エキスパンダのいずれかで、隣接する 2 つのポート (A–B、C–D、E–F、または G–H) を占有します。ペアの最初のポート (A、C、E、または G) を、 |
例#
// 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 Functionsvoid setPosition(
double value,
rotationUnits units);
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
設定する回転位置。 |
|
|
The unit that represents the position:
|
この関数は値を返しません。
position#
エンコーダに接続されたシャフトがどれだけ回転したかを返します。
Available Functionsdouble position(
rotationUnits units );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
The unit that represents the position:
|
指定された単位での回転を表す、 double 倍精度浮動小数点数を返します。
velocity#
エンコーダの回転速度を返します。
Available Functionsdouble velocity(
velocityUnits units );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
速度を表す単位:
|
指定された単位での速度を表す、 double を返します。