Lidar Drivers
RPLidar2
Adafruit RPLidar driver with filtering and batch processing. Constructor:float
default:"0.0"
Minimum angle to include (degrees, 0-360)
float
default:"360.0"
Maximum angle to include (degrees, 0-360)
float
default:"sys.float_info.min"
Minimum distance to include (millimeters)
float
default:"sys.float_info.max"
Maximum distance to include (millimeters)
float
default:"0.0"
Angle that represents “forward” direction (degrees)
int
default:"CLOCKWISE"
Direction of angle increase: CLOCKWISE (1) or COUNTER_CLOCKWISE (-1)
float
default:"50"
Time in milliseconds to collect measurements in run() mode
bool
default:"false"
Enable debug logging
() -> list
Collect measurements for batch_ms duration and return list of (distance, angle, time, scan, index) tuples
() -> list
Return most recent measurements from background thread
() -> None
Continuously poll lidar in background thread
() -> None
Stop lidar and release resources
distance: Distance in millimeters (float)angle: Angle in degrees (float), adjusted for forward_angletimestamp: Time in seconds (float)scan_number: Full scan sequence number (int)index_in_scan: Index within current scan (int)
- Scan rate: ~7 scans/second
- Measurement rate: ~1850 measurements/second
RPLidar (Legacy)
Simpler RPLidar interface (deprecated, use RPLidar2). Constructor:float
default:"0"
Lower angle limit (degrees)
float
default:"360"
Upper angle limit (degrees)
() -> np.ndarray
Returns sorted distances as NumPy array
YDLidar
YDLidar X4 driver. Constructor:str
default:"/dev/ttyUSB0"
Serial port for lidar
() -> (distances, angles)
Returns tuple of (distance_list, angle_list)
Visualization
LidarPlot2
Plots lidar measurements as a polar plot image. Constructor:tuple
default:"(500, 500)"
Output image size in pixels (width, height)
int
default:"PLOT_TYPE_CIRCLE"
PLOT_TYPE_CIRCLE or PLOT_TYPE_LINE
int
default:"3"
Size of measurement marks in pixels
float
default:"4000"
Maximum distance to plot (millimeters)
int
default:"COUNTER_CLOCKWISE"
Direction of increasing angles
float
default:"0"
Angle to rotate plot (degrees)
tuple
default:"(224, 224, 224)"
RGB background color
tuple
default:"(128, 128, 128)"
RGB border color
tuple
default:"(255, 64, 64)"
RGB measurement point color
(measurements: list) -> PIL.Image
Convert measurements to polar plot image
LidarPlot (Legacy)
Simpler plotting interface (deprecated, use LidarPlot2). Constructor:SLAM Mapping
BreezySLAM
Simple SLAM implementation for map building. Constructor:int
default:"500"
Map resolution in pixels
int
default:"10"
Map size in meters
(distances, angles, map_bytes) -> (x, y, theta)
Update SLAM with new scan and return position estimate
BreezyMap
Map byte storage for BreezySLAM. Constructor:() -> bytearray
Return map bytes
MapToImage
Converts SLAM map bytes to PIL image. Constructor:(map_bytes: bytearray) -> PIL.Image
Convert map to image
Obstacle Detection
Simple Obstacle Detector
Configuration
Typical lidar configuration inmyconfig.py:
Integration Example
Complete Lidar Setup
Troubleshooting
Lidar Not Found
Symptoms: RuntimeError: “No RPLidar is connected” Solutions:- Check USB connection:
ls /dev/ttyUSB* - Verify permissions:
sudo chmod 666 /dev/ttyUSB0 - Check power supply (lidar needs 5V)
Serial Port Conflicts
Symptoms: SerialException Solutions:- Close other programs using the port
- Unplug and replug USB
- Reboot
Poor Quality Scans
Symptoms: Noisy or incomplete scans Solutions:- Clean lidar lens
- Avoid reflective surfaces
- Check motor speed (should be steady)
- Reduce ambient light
Performance Tips
- Use threading: Always run lidar in threaded mode
- Filter data: Use angle and distance filters to reduce data
- Batch processing: Adjust batch_ms for your needs
- Visualization: Reduce plot resolution for better performance
