軸#

導入#

axis クラスは、controller クラスの派生クラスです。コントローラーのジョイスティック軸の値とジョイスティック軸の変更コールバックへのアクセスを提供します。

axis オブジェクトは、 controller オブジェクトを介してアクセスされます。直接構築されるものではありません。

EXPコントローラーの前面。ジョイスティックの軸番号が赤で強調表示されています。コントローラーの表面では、左ジョイスティックは左右の動きを軸4、上下の動きを軸3と表示し、右ジョイスティックは左右の動きを軸1、上下の動きを軸2と表示しています。

アクセス#

controller クラスは、以下の軸オブジェクトを提供します。各オブジェクトは axis クラスのインスタンスです。

軸オブジェクト

使用例

説明

Axis1

Controller.Axis1.position()

右ジョイスティックの水平軸。

Axis2

Controller.Axis2.position()

右ジョイスティックの垂直軸。

Axis3

Controller.Axis3.position()

左ジョイスティックの垂直軸。

Axis4

Controller.Axis4.position()

左ジョイスティックの水平軸。

注記#

  • axis メンバ関数を使用する前に、 controller オブジェクトを作成します。

  • position -100 から 100までの値を返します。

// Create a controller object
controller Controller = controller();

メンバーの機能#

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

ゲッター — ジョイスティックの軸位置を読み取る。

  • position — ジョイスティック軸の位置を返します。

コールバック — ジョイスティックの位置が軸に沿って変化したときに実行される関数。

  • changed — ジョイスティックの位置がその軸に沿って変化したときに関数を実行します。

ゲッター#

position#

position は、ジョイスティック軸の位置を -100 から 100の値として返します。

利用可能な機能

int32_t position(percentUnits units = percentUnits::pct) const;

パラメータ

タイプ

説明

units

percentUnits

オプション。返される軸の値に使用される単位。デフォルトは percentUnits::pctです。

戻り値

int32_t から -100 から 100までの値を返します。

  • 100 — ジョイスティックの軸が正の方向に完全に移動しています。

  • 0 — ジョイスティックの軸が中央に配置されています。

  • -100 — ジョイスティックの軸が完全に負の方向に動いた状態。

例

// Turn with the left joystick
while (true) {
  if (Controller.Axis4.position() > 10) {
    Drivetrain.turn(right);
  }
  else if (Controller.Axis4.position() < -10) {
    Drivetrain.turn(left);
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

折り返し電話#

changed#

changed ジョイスティックの位置がその軸に沿って変化したときに関数を実行します。

利用可能な機能

void changed(void (* callback)(void)) const;

パラメータ

タイプ

説明

callback

void (*)(void)

ジョイスティックの位置がその軸に沿って変化するたびに実行される関数。

戻り値

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

例

mainの外でコールバック関数を定義します。

// Rumble when the left joystick moves
void controllerRumble() {
  Controller.rumble(".");
}

main内でコールバックを登録します。

int main() {
  vexcodeInit();

  // Run controllerRumble when the joystick's position changes along Axis4
  Controller.Axis4.changed(controllerRumble);
}