Autonomous mobile robot with SLAM mapping and Nav2 navigation
ROS 2 Jazzy | Gazebo Harmonic | Nav2 Navigation | SLAM Toolbox
# Verify ROS 2 Jazzy is installed
ros2 --version
# Verify Gazebo Harmonic is installed
gz sim --version
# Install required packages if missing
sudo apt install ros-jazzy-navigation2 ros-jazzy-nav2-bringup
sudo apt install ros-jazzy-slam-toolboxcd ~/Final
colcon build --packages-select squarobot_gazebo
source install/setup.bashUse this when: You want to see the robot immediately with RViz
Steps:
-
Launch simulation with RViz:
cd ~/Final source install/setup.bash ros2 launch squarobot_gazebo simulation_with_rviz.launch.py
-
Control the robot (in another terminal):
ros2 run teleop_twist_keyboard teleop_twist_keyboard
-
What you'll see:
- β Gazebo simulation window
- β RViz with robot model
- β Real-time lidar visualization
- β TF frames (odom β base_link β sensors)
Controls:
i= Forward,= Backwardj= Turn Leftl= Turn Rightk= Stop
Use this when: You already have a map and want autonomous navigation
Steps:
-
Launch the navigation system:
cd ~/Final source install/setup.bash ros2 launch squarobot_gazebo navigation_with_map.launch.py
-
Wait for all nodes to start (5-10 seconds)
-
Set initial robot pose in RViz:
- Click "2D Pose Estimate" button (toolbar at top)
- Click on the center of the map where robot spawned (~0, 0)
- Drag to set the robot's orientation
-
Verify everything is working:
- β Map appears (gray/white/black)
- β Robot model is visible
- β Green particle cloud around robot (AMCL)
- β No red errors in terminal
- β "Global Status: OK" in RViz
-
Send navigation goal:
- Click "Nav2 Goal" button
- Click destination on map
- Drag to set goal orientation
- Robot navigates autonomously! π€
Map file location: ~/Final/my_maze_map.yaml (already included)
Use this when: You want to explore and map a new environment while navigating
Steps:
-
Launch SLAM + Navigation:
cd ~/Final source install/setup.bash ros2 launch squarobot_gazebo slam_nav_simulation.launch.py
-
Activate SLAM Toolbox (in another terminal):
cd ~/Final source install/setup.bash ros2 lifecycle set /slam_toolbox configure ros2 lifecycle set /slam_toolbox activate
-
Set initial pose in RViz (same as Option 1, step 3)
-
Navigate and map:
- Use "Nav2 Goal" to send robot to unexplored areas
- Map builds as robot moves
- Watch map expand in RViz
-
Save the map when complete:
ros2 run nav2_map_server map_saver_cli -f ~/Final/my_new_map
Use this when: You want to manually drive and create a map
Steps:
-
Launch SLAM mapping:
cd ~/Final source install/setup.bash ros2 launch squarobot_gazebo slam_simulation.launch.py
-
Activate SLAM (in another terminal):
ros2 lifecycle set /slam_toolbox configure ros2 lifecycle set /slam_toolbox activate
-
Drive robot manually:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Controls:
i= Forward,= Backwardj= Turn Leftl= Turn Rightk= Stop
-
Save map:
ros2 run nav2_map_server map_saver_cli -f ~/Final/my_map
Frames (coordinate systems) tell the robot where everything is in 3D space. Think of them like GPS coordinates but for the robot.
Basic Simulation (testing, teleoperation):
odom (tracks where robot has moved)
ββ base_link (robot body)
ββ wheels (drive the robot)
ββ lidar (sees obstacles)
With Navigation/SLAM (autonomous):
map (the global map - like Google Maps)
ββ odom (where robot thinks it is)
ββ base_link (actual robot)
ββ sensors
| Frame | Purpose | Analogy |
|---|---|---|
| map | Global reference, never moves | Street address |
| odom | Tracks movement (drifts over time) | Counting steps |
| base_link | Robot body | Your body |
Key Insight:
odomdrifts (wheels slip, errors accumulate) βmapcorrects this drift (SLAM/AMCL fixes it) β- Both together = accurate navigation!
π Deep dive: Complete Frames and Transforms Guide
-
Launch SLAM mapping:
ros2 launch squarobot_gazebo slam_simulation.launch.py
-
Activate SLAM (new terminal):
cd ~/Final && source install/setup.bash ros2 lifecycle set /slam_toolbox configure ros2 lifecycle set /slam_toolbox activate
-
Drive around to map environment:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
-
Save map:
ros2 run nav2_map_server map_saver_cli -f ~/Final/my_maze_map -
Stop launch (Ctrl+C)
-
Launch navigation with saved map:
cd ~/Final && source install/setup.bash ros2 launch squarobot_gazebo navigation_with_map.launch.py
-
Set initial pose in RViz (2D Pose Estimate tool)
-
Send navigation goals (Nav2 Goal tool)
-
Robot navigates autonomously! β¨
Final/
βββ src/
β βββ squarobot_gazebo/ # Main robot package
β β βββ launch/
β β β βββ navigation_with_map.launch.py β Map-based navigation
β β β βββ slam_nav_simulation.launch.py SLAM + Navigation
β β β βββ slam_simulation.launch.py SLAM mapping only
β β β βββ simulation.launch.py Basic simulation
β β βββ config/
β β β βββ nav2_params.yaml # Navigation parameters
β β β βββ slam_params.yaml # SLAM parameters
β β β βββ nav.rviz # Navigation RViz config
β β β βββ slam.rviz # SLAM RViz config
β β βββ worlds/ # Gazebo environments
β β βββ gazebo/ # Robot URDF/Xacro
β β βββ src/
β β βββ odom_to_tf.py # Odometry TF broadcaster
β βββ squarobot_urdf/ # Additional URDF files
βββ docs/ # π Documentation
β βββ AUTONOMOUS_NAVIGATION_DOCUMENTATION.md # Main docs
β βββ TROUBLESHOOTING_GUIDE.md # Error solutions
β βββ QUICK_START_NAVIGATION.md
β βββ COMPLETE_NAVIGATION_GUIDE.md
β βββ SYSTEM_ARCHITECTURE.md
βββ my_maze_map.yaml # Saved map metadata
βββ my_maze_map.pgm # Saved map image
βββ build/ # Build artifacts (generated)
βββ install/ # Installed packages (generated)
βββ log/ # ROS 2 logs (generated)
| Launch File | Description | Frames | Use Case |
|---|---|---|---|
simulation.launch.py |
Basic robot simulation | odom, base_link | Testing, development, teleoperation |
simulation_with_rviz.launch.py β |
Simulation + RViz visualization | odom, base_link | Testing with visual feedback |
slam_simulation.launch.py |
SLAM mapping with teleoperation | map, odom, base_link | Create/update maps manually |
slam_nav_simulation.launch.py |
SLAM + Navigation simultaneously | map, odom, base_link | Explore unknown environments |
navigation_with_map.launch.py |
Navigation with pre-saved map β | map, odom, base_link | Production navigation, fastest setup |
All launch files maintain proper TF tree structure:
Basic Simulation:
odom
ββ base_link
ββ left_wheel_1, right_wheel_1, caster_1
ββ lidar_1
With Navigation/SLAM:
map (global reference)
ββ odom (continuous tracking)
ββ base_link (robot body)
ββ sensors
π Learn more: Frames and Transforms Guide
Solution:
- Wait 5-10 seconds for all nodes to start
- Set initial pose using "2D Pose Estimate" in RViz
- See docs/TROUBLESHOOTING_GUIDE.md
Solution:
- Verify all nodes are running:
ros2 node list - Check TF tree:
ros2 run rqt_tf_tree rqt_tf_tree - Set initial pose in RViz
Solution:
- Ensure initial pose was set correctly
- Check goal is in free space (white area on map)
- Verify
/cmd_velis publishing:ros2 topic hz /cmd_vel
Already fixed! This was resolved by excluding docking_server from the launch file.
π For detailed troubleshooting: See docs/TROUBLESHOOTING_GUIDE.md
# 1. List all running nodes
ros2 node list
# 2. Check TF tree is complete
ros2 run rqt_tf_tree rqt_tf_tree
# 3. Verify map is loaded
ros2 topic echo /map --once
# 4. Check AMCL is localizing
ros2 topic hz /amcl/pose
# 5. Verify odometry is publishing
ros2 topic hz /odom
# 6. Check laser scan
ros2 topic hz /scanExpected nodes for navigation_with_map.launch.py:
/amcl- Localization/bt_navigator- Behavior tree navigator/controller_server- Path following/planner_server- Path planning/map_server- Map provider/lifecycle_manager_localization/lifecycle_manager_navigation/lifecycle_manager_map
All documentation is organized in the docs/ folder:
- Quick Start β - Get started in 5 minutes
- Complete Navigation Guide - Full workflow
- SLAM & Nav2 Guide - SLAM integration
- Frames and Transforms Guide β - Complete frame system explained
- System Architecture - System design and TF tree
- Autonomous Navigation Docs - Complete technical reference
- Implementation Summary - Design decisions
- Troubleshooting Guide β - All common errors
- Error Fixes - Specific error documentation
- Launch Files Reference β - All 5 launch files explained
- Workspace Organization - Project structure
π Full Documentation Index: docs/README.md
- OS: Ubuntu 24.04 (Noble)
- ROS 2: Jazzy Jalisco
- Gazebo: Harmonic
- Python: 3.12+
sudo apt install ros-jazzy-navigation2
sudo apt install ros-jazzy-nav2-bringup
sudo apt install ros-jazzy-nav2-amcl
sudo apt install ros-jazzy-slam-toolbox
sudo apt install ros-jazzy-teleop-twist-keyboard- RAM: 8GB minimum (16GB recommended)
- CPU: 4 cores minimum
- GPU: Integrated graphics sufficient for Gazebo
| Topic | Type | Description |
|---|---|---|
/scan |
sensor_msgs/LaserScan | Lidar data |
/odom |
nav_msgs/Odometry | Robot odometry |
/cmd_vel |
geometry_msgs/Twist | Velocity commands |
/map |
nav_msgs/OccupancyGrid | Static map |
/amcl/pose |
geometry_msgs/PoseWithCovarianceStamped | Estimated robot pose |
/initialpose |
geometry_msgs/PoseWithCovarianceStamped | Initial pose for AMCL |
/goal_pose |
geometry_msgs/PoseStamped | Navigation goal |
cd ~/Final
colcon build --packages-select squarobot_gazebo
source install/setup.bash# Latest logs
cd ~/.ros/log/latest
# Specific node log
cat ~/.ros/log/latest/amcl-*.log# Monitor all topics for issues
ros2 topic list
# Check node info
ros2 node info /amcl
# View parameters
ros2 param list /amclThis project implements:
- β Differential drive robot simulation
- β SLAM Toolbox integration
- β Nav2 navigation stack
- β AMCL localization
- β Map-based autonomous navigation
- β Comprehensive error handling
- β Complete documentation
This project follows ROS 2 conventions and best practices.
- Check documentation: docs/
- Troubleshooting guide: TROUBLESHOOTING_GUIDE.md
- Error history: All fixed errors are documented
- ROS 2 resources:
You know it's working when:
- β Gazebo shows robot in maze environment
- β RViz displays the map clearly
- β Robot model appears on the map
- β Green particle cloud visible (AMCL)
- β Setting nav goal shows green path
- β Robot moves smoothly to goal
- β Obstacle avoidance works
- β No error messages in terminal
π Ready to navigate! Launch the system and explore autonomous robotics with ROS 2!
Last Updated: January 17, 2026
Status: Fully Functional β
ROS 2 Version: Jazzy Jalisco
Gazebo Version: Harmonic