SLAM Explained Simply

SLAM lets a robot map an unknown space while tracking its own position inside that map — the foundation of robot autonomy. This guide explains the chicken-and-egg problem, the sensors, loop closure, the main algorithm flavors, and the practical tips that make student SLAM demos actually work.

Written by Projectech7 min readPublished
For B.E./B.Tech Computer Science, Electronics, and Mechanical students building autonomous robots who have heard SLAM is required but find the explanations impenetrable Topics: SLAM, ROS2, Lidar, Robotics
Illustration of SLAM showing a robot building a floor map while tracking its own position with lidar scan rays.
Illustration generated for this guide.
In this guide

Imagine waking up in a dark, unfamiliar building with no map. You shuffle forward, feeling walls, counting steps. Gradually you build a mental map — "the corridor turns left here" — while simultaneously tracking where you are within that map. Each helps the other: the map tells you where you are, and knowing where you are lets you extend the map.

That is SLAM: Simultaneous Localization and Mapping. A robot in an unknown environment builds a map of its surroundings while figuring out its own position inside that map, at the same time. It is the foundation of every autonomous vacuum cleaner, warehouse robot, and self-driving car prototype.

Why it is "simultaneous" (the chicken-and-egg problem)

  • Mapping needs localization: to place a wall on the map, you must know where you were when you saw it.
  • Localization needs a map: to know where you are, you match what you see against a known map.

With neither, you bootstrap: start assuming you are at the origin, record sensor data as you move, and continuously refine both estimates. The magic of SLAM algorithms is that the two estimates constrain each other — errors in one show up as inconsistencies the algorithm can detect and correct.

The sensors SLAM uses

Sensor What it gives Strengths Weaknesses
2D lidar Distance to obstacles in a plane, 360 degrees Accurate, lighting-independent Expensive-ish, single plane
Depth/RGB-D camera Color + per-pixel depth Rich data, cheap Fails in sunlight, limited range
Wheel odometry Distance traveled (encoders) Free with any wheeled robot Drifts badly (wheel slip)
IMU Acceleration + rotation High rate, cheap Drifts within seconds alone
GPS Global position Absolute reference Useless indoors, meter-level accuracy

No single sensor is enough. Wheel odometry drifts, lidar sees geometry but not what things are, cameras fail in bad light. Practical SLAM fuses sensors: each covers the others' weaknesses. This is why your robot needs more than one sensing modality for reliable autonomy.

The core concepts, plainly

Landmarks and scan matching

The robot detects stable features (corners, wall segments) in each sensor scan. When the next scan arrives slightly shifted, the algorithm figures out the motion that aligns the overlapping features most accurately — that motion estimate is odometry, and the aligned features extend the map.

Loop closure: the drift killer

Odometry accumulates error — after 100 meters your position estimate might be meters off. But when the robot recognizes a place it has been before ("this corridor looks like the start"), it can snap the whole trajectory back into consistency. Loop closure is what turns a drifting squiggle into a coherent map. It is the single most important event in a SLAM run.

Probabilistic thinking

SLAM never says "the robot is at (3.2, 1.1)." It says "the robot is probably near (3.2, 1.1), with this uncertainty." Every estimate carries uncertainty, sensors have noise models, and the algorithms (particle filters, graph optimization) are machinery for combining uncertain evidence correctly. You do not need the math to use SLAM — but knowing it is probabilistic explains why parameters like noise covariances exist.

The main SLAM flavors

Approach Sensors Map type Notes
GMapping / particle filter 2D lidar + odometry 2D occupancy grid Classic, lightweight, great for student robots
Hector SLAM 2D lidar (no odometry needed) 2D occupancy grid Works without wheel encoders
Cartographer (Google) 2D/3D lidar + IMU 2D/3D Accurate, heavier compute
ORB-SLAM / visual SLAM Cameras Sparse 3D landmarks Camera-only; needs good lighting and texture
RTAB-Map RGB-D / lidar 3D Popular in ROS2 for 3D mapping

For a student wheeled robot with a 2D lidar: start with the ROS2 SLAM Toolbox or GMapping-style approaches producing a 2D occupancy grid — the black/white/gray map where black is obstacle, white is free, gray is unknown. It is the fastest path to a robot that maps a room.

An occupancy grid deserves one more sentence: the world is divided into cells, each storing the probability it is occupied. Simple, visualizable in RViz, and directly usable by path planners.

SLAM vs localization vs navigation

Students conflate these. The pipeline is:

  1. SLAM — explore an unknown space, produce a map (done once, or continuously).
  2. Localization — with a known map, figure out where you are (AMCL in ROS2 — cheaper than SLAM, runs forever).
  3. Path planning — given map + position + goal, compute a route (A*, Dijkstra on the grid).
  4. Navigation — follow the route while avoiding new obstacles (the ROS2 Nav2 stack does 2–4 together).

Typical student workflow: run SLAM once to map the lab, save the map, then run localization + navigation on the saved map forever after. You do not re-run SLAM every demo.

Practical tips for a working SLAM demo

  • Drive slowly during mapping. Fast motion blurs scans and breaks scan matching. Mapping speed is patience speed.
  • Close loops deliberately. Plan your mapping route to revisit places — drive a loop, not a line. No loop closures = drifting map.
  • Fix your odometry first. Calibrate wheel diameter and track width; bad odometry poisons everything downstream. Test: drive the robot 2 meters and check the odometry agrees.
  • Lidar mounting matters. Mounted level, unobstructed 360 degrees, above the robot body's own clutter. A lidar that sees your own chassis gets confused.
  • Feature-poor environments fail. Long blank corridors with no distinguishing features give scan matching nothing to grip. If your test area is a white empty hall, expect trouble.
  • Tune for your sensor. Default noise parameters assume specific hardware. The laser_max_range, odometry noise, and resolution parameters exist because sensors differ.

Judging map quality

After a mapping run, open the map and read it like an engineer:

  • Walls are crisp thin lines. Thick, fuzzy, or doubled walls mean scan matching struggled — usually too-fast driving or a vibrating lidar mount.
  • Corridors are straight and rooms close properly. A corridor that bends like a banana or a room whose walls do not meet indicates odometry drift without loop closure — recalibrate odometry and re-map with deliberate loop-closing routes.
  • No ghost obstacles. Smears and blobs in open space come from dynamic objects (people walking through) during mapping, or reflective surfaces confusing the lidar. Map when the space is still.
  • Known dimensions check out. Measure a real doorway, measure it on the map. Systematic scale errors point at odometry calibration; local distortions point at scan-matching trouble.

A clean map is the foundation everything else (localization, planning, navigation) stands on. Time spent getting the map right pays back in every later stage — a robot navigating a bad map fails in ways that look like planning bugs but are really mapping bugs.

Common mistakes

  • Expecting SLAM to fix bad odometry. SLAM tolerates drift; it cannot fix encoders that slip constantly or wheels that were never calibrated.
  • Mapping too fast. The number one student SLAM failure. Slow down.
  • No loop closure in the route. A straight-line mapping run produces a map that drifts increasingly — always loop back.
  • Dynamic environments. Mapping a corridor while people walk through it bakes ghosts into the map. Map when the space is still; navigation handles dynamic obstacles later.
  • Confusing the map with the territory. The occupancy grid is a probabilistic estimate, not ground truth — glass walls, mirrors, and black surfaces all lie to lidar.
  • Running SLAM forever instead of localizing. SLAM is for building the map; AMCL-style localization on a saved map is cheaper and more stable for repeated demos.

A realistic learning path

  • ROS2 basics solid (see ROS2 Basics for Students)
  • Robot simulated in Gazebo with lidar (TurtleBot3 is the canonical start)
  • 2D occupancy grid built in simulation; loop closure observed in RViz
  • Saved map + AMCL localization + Nav2 goal navigation in simulation
  • Same pipeline on physical hardware in a controlled room

Where to go from here