Controller#
rc.controller
Copyright MIT MIT License
BWSI Autonomous RACECAR Course Racecar Neo LTS
File Name: controller.py File Description: Defines the interface of the Controller module of the racecar_core library.
- class controller.Controller#
Handles input from the controller and exposes constant input state per frame.
- class Button(value)#
The buttons on the controller.
- A = 0#
- B = 1#
- LB = 4#
- LJOY = 6#
- RB = 5#
- RJOY = 7#
- X = 2#
- Y = 3#
- abstract get_joystick(joystick: Joystick) tuple[float, float] #
Returns the position of a certain joystick as an (x, y) tuple.
- Parameters:
joystick – Which joystick to check.
- Returns:
The x and y coordinate of the joystick, with each axis ranging from -1.0 (left or down) to 1.0 (right or up).
Note
The joystick argument must be an associated value of the Joystick enum, which is defined in the Controller module.
Example:
# x and y will be given values from -1.0 to 1.0 based on the position of # the left joystick (x, y) = rc.controller.get_joystick(rc.controller.Joystick.LEFT)
- abstract get_trigger(trigger: Trigger) float #
Returns the position of a certain trigger as a value from 0.0 to 1.0.
- Parameters:
trigger – Which trigger to check.
- Returns:
A value ranging from 0.0 (not pressed) to 1.0 (fully pressed) inclusive.
Note
The trigger argument must be an associated value of the Trigger enum, which is defined in the Controller module.
Example:
# Speed will receive a value from 0.0 to 1.0 based on how much the left # trigger is pressed speed = rc.controller.get_trigger(rc.controller.Trigger.LEFT)
- abstract is_down(button: Button) bool #
Returns whether a certain button is currently pressed.
- Parameters:
button – Which button to check.
- Returns:
True if button is currently pressed.
Note
The button argument must be an associated value of the Button enum, which is defined in the Controller module.
Example:
# This update function will print a message for every frame in which # the A button is held down. Thus, multiple messages will be printed # if we press and hold the A button def update(): if rc.controller.is_down(rc.controller.Button.A): print("The A button is currently pressed.")
- abstract was_pressed(button: Button) bool #
Returns whether a certain button was pressed this frame.
- Parameters:
button – Which button to check.
- Returns:
True if button is currently pressed and was not pressed last frame.
Note
The button argument must be an associated value of the Button enum, which is defined in the Controller module.
Example:
# This update function will print a single message each time the A # button is pressed on the controller def update(): if rc.controller.was_pressed(rc.controller.Button.A): print("The A button was pressed")
- abstract was_released(button: Button) bool #
Returns whether a certain button was released this frame.
- Parameters:
button – Which button to check.
- Returns:
True if button is currently released and was pressed last frame.
Note
The button argument must be an associated value of the Button enum, which is defined in the Controller module.
Example:
# This update function will print a single message each time the A # button is released on the controller def update(): if rc.controller.was_released(rc.controller.Button.A): print("The A button was released")