コントローラ#

導入#

controller クラスは、V5 Brain に接続された VEX V5 コントローラーを表します。2 controller オブジェクトを使用すると、ジョイスティックの軸値にアクセスしたり、ボタンの状態を読み取ったり、ボタンまたはジョイスティックのコールバックを登録したり、コントローラーを振動させたり、コントローラーの画面に書き込んだり、コントローラーが接続されているかどうかを確認したりできます。

VEX V5はEXPコントローラーと互換性があります。詳細については、EXPコントローラーAPIを参照してください。

デバイスウィンドウで 1 つ以上のコントローラーが設定されている場合、VEXcode V5 は RemoteControlCodeEnabledも提供します。このグローバル変数は、デバイスメニューで設定されたコントローラーのアクションを有効または無効にします。

派生クラス#

controller クラスは、以下の派生クラスを提供します。

  • Axis - ジョイスティック軸の入力値と変更イベントへのアクセスを提供します。

  • Button - ボタンの状態とボタンのイベントコールバックへのアクセスを提供します。

  • Screen - コントローラ画面にテキストを書き込む機能を提供します。

建設業者#

1 - プライマリコントローラタイプを使用してコントローラを作成します。通常、単一のコントローラが接続されている場合に使用されます。

controller();

2 - 指定されたコントローラータイプのコントローラーを作成します。2 つのコントローラーが接続されている場合に使用します。

controller(
    controllerType id );

利用可能な機能

controller();

controller(controllerType id);

パラメータ

タイプ

説明

id

controllerType

オプション。作成するコントローラーの種類: primary はブレインに接続されたプライマリコントローラー、 partner はブレインに接続されたセカンドコントローラーです。

注記

Only one primary Controller and one partner Controller can be created in a single project.

例

// Create the primary Controller
controller Controller1 = controller();

// Create a partner Controller
controller Controller2 = controller(partner);

破壊者#

コントローラー#

~controller destroys the controller object and releases associated resources.

利用可能な機能

~controller();

パラメータ#

パラメータ

タイプ

説明

id

controllerType

作成中のコントローラーの種類:

  • primary - ブレインに接続されたプライマリコントローラー。
  • partner - ブレインに接続されたパートナー(2番目の)コントローラー。

注記#

  • Only one primary and one partner controller may exist in a single project.

例#

// Create a V5 controller instance
controller Controller = controller();

メンバーの機能#

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

  • rumble - パターンを使用してコントローラーを振動させます。

  • installed - コントローラーがブレインに接続されているかどうかを確認します。

ゴロゴロ#

rumble コントローラーをパターンで振動させます。パターン文字列では、ドットは短い振動、ダッシュは長い振動、スペースは休止を表します。

利用可能な機能

void rumble(const char *str);

パラメータ

タイプ

説明

str

const char *

点、線、空白で構成された文字列で、ランブルパターンを表します。

戻り値

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

例

// Rumble with a short-short-long pattern
Controller1.rumble("..-");

ゲッター#

インストール済み#

installed 、コントローラーがブレインに接続されているかどうかを返します。

利用可能な機能

bool installed();

パラメータ

この関数には引数がありません。

戻り値

ブール値を返します。

  • true - The controller is installed/connected.
  • false - The controller is not installed/connected.

グローバル変数#

RemoteControlCodeEnabled#

RemoteControlCodeEnabled デバイスメニューで設定されたコントローラーアクションを有効または無効にします。コントローラーで設定されたアクションはデフォルトで有効になっています。

Usage:
RemoteControlCodeEnabled = state;

価値

説明

true

コントローラーで設定されたアクションを有効にします。

false

コントローラーで設定されたアクションを無効にします。

Values
  • true - Controller-configured actions are enabled.
  • false - Controller-configured actions are disabled.
Notes
  • コントローラーで設定されたアクションは、デフォルトで有効になっています。

Examples
// Drive forward or backward using the left joystick
RemoteControlCodeEnabled = false;

while (true) {
  if (Controller1.Axis3.position() > 0) {
    Drivetrain.drive(forward);
  }
  else if (Controller1.Axis3.position() < 0) {
    Drivetrain.drive(reverse);
  }
  // Press A to use Controller configured actions again
  else if (Controller1.ButtonA.pressing()) {
    break;
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

RemoteControlCodeEnabled = true;