-
Notifications
You must be signed in to change notification settings - Fork 24
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
Possible SOLUTION - Index out of range error #12
Comments
Hi T-622, thanks for the detailed response! I'm having a really strange issue with my SLAMTEC C1 LiDAR on my Raspberry Pi 4. It works fine on my PC, but on the Pi, it causes the whole system to crash for a few seconds when I try to get scan data! I've tried your suggestions (baud rate, edit library), but no luck. Any ideas what could be causing such a dramatic crash? Here's the code and error:
This one doesn't works too :
Please let me know if you have any ideas – I'm desperate! 🙏 |
I will fire up my Pi 4 and give this code a try to see if I can reproduce your error, will give you an update! |
Hi everyone,
Background:
I was tinkering around with this library and encountered an error with an "Out Of Range" issue outputting
self.sync_byte1 = raw_bytes[0] IndexError: index out of range
. I combed through the new documentation for the "Cx, Ax, and Sx" series of firmware versions and discovered that this error is related to the sensor not reciving data.Here is the documentation for V2.8 of the communication protocol:
LR001_SLAMTEC_rplidar_S&C series_protocol_v2.8_en.pdf
This is documentation for V2.3 of the communication protocol:
LR001_SLAMTEC_rplidar_protocol_v2.3_en.pdf
Notice that under
pyrplidar_protocol.py
included in the repo has the following on line 17:RPLIDAR_CMD_FORCE_SCAN = b'\x20'
. Under V2.8 of the protocol, "FORCE_SCAN" no longer exists, and thus issuing 0x21 over serial to the LiDAR no longer works, thus we get an out of range error, since no data is returned; the sensor is confused by this command if it has a firmware version recent enough (I cannot tell what versions discontinued this function, just that it has been changed).Possible Solution:
If you have this issue, you MUST check the baud rate, and set it to the correct one. Mine was 480600 with the C1 LiDAR module, but yours may differ. Examples below:
A1 / A1M8: 57600 baud
A2M8: 115200 baud
A2M12 / A3 / S1: 256000 baud
S2 / S3: 1000000 baud
You can verify that the communication is working and the baud rate works by checking the "check_connection.py" example included under the "examples" folder of this repo.
Once that works, and the example scans seem to be your issue, this is what i've discovered. Given my above reasonning, we can no longer issue 0x21 to the sensor for the "FORCE_SCAN", but we need to instead use "SCAN", which is issued with 0x21. To fix this issue, you can either change line 17:
From
RPLIDAR_CMD_FORCE_SCAN = b'\x21'
To
RPLIDAR_CMD_FORCE_SCAN = b'\x20'
Which will change the FORCE_SCAN command to the regular scan command. Else, you can change line 169 in
pyrplidar.py
From
self.send_command(RPLIDAR_CMD_FORCE_SCAN)
To
self.send_command(RPLIDAR_CMD_SCAN)
And thus, the "force_scan()" command will issue a normal scan and spin up the motor. Please feel free to comment if you have found anything different, or if this work solves the issue for you! Note, this support issue exists both in the Adafruit Circuitpython library and Roboticia library from what I can tell, since they all issue the 0x21 command for forcing to scan.
For those interested:
The "FORCE_SCAN" command forces the lidar to output data for position even if the motor is not spinning.
The text was updated successfully, but these errors were encountered: