控制器#

介绍#

The V5 Controller is represented by the controller class. You create a controller object and can access joystick input, button states, and screen functionality through its derived classes.

V5 与 EXP 控制器兼容,有关更多信息,请参阅 EXP 控制器 API

派生类#

The controller class provides the following derived classes:

  • Axis — Provides access to joystick axis input values and change events.

  • Button — Provides access to button state and button event callbacks.

  • Screen — Provides functions for writing text to the controller screen.

类构造函数#

1 使用主控制器类型创建控制器。通常用于连接单个控制器的情况。

controller();

2 为指定的控制器类型创建一个控制器。用于连接两个控制器时。

controller(
    controllerType id );

类析构函数#

~controller();

参数#

范围

类型

描述

id

controllerType

The type of controller being created:

  • primary — The primary controller connected to the Brain.
  • partner — The partner (second) controller connected to the Brain.

笔记#

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

例子#

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

成员功能#

The controller class includes the following member functions:

  • rumble — Rumbles the controller using a pattern.

  • installed — Checks whether the controller is connected to the brain.

隆隆#

根据参数定义的模式使控制器震动。点代表短促震动,短划线代表长促震动,空格代表停顿。

Available Functions
void rumble(
    const char *str );

Parameters

范围

类型

描述

str

const char *

由点和划组成的字符串,代表隆隆声模式。

Return Values

此函数不返回值。

Examples
// Short-short-long pattern
Controller1.rumble("..-");

已安装#

检查控制器是否已安装/连接。

Available Functions
bool installed();

Parameters

此函数不接受任何参数。

Return Values

返回一个布尔值,指示控制器是否已安装。

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

全局变量#

当在“设备”窗口中配置一个或多个控制器时,VEXcode V5 提供了一个全局变量来控制控制器配置的操作的执行。

RemoteControlCodeEnabled#

启用或禁用在设备配置中定义的控制器配置操作。

Assignment
RemoteControlCodeEnabled = 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 the controller configured actions
    } else if (Controller1.ButtonA.pressing()) {
        break;
    } else {
        Drivetrain.stop();
    }
    wait(20, msec);
}
RemoteControlCodeEnabled = true;