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

Still not sure how to fix the "Descriptor length mismatch" A1M8-R6 firmware issue #25

Closed
javadan opened this issue Jul 26, 2022 · 12 comments

Comments

@javadan
Copy link

javadan commented Jul 26, 2022

I see other users are asking this still, and their questions are just being closed.

But it would be nice to use the RPLidar (A1M8-R6)

The results of running the example (all required python libs installed)

pi@raspberrypi:~/Adafruit_CircuitPython_RPLIDAR/examples $ python3 rplidar_simpletest.py
Traceback (most recent call last):
File "/home/pi/Adafruit_CircuitPython_RPLIDAR/examples/rplidar_simpletest.py", line 24, in
for scan in lidar.iter_scans():
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 540, in iter_scans
for new_scan, quality, angle, distance in iterator:
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 445, in iter_measurements
self.start(scan_type)
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 360, in start
status, error_code = self.health
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 328, in health
dsize, is_single, dtype = self._read_descriptor()
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 268, in _read_descriptor
raise RPLidarException("Descriptor length mismatch")
adafruit_rplidar.RPLidarException: Descriptor length mismatch

Any ideas? Thanks

@makermelissa
Copy link
Contributor

What firmware revision do you have? It was updated to work with version 1.29 in #17. It's possible your unit has something newer that added new features or broke compatibility.

@javadan
Copy link
Author

javadan commented Jul 26, 2022

Hi Melissa, I bought it on digikey, and it's branded as a DF Robot product.

The only info I can find in the specification is:
• Model: RPLIDAR A1M8-R6

Not sure how to verify firmware revision unfortunately.

@makermelissa
Copy link
Contributor

The one I have is from Adafruit and is stuck on firmware 1.27. I think I was able to check that using the SLAMTEC software. You might want to see if that software works with yours. Without more information, this can be difficult to troubleshoot.

Some other possibilities I can think of might be it needing to be updated for the Python version (though unlikely) or your environment setup.

@javadan
Copy link
Author

javadan commented Jul 26, 2022

Ok thanks, I'll give the SLAMTEC software a go, next time I try. Will probably leave it for a day or two.

@javadan
Copy link
Author

javadan commented Jul 29, 2022

Well, indeed it is 1.29. The Firmware program refuses to upgrade/downgrade to 1.27.

From what I can see on various forums, it might be an issue of USB not providing enough power. But I've tried with a USB3 port, so it's probably not that.

Hmm. Dunno. Anyway I'll close the issue. Probably a power issue.

C:\Users\db\Downloads>simple_grabber.exe \\.\COM9 RPLIDAR S/N: XXXXXXXXXXXXXXXXXXXX(edited) Version: 1.10.0 Firmware Ver: 1.29 Hardware Rev: 7 RPLidar health status : OK. (errorcode: 0) waiting for data... *WARN* YOU ARE USING DEPRECATED API: grabScanData(), PLEASE MOVE TO grabScanDataHq() *WARN* YOU ARE USING DEPRECATED API: ascendScanData(rplidar_response_measurement_node_t*, size_t), PLEASE MOVE TO ascendScanData(rplidar_response_measurement_node_hq_t*, size_t) *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** *************************************************************************** --------------------------------------------------------------------------- Do you want to see all the data? (y/n) y Error, cannot grab scan data.

@javadan javadan closed this as completed Jul 29, 2022
@javadan
Copy link
Author

javadan commented Jul 30, 2022

Followup: I connected the motor to a dedicated 5V instead of the USB. Still, same error message. Damn. $99 spinning plastic.

@javadan
Copy link
Author

javadan commented Jul 30, 2022

Followup: I ran frame_grabber.exe and it works! Ha. Ok, now to try work out how to compile VS 2010 code missing various libraries, in 2022.

@javadan
Copy link
Author

javadan commented Aug 30, 2022

A followup that might help someone work it out eventually...

So I got the RPLidar SDK compiling (with this fix). And came back to this code, and tried again, and managed to get past a null byte, which seems to be the error, for v1.29

line 280-ish
    def _read_response(self, dsize: int) -> bytes:
        """Reads response packet with length of `dsize` bytes"""
        self.log("info", "Trying to read response: %d bytes" % dsize)
        data = self._serial_port.read(dsize)
        self.log_bytes("info", "Received data:", data)
        print(data)
        **if len(data) != dsize:
            print(data)
            #raise RPLidarException("Wrong body size")**
        return data


line 460-ish
           if self.scan_type == SCAN_TYPE_NORMAL:
                raw = self._read_response(dsize)
                self.log_bytes("info", "Received scan response: ", raw)
                **if raw != b'':
                    yield _process_scan(raw)**


line 92-ish
def _process_scan(raw: bytes) -> Tuple[bool, int, float, float]:
    """Processes input raw data and returns measurement data"""
    new_scan = bool(raw[0] & 0b1)
    inversed_new_scan = bool((raw[0] >> 1) & 0b1)
    quality = raw[0] >> 2
    if new_scan == inversed_new_scan:
        raise RPLidarException("New scan flags mismatch")
    check_bit = raw[1] & 0b1
    if check_bit != 1:
        raise RPLidarException("Check bit not equal to 1")
    angle = ((raw[1] >> 1) + (raw[2] << 7)) / 64.0
    distance = (raw[3] + (raw[4] << 8)) / 4.0
    **print("Theta ", angle, " Distance ", distance)**
    return new_scan, quality, angle, distance

and manually turned on the logging 
line 166ish
    self.logging = True #logging

So now I'm getting a stream of data.

pi@raspberrypi:~ $ python3 lidartest.py
info: Starting motor
info: Command sent: a5 f0 02 94 02 c1
HELLO
info: Command sent: a5 50
info: Received descriptor:a5 5a 14 00 00 00 04
info: Trying to read response: 20 bytes
info: Received data:18 1d 01 07 b9 c4 ed 93 c0 ea 98 c6 c2 e2 9e f5 4b 1e 40 61
b'\x18\x1d\x01\x07\xb9\xc4\xed\x93\xc0\xea\x98\xc6\xc2\xe2\x9e\xf5K\x1e@a'
{'model': 24, 'firmware': (1, 29), 'hardware': 7, 'serialnumber': '61401e4bf59ee2c2c698eac093edc4b9'}
info: Starting motor
info: Command sent: a5 f0 02 94 02 c1
info: Command sent: a5 52
info: Received descriptor:a5 5a 03 00 00 00 06
info: Trying to read response: 3 bytes
info: Received data:00 00 00
b'\x00\x00\x00'
info: Health status: Good [0]
info: starting scan process in 0 mode
info: Command sent: a5 20
info: Received descriptor:a5 5a 05 00 00 40 81
info: Trying to read response: 5 bytes
info: Received data:
b''
b''
info: Received scan response:
info: Trying to read response: 5 bytes
info: Received data:02 1d 45 00 00
b'\x02\x1dE\x00\x00'
info: Received scan response: 02 1d 45 00 00
Theta  138.21875  Distance  0.0
info: Trying to read response: 5 bytes
info: Received data:02 35 04 00 00
b'\x025\x04\x00\x00'
info: Received scan response: 02 35 04 00 00
Theta  8.40625  Distance  0.0
info: Trying to read response: 5 bytes
info: Received data:02 d9 04 00 00
b'\x02\xd9\x04\x00\x00'
info: Received scan response: 02 d9 04 00 00
Theta  9.6875  Distance  0.0
info: Trying to read response: 5 bytes
info: Received data:02 7d 05 00 00
b'\x02}\x05\x00\x00'
info: Received scan response: 02 7d 05 00 00
Theta  10.96875  Distance  0.0
info: Trying to read response: 5 bytes
info: Received data:02 21 06 00 00
b'\x02!\x06\x00\x00'
info: Received scan response: 02 21 06 00 00
Theta  12.25  Distance  0.0

When running the simple test.

So, anyhow, that seems to be the v1.29 issue. Some null bytes. FYI.

@makermelissa
Copy link
Contributor

Thanks for finding this. Would you like to submit a PR with the fix? I could at least test and verify it runs on the older 1.27 firmware (which unfortunately doesn't appear to be upgradeable).

@javadan
Copy link
Author

javadan commented Aug 30, 2022

I also get a crash later, randomly, so I'll need to look at that too. Seems fine to just catch and drop the exception though.

But if/when I get the visualisation working over a network, I'll submit a PR with a proper fix. ( The quick fix above is pretty hacky, and might swallow legitimate exceptions. )

File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 99, in _process_scan
    raise RPLidarException("New scan flags mismatch")

@makermelissa
Copy link
Contributor

I might see if getting a more recent RPLIDAR would have the latest firmware now

@gaultierlecaillon
Copy link

I had the same error trying to run the readme example and I solved this by doing so:

When you create the object RPLidar like below, the default baudrate is 115200:
lidar = RPLidar(None, PORT_NAME, timeout=3)

You probably need to set baudrate to 256000 like this:
lidar = RPLidar(None, PORT_NAME, baudrate=256000, timeout=3)

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

3 participants