How to deploy Gmapping SLAM algorithms in mobile robots

How to deploy Gmapping SLAM algorithms in mobile robots

Written by GuYueHome

01 What is SLAM

The full name of SLAM is Simultaneous Localization And Mapping, which translates to instant localization and map construction. There are two key words here: localization and map construction, which means that the robot will determine its position in an unknown environment while building a map, and finally output a map like this.

In short, the process of SLAM map construction is to measure the distance information between the robot and the surrounding environment with depth sensors, so as to complete the map construction of the surrounding environment. At the same time, the robot will check the consistency of the environment and detect whether it moves to the place where the map has been constructed, and finally complete the map closed loop to finish the whole map.

The most commonly used SLAM algorithm in ROS is Gmapping, a common open source SLAM algorithm based on the filtered SLAM framework, which is based on the RBpf particle filtering algorithm, i.e., the localization and map building processes are separated, and the localization is performed first and then the map is built. If you are interested in the Gmapping algorithm, you can read the paper on the algorithm at:

02 LIMO Mobile Robot Motion Control

2.1 LIMO multimodal robot

Our common mobile robot movement types are generally four-wheel differential, Ackermann steering, crawler differential, omnidirectional movement, etc., but as the saying goes, adults do not make a choice, Songling Robotics LIMO one to meet all your needs, four types of movement at will any switch.

We will devote to the testing of multimodal motion types in the future. Today's focus is on the implementation of SLAM application functions in the motion state of the LIMO robot with four-wheel differential speed.

2.2 Remote connection to LIMO

You can download NoMachine - Free Remote Desktop For Everybody directly from the official website of LIMO:

Once the software is installed, the computer and the cart are connected to the same WiFi so that you can connect with the cart remotely.

2.3 Download and compile the code

The code for the LIMO robot is continuously being updated, as we can see on the Github homepage. To ensure that we are using the latest code, here we use the following command to download the code package to the workspace in the LIMO on-board system, replacing the original code.

Then use the catkin_make command to compile the space. This is a regular operation for ROS, so if you are not familiar with it, you can read "21 Lectures on Getting Started with ROS" by Guyue Jun.

2.4 Make the cart run

To make sure the underlying functionality of the robot is ready to work, let's try the most basic keyboard control to get the cart moving.

Start up a terminal to activate the cart's chassis and sensors.

After the chassis is successfully started, it will subscribe to the cmd_vel topic, just like controlling a small sea turtle, and start the following keyboard control node, you can control the LIMO smooth movement through the keyboard.

 03 Gmapping SLAM function configuration analysis

3.1 Gmapping package

Before using the Gmapping package in ROS, you need to install it using the following command, here is the Melodic version, if you are using other versions of ROS, replace the version name in the command.

The SLAM algorithm is not simple, but Gmapping is a "building block" that has been packaged very well, and we can find the interface on the ROS wiki The description is shown in the following figure.

As can be seen, Gmapping needs to subscribe to the robot joint transformation topic /tf and the LiDAR scan data topic /scan, and then publish the raster map topic /map.

Regarding /tf is further divided into two parts, the TF transformations in the Gmapping feature package are shown in the following figure.

So we can determine that the necessary conditions for the Gmapping algorithm: /tf, /odom, /scan, will be ready to publish/map through the algorithm.

After the start of the previous LIMO robot chassis, these basic conditions have been published or updated normally in the underlying node, so our focus is to configure the Gmapping function node through a launch file.

3.2 SLAM function configuration

Create a feature package called limo_slam under the src file in the workspace, where another launch folder is created, and the launch file about the Gmapping launch configuration is placed here.

The details of the launch file gmapping.launch are as follows. If you use other robots, you will need to change the parts commented in the following file according to your respective situation.

If you are familiar with the SLAM algorithm, these parameters may not be new to you, but if you don't know the SLAM algorithm, don't worry, these parameters have default values and most of the time you can just use the default values or use the configuration of similar robots in ROS.

Since the framework of the Gmapping algorithm is shown below, the main parameters we need to change are odom (odometer coordinate system, required), scan (LIDAR topic, required), base_footprint_frame (robot base coordinate system, required), imu_data (IMU topic, optional), and the names and values of these parameters need to be the same as The names and values of these parameters need to correspond to the topic names and values published in the robot chassis driver limo_start, otherwise Gmapping does not receive these parameters and cannot perform SALM.


04 Gmapping SLAM operation results

After doing the relevant preparations, we can use the LiDAR for SLAM.

First, the code is compiled under the workspace using catkin_make, and then a terminal is started separately to run the following commands.

In order to see the effect of dynamic SLAM, we also need to use the Rviz visual display by opening a terminal and entering the following command.

Then click the ADD button to add the required settings, such as Map, LaserScan, TF, etc., subscribe to the corresponding topic data, for example, when adding Map, we need to change the Topic under Map to /map.


Then we can control the slow movement of the cart for SLAM by keyboard. If we move the cart after starting SLAM, we need to do SLAM again, because the TF of the cart is likely to be wrong.

Pay attention to control the speed of movement of the car, if the speed is too fast when turning, it is easy to appear the phenomenon of map shift.

After configuring Rviz, we can also save the current configuration to the feature package and then add the following configuration of Rviz nodes and parameters to the Gmapping launch Launch file to avoid the need to create a new terminal each time to enter the rviz command and re-add the display in Rviz.

We can also use the rqt_graph command to see the relationships between the nodes:

At the end of SLAM, the following command is required to save the map:

Due to the limited space, we constructed the map as shown below.

At this point, we have implemented SLAM in a LIMO mobile robot using the Gmapping algorithm! Using a similar approach, we can also implement other SLAM function packages to run, such as hector, cartographer and rtabmap, etc. Each algorithm has its own advantages and disadvantages, so you can choose a suitable algorithm package according to your needs.


Back to blog