Perception & SLAM

Perception turns raw sensor streams into a model of the robot and its surroundings. SLAM (Simultaneous Localization and Mapping) is the core problem when no prior map exists: the robot must estimate its own pose using a map that it is building from those same pose estimates. This page covers state estimation with Kalman filters, the SLAM formulation, visual and LiDAR SLAM pipelines, and practical pitfalls.


1. State Estimation and Sensor Fusion

Sensor Fusion for State Estimation IMU 100–1000 Hz Wheel odom encoders Camera features / depth LiDAR point clouds GNSS absolute, outdoor EstimatorEKF / UKF / factor graphpredict + update State x̂, covariance Ppose, velocity, biases High-rate sensors drive prediction; slower absolute sensors correct drift.

No single sensor is enough. IMUs are fast but drift when integrated; wheel odometry slips; cameras fail in low light or texture-less scenes; LiDAR is precise but sparse and costly; GNSS is absolute but unavailable indoors. A probabilistic estimator combines them, weighting each by its noise model, and tracks uncertainty as a covariance matrix.

2. The Kalman Filter

For a linear system xk = F xk-1 + B uk + w, zk = H xk + v with Gaussian noise w ~ N(0,Q), v ~ N(0,R), the Kalman filter is the optimal estimator:

The Extended Kalman Filter (EKF) linearizes nonlinear models with Jacobians; the Unscented KF propagates sigma points instead; particle filters represent multimodal beliefs with samples (used in Monte Carlo localization against a known map).

import numpy as np

dt = 0.1
F = np.array([[1, dt], [0, 1]])          # state: [position, velocity]
H = np.array([[1.0, 0.0]])               # we measure position only
Q = np.diag([1e-4, 1e-2])                # process noise
R = np.array([[0.5]])                    # measurement noise (variance)

x = np.zeros(2); P = np.eye(2)
rng = np.random.default_rng(0)
true_x, est = np.array([0.0, 1.0]), []

for k in range(100):
    true_x = F @ true_x
    z = H @ true_x + rng.normal(0, np.sqrt(R[0, 0]), 1)

    x = F @ x;  P = F @ P @ F.T + Q                       # predict
    S = H @ P @ H.T + R;  K = P @ H.T @ np.linalg.inv(S)  # gain
    x = x + K @ (z - H @ x);  P = (np.eye(2) - K @ H) @ P # update
    est.append(x.copy())

print("final estimate", est[-1], "truth", true_x)        # velocity recovered without measuring it

3. The SLAM Problem

SLAM as a Pose Graph x0 x1 x2 x3 x4 x5 x6 blue = odometry constraints green = landmark observations dashed yellow = loop closure Optimization finds poses minimizing total weighted error of all constraints.

SLAM estimates the robot trajectory x0:t and map m from controls and observations: p(x0:t, m | z1:t, u1:t). Early approaches used EKF-SLAM (a state vector holding all landmarks, quadratic cost) and FastSLAM (particle filter). Modern systems use graph-based SLAM: nodes are poses (and optionally landmarks), edges are relative constraints from odometry and observations, and a sparse nonlinear least-squares solver (g2o, GTSAM, Ceres) finds the configuration that best satisfies all of them.

Loop closure — recognizing a previously visited place — adds a constraint that corrects the drift accumulated along the loop. It is also the most dangerous step: one false loop closure can corrupt the whole map, so robust kernels and geometric verification are standard.

4. Visual and LiDAR SLAM

Visual SLAM Pipeline (front end / back end) Imagesmono / stereo / RGB-D FeaturesORB, keypoints Trackingmatch → pose Local BAkeyframes Loop closureplace recognition Global opt.pose graph Front end: per-frame data association (fast). Back end: nonlinear least squares over keyframes (slower). Bundle adjustment jointly refines camera poses and 3D point positions to minimize reprojection error.

Visual SLAM systems such as ORB-SLAM track sparse features; direct methods (LSD-SLAM, DSO) use pixel intensities. Monocular cameras cannot observe metric scale, so they are usually fused with an IMU (visual-inertial odometry, e.g. VINS-Mono, OKVIS) or replaced by stereo / RGB-D. LiDAR SLAM (LOAM, LIO-SAM, Cartographer) registers point-cloud scans using ICP or feature-based matching and is the default on autonomous vehicles and outdoor robots.

Learned components increasingly replace hand-crafted ones: learned keypoints and matchers, monocular depth networks, and place-recognition embeddings for loop closure. Neural scene representations (NeRF, 3D Gaussian Splatting) are being used for dense mapping.

5. Pitfalls

6. A Kalman Filter, Worked Through

Consider a robot moving along a line with state x = position. Its belief is x̂ = 0.0 m with variance P = 1.0 m2. It commands a 1.0 m move; odometry adds process noise Q = 0.5. Predict: x̂ = 0 + 1.0 = 1.0, P = 1.0 + 0.5 = 1.5. A range sensor then measures the position as z = 1.4 with noise R = 0.5 (H = 1). Update: the Kalman gain is K = P / (P + R) = 1.5 / 2.0 = 0.75. The new estimate is x̂ = 1.0 + 0.75 × (1.4 − 1.0) = 1.3, and the variance shrinks to P = (1 − 0.75) × 1.5 = 0.375.

The gain expresses relative trust: because the prediction had become more uncertain than the sensor, the estimate moved three-quarters of the way toward the measurement. Repeating predict and update keeps variance bounded as long as measurements keep arriving; without them it grows with every step, which is drift. In multi-dimensional problems the same equations run on vectors and covariance matrices, and the innovation z − Hx̂ with its covariance is also used to reject outliers: a measurement with a large Mahalanobis distance is gated out instead of being fused.

7. Front End and Back End

Front End and Back End of a SLAM System Sensors camera, LiDAR, IMU, wheels Front end features / scan match odometry, place recognition Back end pose graph nonlinear least squares Map poses + landmarks, point cloud or occupancy grid The front end turns raw data into constraints; the back end makes them consistent.

Practical SLAM systems split into two halves. The front end is sensor-specific: it detects and matches features or registers point clouds (ICP, NDT), estimates frame-to-frame motion, decides when to create a keyframe, and runs place recognition, for example bag-of-words image retrieval or LiDAR scan descriptors, to propose loop closures. The back end is sensor-agnostic: it treats every relative measurement as a constraint with an information matrix and solves for the poses that minimize the total weighted squared error, using Gauss-Newton or Levenberg-Marquardt on a sparse problem. Bundle adjustment is the same idea for cameras, jointly refining poses and 3-D points by minimizing reprojection error. Incremental solvers such as iSAM2 update the solution as new nodes arrive instead of solving from scratch.

8. Choosing Sensors and Methods

SettingCommon choiceWatch out for
Indoor mobile robot, 2-D2-D LiDAR with a grid-based SLAM (Cartographer, slam_toolbox), then AMCL localizationGlass, mirrors, long featureless corridors
Drone or handheld deviceVisual-inertial odometry (camera + IMU)Motion blur, low light, IMU calibration and time sync
Outdoor vehicle3-D LiDAR + IMU (LIO-SAM style), fused with GNSSDynamic objects, rain and dust, GNSS multipath
AR on phonesPlatform VIO (ARKit, ARCore)Scale drift without depth, relocalization after tracking loss

9. Evaluation and Production Notes

Trajectory accuracy is measured against ground truth from motion capture or survey-grade GNSS. Absolute trajectory error aligns the estimated and true paths and reports the RMSE of position differences; relative pose error measures drift over fixed distances or time windows and is less dominated by a single bad segment. Public datasets such as KITTI, EuRoC and TUM RGB-D allow comparison, with tools like evo for computing the metrics. Beyond accuracy, track CPU load and latency, tracking-loss rate, and how often relocalization succeeds.

In deployment, most failures trace back to calibration and timing: incorrect camera intrinsics, camera-to-IMU extrinsics, or unsynchronized timestamps degrade every estimate downstream. Recalibrate after hardware changes, log raw sensor data so failures can be replayed offline, and treat long-term map maintenance (furniture moves, seasons change) as an explicit problem rather than assuming a map built once stays valid. In ROS 2, the robot_localization package provides EKF/UKF fusion and Nav2 consumes the resulting pose for path planning and control.

10. Learning-Based Perception

Deep learning now supplies many front-end components: learned feature detectors and matchers (SuperPoint, SuperGlue), monocular depth estimation, semantic segmentation that labels map points as road, building or person so that moving objects can be excluded, and object detection feeding semantic maps. End-to-end learned odometry exists but classical geometric back ends remain the norm for reliability and interpretability. Neural scene representations (NeRF, 3-D Gaussian splatting) are an active research area for dense mapping.

Further reading. Thrun, Burgard and Fox (2005), Probabilistic Robotics; Kalman (1960), "A New Approach to Linear Filtering and Prediction Problems"; Durrant-Whyte and Bailey (2006), "Simultaneous Localization and Mapping: Part I", IEEE Robotics and Automation Magazine; Cadena et al. (2016), "Past, Present, and Future of Simultaneous Localization and Mapping", arXiv:1606.05830; Mur-Artal, Montiel and Tardós (2015), "ORB-SLAM"; Grisetti et al. (2010), "A Tutorial on Graph-Based SLAM"; Kaess et al. (2012), "iSAM2".