41
41
* Adafruit CircuitPython firmware for the supported boards:
42
42
https://github.com/adafruit/circuitpython/releases
43
43
44
- Version 0.0.1 does NOT support CircutPython . Future versions will.
44
+ Version 0.0.1 does NOT support CircuitPython . Future versions will.
45
45
"""
46
46
47
+ import struct
47
48
import sys
48
49
import time
49
- import struct
50
+ import warnings
50
51
51
52
# pylint:disable=invalid-name,undefined-variable,global-variable-not-assigned
52
- # pylint:disable=too-many-arguments
53
+ # pylint:disable=too-many-arguments,raise-missing-from
53
54
54
55
__version__ = "0.0.1-auto.0"
55
56
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RPLIDAR.git"
@@ -91,7 +92,7 @@ class RPLidarException(Exception):
91
92
92
93
93
94
def _process_scan (raw ):
94
- """Processes input raw data and returns measurment data"""
95
+ """Processes input raw data and returns measurement data"""
95
96
new_scan = bool (raw [0 ] & 0b1 )
96
97
inversed_new_scan = bool ((raw [0 ] >> 1 ) & 0b1 )
97
98
quality = raw [0 ] >> 2
@@ -116,7 +117,7 @@ class RPLidar:
116
117
baudrate = 115200 #: Baudrate for serial port
117
118
118
119
def __init__ (self , motor_pin , port , baudrate = 115200 , timeout = 1 , logging = False ):
119
- """Initilize RPLidar object for communicating with the sensor.
120
+ """Initialize RPLidar object for communicating with the sensor.
120
121
121
122
Parameters
122
123
@@ -189,7 +190,7 @@ def set_pwm(self, pwm):
189
190
self ._send_payload_cmd (SET_PWM_BYTE , payload )
190
191
191
192
def _control_motor (self , val ):
192
- """Manipular the motor"""
193
+ """Manipulate the motor"""
193
194
if self .is_CP :
194
195
self .motor_pin .value = val
195
196
else :
@@ -313,42 +314,42 @@ def clear_input(self):
313
314
"""Clears input buffer by reading all available data"""
314
315
315
316
def stop (self ):
316
- """Stops scanning process, disables laser diode and the measurment
317
+ """Stops scanning process, disables laser diode and the measurement
317
318
system, moves sensor to the idle state."""
318
- self .log ("info" , "Stoping scanning" )
319
+ self .log ("info" , "Stopping scanning" )
319
320
self ._send_cmd (STOP_BYTE )
320
321
time .sleep (0.001 )
321
322
self .clear_input ()
322
323
323
324
def reset (self ):
324
325
"""Resets sensor core, reverting it to a similar state as it has
325
326
just been powered up."""
326
- self .log ("info" , "Reseting the sensor" )
327
+ self .log ("info" , "Resetting the sensor" )
327
328
self ._send_cmd (RESET_BYTE )
328
329
time .sleep (0.002 )
329
330
330
- def iter_measurments (self , max_buf_meas = 500 ):
331
- """Iterate over measurments . Note that consumer must be fast enough,
331
+ def iter_measurements (self , max_buf_meas = 500 ):
332
+ """Iterate over measurements . Note that consumer must be fast enough,
332
333
otherwise data will be accumulated inside buffer and consumer will get
333
- data with increaing lag.
334
+ data with increasing lag.
334
335
335
336
Parameters
336
337
337
338
max_buf_meas : int
338
- Maximum number of measurments to be stored inside the buffer. Once
339
- numbe exceeds this limit buffer will be emptied out.
339
+ Maximum number of measurements to be stored inside the buffer. Once
340
+ number exceeds this limit buffer will be emptied out.
340
341
341
342
Yields
342
343
343
344
new_scan : bool
344
- True if measurment belongs to a new scan
345
+ True if measurement belongs to a new scan
345
346
quality : int
346
347
Reflected laser pulse strength
347
348
angle : float
348
- The measurment heading angle in degree unit [0, 360)
349
+ The measurement heading angle in degree unit [0, 360)
349
350
distance : float
350
351
Measured object distance related to the sensor's rotation center.
351
- In millimeter unit. Set to 0 when measurment is invalid.
352
+ In millimeter unit. Set to 0 when measurement is invalid.
352
353
"""
353
354
self .start_motor ()
354
355
status , error_code = self .health
@@ -387,12 +388,21 @@ def iter_measurments(self, max_buf_meas=500):
387
388
if data_in_buf > max_buf_meas * dsize :
388
389
self .log (
389
390
"warning" ,
390
- "Too many measurments in the input buffer: %d/%d. "
391
+ "Too many measurements in the input buffer: %d/%d. "
391
392
"Clearing buffer..." % (data_in_buf // dsize , max_buf_meas ),
392
393
)
393
394
self ._serial_port .read (data_in_buf // dsize * dsize )
394
395
yield _process_scan (raw )
395
396
397
+ def iter_measurments (self , max_buf_meas = 500 ):
398
+ """For compatibility, this method wraps `iter_measurements`"""
399
+ warnings .warn (
400
+ "The method `iter_measurments` has been renamed "
401
+ "`iter_measurements` to correct spelling" ,
402
+ PendingDeprecationWarning ,
403
+ )
404
+ self .iter_measurements (max_buf_meas = max_buf_meas )
405
+
396
406
def iter_scans (self , max_buf_meas = 500 , min_len = 5 ):
397
407
"""Iterate over scans. Note that consumer must be fast enough,
398
408
otherwise data will be accumulated inside buffer and consumer will get
@@ -401,20 +411,20 @@ def iter_scans(self, max_buf_meas=500, min_len=5):
401
411
Parameters
402
412
403
413
max_buf_meas : int
404
- Maximum number of measurments to be stored inside the buffer. Once
405
- numbe exceeds this limit buffer will be emptied out.
414
+ Maximum number of measurements to be stored inside the buffer. Once
415
+ number exceeds this limit buffer will be emptied out.
406
416
min_len : int
407
- Minimum number of measurments in the scan for it to be yelded .
417
+ Minimum number of measurements in the scan for it to be yielded .
408
418
409
419
Yields
410
420
411
421
scan : list
412
- List of the measurments . Each measurment is tuple with following
422
+ List of the measurements . Each measurement is tuple with following
413
423
format: (quality, angle, distance). For values description please
414
- refer to `iter_measurments ` method's documentation.
424
+ refer to `iter_measurements ` method's documentation.
415
425
"""
416
426
scan = []
417
- iterator = self .iter_measurments (max_buf_meas )
427
+ iterator = self .iter_measurements (max_buf_meas )
418
428
for new_scan , quality , angle , distance in iterator :
419
429
if new_scan :
420
430
if len (scan ) > min_len :
0 commit comments