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

RC.LIDAR.

The module is your 360° sense of distance. One call hands you a flat array of 720 distances in centimetres, and the library gives you the exact same array in the Playground sim and on the car, so a wall-follower you write in the browser runs unchanged on the NeoRacer.

Sim ↔ car identical720 samples0.5° apartindex 0 = forward
METHODS

THE LIDAR METHODS.

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

The current scan as a flat array of 720 distances in centimetres. Index 0 is directly ahead and the samples run clockwise, so each index is 0.5° from the next.

rc.lidar.get_num_samples()returns int

How many samples a full scan contains. Always 720 on the NeoRacer, so you rarely need it, but it keeps a loop honest if you index relative to the length.

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

The same 720-float scan, but 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.

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.

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".

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 racecar_core import racecar_utils as rc_utils rc = racecar_core.create_racecar() def start(): rc.drive.set_max_speed(0.4) def update(): scan = rc.lidar.get_samples() # 720 distances, 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()