What is Mapping in robotics? How to create Map in Ros

Mansoor Alam
4 min readJul 22, 2023

--

Mapping, in the context of robotics and ROS (Robot Operating System), refers to the process of creating a representation of the environment that a robot or sensor can perceive. The goal of mapping is to generate a map, which is typically a 2D or 3D representation, that captures the spatial layout, obstacles, and other relevant features of the surroundings.

Mapping is a fundamental capability for robots to navigate and operate autonomously in their environment. By building a map, a robot can understand where it is located, plan paths, avoid obstacles, and make intelligent decisions based on its surroundings.

In ROS, there are several mapping packages available to create maps of the environment. Some of the commonly used mapping packages are:

  1. gmapping: gmapping (Grid-based FastSLAM) is a popular package for generating 2D occupancy grid maps. It uses the FastSLAM algorithm to build a probabilistic map of the environment based on laser range data and odometry information.
  2. Cartographer: Cartographer is another package that can create 2D and 3D maps. It uses various sensor inputs, such as LIDAR and IMU, to perform simultaneous localization and mapping (SLAM). Cartographer is known for its accurate mapping capabilities.
  3. Hector SLAM: Hector SLAM is a lightweight mapping package suitable for 2D mapping using LIDAR data. It is designed to work well in real-time applications and can be used on robots with limited computational resources.
  4. RTAB-Map: RTAB-Map (Real-Time Appearance-Based Mapping) is a versatile package that not only creates maps but also performs loop closure detection for better mapping accuracy and supports 3D mapping as well.
  5. Karto SLAM: Karto SLAM is a feature-based mapping package that uses scan-matching algorithms to build 2D maps. It is known for its fast mapping capabilities.
  6. OctoMap: OctoMap is primarily used for 3D mapping. It generates an Octree-based representation of the environment, which provides a more detailed and volumetric map.
Environment Map (source ros wiki)

These mapping packages leverage various sensor data such as laser scans, RGB-D data (from sensors like Kinect), and odometry to create the maps. The choice of the mapping package depends on the robot’s hardware, computational capabilities, the level of mapping accuracy required, and the specific environment in which the robot operates.

Remember that mapping is just one part of the robot’s perception and decision-making pipeline. To perform tasks effectively, robots also need to utilize other ROS components like localization (e.g., AMCL — Adaptive Monte Carlo Localization), path planning (e.g., using the move_base package), and control systems. These components work together to enable autonomous navigation and efficient operation of the robot.

Next is How to create Map in ROS?

Creating a map in ROS involves using a mapping package, such as “gmapping” or “Cartographer,” to generate a representation of the environment. Below are the step-by-step instructions to create a 2D map using the “gmapping” package in ROS:

Step 1: Set up ROS Workspace Make sure you have a working ROS installation and have created a catkin workspace. If you haven’t done this yet, follow the ROS installation and workspace setup instructions.

Step 2: Install Required Packages Install the “gmapping” package, which allows you to perform SLAM (Simultaneous Localization and Mapping) and create a 2D map. Open a terminal and run:

sudo apt-get install ros-<YOUR_ROS_DISTRO>-gmapping

Replace “<YOUR_ROS_DISTRO>” with your ROS distribution name, such as “melodic,” “noetic,” etc.

Step 3: Launch the Required Nodes You’ll need to launch the ROS nodes responsible for interfacing with your robot’s sensors and the gmapping node.

For example, if you’re using a Turtlebot with a Kinect sensor, you could do the following:

roslaunch turtlebot_gazebo turtlebot_world.launch roslaunch turtlebot_navigation gmapping_demo.launch

The first command launches Gazebo with the Turtlebot in a simulated world, and the second command starts the gmapping node.

Step 4: Drive the Robot to Map the Environment Use teleoperation to drive the robot around the environment you want to map. As the robot moves, the gmapping algorithm will use sensor data (e.g., laser scans, Kinect data) to build a map of the surroundings.

You can use a tool like “teleop_twist_keyboard” to drive the robot using the keyboard. In a new terminal, run:

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

This will allow you to control the robot’s movement using the keyboard’s arrow keys.

Step 5: Save the Map Once you’ve explored the entire area, you can save the generated map using the “map_server” package. The gmapping node should publish the map to the “map” topic.

Open a new terminal and run:

rosrun map_server map_saver -f <path_to_save_map>

Replace “<path_to_save_map>” with the directory where you want to save the map. The command will save the map in two files: “<path_to_save_map>.pgm” (map image) and “<path_to_save_map>.yaml” (map metadata).

Mapping of Gazebo environment

That’s it! You’ve now created a map of the environment using ROS and the gmapping package. You can use this map for localization and navigation tasks in other ROS applications.
Thanks for reading!

Next, we will target Path Planning :)

--

--

Mansoor Alam

I'm a mechatronics engineer with a passion for cutting-edge technology and a particular expertise in computer vision, deep learning, Robotics and ROS .