The original setup had issues with:
- RViz Fixed Frame: Was set to
base_linkinstead ofmapfor SLAM - Missing Map Display: RViz config didn't include Map visualization
- Manual Configuration Required: User had to manually add displays in RViz
Created an all-in-one SLAM launch file that:
- Launches Gazebo simulation with wall maze world
- Starts SLAM Toolbox for mapping
- Opens RViz2 with pre-configured SLAM displays (Map + LaserScan)
- All ready to use in one command!
squarobot_gazebo/
├── config/
│ ├── slam_params.yaml # SLAM Toolbox configuration
│ ├── nav2_params.yaml # Nav2 navigation configuration
│ ├── sim.rviz # Basic simulation RViz config
│ └── slam.rviz # SLAM-specific RViz config (Fixed Frame: map, with Map display)
│
└── launch/
├── simulation.launch.py # Gazebo only
├── simulation_with_rviz.launch.py # Gazebo + RViz
├── slam.launch.py # SLAM Toolbox only
├── navigation.launch.py # Nav2 only
└── slam_simulation.launch.py # ✨ ALL-IN-ONE: Gazebo + SLAM + RViz
# Single command launches everything!
cd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo slam_simulation.launch.pyWhat this launches:
- ✅ Gazebo with simple_wall world
- ✅ SLAM Toolbox for mapping
- ✅ RViz2 with map visualization pre-configured
- ✅ All bridges and transforms
You should see:
- Gazebo window with robot in maze
- RViz window showing:
- Red laser scan
- Robot model
- Blue/gray map building in real-time
- Fixed Frame set to
map(check top-left)
Open a new terminal:
cd ~/Final
source install/setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboardDrive around the maze:
i= forwardk= stopj= turn leftl= turn right,= backwardu,o,m,.= diagonal movements
Watch the map build in RViz as you drive!
When you've explored the entire maze:
cd ~/Final
ros2 run nav2_map_server map_saver_cli -f my_maze_mapCreates:
my_maze_map.yaml- Map metadatamy_maze_map.pgm- Map image
If you want to launch components separately for learning:
cd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo simulation_with_rviz.launch.pycd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo slam.launch.pycd ~/Final
source install/setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboardIn RViz:
- Change Fixed Frame from
base_linktomap - Click Add → By topic →
/map→ Map → OK - Now you'll see the map building
- You must have a saved map (from SLAM above)
- Stop the SLAM launch if still running
Terminal 1: Simulation
cd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo simulation_with_rviz.launch.pyTerminal 2: Map Server
cd ~/Final
source install/setup.bash
ros2 run nav2_map_server map_server --ros-args \
-p yaml_filename:=$PWD/my_maze_map.yaml \
-p use_sim_time:=trueTerminal 3: Lifecycle Manager (for map server)
source install/setup.bash
ros2 run nav2_lifecycle_manager lifecycle_manager --ros-args \
-p use_sim_time:=true \
-p autostart:=true \
-p node_names:="['map_server']"Terminal 4: Navigation
cd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo navigation.launch.py-
Set Initial Pose:
- Click "2D Pose Estimate" button (top toolbar)
- Click on map where robot actually is
- Drag to set orientation
-
Set Navigation Goal:
- Click "2D Goal Pose" button
- Click where you want robot to go
- Drag to set desired final orientation
-
Watch autonomous navigation!
# Check map topic is publishing
ros2 topic hz /map
# Should show updates every few seconds
# Check SLAM node is running
ros2 node list | grep slam
# Should show: /slam_toolbox
# Echo map to see data
ros2 topic echo /map --onceIn RViz, verify:
- Fixed Frame: Top-left should show
map(notbase_link) - Displays Panel: Should show "Map" with checkmark
- Map Topic: Should be
/map - Map Alpha: Set to 0.7 for semi-transparent
Solution:
# Check Fixed Frame
# In RViz: Global Options → Fixed Frame → Change to "map"
# Verify map topic exists
ros2 topic list | grep map
# Should show: /map
# Check SLAM is publishing
ros2 topic hz /mapSolution:
# SLAM needs time to initialize
# Drive robot a bit (at least 0.5m) to trigger first map update
# Verify scan is working
ros2 topic hz /scan
# Should show ~10 HzSolution:
- Drive slower with teleopincrease SLAM
minimum_travel_distancein slam_params.yaml - Ensure good lidar visibility (not too close to walls)
Solution:
# SLAM creates map→odom transform
# Verify SLAM is running
ros2 run tf2_tools view_frames
# Should show: map → odom → base_link
# Check TF tree
ros2 run tf2_ros tf2_echo map odomFor better mapping in tight spaces:
minimum_travel_distance: 0.1 # Default: 0.2
minimum_travel_heading: 0.1 # Default: 0.2For faster map updates:
map_update_interval: 2.0 # Default: 5.0For loop closure (recognizing visited places):
do_loop_closing: true # Already enabled
loop_search_maximum_distance: 5.0 # Increase for larger mapsAdjust robot speed:
controller_server:
FollowPath:
max_vel_x: 0.5 # Default: 0.3 (increase for faster)
max_vel_theta: 1.5 # Default: 1.0 (faster turning)Adjust obstacle avoidance:
local_costmap:
robot_radius: 0.2 # Increase if robot hits obstacles
inflation_radius: 0.7 # Increase for wider berthAdjust path planning tolerance:
planner_server:
GridBased:
tolerance: 0.3 # Default: 0.5 (smaller = closer to goal)# Map 1: Exploration
ros2 run nav2_map_server map_saver_cli -f exploration_map
# Map 2: After optimization
ros2 run nav2_map_server map_saver_cli -f optimized_map
# Map 3: Different area
ros2 run nav2_map_server map_saver_cli -f area2_map# Record all SLAM data
ros2 bag record /scan /odom /tf /tf_static /map
# Replay later
ros2 bag play my_recording.bagModify slam_params.yaml:
mode: localization # Change from "mapping"Then launch:
ros2 launch squarobot_gazebo slam_simulation.launch.py
# Robot will localize on existing map without creating new oneslam_params.yaml:
- SLAM algorithm settings
- Map frame names (map, odom, base_link)
- Loop closure thresholds
- Mapping frequency and quality
nav2_params.yaml:
- Navigation behavior configuration
- Costmap settings (obstacle detection)
- Path planning algorithms
- Recovery behaviors
slam.rviz:
- RViz visualization for SLAM
- Fixed Frame:
map(required for SLAM) - Displays: Grid, Robot, LaserScan, TF, Map
- Pre-configured for immediate use
slam_simulation.launch.py ⭐:
- All-in-one SLAM solution
- Launches: Gazebo + SLAM + RViz
- Uses slam.rviz config automatically
- Recommended for SLAM mapping
slam.launch.py:
- SLAM Toolbox node only
- Use with existing simulation
- For manual control
navigation.launch.py:
- Nav2 navigation stack
- Requires separate map server
- Use after mapping is complete
- Run
slam_simulation.launch.py - Drive robot with teleop
- Watch map build in RViz
- Save map when done
- Success! You've created a map
- Load saved map with map_server
- Launch navigation.launch.py
- Set initial pose in RViz
- Set goal pose
- Watch autonomous navigation
- Adjust SLAM sensitivity
- Modify Nav2 costmaps
- Change robot speeds
- Optimize for your environment
# SLAM Mapping (All-in-One)
ros2 launch squarobot_gazebo slam_simulation.launch.py
# Teleoperation
ros2 run teleop_twist_keyboard teleop_twist_keyboard
# Save Map
ros2 run nav2_map_server map_saver_cli -f my_map
# Check Topics
ros2 topic list
ros2 topic hz /map
ros2 topic hz /scan
# Check Nodes
ros2 node list
ros2 node info /slam_toolbox
# Check TF Tree
ros2 run tf2_tools view_frames
ros2 run tf2_ros tf2_echo map odom
# Launch Navigation (separate terminals)
ros2 launch squarobot_gazebo simulation_with_rviz.launch.py
ros2 run nav2_map_server map_server --ros-args -p yaml_filename:=./my_map.yaml
ros2 launch squarobot_gazebo navigation.launch.py✅ SLAM Working Correctly:
- Map appears in RViz (blue/gray)
- Map updates as robot moves
/maptopic publishing (~5 Hz)- No TF errors in console
- Robot tracks correctly on map
✅ Navigation Working Correctly:
- Robot localizes on map (green arrow)
- Path appears when goal is set (green line)
- Robot follows path smoothly
- Avoids obstacles
- Reaches goal within tolerance
What was created:
- ✅ Complete SLAM configuration
- ✅ Complete Nav2 configuration
- ✅ SLAM-specific RViz config with Map display
- ✅ All-in-one launch file for easy SLAM
- ✅ Separate launch files for flexibility
Ready to use:
cd ~/Final
source install/setup.bash
ros2 launch squarobot_gazebo slam_simulation.launch.py
# Everything works out of the box!For navigation:
- First create map with SLAM
- Save it with map_saver_cli
- Launch navigation stack
- Set goals in RViz
You now have a complete SLAM and navigation system ready to use! 🎉