Controller#
Introduction#
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 is compatible with the V5 Controller. See the V5 Controller API for more information.
When one or more controllers are configured in the Devices window, VEXcode EXP 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 an EXP controller instance
controller Controller = controller();
Member Functions#
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.
rumble#
rumble makes the controller vibrate using a pattern. In the pattern string, dots are short vibrations, dashes are long vibrations, and spaces are pauses.
Available Function
void rumble(const char *str);
Parameter |
Type |
Description |
|---|---|---|
|
|
A string made of dots, dashes, and spaces that represent the rumble pattern. |
Return Value
This function does not return a value.
Example
// Rumble with a short-short-long pattern
Controller1.rumble("..-");
Getter#
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.
This variable will only work when using 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;