Skip to content

Simultaneous Localization and Mapping (SLAM)

Emiliano Borghi edited this page Nov 23, 2021 · 11 revisions

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


Gazebo

# Run cartographer in mapping mode
export LOCALIZATION=cartographer
# Set this to true if you want to open RViz
export RVIZ=true
# Use a 2D sensor
export LASER=rplidar
# Run gazebo in any environment (like a House)
roslaunch ca_gazebo create_sweet_house_5.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:

rosrun cartographer_ros cartographer_pbstream_to_ros_map -pbstream_filename <PbstreamFullPath>

and it will generate a PGM.


Gazebo

export LOCALIZATION=rtab
# Open RViz
export RVIZ=true
# Select the RGBD camera that the robot will use
export LASER=d435
# Open the simulation in an environment
roslaunch ca_gazebo create_sweet_house_5.launch

Real robot

TODO

Gazebo

slam_gmapping only works with one robot simultaneously.

# slam option runs slam_gmapping
export LOCALIZATION=slam
# Open RViz with navigation.rviz
export RVIZ=true
# Specify only 1 robot (optional)
export NUM_ROBOTS=1
# Select the laser that the robot is using
export LASER=astra
# Open the simulation in a maze environment
roslaunch ca_gazebo create_maze.launch

Real robot

# Set the robot unique identifier
export ID=1
# Run cartographer in mapping mode
export LOCALIZATION=slam
# Select sensor type
export LASER=astra
# Run driver
LASER=astra roslaunch ca_bringup complete.launch
# Debugging
export RVIZ_CONFIG=navigation
roslaunch ca_tools rviz.launch
# Move robot with keyboard teleop
roslaunch ca_tools keyboard_teleop.launch