Axis#
Introduction#
The axis class is derived from the controller base class and provides access to the V5 Controller’s joysticks, allowing your robot to monitor changes in position along the four available axes.

Access#
The controller class provides four axis objects (Axis1–Axis4). Each object is an instance of the axis class and can be accessed through a controller instance.
Axis Object |
Example Usage |
Description |
|---|---|---|
|
|
Right joystick horizontal axis. |
|
|
Right joystick vertical axis. |
|
|
Left joystick vertical axis. |
|
|
Left joystick horizontal axis. |
Notes#
The
axisobject is provided by the controller. It is not constructed directly.
Member Functions#
The Axis class includes the following member functions:
position — Returns the position of the joystick’s specified axis.
changed — Registers a function to be called when the joystick’s position changes.
Before calling any axis member functions, a controller instance must be created, as shown below:
// Create a V5 controller instance
controller Controller = controller();
position#
Returns the position of a joystick axis as an integer from -100 to 100, representing a percentage.
Available Functionsint32_t position(
percentUnits units = percentUnits::pct ) const
This function does not accept any parameters.
Return ValuesThis function returns an int32_t as a percent from -100 to 100.
This function can be called on any controller axis object, for example:
Controller.Axis1Controller.Axis2Controller.Axis3Controller.Axis4
while (true) {
if (Controller.Axis4.position() > 10) {
Drivetrain.turn(right);
} else if (Controller.Axis4.position() < -10) {
Drivetrain.turn(left);
} else {
Drivetrain.stop();
}
wait(20, msec);
}
changed#
Registers a callback function that runs when a joystick axis position changes.
Available FunctionsThe controller provides four axis objects (Axis1–Axis4):
void changed(
void (* callback)(void) ) const;
Parameter |
Description |
|---|---|
|
A previously defined callback function that is called automatically when the axis value changes. The function must match the required callback signature. See Callback Functions for more information. |
This function does not return a value.
ExamplesThis function can be called on any controller axis object, for example:
Controller.Axis1Controller.Axis2Controller.Axis3Controller.Axis4
// Play a rumble pattern when the left joystick moves
void rumblePattern() {
Controller.rumble("..--");
wait(1, seconds);
}
// Call the rumble function when the left joystick moves
Controller.Axis4.changed(rumblePattern);