Controller#

Introduction#

The VEX AIM One Stick Controller has four buttons and a joystick. The joystick can be moved along two axes and can also be pressed like a button.

Controller methods can be used to check button presses, read joystick movement, check connection and battery status, or run functions when controller events happen.

Below is a list of all methods:

Getters — Read button, joystick, connection, and battery status.

  • .pressing — Returns whether a specified button is being pressed.

  • .position — Returns the joystick position along a specified axis.

  • is_connected — Returns whether the controller is connected.

  • get_battery_level — Returns the controller’s battery level.

Callbacks — Run functions when controller input changes.

  • .pressed — Runs a function when a specified button is pressed.

  • .released — Runs a function when a specified button is released.

  • .changed — Runs a function when the joystick’s position changes along a specified axis.

Getters#

.pressing#

.pressing returns whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as controller.button_up.

  • True — The specified button is being pressed.

  • False — The specified button is not being pressed.

Usage:
One of five available button objects can be used with this method:

Button

Command

button_up

controller.button_up.pressing() — The Up button

button_down

controller.button_down.pressing() — The Down button

button_left

controller.button_left.pressing() — The Left button

button_right

controller.button_right.pressing() — The Right button

button_stick

controller.button_stick.pressing() — The Joystick button

VEX AIM One Stick Controller with a joystick on the left and four buttons to the right. The joystick and four buttons are highlighted.

Parameters

Description

This method has no parameters.

# Move forward while the Up button is being pressed
while True:
    if controller.button_up.pressing():
        robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(20, MSEC)

.position#

.position returns the position of a joystick axis as a number from -100 to 100.

This method must be called on a specific axis object, such as controller.axis1.

Usage:
One of two available axis objects can be used with this method:

Axis

Command

axis1

controller.axis1.position() — The vertical axis

axis2

controller.axis2.position() — The horizontal axis

VEX AIM Controller with a joystick on the left and four buttons to the right. The 1 and 2 axes for the joystick are highlighted.

Parameters

Description

This method has no parameters.

# Move forward when the joystick is moved up
while True:
    if controller.axis1.position() > 0:
        robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(20, MSEC)

is_connected#

is_connected returns whether the controller is connected.

  • True — The controller is connected.

  • False — The controller is not connected.

Usage:
controller.is_connected()

Parameters

Description

This method has no parameters.

# Stop the robot if the controller disconnects
robot.move_at(0)

while True:
    if not controller.is_connected():
        robot.stop_all_movement()

    wait(100, MSEC)

get_battery_level#

get_battery_level returns the controller’s battery level as a number from 0 to 100.

Usage:
controller.get_battery_level()

Parameters

Description

This method has no parameters.

# Display the controller's battery level
robot.screen.print(controller.get_battery_level())

Callbacks#

.pressed#

.pressed runs a function when the specified button is pressed. Once it is used, the function will run automatically each time that button is pressed.

Usage:
One of five available button objects can be used with this method:

Button

Command

button_up

controller.button_up.pressed(callback, arg) — The Up button

button_down

controller.button_down.pressed(callback, arg) — The Down button

button_left

controller.button_left.pressed(callback, arg) — The Left button

button_right

controller.button_right.pressed(callback, arg) — The Right button

button_stick

controller.button_stick.pressed(callback, arg) — The Joystick button

VEX AIM One Stick Controller with a joystick on the left and four buttons to the right. The joystick and four buttons are highlighted.

Parameter

Description

callback

A previously defined function to run each time the specified button is pressed.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information.

# Kick hard when the Up button is pressed
def kick_object():
    robot.kicker.kick(HARD)

controller.button_up.pressed(kick_object)

.released#

.released runs a function when the specified button is released. Once it is used, the function will run automatically each time that button is released.

Usage:
One of five available button objects can be used with this method:

Button

Command

button_up

controller.button_up.released(callback, arg) — The Up button

button_down

controller.button_down.released(callback, arg) — The Down button

button_left

controller.button_left.released(callback, arg) — The Left button

button_right

controller.button_right.released(callback, arg) — The Right button

button_stick

controller.button_stick.released(callback, arg) — The Joystick button

VEX AIM One Stick Controller with a joystick on the left and four buttons to the right. The joystick and four buttons are highlighted.

Parameter

Description

callback

A previously defined function to run each time the specified button is released.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information.

# Clear the screen after the Up button is released
def clear_screen():
    robot.screen.clear_screen()

controller.button_up.released(clear_screen)

robot.screen.print("Press Up, then")
robot.screen.next_row()
robot.screen.print("Release Up!")

.changed#

.changed runs a function when the joystick’s position changes along the specified axis. Once it is used, the function will run automatically each time the joystick’s position changes along that axis.

Usage:
One of two available axis objects can be used with this method:

Axis

Command

axis1

controller.axis1.changed(callback, arg) — The vertical axis

axis2

controller.axis2.changed(callback, arg) — The horizontal axis

VEX AIM Controller with a joystick on the left and four buttons to the right. The 1 and 2 axes for the joystick are highlighted.

Parameter

Description

callback

A previously defined function to run each time the joystick’s position changes along the specified axis.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information.

# Show an emoji when the joystick moves up or down
def move_joystick():
    robot.screen.show_emoji(CONFUSED)

controller.axis1.changed(move_joystick)