控制器#

介绍#

The controller class represents a VEX IQ Controller connected to the IQ Brain. A controller object can be used to access joystick axis values, read button states, register button or joystick callbacks, and check whether the controller is connected.

第二代 IQ 大脑可以连接到第二代 IQ 控制器或第一代 IQ 控制器。第一代 IQ 控制器必须安装蓝色智能无线电模块。

When one or more controllers are configured in the Devices window, VEXcode IQ also provides RemoteControlCodeEnabled. This global variable enables or disables controller actions configured in the Devices menu.

派生类#

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.

构造函数#

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

controller();

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

controller(
    controllerType id );

可用功能

controller();

controller(controllerType id);

范围

类型

描述

id

controllerType

Optional. The controller type to create: primary for the primary controller connected to the Brain or partner for the second controller connected to the Brain.

笔记

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

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 controller instance
controller Controller = controller();

成员功能#

The controller class includes the following member function:

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

已安装#

installed returns whether the controller is connected to the Brain.

可用功能

bool installed();

参数

此函数没有参数。

返回值

返回布尔值。

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

全局变量#

远程控制代码已启用#

RemoteControlCodeEnabled enables or disables controller actions configured in the Devices menu. Controller configured actions are enabled by default.

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.AxisA.position() > 0) {
    Drivetrain.drive(forward);
  }
  else if (Controller1.AxisA.position() < 0) {
    Drivetrain.drive(reverse);
  }
  // Press E Up to use controller configured actions again
  else if (Controller1.ButtonEUp.pressing()) {
    break;
  }
  else {
    Drivetrain.stop();
  }

  wait(20, msec);
}

RemoteControlCodeEnabled = true;