Exploring ROS with a 2 wheeled robot #13 – GMapping

Exploring ROS with a 2 wheeled robot #13 – GMapping

Step 0 – Introduction

Hey ROS Developers!

This is our last post of the series, actually a Bonus post, to show something ready-to-use ROS provides to us. The GMapping package, to create maps while our robot navigates in a given environment. We are going to show how to configure a launch file in order to use the same robot we have been using throughout this series.

Let’s start!

Step 1 – Configuring the environment

First thing, we will use the same robot in the last world we have worked. If you don’t have the ROSJect, just do a copy by clicking here

Next, launch a simulation, as we have done before:

ROS GMapping launch robot

 

And spawn the robot using the command below in a shell:

roslaunch m2wr_description spawn y:=8

You must have the robot there, waiting to be used:

ROS GMapping robot

 

Step 2 – Configuring GMapping launch file

We need to create a new launch file, and I chose to do it in the motion_plan package (~/catkin_ws/src/motion_plan/launch/gmapping.launch)

The content must be the same as below, and I’ll explain the major points:

<launch>
  <arg name="scan_topic"  default="/m2wr/laser/scan" />
  <arg name="base_frame"  default="link_chassis"/>
  <arg name="odom_frame"  default="odom"/>

  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher"></node>

  <node pkg="rviz" type="rviz" name="rviz"></node>

  <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
    <param name="base_frame" value="$(arg base_frame)"/>
    <param name="odom_frame" value="$(arg odom_frame)"/>
    <param name="map_update_interval" value="5.0"/>
    <param name="maxUrange" value="6.0"/>
    <param name="maxRange" value="8.0"/>
    <param name="sigma" value="0.05"/>
    <param name="kernelSize" value="1"/>
    <param name="lstep" value="0.05"/>
    <param name="astep" value="0.05"/>
    <param name="iterations" value="5"/>
    <param name="lsigma" value="0.075"/>
    <param name="ogain" value="3.0"/>
    <param name="lskip" value="0"/>
    <param name="minimumScore" value="200"/>
    <param name="srr" value="0.01"/>
    <param name="srt" value="0.02"/>
    <param name="str" value="0.01"/>
    <param name="stt" value="0.02"/>
    <param name="linearUpdate" value="0.5"/>
    <param name="angularUpdate" value="0.436"/>
    <param name="temporalUpdate" value="-1.0"/>
    <param name="resampleThreshold" value="0.5"/>
    <param name="particles" value="80"/>
  <!--
    <param name="xmin" value="-50.0"/>
    <param name="ymin" value="-50.0"/>
    <param name="xmax" value="50.0"/>
    <param name="ymax" value="50.0"/>
  make the starting size small for the benefit of the Android client's memory...
  -->
    <param name="xmin" value="-1.0"/>
    <param name="ymin" value="-1.0"/>
    <param name="xmax" value="1.0"/>
    <param name="ymax" value="1.0"/>

    <param name="delta" value="0.05"/>
    <param name="llsamplerange" value="0.01"/>
    <param name="llsamplestep" value="0.01"/>
    <param name="lasamplerange" value="0.005"/>
    <param name="lasamplestep" value="0.005"/>
    <remap from="scan" to="$(arg scan_topic)"/>
  </node>
</launch>

The first 3 tags, the arguments, are the ones related to our robot:

  • scan_topic is the topic we have been reading to get the laser data
  • base_frame is the frame of the frame, but to be more precise, it must be the frame of the laser
  • odom_frame is the frame used by the odometry, so yes, it depends on odometry

There are other parameters you can play with (many actually), for example:

  • maxRange to set the maximum distance to use to map
  • max_update_interval that is used to improve the map updating rate (but you have to be careful with your hardware performance also)

These are the main parameters to a basic usage of gmapping. You can check the official documentation here: http://wiki.ros.org/gmapping

 

Step 3 – Launch Gmapping

So, let’s put it to work!

Open another shell and execute:

roslaunch motion_plan gmapping.launch

Open the graphical tools and configure RViz to show the robot model and the map being generated:

ROS GMapping RViz

One more shell.. Let’s use the teleop to drive the robot while it maps the environment:

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

If you don’t know yet this package, this is used to send velocity commands to the robot using the keyboard. You can check the instructions on the shell itself:

ROS GMapping shell

 

Step 4 – Results

After driving the robot around the environment, you must have something similar to the image below:

ROS GMapping

The robot is placed more or less at the center of the world and we have almost the entire map generated.

It depends on the hardware, the odometry and the way you have navigated. But we have a map! Don’t we?!

Related Courses

ROS Navigation Course Cover - ROS Online Courses - Robot Ignite Academy

ROS Navigation

RTAB-Map Course Cover - ROS Online Courses - Robot Ignite Academy

RTAB-Map Course

 

Conclusion

After configuring the launch file, it’s quite easy to use gmapping. You can take advantage of this package to generate maps of different environments!

Don’t forget: If you have suggestions, doubts or just like this post, please, leave a comment and let us know your opinion.

See you!

[ROS Q&A] 159 – How to create a Restricted Area on a Map

[ROS Q&A] 159 – How to create a Restricted Area on a Map

In the following video, we are going to show how to create a restricted area (the robot cannot go in) in a Map generated with gmapping.

RELATED LINKS

Robot Ignite Academy
ROS Development Studio (ROSDS)
Original Question

We love feedback!

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

[ROS Q&A] 136 – How to edit a map generated with gmapping

In this video we are going to see how to edit a map (PGM file) which has been generating with the gmapping package.

This is a video based on the following post on ROS Answers:
https://answers.ros.org/question/295879/how-to-edit-the-map-pbm-built-by-gmapping-pkg/

// RELATED LINKS

▸ Original question: https://answers.ros.org/question/295879/how-to-edit-the-map-pbm-built-by-gmapping-pkg/
ROS Development Studio (ROSDS)
Robot Ignite Academy
ROS Navigation in 5 Days Online Course

Step 1. Create a project in ROS Development Studio(ROSDS)

ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here. Let’s create a new project and call it edit_map_qa.

Step 2. Map generation

In ROS, you can generate a map with SLAM algorithm like gmapping. The map file normally has the .pgm and .yaml foramt where the .pgm is basically an image and .yaml file contains some information like origin, resolution and etc. In this tutorial, I a map is generated using the summit xl robot.

Step 3. Edit map

There are many edit tools available. As a demonstration, we use GIMP on mac to edit the .pgm image. For example, Add a wall in the map.

Step 4. Publish the new map to the map server

Now, you can launch the navigation package again, you’ll see that a new ‘wall’ appears on the map. If you do the path planning again, you should notice that the path is changed due to the wall is blocking the way now.

Want to learn more?

If you are interested in this topic and want to learn more about the navigation stack in ROS and how to use map sever, please check our ROS Navigation in 5 Days Online Course for more information.

 

 

Edit by: Tony Huang


Feedback

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

Pin It on Pinterest