adafruit_rplidar
¶
Provide an interface to the Slamtech RPLidar that works in plain Python3 as well as CircuitPython/Blinka.
Author(s): Dave Astels
Based on https://github.com/SkoltechRobotics/rplidar by Artyom Pavlov
and updates from https://github.com/Roboticia/RPLidar by Julien JEHL
Implementation Notes¶
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
The Current Version does NOT support CircuitPython. Future versions will.
- class adafruit_rplidar.ExpressPacket(distance, angle, new_scan, start_angle)¶
Class representing a Express type Packet
- classmethod from_string(data: bytes) ExpressPacket ¶
Decode and Instantiate the class from a string packet
- class adafruit_rplidar.RPLidar(motor_pin: DigitalInOut, port: UART, baudrate: int = 115200, timeout: float = 1, logging: bool = False)¶
Class for communicating with RPLidar rangefinder scanners
- baudrate = 115200¶
Baudrate for serial port
- connect() None ¶
Connects to the serial port named by the port instance var. If it was connected to another serial port disconnects from it first.
- property health: Tuple[str, int]¶
Get device health state. When the core system detects some potential risk that may cause hardware failure in the future, the returned status value will be ‘Warning’. But sensor can still work as normal. When sensor is in the Protection Stop state, the returned status value will be ‘Error’. In case of warning or error statuses non-zero error code will be returned.
Returns
- statusstr
‘Good’, ‘Warning’ or ‘Error’ statuses
- error_codeint
The related error code that caused a warning/error.
- property info: Dict[str, Any]¶
Get device information
Returns
- dict
Dictionary with the sensor information
- iter_measurements(max_buf_meas: int = 500, scan_type: int = 0) Iterator[Tuple[bool, int | None, float, float]] ¶
Iterate over measurements. Note that consumer must be fast enough, otherwise data will be accumulated inside buffer and consumer will get data with increasing lag.
Parameters
- max_buf_measint, optional
Maximum number of measurements to be stored inside the buffer. Once number exceeds this limit buffer will be emptied out. Default is 500.
- scan_typeint, optional
Normal, force or express; default is normal
Yields
- new_scanbool
True if measurement belongs to a new scan
- qualityint | None
Reflected laser pulse strength
- anglefloat
The measurement heading angle in degree unit [0, 360)
- distancefloat
Measured object distance related to the sensor’s rotation center. In millimeter unit. Set to 0 when measurement is invalid.
- iter_measurments(max_buf_meas: int = 500) Iterator[Tuple[bool, int, float, float]] ¶
For compatibility, this method wraps
iter_measurements
- iter_scans(max_buf_meas: int = 500, min_len: int = 5) List[int | float] ¶
Iterate over scans. Note that consumer must be fast enough, otherwise data will be accumulated inside buffer and consumer will get data with increasing lag.
Parameters
- max_buf_measint, optional
Maximum number of measurements to be stored inside the buffer. Once number exceeds this limit buffer will be emptied out. Default is 500.
- min_lenint, optional
Minimum number of measurements in the scan for it to be yielded. Default is 5.
Yields
- scanlist
List of the measurements. Each measurement is tuple with following format: (quality, angle, distance). For values description please refer to
iter_measurements
method’s documentation.
- motor = False¶
Is motor running?
- motor_pin = None¶
DigitalInOut instance controlling the motor
- port = None¶
Serial port name, e.g. /dev/ttyUSB0
- start(scan_type: int = 0) None ¶
Start the scanning process
Parameters
- scan_typeint, optional
Normal, force or express; default is normal
- stop() None ¶
Stops scanning process, disables laser diode and the measurement system, moves sensor to the idle state.
- timeout = 1¶
Serial port timeout
- exception adafruit_rplidar.RPLidarException¶
Basic exception class for RPLidar