These docs are public and open source.Edit on GitHub
API REFERENCE / PYTHON
RC.LIDAR.
The module is your sense of distance. One call hands you the current scan in centimetres: ~1440 samples on the car, 720 in the Playground sim. Work in degrees through the rc_utils helpers or index relative to len(scan), and the same program runs unchanged on both.
~1440 samples · 0.25°270° live windowindex 0 = forwardno return = 0
SIM AND CAR
SAME DEGREES, DIFFERENT COUNTS.
The API and the angle conventions are identical everywhere: index 0 forward, clockwise, centimetres. The sample count is not, so a program that hardcodes an index breaks the moment it changes platform. Work in degrees, or divide len(scan).
| NeoRacer | Playground sim | |
|---|---|---|
| Samples per scan | ~1440 | 720 |
| Angle per sample | 0.25° | 0.5° |
| Coverage | 360° array · 270° live | 360° |
| 90° right | scan[len(scan) // 4] | scan[len(scan) // 4] |
pythonscan = rc.lidar.get_samples() right = scan[len(scan) // 4] # 90° right on any platform rear = scan[len(scan) // 2] # directly behind (0 on the car: rear wedge) # or skip indexing entirely and work in degrees: right = rc_utils.get_lidar_average_distance(scan, 90)
METHODS
THE LIDAR METHODS.
HELPERS · RACECAR_UTILS
LIDAR HELPERS.
Reading a direction by hand means converting an angle to an index and averaging a window. The racecar_utils module (imported as rc_utils) already does it, so most programs use these two instead of indexing the raw array.
TYPICAL USE
A WALL-STOP EXAMPLE.
pythonimport sys sys.path.insert(0, "../library") # the racecar-neo library on the car import racecar_core import racecar_utils as rc_utils rc = racecar_core.create_racecar() def start(): rc.drive.set_max_speed(0.4) # a calmer scale for close-quarters work def update(): scan = rc.lidar.get_samples() # ~1440 distances on the car, cm # average distance in a 10-degree window straight ahead front = rc_utils.get_lidar_average_distance(scan, 0, 10) rc.drive.set_speed_angle(0.0 if front < 50 else 0.3, 0) rc.set_start_update(start, update) rc.go()
