Lidar - SmartAsphalt159/Controls GitHub Wiki
Setup
Hardware
Use a microUSB data cable to connect the LIDAR to the microcomputer. ls /dev
and look for ttyUSB0. If TTYUSB0 is not shown, use sudo lsusb
. If Cygnal Integrated Products
is shown it is connected. If not, the cable may be a power not data cable.
Software
Install the RPLidar using pip
> pip install rplidar
Usage
Once installed via pip, import into python
>>> from rplidar import RPLidar
Create instance of RPLidar object
>>> lidar = RPLidar('/dev/ttyUSB0')
To get the status of the LIDAR, use lidar.get_health()
To get info of the LIDAR including model, firmware version, and serial number, use lidar.get_info()
lidar.stop()
stops scanning and disables the laser putting the system into an idle state.
lidar.reset()
resets the sensor and puts it into a state similar to startup
lidar.iter_measurements(max_buf_meas)
and lidar.iter_scans(max_buf_meas,min_len)
create generators with a default buffer length of 500. lidar.iter_measurements(max_buf_meas)
iterates individual measurements and lidar.iter_scans(max_buf_meas,min_len)
iterates over a scan with a default minimum of stored measurements within a single scan of 5.
Example
from rplidar import RPLidar
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
for i, scan in enumerate(lidar.iter_scans()):
... print('%d: Got %d measurments' % (i, len(scan)))
... if i > 10:
... break
lidar.stop()
lidar.stop_motor()
lidar.disconnect()