Previous post ends with a question: why Hector Slam perform better than GMapping when in theory should be the opposite? The right question should be: why GMapping works bad with RPLidar? Since I'm not the only developer asking this question I hope will be helpful for everyone share my results.
There are several reasons for which RPLidar and GMapping does not work well together:
- the LaserScan message expected by GMapping;
- the RPLidar reference frame;
- the LaserScan message created by RPLidar node.
The good new is that all issues can be easily fixed. On this post I will show you how I success to make RPLidar and GMapping work together.
The LaserScan expected by GMapping
First issue regards the LaserScan expected by GMapping. Unfortunately this is not documented anywhere and I found it only checking out source code: on latest commits (not yet released) a new check was added to make sure LaserScan message min angle and max angle are opposite:
maxAngle = - minAngle
This condition is not satisfied by RPLidar node but, since released version of GMapping does not include this check, is not easy to notice.
The RPLidar reference frame
Second issue came from RPLidar frame and RPLidar rotation direction. It assume positive angle in CW direction: in order to reflect this orientation Z-axis must be directed to the RPLidar's bottom side (this is not a bug but, since this is not pointed out in documentation, is quite common to make a mistake broadcasting laser scan frame).
Further more, in order to satisfy the GMapping required condition about angles shown on previous section, is better to use a frame rotated by 180° respect one shown in RPLidar documentation: using this frame the resulting min and max angle will be (approximately) equals to -3.14 and 3.14 according to GMapping condition.
|The RPLidar frame from RoboPeak documentation|
|The RPLidar frame must be used in ROS|
The LaserScan message created by RPLidar node
The RPLidar node require some modification in order to reflect corrections shown before about min and max angle (they must take count of the frame rotated by 180°):
scan_msg.angle_min = M_PI - angle_min;
scan_msg.angle_max = M_PI - angle_max;
Applying this fix will result in negative value of published angle_increment according to the fact that RPLidar rotate CW.
GMapping default settings are designed for high speed and large range lidars. RPLidar has really good value/price rate but it does not fit those requirements so modifications of GMapping parameters is needed in order to have best result.
Those are the GMapping parameters I used with best results:
maxRange: 5.5 it was 6.0 but after better tuning 5.5 is suggested
In conclusion RPLidar can works with GMapping with good performance after those issues are fixed:
|The GMapping built map before fixes|
|The GMapping built map after fixes. Unfortunately was not possible to use the same bag file for this test since the LaserScan message was changed. Anyway the test was conducted on same environment with same conditions.|
The RPLidar node with fixes it is available on GitHub repo.