gmapping make missing map when follows a straight wall

I have a mobile robot with Lidar sensor for mapping and localization in gazebo environment. i am using slam_gmapping for mapping.

My problem is about gmapping and its own parameters. It can create a map while my robot follow obstacle area and a unobstacle area. But when i follow a straight wall, gmapping make a missing map and my robot doesn't locate the true localization. You can look the youtube link for understanding my problem. How can i solve it?

2 Answers

It's a common "issue" with gmapping, it's not really an issue because that is how the algorithm is working.
In your video we can see that your robot has a limited angle of view (about 90°, from -45° to 45° apparently), so when your robot is following a straight wall at its right it doesn't detect anything else at his left (because of how far your walls are between each other).

What gmapping does for localization is comparing what the sensor is detecting with the map it is building. In your case the sensor always have the similar data because your wall is straight, that wouldn't be problematic if the robot encounter another obstacle a little further or if you could see the wall behind the robot. But your robot is getting always the same data and after a while it will consider that it's an issue, the algorithm will consider that the odometry data has been wrong (because odometry data can be very noisy, gmapping will give priority to the scan data over it) and will correct the robot position accordingly.

You have some options to avoid this :

If you are just using your simulation to test the mapping and don't care to change your gazebo world, you can add more obstacles that would be detected by the sensor when following the wall. But you could find the same issue if you add your obstacles symetrically and spaced at the same distance. Here's a picture to explain it better :

You can change your SLAM algorithm to one that give more importance to the odometry, if your odometry data is good.

Maybe you can tune some of the gmapping parameters but I'm not sure about that.

@duck-development Yes I agree that only one source isn't enough but you don't always require a camera AND ultrasonic sensor AND encoders etc, it's just too much. Some applications can work fine only with a lidar, imu and odometry. It just depends on how precize you want/need to be.

You can create an enviroment wehere an lidar is enought. But you create it. If you look at the xiaomi vac you get lds, imu, Encoder, extra ir Sensors, ultrasonic. and the look at every Part to Keep the Cost Down.