Controller#

Introduction#

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.

The IQ (2nd gen) Brain can connect to either an IQ (2nd gen) or IQ (1st gen) Controller. An IQ (1st gen) Controller must have a blue Smart Radio installed.

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.

Derived Classes#

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.

Constructors#

1 - Creates a controller using the primary controller type. Typically used when a single controller is connected.

controller();

2 - Creates a controller for the specified controller type. Used when two controllers are connected.

controller(
    controllerType id );

Available Functions

controller();

controller(controllerType id);

Parameter

Type

Description

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.

Notes

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

Example

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

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

Destructor#

~controller#

~controller destroys the controller object and releases associated resources.

Available Function

~controller();

Parameters#

Parameter

Type

Description

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.

Notes#

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

Example#

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

Member Functions#

The controller class includes the following member function:

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

installed#

installed returns whether the controller is connected to the Brain.

Available Function

bool installed();

Parameters

This function does not have parameters.

Return Value

Returns a Boolean value.

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

Global Variables#

RemoteControlCodeEnabled#

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

Usage:
RemoteControlCodeEnabled = state;

Value

Description

true

Enables controller configured actions.

false

Disables controller configured actions.

Values
  • true - Controller-configured actions are enabled.
  • false - Controller-configured actions are disabled.
Notes
  • Controller-configured actions are enabled by default.

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;