adafruit_rplidar

Provide an interface to the Slamtech RPLidar that works in plain Python3 as well as CircuitPython/Blinka.

Implementation Notes

Hardware:

Software and Dependencies:

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

clear_input() None

Clears input buffer by reading all available data

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.

disconnect() None

Disconnects from the serial port

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.

log(level: str, msg: str) None

Output the level and a message if logging is enabled.

log_bytes(level: str, msg: str, ba: bytes) None

Log and output a byte array in a readable way.

motor = False

Is motor running?

motor_pin = None

DigitalInOut instance controlling the motor

port = None

Serial port name, e.g. /dev/ttyUSB0

reset() None

Resets sensor core, reverting it to a similar state as it has just been powered up.

set_pwm(pwm: int) None

Set the motor PWM

start(scan_type: int = 0) None

Start the scanning process

Parameters

scan_typeint, optional

Normal, force or express; default is normal

start_motor() None

Starts sensor motor

stop() None

Stops scanning process, disables laser diode and the measurement system, moves sensor to the idle state.

stop_motor() None

Stops sensor motor

timeout = 1

Serial port timeout

exception adafruit_rplidar.RPLidarException

Basic exception class for RPLidar

class adafruit_rplidar.express_packet(distance, angle, new_scan, start_angle)
angle

Alias for field number 1

distance

Alias for field number 0

new_scan

Alias for field number 2

start_angle

Alias for field number 3