rc.lidarNEORACER DOCS
NEORACER DOCS
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).

NeoRacerPlayground sim
Samples per scan~1440720
Angle per sample0.25°0.5°
Coverage360° array · 270° live360°
90° rightscan[len(scan) // 4]scan[len(scan) // 4]
python
scan = 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.

rc.lidar.get_samples()returns NDArray[Float]

The current scan as a flat array of distances in centimetres. Index 0 is directly ahead and the samples run clockwise at equal angles. On the car a scan holds ~1440 samples (0.25° apart); in the simulator it holds 720 (0.5° apart), so index with len(scan), never a fixed number. A sample with no return reads 0.

rc.lidar.get_num_samples()returns int

How many samples a full scan contains: 1440 on the NeoRacer, 720 in the simulator. Use it (or len(scan)) whenever you index relative to the whole circle, for example scan[rc.lidar.get_num_samples() // 4] for 90° right.

rc.lidar.get_samples_async()returns NDArray[Float]

The same scan, readable outside the start/update loop. Use it in a one-off script or a notebook cell when the car is not in go mode. Before the first scan arrives it returns an empty array, so check len() when polling it directly.

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.

rc_utils.get_lidar_average_distance(scan, angle, window_angle=4)returns float

Average distance to whatever sits at a given angle, smoothed over a small window so one noisy ray does not throw you off. Works in degrees, so the same call is correct on the car and in the sim regardless of sample count.

scan: NDArrayThe array from rc.lidar.get_samples().
angle: floatDegrees clockwise from straight ahead. 0 is forward, 90 is right, 270 is left.
window_angle: floatTotal width of the averaging window in degrees. Defaults to 4.
rc_utils.get_lidar_closest_point(scan, window=(0, 360))returns tuple[float, float]

The (angle, distance) of the nearest return, optionally restricted to an angular window. Handy for "how close is the nearest wall, and where is it". Zero samples (no return) are ignored.

scan: NDArrayThe array from rc.lidar.get_samples().
window: tuple(start, end) degrees to search within. Defaults to the full circle.
TYPICAL USE

A WALL-STOP EXAMPLE.

python
import 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()