Neobotics Foundation Inc.
These docs are public and open source.Edit on GitHub

RC.LIDAR

The Lidar module provides the LiDAR's current scan, number of samples, and distances.

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.

rc.lidar.get_num_samples()returns int

Number of samples a full scan contains. Use it to index relative to the whole scan, for example scan[rc.lidar.get_num_samples() // 4] for 90° right.

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

The current scan but readable outside the start/update loop. This function should only be used in a Jupyter Notebook cell, after rc.go_async() has been called.

HELPERS

The racecar_utils module converts an angle to an index and averages a window.

racecar_utils.get_lidar_average_distance(scan: NDArray, angle: float, window_angle: float = 4)returns float

Returns the average distance in cm over a small window of samples centred on the given angle. scan is the samples from a lidar scan. angle is degrees clockwise from straight ahead: 0 is forward, 90 is right, 270 is left. window_angle is the number of degrees around angle. Defaults to 4.

racecar_utils.get_lidar_closest_point(scan: NDArray, window: tuple[float, float] = (0, 360))returns tuple[float, float]

Returns the (angle, distance) of the nearest return. scan is the samples from a lidar scan. window is the (start, end) degrees to search within. Defaults to (0, 360). Samples with no return are ignored.

EXAMPLE USAGE

python
import sys sys.path.insert(0, "../library") # the racecar-neo library on the car import racecar_core import racecar_utils rc = racecar_core.create_racecar() def start(): print("start: capping speed at 0.4") rc.drive.set_max_speed(0.4) def update(): scan = rc.lidar.get_samples() # ~1440 distances on the car, cm # average distance in a 10-degree window straight ahead front = racecar_utils.get_lidar_average_distance(scan, 0, 10) print(f"wall ahead at {front:.0f} cm") rc.drive.set_speed_angle(0.0 if front < 50 else 0.3, 0) rc.set_start_update(start, update) rc.go()

For full documentation, visit the racecar-neo-library documentation.