B3: SLAM and Navigation Concepts
How Robots Map Their World and Find Their Way
Learning Objectives
By the end of this lesson, you will be able to:
- Explain what SLAM is and why it's challenging
- Describe the localization-mapping chicken-and-egg problem
- Identify the components of autonomous navigation
- Understand the difference between global and local planning
Prerequisites
- Completed B1: Introduction to Robotic Perception
- Completed B2: Understanding Sensor Types
- Basic understanding of coordinate frames (Gazebo Refresher)
Theory: The SLAM Problem
What is SLAM?
SLAM stands for Simultaneous Localization and Mapping. It's the process by which a robot:
- Builds a map of an unknown environment
- Localizes itself within that map
- Does both at the same time
The Chicken-and-Egg Problem
SLAM is fundamentally challenging because:
- To build a map, you need to know where you are (localization)
- To know where you are, you need a map (mapping)
Neither can be solved independently - they must be solved together!
How SLAM Works (Conceptual)
┌─────────────────────────────────────────────────────────────┐
│ SLAM Loop │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Sensor │────>│ Feature │────>│ Map │ │
│ │ Data │ │ Matching │ │ Update │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │ │ │
│ │ ┌──────────┐ │ │
│ └──────────>│ Pose │<─────────┘ │
│ │ Estimate │ │
│ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
- Sensor data arrives (LIDAR scan, camera image)
- Features are extracted and matched to existing map
- Pose estimate is updated based on matches
- Map is updated with new observations
- Loop closure: When revisiting a location, correct accumulated drift
Types of SLAM
| Type | Sensor | Map Output | Use Case |
|---|---|---|---|
| 2D SLAM | 2D LIDAR | Occupancy grid (2D) | Indoor mobile robots |
| 3D SLAM | 3D LIDAR | Point cloud / mesh | Autonomous vehicles |
| Visual SLAM | Camera | Feature map | Drones, AR/VR |
| RGB-D SLAM | RGBD camera | Dense 3D map | Manipulation |
SLAM Output: The Occupancy Grid
Most 2D SLAM systems produce an occupancy grid map:
┌───┬───┬───┬───┬───┬───┬───┬───┐
│ │ │ █ │ █ │ █ │ │ │ │ █ = Occupied (wall)
├───┼───┼───┼───┼───┼───┼───┼───┤
│ │ │ │ │ █ │ │ │ │ ░ = Unknown
├───┼───┼───┼───┼───┼───┼───┼───┤
│ │ R │ │ │ █ │ │ │ │ (blank) = Free
├───┼───┼───┼───┼───┼───┼───┼───┤
│ █ │ █ │ │ │ █ │ █ │ █ │ █ │ R = Robot
├───┼───┼───┼───┼───┼───┼───┼───┤
│ ░ │ ░ │ │ │ │ │ ░ │ ░ │
└───┴───┴───┴───┴───┴───┴───┴───┘
Each cell stores probability: 0 (free) to 1 (occupied), with 0.5 meaning unknown.
Theory: Autonomous Navigation
Once we have a map, how does the robot navigate? Navigation has three main components:
Alt-text: Navigation architecture diagram showing three layers. Global Planning (top, blue) computes path from current position to goal. Local Planning (middle, sky blue) avoids obstacles while following global path. Execution Layer (bottom, green) sends velocity commands to motors. Arrows show data flow between layers and to sensors and motors.
1. Global Planning
Goal: Find a path from current position to goal on the map.
Algorithms:
- A*: Classic pathfinding, optimal but can be slow
- Dijkstra: Finds shortest path, explores more than A*
- NavFn: ROS 2/Nav2's default, based on wavefront propagation
Output: A sequence of waypoints (the global path)
2. Local Planning
Goal: Follow the global path while avoiding dynamic obstacles.
Algorithms:
- DWB (Dynamic Window): Samples velocities, simulates trajectories
- TEB (Timed Elastic Band): Optimizes trajectory in real-time
- MPPI (Model Predictive Path Integral): Modern sampling-based approach
Output: Velocity commands (linear and angular velocity)
3. Execution Layer
Goal: Convert velocity commands to motor signals.
Responsibilities:
- Motor control
- Odometry publishing
- Safety limits (max speed, acceleration)
Recovery Behaviors
What happens when the robot gets stuck?
- Clear costmaps: Reset obstacle layer, try again
- Spin: Rotate in place to get new sensor data
- Back up: Move away from obstacle
- Wait: Wait for dynamic obstacle to move
The Navigation Stack (Nav2)
ROS 2's navigation stack is called Nav2. It provides:
| Component | Function |
|---|---|
| Map Server | Loads and serves the map |
| AMCL | Localization (where am I on the map?) |
| Planner Server | Global path planning |
| Controller Server | Local planning / trajectory following |
| Behavior Server | Recovery behaviors |
| BT Navigator | Coordinates everything via behavior tree |
Nav2 Lifecycle
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Unconfigured │────>│ Inactive │────>│ Active │
└─────────────┘ └─────────────┘ └─────────────┘
│ │
│ ▼
│ ┌─────────────┐
└───────────>│ Finalized │
└─────────────┘
Nav2 uses lifecycle nodes that must be configured and activated before they work.
Demonstration: Viewing Navigation in Action
Step 1: Launch Navigation Simulation
# Terminal 1: Launch Gazebo with TurtleBot3
export TURTLEBOT3_MODEL=waffle
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
# Terminal 2: Launch Nav2 with pre-made map
ros2 launch turtlebot3_navigation2 navigation2.launch.py \
map:=/opt/ros/${ROS_DISTRO}/share/turtlebot3_navigation2/map/map.yaml
Step 2: Set Initial Pose
In RViz2:
- Click 2D Pose Estimate button
- Click on the map where the robot actually is
- Drag to indicate orientation
Step 3: Send Navigation Goal
- Click Nav2 Goal button
- Click destination on the map
- Watch the robot navigate!
Step 4: Observe the Components
# See the global path
ros2 topic echo /plan
# See local velocity commands
ros2 topic echo /cmd_vel
# See the costmap
ros2 topic echo /local_costmap/costmap
Key Concepts Summary
| Concept | Definition |
|---|---|
| SLAM | Simultaneous Localization and Mapping |
| Occupancy Grid | 2D map with obstacle probabilities |
| Global Planning | Path from start to goal |
| Local Planning | Real-time obstacle avoidance |
| Loop Closure | Correcting drift when revisiting locations |
| Nav2 | ROS 2 navigation stack |
Hands-On Exercise
Exercise B3.1: SLAM Conceptual Questions
Answer the following without code:
-
Why is SLAM called "simultaneous"?
- Why can't we map first, then localize?
-
Loop Closure Scenario:
- A robot drives in a large loop and returns to its starting point
- The odometry says it's 2 meters away from start
- What does this mean, and how does loop closure help?
-
Planning Trade-offs:
- A global path goes through a narrow doorway
- A dynamic obstacle (person) blocks the doorway
- What should happen?
Click for answers
-
SLAM is "simultaneous" because mapping requires knowing your pose (to place observations correctly) and localization requires a map (to match observations against). Neither can happen first - they must happen together.
-
The 2m error is odometry drift (wheel slip, measurement errors). Loop closure detects "I've been here before" and corrects the entire trajectory, spreading the error throughout the path.
-
The local planner should detect the obstacle and either: (a) stop and wait, (b) request a replan, or (c) find a local detour. If stuck too long, recovery behaviors activate.
Exercise B3.2: Navigation Components Matching
Match each Nav2 component to its responsibility:
| Component | Responsibility |
|---|---|
| Map Server | ? |
| AMCL | ? |
| Planner Server | ? |
| Controller Server | ? |
Options:
- A. Computes global path to goal
- B. Generates velocity commands
- C. Loads and serves the map
- D. Estimates robot pose on map
Click for answers
- Map Server → C. Loads and serves the map
- AMCL → D. Estimates robot pose on map
- Planner Server → A. Computes global path to goal
- Controller Server → B. Generates velocity commands
AI Agent Assisted Prompts
Prompt 1: SLAM Challenges
I'm building a robot that needs to map a large warehouse with many similar-
looking aisles. What challenges might SLAM face in this environment? What
sensors or techniques could help?
Prompt 2: Navigation Safety
My mobile robot navigates near humans. What safety considerations should I
build into the navigation system? How can I ensure the robot stops in time
when a person walks in front of it?
Prompt 3: Map Representation Trade-offs
Compare occupancy grid maps vs feature-based maps for mobile robot navigation.
What are the advantages and disadvantages of each? When would I choose one
over the other?
Summary
In this lesson, you learned:
- SLAM solves localization and mapping simultaneously
- The chicken-and-egg problem makes SLAM fundamentally challenging
- Occupancy grids represent maps as probability grids
- Navigation has three layers: global planning, local planning, and execution
- Nav2 is ROS 2's navigation stack with lifecycle-managed nodes
Next Steps
Congratulations! You've completed the Beginner tier!
- Test yourself: Complete Beginner Exercises
- Ready for more?: Continue to Intermediate Tier
You now understand the fundamental concepts of robotic perception and navigation. The Intermediate tier will teach you to implement these systems with actual code!