SkoltechRobotics / rplidar

Python module for RPLidar A1 and A2 rangefinder scanners
MIT License
186 stars 126 forks source link

Example doesn't work #10

Open Sparafucil3 opened 7 years ago

Sparafucil3 commented 7 years ago

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'

luckywang95 commented 7 years ago

which example are you running? have you installed the latest pyserial?

Sparafucil3 commented 7 years ago

Updating pyserial resolved the issue (I am using an A2).

I am using an RPLidar A2 to run the simple example on the bottom of the front page. It works about 70% of the time and gives me the error above the rest of the time. Any idea why that might be happening? Does the Lidar need a warm up time to work reliably?

Here is the out of two runs of the same script, seconds apart:

pi@prototype:~/python $ python lidar.py
{'hardware': 2, 'model': 40, 'firmware': (1, 20), 'serialnumber': u'DADXXX'}
('Good', 0)
0: Got 134 measurments
1: Got 128 measurments
2: Got 131 measurments
3: Got 125 measurments
4: Got 121 measurments
5: Got 119 measurments
6: Got 112 measurments
7: Got 116 measurments
8: Got 120 measurments
9: Got 115 measurments
10: Got 117 measurments
11: Got 113 measurments
pi@prototype:~/python $ python lidar.py
{'hardware': 2, 'model': 40, 'firmware': (1, 20), 'serialnumber': u'DADXXXX'}
('Good', 0)
Traceback (most recent call last):
  File "lidar.py", line 17, in <module>
    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 323, in iter_measurments
    raw = self._read_response(dsize)
  File "/usr/local/lib/python2.7/dist-packages/rplidar.py", line 199, in _read_response
    raise RPLidarException('Wrong body size')
rplidar.RPLidarException: Wrong body size

I edited my serial number just in case.

luckywang95 commented 7 years ago

i encountered similar issue previously. If im not mistaken, is this problem occurs only after u reinitialize a scan after the motor start rotating and scanning?

Sparafucil3 commented 7 years ago

OK. I will keep an eye out for it. Thanks very much for your help. I was getting pretty frustrated by the error.

rjelbert commented 7 years ago

I had the same problem on a Raspberry Pi 3 connected to an A1 but force upgraded pyserial 3.3 and this seemed to clear up the issue. The example in the readme now works. To get around apt and pip refusing to upgrade pyserial, I downloaded the source zip from https://pypi.python.org/packages/8d/88/cf848688ae011085a6da5a470740dafa3a4b105f84a5f79c3b720c19279c/pyserial-3.3.tar.gz ...and installed using "sudo python setup.py install"

PineappleSunday commented 6 years ago

@Sparafucil3 Did you ever figure out a fix to this? I continue to get:

File "/usr/local/lib/python2.7/dist-packages/rplidar.py", line 199, in _read_response raise RPLidarException('Wrong body size') rplidar.RPLidarException: Wrong body size

DnzDmR commented 5 years ago

I solved this error. You should put time.sleep(...) before "loop";

For example;

time.sleep(5) for i, scan in enumerate(lidar.iter_scans()): print('%d: Got %d measurments' % (i, len(scan))) if i > 10: break

craiganderson-53546 commented 4 years ago

I see the same error message interfacing an RPLidar A1M8 from Raspberry Pi 2. I upgraded the version of pyserial(3.4) and added the loop, still see the same behavior. Has anyone else found other answers?

evanzummeren commented 4 years ago

Did anyone figure this out? Running into similar issues with a A1M8/Raspberry Pi (Rasbian) setup. Just like Craig I also tried to upgrade pyserial and adding sleep before the loop, but still running into issues.

PineappleSunday commented 4 years ago

Erik:

I do believe I found a solution many years ago, but will need to find the code on where I overcame it. Hope to have a response to you soon.

On Wed, Jun 3, 2020 at 1:16 PM Erik van Zummeren notifications@github.com wrote:

Did anyone figure this out? Running into similar issues with a A1M8/Raspberry Pi (Rasbian) setup. Just like Craig I also tried to upgrade pyserial and adding sleep before the loop, but still running into issues.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SkoltechRobotics/rplidar/issues/10#issuecomment-638335569, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADII2E63HPTP6ZQX6HYX543RU2AOTANCNFSM4DQGUULQ .

evanzummeren commented 4 years ago

Erik: I do believe I found a solution many years ago, but will need to find the code on where I overcame it. Hope to have a response to you soon. On Wed, Jun 3, 2020 at 1:16 PM Erik van Zummeren @.***> wrote: Did anyone figure this out? Running into similar issues with a A1M8/Raspberry Pi (Rasbian) setup. Just like Craig I also tried to upgrade pyserial and adding sleep before the loop, but still running into issues. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#10 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADII2E63HPTP6ZQX6HYX543RU2AOTANCNFSM4DQGUULQ . -- Best Regards, Colin Runnion Electrical Engineer Cell: (812) 774-2950 http://linkedin.com/in/colin-runnion-ba5636a2

Ah that'd be truly wonderful. Please let me know in case you manage to find it!

PineappleSunday commented 4 years ago

@evanzummeren Which example are you running? It has been so long and I no longer have access to the lidar system, if you can show me which line you are having difficulties with hopefully I can help. If you look at my repos, you should be able to see some code I had working and used to implement a SLAM algorithm - they should work.

perrinj3 commented 3 years ago

Hi I saw this thread and am having the same error Traceback (most recent call last): File "Basic_RPlidar.py", line 10, in for i, scan in enumerate(lidar.iter_scans()): File "C:\Users\john\AppData\Roaming\Python\Python38\site-packages\rplidar.py", line 357, in iter_scans for new_scan, quality, angle, distance in iterator: File "C:\Users\john\AppData\Roaming\Python\Python38\site-packages\rplidar.py", line 323, in iter_measurments raw = self._read_response(dsize) File "C:\Users\john\AppData\Roaming\Python\Python38\site-packages\rplidar.py", line 199, in _read_response raise RPLidarException('Wrong body size') rplidar.RPLidarException: Wrong body size

I get this error every time with a basic script like the following. When I run with debug logging it seems to show

import time from rplidar import RPLidar as Lidar LIDAR_DEVICE = 'com6' if name == 'main':

# Connect to Lidar unit
lidar = Lidar(LIDAR_DEVICE)
iterator = lidar.iter_scans()
time.sleep(5)
for i, scan in enumerate(lidar.iter_scans()):
    print('%d: Got %d measurements' % (i, len(scan)))
    if i > 10:
        break
lidar.stop()
lidar.disconnect()

The following is the debug logging output 2021-06-17 20:21:19,567::INFO::rplidar::rplidar.py::147::Starting motor 2021-06-17 20:21:19,567::DEBUG::rplidar::rplidar.py::174::Command sent: b'\xa5\xf0\x02\x94\x02\xc1' 2021-06-17 20:21:21,686::INFO::rplidar::rplidar.py::147::Starting motor 2021-06-17 20:21:21,687::DEBUG::rplidar::rplidar.py::174::Command sent: b'\xa5\xf0\x02\x94\x02\xc1' 2021-06-17 20:21:21,687::DEBUG::rplidar::rplidar.py::180::Command sent: b'\xa5R' 2021-06-17 20:21:21,687::DEBUG::rplidar::rplidar.py::185::Recieved descriptor: b'\xa5\x9c\x00\x00\x02\xbd\x9d'

I'm using a RPlidar A2M8 and the device runs fine with simplegrabber or RoboStudio but I want to use Python with a C++ extension

perrinj3 commented 3 years ago

I think rplidar.py may be too slow to handle it. Does anyone know of a Window X64 version that uses Python with a C++ Extension? I'm not expert enough to build my own wrapper