Need help with RPLIDAR A2 data compression

In RPLIDAR document, “Interface Protocol and Application Notes”, page 19, Figure 4-11, (far right) , d-theta-1 is referred to twice, once as the lowest bit of byte#0 and once as the lower four bits of byte#4. Both references have the descriptor “[3:0]”. There must be an error here as four bits cannot occupy the space of one bit. Later, on page 21, it says, “The top bit is sign bit.” Does that mean that the bit in byte#0 is the sign bit and the bits in byte#4 are the numeric part? or what? Please help.
(similar for d-theta-2)

Yeah, this does not seem clear at all. When in doubt, look at the SDK/drivers/etc. for answers! I mean, the example software obviously works, so they must be able to read their own protocol! :stuck_out_tongue:

Actually, it seems to be the lowest two bits (more on that below).

That part seems about right.

I think that is just a typo/mistake in how the protocol is described (also more on that below).

Yeah, that is also unclear since it does not describe how they are combined (i.e.: which part goes “higher/lower” than the other). Another good reason to check the SDK for details.

Indeed. They both seem to be handled the exact same way. Makes sense since they have a similar purpose.

From what I gathered from the drivers in the SDK (rplidar_driver.cpp), the bits reserved are actually the two lower bits of the distance_angle_n ( where n ∈ {1, 2} ). Those two bits are then shifter 4 bits to the left and end up being the 2 most significant bits of the angular compensation.
You can see more details on line 790 of that file (link here [with specific version, newest when this was posted]).

As you can see above, the 4 lower bits are used (masked with 0xF) for the offset #1 and the 4 higher bits (shifted 4 to the right) are used for the offset #2. Similarly, the 2 lower bits are obtained from distance (value masked with 0x3) and then shifted 4 bits to the left before being combined (logical OR) with the other 4 bits (as mentioned above). Distance #1 is used for offset #1 and distance #2 is used for offset #2.

If you keep reading that piece of code, you’ll notice they then proceed to recover the angle from the Q3 format used to determine the actual angle.

I hope that helps! :slight_smile:

Sincerely,

1 Like

Thank you, Scharette, for you patient and detailed response to my query.
I think I have a handle on it now and can take it from here.