skoltechrobotics / rplidar Goto Github PK
View Code? Open in Web Editor NEWPython module for RPLidar A1 and A2 rangefinder scanners
License: MIT License
Python module for RPLidar A1 and A2 rangefinder scanners
License: MIT License
I am running an RPLidar A1M8 R5 model through the usb2serial board, into usb on a rasp pi 3b+. I have yet to be able to get any combination of commands involving stop() and stop_motor() to actually get the motor to stop sending/receiving, return to the "zero" point, and stop spinning. Has anyone else been successful in this?
The "get_info()" and "get_health()" functions work just fine. But the lidar scanner does not respond at all to the following stop commands....BUT, it DOES disconnect...
from rplidar import RPLidar
lidar = RPLidar('/dev/ttyUSB0')
lidar.stop()
lidar.stop_motor()
lidar.disconnect()
Hello, i am using an A3 lidar, I already changed the rplidar.py baudrate , now I am getting errors in rplidar line 211: dsize, is _single, dtype = self._read_descriptor()
and in line 189 in _read_descriptor
raise RPLidarException('Incorrect descriptor starting bytes')
rplidar.RPLidarException: Incorrect descriptor starting bytes
anyone has any idea how to fix this?
Hi, this is a great repository! All the examples work out great for me. The only problem I have is when I call lidar.iter_scan(), it returns measurement continuously and the program just stucks there so that I can not do that tasks in the code. I am curious how can I get one measurement at a time from lidar so that I can do others tasks in a while loop.
Pseudo code for my desired program is:
while True:
1. Get raspberry pi v2 camera image
2. Get measurement from lidar (when I use lidar.iter_scan(), lidar starts returning scans continuously and the program gets stuck here forever)
3. Command robot to move
Appreciate your help.
Output is below. I am not sure this is a library problem or a problem initiating the scanner on my side.
{'hardware': 2, 'model': 40, 'firmware': (1, 20), 'serialnumber': u'DAD28AC1E8839EF2C0E69EF702652105'}
('Good', 0)
Traceback (most recent call last):
File "lidar.py", line 15, in
for i, scan in enumerate(lidar.iter_scans()):
File "/usr/local/lib/python2.7/dist-packages/rplidar.py", line 357, in iter_scans
for new_scan, quality, angle, distance in iterator:
File "/usr/local/lib/python2.7/dist-packages/rplidar.py", line 326, in iter_measurments
data_in_buf = self._serial_port.in_waiting
AttributeError: 'Serial' object has no attribute 'in_waiting'
It was reported that A2 sensor is not powering up motor while using this driver.
Seems that A2 does not react to DTR (Data Terminal Ready) signal, in case of A1 its not only used for initiating communication channel, but also to turn on motor. Evidently because motor stays turned off lidar can't collect data and returns nothing, which results in error.
Unfortunately I don't have A2 to test code on it, so help are welcomed!
I am using the forked version from rplidar-roboticia @jjehl and run the example python code in my Raspberry Pi 3. I am new to python so I don't understand what cause this not working. The scanner motor is running but no scan datas are being read.
Traceback (most recent call last):
File "/home/pi/example.py", line 10, in
for i, scan in enumerate(lidar.iter_measures()):
File "/usr/local/lib/python3.5/dist-packages/rplidar.py", line 397, in iter_measures
raw = self._read_response(dsize)
File "/usr/local/lib/python3.5/dist-packages/rplidar.py", line 223, in _read_response
while self._serial.inWaiting() < dsize:
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 572, in inWaiting
return self.in_waiting
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 456, in in_waiting
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
OSError: [Errno 5] Input/output error
Hope someone can help me on this. Thank you and sorry for my bad english.
I came across an error while running RPLidar/examples/animate.py
It loaded for a few second then gave error message Illegal Instructions (core Dumped)
I am using a jetson nano (ubuntu)
Please help!
I have A1 with Raspberrypi 3B, and I have encountered the Wrong Body Size, that is because there is a mistake in the rplidar.py file when defining the function start_motor() ,and stop_motor ().
in rplidar.py it is " self._serial_port.setDTR(False) " & "self.motor_running = False" for start_motor(),
and "self._serial_port.setDTR(True)" & "self.motor_running = True" for stop_motor(),
you need to opposite them.
\x is a string escape code in python which cause some confusion for example in the reset function.
b = '\x40'
print(b)
'@'
because \x40 is the ascii code for '@'
I have a problem about pwm of rplidar.
I called lidar.set_pwm(250) and the rplidar exactly slow down.
But the motor speed up after I called lidar.iter_scan() to get data.
Could I acquire data with different frequency ?
Thanks!
when I run record_scans.py
and inside this for loop here :
try: print('Recording measurments... Press Crl+C to stop.') for scan in lidar.iter_scans(): data.append(np.array(scan)) except KeyboardInterrupt:
instead of data.append(np.array(scan)) line I print the "scan" object which is tuple that contain (quality,degree,distance)
but the problem is that I do not get 360 measurements in the scan, in each loop I get different number of measurement in a "scan" object, note that I did not change the lidar's position when it test it.
can you explain the cause or the solution to this problem urgently.
many thanks in advance
raise RPLidarException('Check bit not equal to 1')
rplidar.RPLidarException: Check bit not equal to 1
I've tried the python version on ubuntu and I keep getting about the third of the number of detected points resulted from the C++ version.
Using A1 Lidar
Thank you
When I run the scan method using the default pwm speed I only get around 120 scans back. Sometimes the gap is even 5 degrees. But when I lower the pwm speed and get back more samples, the speed between the samples is too low. Does anyone know how to fix this?
I modified the DEFAULT_MOTOR_PWM in 'rplidar.py' in the folder, but it did not change.
However, pwm did not change when I ran the examples.
How can I change the pwm?
1- "new_scan" is always False in txt file. What does that mean ?
2- What is the range of "quality" ? . What does it mean literally ? How can i improve it ?
"quality" always is one of either 0 or 15 for every scan.
Yields
------
new_scan : bool
True if measures belongs to a new scan
quality : int
Reflected laser pulse strength
angle : float
The measure 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 measure is invalid.
'''
In every 5 executions, there always are 4 times of "check bit not equal to 1" and 1 success. So weird :-)
Originally posted by @Cen-XIN in #23 (comment)
Same issue here!
I ran the simple example described in "README.md" for several times. Sometimes it threw the exception "check bit not equal to 1". Sometimes it worked well. I don't know why...
Btw I use RPLidar A1 and connect it to a Raspberry Pi 3B.
Its been almost one month and i could not find a way to animate the graph which will show the surrounding. can you please tell me where should i do the modification?
`from rplidar import RPLidar, RPLidarException
import matplotlib.pyplot as plt
import matplotlib.animation as animation
lidar = RPLidar('/dev/ttyUSB0')
info = lidar.get_info()
print(info)
health = lidar.get_health()
print(health)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='polar')
def run(i):
angle = []
distance = []
for i, scan in enumerate(lidar.iter_scans()):
for d in scan: # d[0] : Quality of the measurement
# if 0< d[1] <200: #d[1] : Angle of the measurement
# print(d[2]/10) #d[2] : Distance of the measurement '''
angle.append(0.0174533 * d[1])
distance.append(d[2])
print('angle:', angle)
ax.clear()
ax.scatter(angle, distance, s=5)
angle.clear()
distance.clear()
ani = animation.FuncAnimation(fig, run, interval=50)
plt.show()
`
Currently following commands are not implemented:
0x21
: this command is analogous to the SCAN command, but also returns debug information. Not fully documented.0x82
: will run scanner at the sampling rate as high as it can be. For A2 it should be 4 kHz.0x59
: returns sampling rates for SCAN and EXPRESS_SCAN commands0xFF
: seems for accessing A2 motor control board. Not documented.Is that possiple have a update with A3 compatibility.
A3 has new model sensitivity. this looks great.
After a iter_scans functions raise an Incorrect descriptor starting bytes.
Probably synchronization issue with the protocol
Trying to get start out with the get info function. And I keep getting this error. I installed the driver for the cP210x and I have '/dev/tty.SLAB_USBtoUART' as my device which is what I found from the IORegistry and also in the Dev folder.
On a mac running the latest OS. Python and everything else is the latest version. I tried different baud rates but no luck. Any Ideas?
how to fill in the data of the "time_increment" and "scan_time" message sensor_msgs/LaserScan.msg ROS?
thank you
your pdf link is broken or times out immediately, refreshing my wifi connection and ip address does not help, im on most recent Chrome browser for Windows 10
who can help fixing the following error: "New scan flags mismatch"
the logs are
request:
b'\xa5P'
descriptor:
b'\xa5Z\x14\x00\x00\x00\x04'
response:
b'\x06\x05\x01\x01\x02\x00\x01\x08\x01\x00\x02\x00\x00\x00\x00\x00\x04\x00\x01\t'
{'model': 6, 'firmware': (1, 5), 'hardware': 1, 'serialnumber': '02000108010002000000000004000109'}
request:
b'\xa5R'
descriptor:
b'\xa5Z\x03\x00\x00\x00\x06'
response:
b'\x00\x00\x00'
('Good', 0)
request:
b'\xa5R'
descriptor:
b'\xa5Z\x03\x00\x00\x00\x06'
response:
b'\x00\x00\x00'
request:
b'\xa5 '
descriptor:
b'\xa5Z\x05\x00\x00@\x81'
response:
b'\xaaU\x01\x01\x03'
response:
b'B\x03B\xabT'
response:
b'\x00\x00\xaaU\x00'
Traceback (most recent call last):
File "C:\Python\test_radar.py", line 17, in
for i, scan in enumerate(lidar.iter_scans(max_buf_meas=500, min_len=5)):
File "C:\Python\lib\site-packages\rplidar.py", line 365, in iter_scans
for new_scan, quality, angle, distance in iterator:
File "C:\Python\lib\site-packages\rplidar.py", line 341, in iter_measurments
yield _process_scan(raw)
File "C:\Python\lib\site-packages\rplidar.py", line 77, in _process_scan
raise RPLidarException('New scan flags mismatch')
rplidar.RPLidarException: New scan flags mismatch
Lots of command raise issues. For example, get_info() after a scan is wrong. I will do some changes in the code to make it more reliable.
Are you interested I make a pull request (this means, you are always active on this project !) or do you prefer I improve only my fork ?
i run the command: for meas in lidar.iter_measurments():
it's occur the
Traceback (most recent call last):
File "/home/nx/Desktop/rplidar/simple.py", line 15, in
for meas in lidar.iter_measurments():
File "/home/nx/.local/lib/python3.6/site-packages/rplidar.py", line 323, in iter_measurments
raw = self._read_response(dsize)
File "/home/nx/.local/lib/python3.6/site-packages/rplidar.py", line 199, in _read_response
raise RPLidarException('Wrong body size')
rplidar.RPLidarException: Wrong body size
i have read some solutions ,but it also occur sometimes . my pyserial version is 3.4.Thank you for your read
run(sys.argv[1]) in line 28 out of index, how to solve it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.