コントローラ#
導入#
The controller class represents a VEX EXP Controller connected to the EXP Brain. A controller object can be used to access joystick axis values, read button states, register button or joystick callbacks, make the controller rumble, and check whether the controller is connected.
VEX EXPはV5コントローラーと互換性があります。詳細については、V5コントローラーAPIを参照してください。
デバイスウィンドウで1つ以上のコントローラーが設定されている場合、VEXcode EXPは RemoteControlCodeEnabledも提供します。このグローバル変数は、デバイスメニューで設定されたコントローラーアクションを有効または無効にします。
派生クラス#
controller クラスは、以下の派生クラスを提供します。
建設業者#
1 - プライマリコントローラタイプを使用してコントローラを作成します。通常、単一のコントローラが接続されている場合に使用されます。
controller();
2 - 指定されたコントローラータイプのコントローラーを作成します。2 つのコントローラーが接続されている場合に使用します。
controller( controllerType id );
利用可能な機能
controller();
controller(controllerType id);
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
オプション。作成するコントローラーの種類: |
注記
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();
パラメータ#
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
作成中のコントローラーの種類:
|
注記#
Only one
primaryand onepartnercontroller may exist in a single project.
例#
// Create an EXP controller instance
controller Controller = controller();
メンバーの機能#
controller クラスには、以下のメンバ関数が含まれています。
ゴロゴロ#
rumble パターンを使用してコントローラーを振動させます。パターン文字列では、ドットは短い振動、ダッシュは長い振動、スペースは休止を表します。
利用可能な機能
void rumble(const char *str);
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
点、線、空白で構成された文字列で、ランブルパターンを表します。 |
戻り値
この関数は値を返しません。
例
// 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- Controller-configured actions are enabled.false- Controller-configured actions are disabled.
コントローラーで設定されたアクションは、デフォルトで有効になっています。
この変数はVEXcodeを使用している場合にのみ機能します。
// 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;