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:
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 |
|---|---|---|
|
|
Optional. The controller type to create: |
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 |
|---|---|---|
|
|
The type of controller being created:
|
Notes#
Only one
primaryand onepartnercontroller 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 |
|---|---|
|
Enables controller configured actions. |
|
Disables controller configured actions. |
true- Controller-configured actions are enabled.false- Controller-configured actions are disabled.
Controller-configured actions are enabled by default.
// 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;