SLAM is how a robot answers two questions at once: where am I, and what does the place look like? It is the difference between a robot that follows a scripted path and one that can be dropped into a new building and find its way. The good news is that open-source 2D SLAM is mature and runs on affordable hardware. The hard part is the plumbing around it: odometry, time sync, sensor mounting and expectations.
What SLAM actually does
Simultaneous Localisation and Mapping estimates the robot’s trajectory while building a map of the environment. Each new sensor scan is matched against what the robot already believes, and both the map and the position are corrected together. That is why SLAM drifts less than dead reckoning: it keeps closing loops against physical features.
For most indoor service robots, “SLAM” means 2D lidar SLAM: a horizontal laser scanner produces a floor-plan slice, wheel encoders provide motion, and a package such as slam_toolbox builds an occupancy grid. This is well understood, cheap and adequate for warehouses, hospitals, showrooms and corridors.
Three sensor routes
| Approach | Sensors | Strengths | Weaknesses |
|---|---|---|---|
| 2D lidar SLAM | 2D lidar plus wheel odometry | Mature, cheap, reliable indoors, easy ROS 2 support | Single plane; struggles with glass, ramps and 3D clutter |
| Visual SLAM | One or two cameras, optionally IMU | No moving part, rich information, works in feature-rich rooms | Sensitive to lighting, motion blur and textureless walls; more compute |
| Depth or 3D lidar SLAM | RGB-D camera or 3D lidar | 3D maps, better obstacle understanding | Higher cost and compute; heavier calibration |
For a first project, 2D lidar plus encoders on a differential-drive base is still the shortest path to a working map. It teaches the concepts without drowning you in calibration.
What it costs in India
| Part | Planning range | Comment |
|---|---|---|
| Entry 2D lidar, 12 m range | ₹8,000–15,000 | Enough for a room-scale map |
| Mid 2D lidar, 16–25 m | ₹20,000–45,000 | Better for corridors and larger halls |
| Depth camera | ₹20,000–40,000 | For visual or RGB-D SLAM |
| Wheel encoders | ₹1,500–6,000 per pair | Optical or magnetic; resolution matters more than brand |
| IMU | ₹300–3,000 | Cheap MEMS is fine for fusion, not for precision heading |
| Compute | ₹8,000–60,000 | Raspberry Pi 5 for 2D; Jetson class for visual SLAM |
A working 2D SLAM prototype can be built for under ₹30,000 in sensors and compute if you already have a chassis. A visual SLAM prototype costs more in compute and time.
The ROS 2 stack that does the work
- Lidar driver publishes a
sensor_msgs/LaserScan. - Odometry publishes the transform from
odomtobase_link, usually from wheel encoders or a motor controller. - slam_toolbox consumes scans and odometry, publishes the map and the
maptoodomcorrection. - Nav2 uses the saved map for localisation and path planning once mapping is done.
The transform tree is where beginners lose days. The chain must be consistent: map to odom comes from SLAM or localisation, odom to base_link comes from your wheel odometry, and base_link to laser comes from the static mounting position. If any link is missing or published twice, the map tears or the robot teleports.
A realistic build sequence
- Step 1: drive straight. Calibrate wheel diameter and track width until the robot drives a measured 2 m within a few centimetres.
- Step 2: publish odometry. Confirm
odomtobase_linkmoves smoothly when you push the robot by hand. - Step 3: mount the lidar level. A tilted scanner produces a map that spirals. Keep it away from the robot’s own body and cables.
- Step 4: teleop and map one room. Drive slowly, make a loop, and return near the start. Watch whether walls overlap when you close the loop.
- Step 5: save the map. Export both the occupancy image and the YAML metadata; keep them together.
- Step 6: localise on the saved map. Start the robot at a known pose and check that the scan aligns with the map before running navigation.
- Step 7: add Nav2. Tune the costmap inflation radius before tuning planners. Most “bad planner” problems are actually bad costmaps.
Why maps come out bad
| Symptom | Likely cause | Fix |
|---|---|---|
| Walls doubled or smeared | Odometry scale wrong or wheel slip | Calibrate wheel diameter and track width; reduce speed |
| Map curves over a long run | Gyro drift or poor scan matching | Add an IMU, slow down, map in smaller loops |
| Glass or mirrors vanish | Lidar sees through or reflects | Add physical landmarks or map those areas manually |
| Robot loses position after a crowd | Dynamic obstacles dominate the scan | Filter short-lived returns; localise in quieter areas |
| Map fine, navigation fails | Costmap or footprint wrong | Set the real robot radius and inflation, check the TF tree |
What accuracy to expect
In a clean indoor environment with a decent 2D lidar and calibrated odometry, a small robot can localise within roughly 2–5 cm and a few degrees. Long corridors with no features are harder, and drift grows with distance between loop closures. Outdoors, sunlight interferes with many 2D lidars, and 3D or visual methods become more attractive.
Do not promise centimetre accuracy to a customer until you have measured it in their building, on their floor, at their busiest hour.
Learn SLAM in the right order
Start with a simulated robot in Gazebo to learn the ROS 2 graph without hardware faults. Then move to a real base with encoders and a lidar. Only after 2D mapping works should you attempt visual SLAM. Each step adds one variable; skipping steps adds several at once and makes debugging impossible.
Related: ROS 2 for beginners, choosing distance sensors, wheel encoders and odometry, OpenCV robot vision, AGV vs AMR.
What is SLAM in robotics in simple terms?
SLAM lets a robot build a map of an unknown place while simultaneously working out where it is on that map. It combines sensor scans with motion estimates so the map and the position correct each other.
Can I run SLAM on a Raspberry Pi 5?
Yes for 2D lidar SLAM at modest resolution. Visual SLAM is possible but limited; a Jetson-class computer gives much better frame rates for camera-based methods.
Do I need a lidar for SLAM?
No. Visual and depth-camera SLAM exist. But 2D lidar SLAM is the most reliable and best documented option for indoor wheeled robots, and entry lidars are affordable in India.
Why does my SLAM map look smeared?
Usually because wheel odometry is miscalibrated or the robot is moving too fast for scan matching. Check wheel diameter and track width, slow down, and confirm the lidar is mounted level.
What is the difference between mapping and localisation?
Mapping builds a new map while estimating position. Localisation uses an existing map to work out where the robot is. In ROS 2, slam_toolbox handles mapping and Nav2 handles localisation and planning on the saved map.
Once the map is saved, the Nav2 tutorial shows how to localise and navigate on it.
If the hardware is not ready, simulate the robot in Gazebo and run the same SLAM nodes.
Mapping runs usually start several nodes at once: ROS 2 launch files tutorial.
SLAM publishes the map to odom transform; ROS 2 TF2 tutorial explains the chain.
For the ROS 2 implementation, follow the SLAM Toolbox tutorial.
For a cheap indoor fix, fiducial markers such as ArUco give a known pose without a full SLAM stack.
Sources and further reading
- ROS documentation — ROS 2 concepts, TF2 and navigation.
- slam_toolbox — 2D SLAM package for ROS 2, with configuration guidance.
- Nav2 documentation — localisation, costmaps and path planning.
- Intel RealSense — depth camera specifications for visual SLAM.


