Skip to content

Mapping and Exploration

Emiliano Borghi edited this page Apr 3, 2021 · 12 revisions

The following page covers how to run mapping algorithms with both the simulator (Gazebo) and the real robot:

Exploration packages:


Note: Multiple robots are not supported yet.

Gazebo

# Run cartographer in mapping mode
export LOCALIZATION=cartographer
# Set this to true if you want to open RViz
export RVIZ=true
# Select sensor type
export LASER=rplidar
# Run gazebo in any environment (like a House)
roslaunch ca_gazebo create_house.launch
# Move around the robot using keyboard teleop
roslaunch ca_tools keyboard_teleop.launch
# Try to close loops with the robot's trajectory
# Once you are satisfied with the map, create the pbstream calling the proper service
rosservice call /write_state "filename: '<NAME>.pbstream'"

Real robot

# Set the robot unique identifier
export ID=1
# Run cartographer in mapping mode
export LOCALIZATION=cartographer
# Select sensor type
export LASER=astra
# Run the real robot with the whole navigation stack
roslaunch ca_bringup complete.launch
# Debugging
export RVIZ=true
roslaunch ca_tools rviz.launch
# Move around the robot using keyboard teleop
roslaunch ca_tools keyboard_teleop.launch
# Try to close loops with the robot's trajectory
# Once you are satisfied with the map, create the pbstream calling the proper service
rosservice call /write_state "filename: '<NAME>.pbstream'"

Using the map

Put the map (.pbstream file) into navigation/ca_cartographer/pbstream sharing the name with the world file.

Extra notes

If you go and come again to the same start place cartographer will be able to define a loop closure. Enabling ceres (scan matching) improves the map quality.

With slam_gmapping, after having mapped the environment, you generate a PGM calling a rosservice, in the case of cartographer the service generates a pbstream. If you want the PGM to use it with, for example, map_server + amcl you can call:

cartographer_pbstream_to_ros_map -pbstream_filename <PbstreamFullPath>

and it will generate a PGM.


hector_slam + map_server

Gazebo

export LOCALIZATION=hector_mapping
export RVIZ=true
export LASER=rplidar
roslaunch ca_gazebo create_house.launch

On another console, move the robot around:

roslaunch ca_tools keyboard_teleop.launch

Map the environment and when finished, save the map:

rosrun map_server map_saver -f <NAME_OF_THE_ENVIRONMENT>

Real robot

# TODO

hector_slam + geotiff

Gazebo

export LOCALIZATION=hector_geotiff
export RVIZ=true
export LASER=rplidar
roslaunch ca_gazebo create_house.launch

On another console, move the robot around:

roslaunch ca_tools keyboard_teleop.launch

Map the environment and when finished, save the map:

roslaunch ca_hector geotiff_map_saver.launch

This will store it under ca_hector/maps with the name _ts.tif and _ts.tfw, where is the name of the mapped environment.

Real robot

# TODO

Octomap is a 3D mapping technique using Octrees:

Hornung, A., Wurm, K.M., Bennewitz, M. et al. OctoMap: an efficient probabilistic 3D mapping framework based on octrees. Auton Robot 34, 189–206 (2013). https://doi.org/10.1007/s10514-012-9321-0

Gazebo

# Select a local planner (optional)
export LOCAL_PLANNER=trajectory_rollout
# Open RViz
export RVIZ=true 
# Octomap mapping is enabled with "octomap" keyword
export LOCALIZATION=octomap
# A 3D camera MUST be selected
export LASER=d435
# Launch an environment in Gazebo
roslaunch ca_gazebo create_sweet_house_5.launch

Real robot

# TODO

Gazebo

# Select method
export LOCALIZATION=rtab
# Select a 3D camera
export LASER=d435
# Open RViz
export RVIZ=true
# Open simulator with RViz
roslaunch ca_gazebo create_sweet_house_5.launch

Real robot

# Select method
export LOCALIZATION=rtab
# Select a 3D camera
export LASER=d435
# Open RViz
export RVIZ=true
# Bring up robot with RViz
roslaunch ca_bringup complete.launch

In order to create a map, you'll need to setup slam_gmapping in the robot. The description for that is described here.

For controlling the robot during the mapping process is recommended to move the robot with any of these methods:

# Use the keyboard
roslaunch ca_tools keyboard_teleop.launch
# Use the joystick
roslaunch ca_tools joy_teleop.launch

After creating a map, you can generate the PGM and YAML files with map_server:

rosrun map_server map_saver -f my_map


To automatically build a map, you can send the robot to explore the environment. This can be done with explore_lite which is a greedy frontier-based exploration package.

Launch the robot in a cave with a mapping/SLAM algorithm:

export LOCALIZATION=hector_mapping
export RVIZ=true
export LASER=rplidar
roslaunch ca_gazebo create_cave.launch

Then, run the exploration node:

roslaunch ca_mapping_exploration explore_lite.launch
Clone this wiki locally