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
¶ Class representing a Express type Packet
-
classmethod
from_string
(data)¶ Decode and Instantiate the class from a string packet
-
classmethod
-
class
adafruit_rplidar.
RPLidar
(motor_pin, port, baudrate=115200, timeout=1, logging=False)¶ Class for communicating with RPLidar rangefinder scanners
-
baudrate
= 115200¶ Baudrate for serial port
-
clear_input
()¶ Clears input buffer by reading all available data
-
connect
()¶ Connects to the serial port named by the port instance var. If it was connected to another serial port disconnects from it first.
-
disconnect
()¶ Disconnects from the serial port
-
health
¶ 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
- status : str
- ‘Good’, ‘Warning’ or ‘Error’ statuses
- error_code : int
- The related error code that caused a warning/error.
-
info
¶ Get device information
Returns
- dict
- Dictionary with the sensor information
-
iter_measurements
(max_buf_meas=500, scan_type=0)¶ 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_meas : int
- Maximum number of measurements to be stored inside the buffer. Once number exceeds this limit buffer will be emptied out.
Yields
- new_scan : bool
- True if measurement belongs to a new scan
- quality : int
- Reflected laser pulse strength
- angle : float
- The measurement heading angle in degree unit [0, 360)
- distance : float
- 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=500)¶ For compatibility, this method wraps
iter_measurements
-
iter_scans
(max_buf_meas=500, min_len=5)¶ 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_meas : int
- Maximum number of measurements to be stored inside the buffer. Once number exceeds this limit buffer will be emptied out.
- min_len : int
- Minimum number of measurements in the scan for it to be yielded.
Yields
- scan : list
- 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, msg)¶ Output the level and a message if logging is enabled.
-
log_bytes
(level, msg, ba)¶ 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
()¶ Resets sensor core, reverting it to a similar state as it has just been powered up.
-
set_pwm
(pwm)¶ Set the motor PWM
-
start
(scan_type=0)¶ Start the scanning process Parameters ———- scan : normal, force or express.
-
start_motor
()¶ Starts sensor motor
-
stop
()¶ Stops scanning process, disables laser diode and the measurement system, moves sensor to the idle state.
-
stop_motor
()¶ Stops sensor motor
-
timeout
= 1¶ Serial port timeout
-
-
exception
adafruit_rplidar.
RPLidarException
¶ Basic exception class for RPLidar