pyrplidar icon indicating copy to clipboard operation
pyrplidar copied to clipboard

IndexError: index out of range

Open NateDKing opened this issue 3 years ago • 9 comments

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?

NateDKing avatar Aug 15 '21 17:08 NateDKing

不知道

wanghaoNB avatar Sep 05 '21 12:09 wanghaoNB

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

sir1st avatar Dec 27 '21 08:12 sir1st

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.

sir1st avatar Dec 27 '21 08:12 sir1st

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

wafflecat avatar Jan 03 '22 09:01 wafflecat

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

sir1st avatar Jan 03 '22 11:01 sir1st

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.

wjacobward avatar Feb 02 '22 20:02 wjacobward

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)"

kamil52512 avatar May 18 '22 07:05 kamil52512

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.

razoentaki avatar May 23 '22 02:05 razoentaki

Anyone who solved this problem?

JhiWhoonKang avatar Dec 27 '22 17:12 JhiWhoonKang