Map a room and navigate to a goal
Run Gazebo, build a map with SLAM Toolbox, and send a real Nav2 navigation goal.
Try the room planner
Choose a goal in the room, then run the robot.
Robot navigation room
The 3D workspace loads when it comes into view.
6 moves remaining
More controls
Robot (2, 4), goal (8, 4). 6 moves remaining. Click a cell to set the goal. The green square is the modeled robot footprint.
2D reference and fallback
Inspect route and obstacle coordinates
Route in travel order: (2, 4) → (3, 4) → (4, 4) → (5, 4) → (6, 4) → (7, 4) → (8, 4)
Occupied cells: (5,3), (5,5), (5,6), (5,7).
Excluded robot-center cells: (5,3), (5,5), (5,6), (5,7).
Planner assumptions
Every cardinal move costs one. Breadth-first search finds a shortest route on this fixed grid. The robot is a square aligned with the grid. For footprint width 2r + 1 cells, centers within r cells horizontally and vertically of an occupied cell are excluded. Centers whose footprint crosses a room edge are also excluded. Routes move only the center. There is no turning radius, acceleration, uncertain localization, or moving obstacle prediction. The movement button advances a discrete simulation state, not a physical robot.
Optional reasoning check
Opening the Python editor…
Requirements and learning goals
Before you start
- Ubuntu 24.04 with ROS 2 Jazzy Desktop installed
- A graphical session that can run Gazebo and RViz2
- An internet connection to install the simulation packages
You will be able to
- Build and save a map from simulated laser scans
- Send a goal to Nav2 and inspect its outcome
- Tell the simulator, mapper, visualizer, and navigation stack apart
Navigate a simulated TurtleBot through a room while its laser builds the map. Gazebo simulates the robot and sensor. Toolbox estimates the map and pose. plans and follows routes. RViz2 displays their data and lets you send goals.
This lesson runs those ROS packages on your computer. Allow 30–45 minutes after installing . Use Ubuntu 24.04 with ROS 2 Jazzy; the commands are not macOS shell commands. If ROS is not installed, complete the official Jazzy installation first.
Start the room
In an Ubuntu terminal:
source /opt/ros/jazzy/setup.bash
sudo apt update
sudo apt install ros-jazzy-navigation2 ros-jazzy-nav2-bringup \
ros-jazzy-nav2-minimal-tb3-sim ros-jazzy-slam-toolbox
ros2 launch nav2_bringup tb3_simulation_launch.py \
slam:=True headless:=False use_sim_time:=TrueKeep this terminal running. Gazebo and RViz should open. If Gazebo is paused, press its play control. This launch starts SLAM as well as navigation; do not start a second SLAM or AMCL process beside it. The commands follow Nav2's Jazzy simulation launch and its integrated SLAM option. Nav2 quickstart, Navigating while mapping
Map one room
- In RViz, set the fixed frame to
map. Add a Map display for/mapand a LaserScan display for/scanif they are absent. - Wait for an initial patch of mapped floor and nearby surfaces. Choose a short goal inside observed free space with room around the robot.
- Use the Navigation2 Goal toolbar tool. Click the destination and drag to choose the final heading.
- Watch Gazebo as the robot moves. RViz should show the route and an expanding map. Send a few short goals around the room, revealing it from different viewpoints.
- Return near the starting area and compare the scan with the mapped walls. Finish the active goal or cancel it in the Nav2 panel before saving.
The mapping run estimates its own starting frame. The 2D Pose Estimate tool is for initializing AMCL when against a saved map; it is not a prerequisite for this SLAM run.
Save the map
Open a second terminal. Create a new output directory so an earlier map is not overwritten:
source /opt/ros/jazzy/setup.bash
mkdir -p ~/wendy-learn-maps
map_dir=$(mktemp -d ~/wendy-learn-maps/room-XXXXXX)
ros2 run nav2_map_server map_saver_cli -f "$map_dir/room" \
--ros-args -p use_sim_time:=true
ls "$map_dir"Expect room.yaml and a map image, normally room.pgm. The YAML records the image reference, resolution, and origin. This saves an occupancy map for localization, not SLAM Toolbox's serialized pose graph.
Navigate and check the expected results
While the same mapping session is running, select another destination in the mapped room. Confirm that the robot reaches it and Nav2 reports success. A drawn route alone is not completion. Try canceling a longer goal and verify that motion stops before sending another.
Success means you observed live laser returns, built a map from multiple positions, saved its files, and received a successful navigation result. Remaining unknown regions are acceptable; do not treat them as verified empty space.
The browser's earlier grid exercise used exact poses and cardinal moves. Here, transforms, localization estimates, velocity commands, and sensor updates participate in the result. RViz is the visualizer; it does not simulate the robot.
Troubleshooting
If /map is absent, check that the simulator is playing and the launch includes slam:=True. In another sourced terminal, run ros2 topic hz /scan; use Ctrl+C to stop that diagnostic. No scan messages means the mapping system has no sensor input.
If a scan exists but the map does not, inspect the launch terminal for SLAM or transform errors. ros2 run tf2_tools view_frames writes a diagram for checking the chain between map, odom, the robot base, and laser frame. Avoid mixing wall time and simulation time.
If Nav2 rejects a goal, place it in observed free space with clearance from walls. Inspect the Nav2 panel and terminal for an inactive server or failed planning action. Do not repeatedly move the robot model manually in Gazebo; that breaks the relationship between motion estimates and observations.
A missing nav2_minimal_tb3_sim package means the simulation dependency is not installed or the wrong ROS environment is sourced. Recheck the Jazzy installation above. End the launch with Ctrl+C when finished.
Before you move on
Can you do each of these?
- Build and save a map from simulated laser scans
- Send a goal to Nav2 and inspect its outcome
- Tell the simulator, mapper, visualizer, and navigation stack apart
0 of 2 checkpoints solved. Try checkpoint 1