LeishenMS10
- class quanser.devices.interfaces.LeishenMS10
A Python wrapper for the Quanser Devices API interface to Leishen MS10 ranging sensors.
Example
>>> from quanser.devices import LeishenMS10 >>> lidar = LeishenMS10()
- close()
Closes the current open LeishenMS10 device.
Example
>>> from quanser.devices import LeishenMS10 >>> lidar = LeishenMS10() >>> lidar.open("serial-cpu://localhost:2?baud='460800',word='8',parity='none',stop='1',flow='none'") ... ... ... >>> lidar.close()
- open(uri, samples_per_scan=1008)
Opens the specified Leishen MS10 LIDAR with the given parameters.
- Parameters
uri (string) – A URI used for communicating with the device. Numerous URI parameters are available.
samples_per_scan (int) – The number of samples per scan. This value defaults to 1008.
Example
>>> from quanser.devices import LeishenMS10 >>> lidar = LeishenMS10() >>> lidar.open("serial-cpu://localhost:2?baud='460800',word='8',parity='none',stop='1',flow='none'") ... ... ... >>> 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 LeishenMS10, RangingMeasurements, RangingMeasurementMode >>> num_measurements = 1008 >>> measurements = RangingMeasurements(num_measurments) >>> lidar = LeishenMS10() >>> lidar.open("serial-cpu://localhost:2?baud='460800',word='8',parity='none',stop='1',flow='none'") >>> 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 LeishenMS10, RangingMeasurements, RangingMeasurementMode >>> num_measurements = 720 >>> measurements = RangingMeasurements(num_measurements) >>> lidar = LeishenMS10() >>> lidar.open("serial-cpu://localhost:2?baud='460800',word='8',parity='none',stop='1',flow='none'") >>> for i in range(100): ... lidar.read(RangingMeasurementMode.INTERPOLATED, 0.05, 0.1, measurements) ... ... ... >>> lidar.close()