Skip to content
  • Home
  • About the Blog
  • About the Author
  • Sitemap

Abdur Rosyid's Blog

Just a few notes on mechanical engineering and robotics

Performing SLAM using GMapping in ROS

July 22, 2021 by Abdur Rosyid

GMapping is a commonly used SLAM package in ROS. Here are some steps to perform GMapping in ROS:

Step 1: Create a package for this. Make a “launch” folder inside the package folder.

Step 2: Create a launch file to run the “gmapping” node. Set the parameters of the “gmapping” node inside this launch file. Below is an example launch file for turtlebot3.

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<launch>
  <!-- Gmapping -->
  <node pkg="gmapping" type="slam_gmapping" name="turtlebot3_slam_gmapping" output="screen">
    <param name="base_frame" value="base_footprint"/> The frame attached to the mobile base
    <param name="odom_frame" value="odom"/> The frame attached to the odometry system
    <param name="map_update_interval" value="2.0"/> Map update interval (sec)
    <param name="maxUrange" value="4.0"/> Max Range of laser sensor to use (meter)
    <param name="minimumScore" value="100"/> Min Score considering the results of scan matching
    <param name="linearUpdate" value="0.2"/> Min travel distance required for processing
    <param name="angularUpdate" value="0.2"/> Min rotation angle required for processing
    <param name="temporalUpdate" value="0.5"/> If the last scan time exceeds this update time, the scan is performed. Negative values will be ignored and not used.
    <param name="delta" value="0.05"/> Map Resolution: Distance / Pixel
    <param name="lskip" value="0"/> Number of beams to skip in each scan
    <param name="particles" value="120"/> Number of particles in particle filter
    <param name="sigma" value="0.05"/> Standard deviation of laser-assisted search
    <param name="kernelSize" value="1"/> Window size of laser-assisted search
    <param name="lstep" value="0.05"/> Initial search step (translation)
    <param name="astep" value="0.05"/> Initial search step (rotation)
    <param name="iterations" value="5"/> Number of scan-matching iterations
    <param name="lsigma" value="0.075"/> The sigma of a beam used for likelihood computation
    <param name="ogain" value="3.0"/> Gain to be used while evaluating the likelihood
    <param name="srr" value="0.01"/> Odometry error (translation→ translation)
    <param name="srt" value="0.02"/> Odometry error (translation→ rotaion)
    <param name="str" value="0.01"/> Odometry error (rotation → translation)
    <param name="stt" value="0.02"/> Odometry error (rotation → rotation)
    <param name="resampleThreshold" value="0.5"/>Resampling threshold value
    <param name="xmin" value="-10.0"/> Initial map size (min x)
    <param name="ymin" value="-10.0"/> Initial map size (min y)
    <param name="xmax" value="10.0"/> Initial map size (max x)
    <param name="ymax" value="10.0"/> Initial map size (max y)
    <param name="llsamplerange" value="0.01"/> Translational sampling range for the likelihood
    <param name="llsamplestep" value="0.01"/> Translational sampling step for the likelihood
    <param name="lasamplerange" value="0.005"/> Angular sampling range for the likelihood
    <param name="lasamplestep" value="0.005"/> Angular sampling step for the likelihood
  </node>
</launch>

Step 3: Create another launch file that launches the following:

  • your robot description
  • the “robot_state_publisher” that publishes tf. This is required because the “gmapping” node requires tf.
  • the “gmapping” node.
  • Rviz node. It is good to see the map creation in Rviz while the “gmapping” node is running.

Step 4: To start the SLAM process, firstly start your robot and your laser scanner. Since you need to tele-operate the robot during the SLAM process, make sure your tele-operation node is also running. While your laser scanner is ON, make sure your laser scanner publishes /scan topic.

Afterwards, you can launch the launch file you created in Step 3. Right after this, optionally you can save the /scan and /tf topics being published during the robot motion:

1
rosbag record -O scan_data /scan /tf

The ‘-O’ option of the following command is an option to specify the name of the output file, and saves the bag file as “scan_data.bag”. The benefit of recording these topic is reusability of these topics. Having these topics as bag files enables you to run another SLAM process, not only using the “gmapping” algorithm but also other 2D SLAM algorithms, without a need to make another run of the robot. This is very useful when working with a real robot. But this even can be useful when working in simulation as well, because you don’t need to rerun teleoperation of your robot in the simulation.

During the SLAM process, move your robot around the environment, so that the scanner captures the whole environment to create a complete map of the environment.

Step 5: Save the created map:

1
rosrun map_server map_saver -f ~/my_map

This will save the “my_map” map into your home folder.

Post navigation

Previous Post:

Fusing Wheel Odometry, IMU Data, and GPS Data Using robot_localization in ROS

Next Post:

Autonomous SLAM Using Frontier Exploration in ROS

One comment

  1. Pingback: Autonomous SLAM Using Frontier Exploration in ROS – Abdur Rosyid's Blog

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • STEM 101
  • Robotics
  • Kinematics
  • Dynamics
  • Control
  • Robot Operating System (ROS)
  • Robot Operating System (ROS2)
  • Software Development
  • Mechanics of Materials
  • Finite Element Analysis
  • Fluid Mechanics
  • Thermodynamics

Recent Posts

  • Pull Request on Github
  • Basics of Git and Github
  • Conda vs Docker
  • A Conda Cheat Sheet
  • Installing NVIDIA GPU Driver on Ubuntu

Archives

  • June 2025
  • July 2021
  • June 2021
  • March 2021
  • September 2020
  • April 2020
  • January 2015
  • April 2014
  • March 2014
  • March 2012
  • February 2012
  • June 2011
  • March 2008
© 2025 Abdur Rosyid's Blog | WordPress Theme by Superbthemes