Skip to content

Commit 724deda

Browse files
Fixed typos in adafruid_rplidar.py; wrapped new spelling of iter_measurments for compatibility
1 parent de5f6fe commit 724deda

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

adafruit_rplidar.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
* Adafruit CircuitPython firmware for the supported boards:
4242
https://github.com/adafruit/circuitpython/releases
4343
44-
Version 0.0.1 does NOT support CircutPython. Future versions will.
44+
Version 0.0.1 does NOT support CircuitPython. Future versions will.
4545
"""
4646

47+
import struct
4748
import sys
4849
import time
49-
import struct
50+
import warnings
5051

5152
# pylint:disable=invalid-name,undefined-variable,global-variable-not-assigned
5253
# pylint:disable=too-many-arguments
@@ -91,7 +92,7 @@ class RPLidarException(Exception):
9192

9293

9394
def _process_scan(raw):
94-
"""Processes input raw data and returns measurment data"""
95+
"""Processes input raw data and returns measurement data"""
9596
new_scan = bool(raw[0] & 0b1)
9697
inversed_new_scan = bool((raw[0] >> 1) & 0b1)
9798
quality = raw[0] >> 2
@@ -116,7 +117,7 @@ class RPLidar:
116117
baudrate = 115200 #: Baudrate for serial port
117118

118119
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.
120121
121122
Parameters
122123
@@ -189,7 +190,7 @@ def set_pwm(self, pwm):
189190
self._send_payload_cmd(SET_PWM_BYTE, payload)
190191

191192
def _control_motor(self, val):
192-
"""Manipular the motor"""
193+
"""Manipulate the motor"""
193194
if self.is_CP:
194195
self.motor_pin.value = val
195196
else:
@@ -313,42 +314,42 @@ def clear_input(self):
313314
"""Clears input buffer by reading all available data"""
314315

315316
def stop(self):
316-
"""Stops scanning process, disables laser diode and the measurment
317+
"""Stops scanning process, disables laser diode and the measurement
317318
system, moves sensor to the idle state."""
318-
self.log("info", "Stoping scanning")
319+
self.log("info", "Stopping scanning")
319320
self._send_cmd(STOP_BYTE)
320321
time.sleep(0.001)
321322
self.clear_input()
322323

323324
def reset(self):
324325
"""Resets sensor core, reverting it to a similar state as it has
325326
just been powered up."""
326-
self.log("info", "Reseting the sensor")
327+
self.log("info", "Resetting the sensor")
327328
self._send_cmd(RESET_BYTE)
328329
time.sleep(0.002)
329330

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,
332333
otherwise data will be accumulated inside buffer and consumer will get
333-
data with increaing lag.
334+
data with increasing lag.
334335
335336
Parameters
336337
337338
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.
340341
341342
Yields
342343
343344
new_scan : bool
344-
True if measurment belongs to a new scan
345+
True if measurement belongs to a new scan
345346
quality : int
346347
Reflected laser pulse strength
347348
angle : float
348-
The measurment heading angle in degree unit [0, 360)
349+
The measurement heading angle in degree unit [0, 360)
349350
distance : float
350351
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.
352353
"""
353354
self.start_motor()
354355
status, error_code = self.health
@@ -387,12 +388,19 @@ def iter_measurments(self, max_buf_meas=500):
387388
if data_in_buf > max_buf_meas * dsize:
388389
self.log(
389390
"warning",
390-
"Too many measurments in the input buffer: %d/%d. "
391+
"Too many measurements in the input buffer: %d/%d. "
391392
"Clearing buffer..." % (data_in_buf // dsize, max_buf_meas),
392393
)
393394
self._serial_port.read(data_in_buf // dsize * dsize)
394395
yield _process_scan(raw)
395396

397+
def iter_measurments(self, max_buf_meas=500):
398+
"""For compatibility, this method wraps `iter_measurements`"""
399+
warnings.warn("The method `iter_measurments` has been renamed "
400+
"`iter_measurements` to correct spelling",
401+
PendingDeprecationWarning)
402+
self.iter_measurements(max_buf_meas=max_buf_meas)
403+
396404
def iter_scans(self, max_buf_meas=500, min_len=5):
397405
"""Iterate over scans. Note that consumer must be fast enough,
398406
otherwise data will be accumulated inside buffer and consumer will get
@@ -401,20 +409,20 @@ def iter_scans(self, max_buf_meas=500, min_len=5):
401409
Parameters
402410
403411
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.
412+
Maximum number of measurements to be stored inside the buffer. Once
413+
number exceeds this limit buffer will be emptied out.
406414
min_len : int
407-
Minimum number of measurments in the scan for it to be yelded.
415+
Minimum number of measurements in the scan for it to be yielded.
408416
409417
Yields
410418
411419
scan : list
412-
List of the measurments. Each measurment is tuple with following
420+
List of the measurements. Each measurement is tuple with following
413421
format: (quality, angle, distance). For values description please
414-
refer to `iter_measurments` method's documentation.
422+
refer to `iter_measurements` method's documentation.
415423
"""
416424
scan = []
417-
iterator = self.iter_measurments(max_buf_meas)
425+
iterator = self.iter_measurements(max_buf_meas)
418426
for new_scan, quality, angle, distance in iterator:
419427
if new_scan:
420428
if len(scan) > min_len:

0 commit comments

Comments
 (0)