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 -ySet the robot model (add to ~/.bashrc so it persists):
echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
source ~/.bashrcPhase 1 — Build the Map with SLAM¶
Step 1 — Launch Gazebo simulation
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.pyStep 2 — Start SLAM (new terminal)
ros2 launch slam_toolbox online_async_launch.py use_sim_time:=trueStep 3 — Open RViz to watch map building (new terminal)
ros2 launch nav2_bringup rviz_launch.pyStep 4 — Drive the robot to build the map (new terminal)
ros2 run turtlebot3_teleop teleop_keyboardStep 5 — Save the map
ros2 run nav2_map_server map_saver_cli -f ~/my_mapThis 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.pyStep 2 — Launch NAV2 with the saved map (new terminal)
ros2 launch nav2_bringup bringup_launch.py use_sim_time:=true map:=$HOME/my_map.yamlStep 3 — Open RViz (new terminal)
ros2 launch nav2_bringup rviz_launch.pyStep 4 — Set initial pose and send goal
- In RViz, click "2D Pose Estimate" and click on the map where the robot currently is
- Click "Nav2 Goal" and click anywhere on the free space of the map
- 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¶
| Package | Role |
|---|---|
turtlebot3_gazebo | Simulated robot + world |
slam_toolbox | SLAM algorithm (map building) |
nav2_bringup | Navigation stack launcher |
nav2_map_server | Map saving and serving |
rviz2 | 3D visualisation |