Controller#
Introduction#
The EXP Controller allows users to control and customize behaviors for their robot.
Below is a list of all available methods:
Actions – Turn Controller-programmed actions on or off.
remote_control_code_enabled– Enable or disable Controller configured actions.
Getters – Read button states and joystick positions.
.pressing– Returns whether the specified button is being pressed..position– Returns the position of the joystick’s specified axis.
Callback – Run code when buttons or joysticks change state.
.pressed– Calls a function when the specified button is pressed..released– Calls a function when the specified button is released..changed– Calls a function when the joystick’s axis changes.
Constructors – Manually initialize and configure the controller.
Controller– Create a controller.
Actions#
remote_control_code_enabled#
remote_control_code_enabled is a variable that can be set to a boolean that enables or disables Controller configured actions from the Devices menu. The Controller is enabled by default. It can be set to either of the following:
True— Enable Controller configured actions.False— Disable Controller configured actions.
Usage:
remote_control_code_enabled = False
# Drive forward or backward using the left joystick
remote_control_code_enabled = False
while True:
if controller.axis3.position() > 0:
drivetrain.drive(FORWARD)
elif controller.axis3.position() < 0:
drivetrain.drive(REVERSE)
# Press A to use the controller configured actions
elif controller.buttonA.pressing():
break
else:
drivetrain.stop()
wait(20, MSEC)
remote_control_code_enabled = True
Getters#
.pressing#
.pressing returns an integer indicating whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as buttonEDown (see full list of button objects below).
1- The specified button is being pressed.0- The specified button is not being pressed.
Usage:
One of ten available button objects can be used with this method, as shown below:
Button |
Command |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters |
Description |
|---|---|
This method has no parameters. |
# Turn right while L1 is pressed
while True:
if controller.buttonL1.pressing():
drivetrain.turn(RIGHT)
else:
drivetrain.stop()
.position#
.position returns the position of the joystick’s specified axis as an integer from –100 to 100, representing a percentage. This method must be called on a specific axis object, such as axis1 (see full list of axis objects below).
Usage:
One of four available axes can be used with this method, as shown below:
Axis |
Command |
|---|---|
|
|
|
|
|
|
|
|
Parameters |
Description |
|---|---|
This method has no parameters. |
# Turn with the left joystick
remote_control_code_enabled = False
while True:
if controller.axis4.position() > 10:
drivetrain.turn(RIGHT)
elif controller.axis4.position() < -10:
drivetrain.turn(LEFT)
else:
drivetrain.stop()
wait(20, MSEC)
Callback#
.pressed#
.pressed registers a function to be called when a specific button on the controller is pressed. This method must be called on a specific button object, such as buttonEDown – (see full list of button objects below).
Usage:
One of the ten available button objects can be used with this method, as shown below:
Button |
Command |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters |
Description |
|---|---|
callback |
A function that is previously defined to execute when the specified button is being pressed. |
arg |
Optional. A tuple containing arguments to pass to the callback function. Functions with Parameters for more information. |
# Drive forward when A is pressed
def drive_forward():
drivetrain.drive_for(FORWARD, 100, MM)
controller.buttonA.pressed(drive_forward)
.released#
.released registers a function to be called when a specific button on the controller is released. This method must be called on a specific button object, such as buttonL1 – (see full list of button objects below).
Usage:
One of the ten available button objects can be used with this method, as shown below:
Button |
Command |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters |
Description |
|---|---|
callback |
A function that is previously defined to execute when the specified button is released. |
arg |
Optional. A tuple containing arguments to pass to the callback function. Functions with Parameters for more information. |
# Drive backward when A is released
def back_up():
drivetrain.drive_for(REVERSE, 100, MM)
controller.buttonA.released(back_up)
.changed#
.changed registers a function to be called when the joystick’s position changes. This method must be called on a specific axis object, such as axis1 (see full list of axis objects below).
Usage:
One of four available axes can be used with this method, as shown below:
Axis |
Command |
|---|---|
|
|
|
|
|
|
|
|
Parameters |
Description |
|---|---|
callback |
A function that is previously defined to execute when the axis’ value changes. |
arg |
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Play a sound when the left joystick moves
def tada_sound():
brain.play_sound(SoundType.TADA)
wait(1, SECONDS)
controller.axis4.changed(tada_sound)
Constructors#
Constructors are used to manually create Controller objects, which are necessary for configuring a controller outside of VEXcode. You can only create two controllers in a project.
Controller#
Controller creates a controller.
Usage:
Controller()
Parameters |
Description |
|---|---|
This constructor has no parameters. |
# Create a Controller
controller = Controller()