THE PYTHON LIBRARY.
racecar-neo-library is the Python module every student writes against. Five modules under an rc.* namespace, with identical signatures in the NeoRacer Playground browser simulator and on the physical car. The same file works in both places.
drive · controller
THE FIVE MODULES.
Click any module to see the methods it exposes. Every behaviour you'll ever ship (, wall follow, gap follower, end-to-end RL) is some combination of these five.
THE LIDAR SCAN.
The sweep on the left is what the scanner is doing while you read this. Each tick mark is one of the 720 samples get_samples() hands you. The full coordinate frame and array layout live on the LiDAR hardware page.
- Index 0 is dead ahead. Index 360 is directly behind. The array sweeps clockwise.
- Samples come back in centimetres. A 0 means no return inside the range gate.
- One scan arrives every ~33 ms. Reading it inside
update()is fast enough for any you'll write.
DRIVE A SQUARE.
The smallest interesting program. The Python tab is the file you save. The other two tabs show how to run it in the Playground or on the car.
import racecar_core
rc = racecar_core.create_racecar()
SIDE_TIME = 1.0 # seconds per straight leg
TURN_TIME = 0.7 # seconds per 90-degree turn
SPEED = 0.25 # 25% throttle
TURN = 1.0 # full lock
timer = 0.0
leg = 0 # 8 legs: even legs drive straight, odd legs turn
def start():
global timer, leg
timer, leg = 0.0, 0
rc.drive.stop()
def update():
global timer, leg
if leg >= 8: # four straights + four turns
rc.drive.stop()
return
timer += rc.get_delta_time() # seconds since the last frame
if leg % 2 == 0:
rc.drive.set_speed_angle(SPEED, 0)
if timer > SIDE_TIME:
leg, timer = leg + 1, 0.0
else:
rc.drive.set_speed_angle(SPEED, TURN)
if timer > TURN_TIME:
leg, timer = leg + 1, 0.0
rc.set_start_update(start, update)
rc.go()TWO WAYS TO SHIP.
The Playground is the comfortable place to iterate until you trust the behaviour, and the same file then runs on the car without a single change. The runtime swaps the Pyodide-backed sensor sources for the ones for you.
- In the sim: the flow is to open NeoRacer Playground, paste the script into the editor, and press Run. Pyodide spins up a Web Worker, and your code executes inside it.
- On the car: SSH in, the file lands in
~/scripts/, andpython3 ~/scripts/drive_square.pyruns it.
