Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: index out of range #6

Open
NateDKing opened this issue Aug 15, 2021 · 9 comments
Open

IndexError: index out of range #6

NateDKing opened this issue Aug 15, 2021 · 9 comments

Comments

@NateDKing
Copy link

I am trying to connect the RPLIDAR A1 to my windows laptop and am receiving this error:

PyRPlidar Info : device is connected
Traceback (most recent call last):
  File "c:\Users\Nate King\Documents\GitHub\Nate-Code\Vision Project\Lidar Test\Example.py", line 10, in <module>
    info = lidar.get_info()
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar.py", line 73, in get_info
    discriptor = self.receive_discriptor()
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar.py", line 42, in receive_discriptor
    discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar_protocol.py", line 110, in __init__
    self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
PyRPlidar Info : device is disconnected

Here is the code I am using:

from pyrplidar import PyRPlidar

lidar = PyRPlidar()

lidar.connect(port="COM3", baudrate=115200, timeout=3)
# Linux   : "/dev/ttyUSB0"
# MacOS   : "/dev/cu.SLAB_USBtoUART"
# Windows : "COM3"

info = lidar.get_info()
print("info :", info)

health = lidar.get_health()
print("health :", health)

samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)

scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
    print(scan_mode)

lidar.disconnect()

Anyone have an idea what could be causing this?

@wanghaoNB
Copy link

不知道

@sir1st
Copy link

sir1st commented Dec 27, 2021

first, change the baudrate to 115200.
second, use the linux based system, not the windows.

@sir1st
Copy link

sir1st commented Dec 27, 2021

my rplidar a1 device doesn't work on win10 paltdorm, but with the same code(change the port from COM3 to /dev/ttyUSB0), it works on deepin os.

@wafflecat
Copy link

my rplidar a1 device doesn't work on win10 paltdorm, but with the same code(change the port from COM3 to /dev/ttyUSB0), it works on deepin os.

Make sure your LED goes green. You need to install the CP210x USB to UART bridge driver.
http://bucket.download.slamtec.com/a7a9b856b9f8e57aad717da50a2878d5d021e85f/LM204_SLAMTEC_rplidarkit_usermanual_A2M4_v1.1_en.pdf

The driver install is available in their SDK .zip.
https://www.slamtec.com/en/Support#rplidar-a-series

Verify everything works using frame_grabber.exe first.
https://github.com/Slamtec/rplidar_sdk/releases

@sir1st
Copy link

sir1st commented Jan 3, 2022

I did check everything else. the frame grambber works really good on win10 os. Here is the screen shot.
微信截图_20220103191251
Sadly, once I start the simple_scan.py (with the config of lidar.connect(port="COM3", baudrate=115200, timeout=3)), the rplidar a1 doesn't work anymore. It even not rotates, just stay static... After I close this python program, the ridar starts rotation again..
Here is the totally logs:

PyRPlidar Info : device is connected
Traceback (most recent call last):
File "c:/Users/11747/Desktop/pyrplidar-master/examples/simple_scan.py", line 30, in
simple_scan()
File "c:/Users/11747/Desktop/pyrplidar-master/examples/simple_scan.py", line 16, in simple_scan
scan_generator = lidar.force_scan()
File "E:\Software\Anaconda3\lib\site-packages\pyrplidar.py", line 170, in force_scan
discriptor = self.receive_discriptor()
File "E:\Software\Anaconda3\lib\site-packages\pyrplidar.py", line 42, in receive_discriptor
discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
File "E:\Software\Anaconda3\lib\site-packages\pyrplidar_protocol.py", line 110, in init
self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
PyRPlidar Info : device is disconnected
But this code (with the port="/dev/ttyUSB0") works really good on Deepin OS. I can bet that no hardware chagnes except the running os

@wjacobward
Copy link

Anyone have luck fixing this issue in Windows? I have the exact same problem. A1 lidar works fine in Slamtec's frame_grabber, but fails with "index out of range" with this library. That seems to indicate that there is no data being sent by the device over the serial port.

@kamil52512
Copy link

kamil52512 commented May 18, 2022

On Windows 10, modifying a file the pyrplidar_serial.py from library helps.
In line 13 replace:
"self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout, dsrdtr=True)"
to
" self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout, dsrdtr=False)"

@razoentaki
Copy link

On Windows 10, modifying a file the pyrplidar_serial.py from library helps. In line 13 replace: "self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout, dsrdtr=True)" to " self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout, dsrdtr=False)"

Tried, but it did not solve the problem.

@JhiWhoonKang
Copy link

JhiWhoonKang commented Dec 27, 2022

Anyone who solved this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants