rc.controllerNEORACER DOCS
NEORACER DOCS
These docs are public and open source.Edit on GitHub
API REFERENCE / PYTHON

RC.CONTROLLER.

The Controller module reads the Xbox controller: buttons, the two analog triggers, and the two joysticks. It is also where your safety lives, since most programs watch a button here for a manual stop. The same calls work against the on-screen controls in the Playground sim.

Sim ↔ car identical8 buttons2 sticks · 2 triggers
METHODS

THE METHODS.

rc.controller.is_down(button)returns bool

True for every frame the button is held. Use it for "while I hold A, drive".

button: ButtonOne of the Button values below.
rc.controller.was_pressed(button)returns bool

True only on the single frame the button goes down. Use it for "each time A is tapped, toggle something".

button: ButtonOne of the Button values below.
rc.controller.was_released(button)returns bool

True only on the frame the button comes back up. The mirror of was_pressed.

button: ButtonOne of the Button values below.
rc.controller.get_trigger(trigger)returns float

How far a trigger is pulled, from 0.0 (released) to 1.0 (fully pressed). Analog, so it makes a smooth throttle.

trigger: TriggerTrigger.LEFT or Trigger.RIGHT.
rc.controller.get_joystick(joystick)returns tuple[float, float]

The (x, y) position of a stick, each from -1.0 to 1.0. x is left-right, y is down-up. Centre is (0, 0).

joystick: JoystickJoystick.LEFT or Joystick.RIGHT.
//Enums you pass in
rc.controller.Button
A · B · X · Y · LB · RB · LJOY · RJOY
rc.controller.Joystick
LEFT · RIGHT
rc.controller.Trigger
LEFT · RIGHT
TYPICAL USE

A TYPICAL LOOP.

python
import racecar_core rc = racecar_core.create_racecar() def start(): rc.drive.stop() def update(): # B is a manual stop. was_pressed fires once, on the tap. if rc.controller.was_pressed(rc.controller.Button.B): rc.drive.stop() return # Left stick x steers; hold A to creep forward. x, _ = rc.controller.get_joystick(rc.controller.Joystick.LEFT) speed = 0.3 if rc.controller.is_down(rc.controller.Button.A) else 0.0 rc.drive.set_speed_angle(speed, x) rc.set_start_update(start, update) rc.go()