SLAM and NAV2 Autonomous Navigation (Gazebo)

Concept

SLAM (Simultaneous Localisation and Mapping) builds a 2D occupancy grid map while the robot moves through an environment using LIDAR data. NAV2 (Navigation 2) uses this map to plan collision-free paths and drive the robot to goal poses autonomously.

This experiment uses TurtleBot3 Burger — a widely supported differential-drive robot with a LIDAR sensor.

Install Everything

sudo apt install ros-humble-turtlebot3*        -y
sudo apt install ros-humble-slam-toolbox       -y
sudo apt install ros-humble-navigation2        -y
sudo apt install ros-humble-nav2-bringup       -y

Set the robot model (add to ~/.bashrc so it persists):

echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
source ~/.bashrc

Phase 1 — Build the Map with SLAM

Step 1 — Launch Gazebo simulation

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

Step 2 — Start SLAM (new terminal)

ros2 launch slam_toolbox online_async_launch.py use_sim_time:=true

Step 3 — Open RViz to watch map building (new terminal)

ros2 launch nav2_bringup rviz_launch.py

Step 4 — Drive the robot to build the map (new terminal)

ros2 run turtlebot3_teleop teleop_keyboard

Step 5 — Save the map

ros2 run nav2_map_server map_saver_cli -f ~/my_map

This saves two files: ~/my_map.pgm (image) and ~/my_map.yaml (metadata).

Phase 2 — Autonomous Navigation

Stop all terminals from Phase 1. Then:

Step 1 — Relaunch Gazebo

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

Step 2 — Launch NAV2 with the saved map (new terminal)

ros2 launch nav2_bringup bringup_launch.py   use_sim_time:=true   map:=$HOME/my_map.yaml

Step 3 — Open RViz (new terminal)

ros2 launch nav2_bringup rviz_launch.py

Step 4 — Set initial pose and send goal

  1. In RViz, click "2D Pose Estimate" and click on the map where the robot currently is
  2. Click "Nav2 Goal" and click anywhere on the free space of the map
  3. The robot will plan a path (shown in green) and navigate autonomously

Expected Result

  • Phase 1: RViz shows a 2D grey map being filled in as you drive
  • Phase 2: Robot plans a path and drives to the goal while avoiding obstacles

Key Package Reference

PackageRole
turtlebot3_gazeboSimulated robot + world
slam_toolboxSLAM algorithm (map building)
nav2_bringupNavigation stack launcher
nav2_map_serverMap saving and serving
rviz23D visualisation