← Back to Blog
navigationslamlidarnavigationros2

SLAM A to Z: LiDAR, Visual and How Robots Localize

Master SLAM from basics to advanced — EKF-SLAM, particle filter, ORB-SLAM3, Cartographer, LIO-SAM and how to choose the right method.

Nguyen Anh Tuan4 tháng 2, 20268 min read
SLAM A to Z: LiDAR, Visual and How Robots Localize

What is SLAM and why does it matter?

SLAM (Simultaneous Localization and Mapping) is the most fundamental problem in robot navigation: the robot simultaneously builds a map of the environment while determining its own location on that map. This is the classic "chicken and egg" problem: to localize you need a map, but to build a map you need to know your position.

Every AMR (Autonomous Mobile Robot) operating in factories, warehouses, or outdoors needs SLAM. Without SLAM, a robot is just a remotely controlled vehicle.

In this article, I'll guide you from fundamental theory (EKF-SLAM, particle filters) to modern frameworks (ORB-SLAM3, Cartographer, LIO-SAM), and help you choose the right method for your use case.

Robot using LiDAR to scan and build an environmental map

Theoretical Foundation of SLAM

SLAM as a Probabilistic Problem

SLAM can be modeled as a Bayesian estimation problem. At each timestep t, the robot needs to estimate:

Objective: find probability distribution P(x_t, m | z_{1:t}, u_{1:t}) — the probability of robot location and map given all observations and controls from start to time t.

EKF-SLAM — Extended Kalman Filter

EKF-SLAM is the most classical method, using Extended Kalman Filter to simultaneously estimate robot position and landmark positions.

How it works:

  1. Predict: use motion model to predict new robot pose
  2. Update: when observing landmarks, update both robot pose and landmark positions

State vector contains robot pose (3 values) + all landmark positions (2N values for N landmarks). Covariance matrix has size (3+2N) x (3+2N).

# EKF-SLAM simplified pseudocode
def ekf_slam_predict(mu, sigma, u):
    # Motion model: predict new robot pose
    mu_bar = motion_model(mu, u)
    G = jacobian_motion(mu, u)
    sigma_bar = G @ sigma @ G.T + R  # R: motion noise
    return mu_bar, sigma_bar

def ekf_slam_update(mu_bar, sigma_bar, z, landmark_id):
    # Observation model: update with landmark measurement
    z_hat = observation_model(mu_bar, landmark_id)
    H = jacobian_observation(mu_bar, landmark_id)
    K = sigma_bar @ H.T @ inv(H @ sigma_bar @ H.T + Q)
    mu = mu_bar + K @ (z - z_hat)
    sigma = (I - K @ H) @ sigma_bar
    return mu, sigma

Advantages: solid theory, easy to understand, convergent with small number of landmarks.

Disadvantages: O(N^2) complexity with N landmarks -- doesn't scale for large maps. Gaussian assumption doesn't fit complex environments well.

Particle Filter SLAM (FastSLAM)

FastSLAM (Montemerlo et al., 2002) solves scalability issues by using particle filters for robot pose and separate EKF for each landmark in each particle.

How it works:

Complexity: O(M * N) with M particles and N landmarks -- much better than EKF-SLAM.

FastSLAM 2.0 further improves by using the latest observation to sample particles, reducing number of particles needed.

LiDAR SLAM — Industrial Standard

Google Cartographer

Cartographer is a 2D/3D SLAM system developed by Google, open-source since 2016. It's one of the most widely used LiDAR SLAM systems in industry.

Architecture:

Strengths:

# Run Cartographer with ROS 2
ros2 launch cartographer_ros cartographer.launch.py \
  use_sim_time:=true

LIO-SAM — LiDAR-Inertial Odometry via Smoothing and Mapping

LIO-SAM (Shan et al., 2020) is a framework for tightly-coupled LiDAR-inertial SLAM using factor graph optimization. Original paper: arXiv:2007.00258.

Architecture:

Why LIO-SAM is powerful:

# LIO-SAM config (params.yaml)
lio_sam:
  pointCloudTopic: "points_raw"
  imuTopic: "imu_correct"
  gpsTopic: "odometry/gps"
  
  # Lidar sensor
  sensor: velodyne  # velodyne, ouster, livox
  N_SCAN: 16
  Horizon_SCAN: 1800
  
  # IMU
  imuAccNoise: 3.9939570888238808e-03
  imuGyrNoise: 1.5636343949698187e-03

3D Pointcloud from LiDAR SLAM creating detailed environmental map

Visual SLAM — Camera is Enough

ORB-SLAM3

ORB-SLAM3 (Campos et al., 2021) is the most comprehensive Visual-Inertial SLAM system to date. Paper: arXiv:2007.11898.

Supports:

Pipeline:

  1. Tracking: extract ORB features, match with local map, estimate camera pose
  2. Local Mapping: triangulate new map points, local bundle adjustment
  3. Loop Closing: DBoW2 bag-of-words for place recognition, pose graph optimization
  4. Multi-map: manage multiple maps when tracking fails, merge when reconnecting

Strengths: accurate, robust, supports many camera types, multi-map system.

Weaknesses: needs texture-rich environment (fails in white corridors), higher computational cost than LiDAR SLAM.

// ORB-SLAM3 basic usage
ORB_SLAM3::System SLAM(
    vocab_path,           // ORB vocabulary
    settings_path,        // Camera + ORB params
    ORB_SLAM3::System::RGBD,  // Sensor type
    true                  // Visualization
);

// Process each frame
cv::Mat Tcw = SLAM.TrackRGBD(imRGB, imD, timestamp);

RTAB-Map — Real-Time Appearance-Based Mapping

RTAB-Map is the Visual SLAM best integrated with ROS 2. Supports many sensor types and has smart memory management.

Highlights:

Comprehensive Comparison Table

Method Sensor Accuracy Speed Outdoor Indoor Scale
EKF-SLAM Any Medium Fast Yes Yes Small (<100 landmarks)
FastSLAM Any High Medium Yes Yes Medium
Cartographer LiDAR High Real-time Limited Best Large
LIO-SAM LiDAR+IMU Very high Real-time Good Good Very large
ORB-SLAM3 Camera(+IMU) High Real-time Yes Good Medium
RTAB-Map Camera/LiDAR High Real-time Yes Good Large

When to use which method?

Choose LiDAR SLAM (Cartographer / LIO-SAM) when:

Choose Visual SLAM (ORB-SLAM3 / RTAB-Map) when:

Choose Hybrid (Visual-Inertial or LiDAR-Inertial) when:

Emerging Trend: Learning-based SLAM

Traditional SLAM methods rely on geometric constraints. But deep learning is changing the game:

We'll dive deeper into learning-based navigation in Part 3 of this series.

Next in the series

This is Part 1 of the Modern Navigation series. In upcoming articles:


Related articles

Related Posts

Deep DiveDigital Twins và ROS 2: Simulation trong sản xuất
simulationros2digital-twinPart 6

Digital Twins và ROS 2: Simulation trong sản xuất

Ứng dụng simulation trong công nghiệp — digital twins, ROS 2 + Gazebo/Isaac integration cho nhà máy thông minh.

3/4/202611 min read
ROS 2 từ A đến Z (Phần 4): ros2_control và Hardware
ros2tutorialrobot-armPart 4

ROS 2 từ A đến Z (Phần 4): ros2_control và Hardware

Kết nối ROS 2 với phần cứng thực — viết hardware interface cho motor driver và đọc encoder với ros2_control framework.

26/3/202611 min read
TutorialViết Hardware Interface cho ros2_control
ros2roboticstutorial

Viết Hardware Interface cho ros2_control

Hướng dẫn tạo custom hardware interface — kết nối ros2_control với motor driver qua serial/CAN bus.

18/3/202610 min read