RPLIDAR

class quanser.devices.interfaces.RPLIDAR

A Python wrapper for the Quanser Devices API interface to RPLIDAR ranging sensors.

Example

>>> from quanser.devices import RPLIDAR
>>> lidar = RPLIDAR()
close()

Closes the current open RPLIDAR device.

Example

>>> from quanser.devices import RPLIDAR, RangingDistance
>>> lidar = RPLIDAR()
>>> lidar.open("serial-cpu://localhost:2?baud='115200',word='8',parity='none',stop='1',flow='none',dsr='on'",
...            RangingDistance.SHORT)
... ...
...
>>> lidar.close()
open(uri, ranging_distance)

Opens the specified RPLIDAR device with the given parameters.

Parameters
  • uri (string) – A URI used for communicating with the device. Numerous URI parameters are available.

  • ranging_distance (RangingDistance) – The type of ranging distance. Valid values are RangingDistance.SHORT, RangingDistance.MEDIUM, and RangingDistance.LONG.

Example

>>> from quanser.devices import RPLIDAR, RangingDistance
>>> lidar = RPLIDAR()
>>> lidar.open("serial-cpu://localhost:2?baud='115200',word='8',parity='none',stop='1',flow='none',dsr='on'",
...            RangingDistance.LONG)
... ...
...
>>> lidar.close()
read(mode, max_interpolated_distance, max_interpolated_angle, measurements)

Reads LIDAR data from the ranging sensor.

Parameters
  • mode (RangingMeasurementMode) –

    The measurement mode, which determines how the scan data is returned.

    When the measurement mode is RangingMeasurementMode.NORMAL, the “raw” sensor readings from the LIDAR are returned (but the values are scaled to the SI units expected). In this case, the number of measurements may vary and the angles may not be consistent between scans. Furthermore, while the angles will be in ascending order, the first angle may not be zero. It will, however, be close to zero. If the size of the measurements buffer provided is not large enough, then a -QERR_BUFFER_TOO_SMALL error will be raised. In this case, the function may be called again with a larger buffer.

    When the measurement mode is RangingMeasurementMode.INTERPOLATED, the raw sensor readings from the LIDAR are not returned. Instead, the number of “measurements” requested will be returned, in which the angles are 360/N degrees apart (in radians), where N is the number of measurements requested and the first angle is zero. The distances will be interpolated from the raw data, as will the standard deviation and quality. Interpolation is only performed between two consecutive valid readings. The advantage of this mode is that the angles are always consistent, as are the number of measurements, so the data is easier to process in Simulink.

  • max_interpolated_distance (float) – In interpolation mode, this is the maximum difference between the distance measurement of contiguous samples for which interpolation will be used. Beyond this difference, the distance of the sample with the closest angle to the desired heading will be used.

  • max_interpolated_angle (float) – In interpolation mode, this is the maximum difference between the angle measurement of contiguous samples for which interpolation will be used. Beyond this difference, the distance and quality will be set to zero.

  • measurements (indicating that no new) – A buffer in which the actual measurement data is stored.

  • Value (Return) –

  • ------------

  • zero (Returns the number of valid measurements. The result may be) –

  • measurements

  • available. (were) –

Notes

If the quality is zero, then it indicates an invalid measurement (no reflected laser pulse).

To efficiently access an array using numpy, use the frombuffer function to wrap the array with a numpy array. For example:

>>> buffer = array.array('i', [0]*7200))
>>> numpy.frombuffer(buffer)

Examples

Continuously read 100 samples of 720 measurements in normal mode.

>>> from quanser.devices import RPLIDAR, RangingMeasurements, RangingMeasurementMode
>>> num_measurements = 720
>>> measurements = RangingMeasurements(num_measurments)
>>> lidar = RPLIDAR()
>>> lidar.open("serial-cpu://localhost:2?baud='115200',word='8',parity='none',stop='1',flow='none',dsr='on'",
...            RangingDistance.LONG)
>>> for i in range(100):
...     lidar.read(RangingMeasurementMode.NORMAL, 0.0, 0.0, measurements)
...     ...
...
>>> lidar.close()

Continuously read 100 samples, consisting of measurements every half degree, in interpolated mode.

>>> from quanser.devices import RPLIDAR, RangingMeasurements, RangingMeasurementMode
>>> num_measurements = 720
>>> measurements = RangingMeasurements(num_measurements)
>>> lidar = RPLIDAR()
>>> lidar.open("serial-cpu://localhost:2?baud='115200',word='8',parity='none',stop='1',flow='none',dsr='on'",
...            RangingDistance.LONG)
>>> for i in range(100):
...     lidar.read(RangingMeasurementMode.INTERPOLATED, 0.05, 0.1, measurements)
...     ...
...
>>> lidar.close()