Imagine: you launch a cart in a warehouse, the map builds beautifully, the robot confidently drives down the first aisle, but on the second — it freezes. Or worse, it crashes into a shelving unit. Sound familiar? The reason is almost always the same: the SLAM you chose is not suitable for that environment. Or maybe you misunderstood what loop closure is and why the map "drifts." In this article, we'll break down how LiDAR localization and navigation for a mobile robot work from the inside, how it differs from visual, and how to choose an algorithm for a specific task — warehouse, apartment, or street. And we'll also explain why the course "Autonomous Systems and Robotics (ROS 2, SLAM, Computer Vision)" can save you months of trial and error.
Why SLAM is not "just a map" but a compromise between sensors and algorithms
SLAM (Simultaneous Localization and Mapping) solves two tasks at once: it builds a map and determines its position on it.? But imagine you are in an unfamiliar city without a map and trying to draw a plan based only on what you see. You walk, notice landmarks, but your position relative to these landmarks is constantly being refined. Error accumulates: if you walked 100 meters and made a 1% error, then at the end of the path your estimated location will differ from the real one by 1 meter. This is the drift problem.
To solve it, SLAM uses two approaches: LiDAR (laser) and visual (camera-based). The first works with a point cloud, the second with images. And each has its strengths and weaknesses.
LiDAR SLAM (GMapping, Cartographer) builds a map based on distances to obstacles. It is accurate in rooms with straight walls and good geometry, but performs poorly in long corridors without distinctive features: the laser sees identical walls and cannot understand where it is. Visual SLAM (ORB-SLAM) uses cameras and looks for feature points in images. It handles textured surfaces better but is sensitive to lighting and fast movements.
Here's a typical beginner mistake: choosing GMapping for a warehouse with high shelving where the laser sees only vertical posts, and then wondering why the map "smears." Or taking ORB-SLAM for the street where the sun shines into the camera and all points merge.
Case study: how a robot got lost in a corridor and what we did
Let's analyze a real situation (typical for many teams). There is a mobile robot based on ROS 2 with an RPLIDAR A2 LiDAR and an Intel RealSense D435 camera. The task: autonomously move around an office floor with a long corridor (30 meters) and several offices. Initially, we chose GMapping because "that's what the tutorial says." We launched it, the map was built, the robot drove. But in the corridor it started to wobble, and on the way back it got completely lost.
What we did step by step:
- Analyzed the LiDAR data. In the corridor, the laser sees only two parallel walls, the distance between them is 2 meters. The scans are almost identical along the entire length — the algorithm cannot extract unique features for matching. This is the classic problem of "degenerate geometry."
- Added visual odometry. We connected the RealSense and ran ORB-SLAM in odometry-only mode (without building a map). Visual points on doors, signs, and the floor provided additional information about movement.
- Performed data fusion. We combined LiDAR and visual odometry via a Kalman filter in the robot_localization package. This allowed us to compensate for LiDAR drift in the corridor.
- Configured loop closure. In Cartographer (we switched to it), we enabled loop closure detection. When the robot returns to a familiar place, the algorithm "closes" the loop and corrects the accumulated error. Without this, the map diverges: the longer the path, the greater the discrepancy.
- Integrated with Nav2. We configured the costmap using the map from Cartographer, and the parameters of the local planner (DWA) so that the robot does not try to squeeze through gaps as narrow as 0.5 meters.
Result: the robot stopped getting lost in the corridor, positioning accuracy increased from ±30 cm to ±5 cm. The map stopped "drifting" on repeated passes.
And what would have happened if we hadn't done this? The robot would continue to wobble, and at high speed (over 1 m/s) the map would simply fall apart due to error accumulation. Or, worse, the robot could crash into a wall because the local planner would receive incorrect obstacle data.
How LiDAR algorithms differ from visual ones: a practical comparison
To choose a SLAM, you need to understand how each behaves under different conditions. Here is a comparison by key parameters.
| Parameter | LiDAR SLAM (GMapping, Cartographer) | Visual SLAM (ORB-SLAM) |
|---|---|---|
| Accuracy in rooms with straight walls | High | Medium (depends on texture) |
| Performance in featureless corridors | Poor (degenerate geometry) | Better if there is texture on floor/walls |
| Lighting | No effect | Critical: shadows, glare, dark areas |
| Fast movement | Good (LiDAR scans quickly) | Poor (image blur) |
| Sensor cost | From $200 (RPLIDAR) to $2,000+ (Velodyne) | From $100 (regular camera) to $500 (RealSense, OAK-D) |
| Computational load | Medium | High (GPU needed for real-time) |
As you can see, there is no ideal solution. For a warehouse with high shelving and uniform aisles, Cartographer with LiDAR and additional visual odometry is better. For an apartment with lots of furniture and textures, you can try ORB-SLAM with a camera. For the street, where there is a lot of movement and changing lighting, LiDAR (e.g., Ouster) is often used together with GPS and visual odometry.
Typical mistake: beginners often think that loop closure is just "closing the map." In fact, it is a complex optimization process of the pose graph that requires a sufficient number of unique features at the return location. If the robot returns to the starting point but the environment has changed (boxes moved), loop closure may not trigger or may trigger incorrectly.
Where beginners get stuck and why
The most common problem is incorrect sensor setup. For example, the RPLIDAR A2 LiDAR has a 360° field of view, but when mounted on a robot, it is obstructed by the body. As a result, the scans contain "dead zones," and SLAM builds a map with holes. Solution: choose the correct mounting location (usually on a mast) and configure data filtering.
The second mistake is ignoring camera calibration. For visual SLAM, the camera's intrinsic parameters (focal length, distortion) are critical. If you don't calibrate the RealSense or OAK-D, ORB-SLAM will perform poorly or not start at all. In ROS 2, there is a camera_calibration package for this.
The third is the absence of loop closure in the configuration. Many take a ready-made GMapping config and do not enable the parameter responsible for loop closure (in GMapping it doesn't exist, but in Cartographer it does and is called optimize_every_n_nodes). Without this, the map will accumulate error.
And the fourth is incorrect integration with Nav2. Nav2 uses the map built by SLAM, but if the map is inaccurate, the planner will build routes through obstacles or, conversely, avoid free zones. You need to properly configure the costmap: specify the robot radius, obstacle inflation, and sensor parameters.
Learning paths: self-study, courses, or practice
If you are just starting, there are three main paths.
Self-study. Free but slow. You will gather information piece by piece from ROS 2 documentation, tutorials, and GitHub. The average time to a first working project is 6–12 months if you study 10 hours a week. Main barriers: no feedback, no one to discuss mistakes with, lots of outdated material (ROS 1 is still popular in articles).
Courses. A structured approach, but costs money (usually $300–$1,000). It is important to choose a course that includes practice on real hardware or in a simulator, and that addresses your specific tasks. For example, the course "Autonomous Systems and Robotics (ROS 2, SLAM, Computer Vision)" has modules on SLAM, navigation, and computer vision, as well as projects on autonomous navigation. Personalized lessons tailored to the student's level help avoid getting stuck on simple things if you are already familiar with robotics. More on the topic: “Robotics from Scratch: A Complete Robotics Course — Arduino, Raspberry Pi, ROS, and Circuit Design”.
Practice in a lab or at work. The fastest path if you have access to equipment and a mentor. But not everyone has this opportunity.
Honest trade-off: self-study gives deep understanding through pain, courses save time but require discipline, and practice gives real experience but may be narrow. More on the topic: “Real-Time Systems: Myths, Realities, and the Engineering Behind Live Apps”.
Who this path suits and who it doesn't
This topic will suit you if you are:
- an engineer or student in a technical field, wanting to work in robotics professionally;
- a software developer who wants to move into robotics (basic knowledge of Python and Linux required);
- an enthusiast who has already built robots on Arduino but wants to move to the next level of autonomy.
You should not go into this topic if you are not ready to deal with mathematics (linear algebra, probability theory) and do a lot of programming. It is also not suitable for those looking for "quick results without effort" — SLAM requires patience and debugging.
In conclusion
Choosing SLAM is not a question of "which algorithm is better" but "which algorithm is better for my task." LiDAR localization and navigation for a mobile robot require understanding the limitations of sensors and algorithms. If you want to systematically master this field, learn to configure Cartographer, ORB-SLAM, and integrate them with Nav2, check out the course Autonomous Systems and Robotics (ROS 2, SLAM, Computer Vision). There, real cases are analyzed and feedback is given on your solutions. More on the topic: “Computer Vision and Image Processing: How to Go from CNN to Generative Models Without Getting Stuck in the Middle”.