Controller#

Introduction#

The VEX AIR Drone Controller features a 12-button layout and two joysticks. These inputs allow the drone to detect button presses and joystick movements, enabling interactive and responsive control.

Below is a list of all available methods:

Getters – Read button, joystick, and connection status.

  • .pressing – Checks if a specific button is currently being pressed.

  • .position – Returns the position of the joystick along a specified axis.

  • is_drone_connected – Returns whether or not the controller is connected to the drone.

  • get_battery_level – Returns the controller’s battery level.

Callbacks – Respond to button or joystick input changes.

  • .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.

Getters#

.pressing#

.pressing returns if a specific controller button is being pressed. This method must be called on a specific button, such as button5 (see full list of buttons below). This will return either of the following:

  • True - The specified button is being pressed.

  • False - The specified button is not being pressed.

Usage:
One of eight available buttons, numbered 5 through 12, can be used with this method, as shown below:

Button

Command

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

A VEX AIR Controller is facing backward with its 8 orange buttons highlighted yellow.

Parameters

Description

This method has no parameters.

# Take a picture when button 5 is pressed.
drone.take_off(starting_altitude=500)
while True:
    # Fly using the controller sticks
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )

    # Capture an image from the forward camera when button 5 is pressed.
    if controller.button5.pressing():
        drone.camera.capture_image(FORWARD_CAMERA)

    wait(5, MSEC)

.position#

.position returns the position of the joystick’s specified axis as a percentage. This will return an integer from –100 to 100.

Usage:

One of four available axes can be used with this method, numbered 1 to 4.

Axis

Command

axis1

controller.axis1.position() — The left joystick vertical axis

axis2

controller.axis2.position() — The left joystick horizontal axis

axis3

controller.axis3.position() — The right joystick horizontal axis

axis4

controller.axis4.position() — The right joystick vertical axis

A VEX AIR Controller is facing forward with the joystick axes bordered by red boxes.

Parameters

Description

This method has no parameters.

# Climb when the left joystick is moved up.
drone.take_off(starting_altitude=500)
while True:
    if controller.axis1.position() > 0:
        drone.climb(direction=UP, velocity=50)
    else:
        drone.hover()
    wait(5, MSEC)

is_drone_connected#

is_drone_connected returns whether the drone is connected. This will return a Boolean value:

  • True - The drone is connected.

  • False - The drone is not connected.

Usage:

controller.is_drone_connected()

Parameters

Description

This method has no parameters.

# Print controller connection status on screen.
while True:
    if controller.is_drone_connected():
        controller.screen.clear_screen()
        controller.screen.set_cursor(1, 1)
        controller.screen.print("Controller connected")
    wait(0.5, SECONDS)

get_battery_level#

get_battery_level returns the Controller’s battery level as a percentage. This returns an integer from 0 to 100.

Usage:

controller.get_battery_level()

Parameters

Description

This method has no parameters.

# Show controller's battery level.
if controller.get_battery_level() > 50:
    controller.screen.print("Battery level ok")
else:
    controller.screen.print("Battery level low")

Callbacks#

.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, such as button5 (see full list of buttons below).

Usage:
One of eight available buttons can be used with this method, numbered 5 to 12.

Button

Command

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

A VEX AIR Controller is facing backward with its 8 orange buttons highlighted yellow.

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. See Using Events with Parameters for more information.

# Take a picture when button 5 is pressed.
def take_picture():
    drone.camera.capture_image(FORWARD_CAMERA)

# Register the button press callback.
controller.button5.pressed(take_picture)

# Fly using the controller sticks.
drone.take_off(starting_altitude=500)
while True:
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )
    wait(5, MSEC)

.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, such as button5 (see full list of buttons below).

Usage:
One of eight available buttons can be used with this method, numbered 5 to 12.

Button

Command

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

A VEX AIR Controller is facing backward with its 8 orange buttons highlighted yellow.

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. See Using Functions with Parameters for more information.

# Take a picture when button 5 is released.
def take_picture():
    drone.camera.capture_image(FORWARD_CAMERA)

# Register the button released callback.
controller.button5.released(take_picture)

# Fly using the controller sticks.
drone.take_off(starting_altitude=500)
while True:
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )
    wait(5, MSEC)

.changed#

.changed registers a function to be called when the joystick’s position changes.

Usage:

One of four available axes can be used with this method, numbered 1 to 4.

Axis

Command

axis1

controller.axis1.position() — The left joystick vertical axis

axis2

controller.axis2.position() — The left joystick horizontal axis

axis3

controller.axis3.position() — The right joystick horizontal axis

axis4

controller.axis4.position() — The right joystick vertical axis

A VEX AIR Controller is facing forward with the joystick axes bordered by red boxes.

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 Using Functions with Parameters for more information.

# Move forward when the left joystick moves.
def on_axis1_changed():
    drone.move_for(direction=0, distance=200, velocity=50, units=MM)

drone.take_off(starting_altitude=500)
controller.axis1.changed(on_axis1_changed)