Concept 02: Bayes’ Rule & 1D Sensor Fusion

▶ Interactive Demo: 1D Kalman Sensor Fusion Sandbox

Open the interactive demo below to drag the Prior (Wheel Odometry) and Measurement (Vision Camera) curves and watch the combined Posterior belief become narrower and more confident than either sensor alone.


1. The Real-World Problem: Two Conflicting Sensors

Suppose your robot is attempting to localize itself on the field:

  1. Wheel Odometry (Prior): Predicts position x₁ = 4.00m with high confidence (σ₁ = 0.20m).
  2. Vision Camera (Measurement): Detects an AprilTag and reports x₂ = 4.50m, but with lower confidence (σ₂ = 0.40m) due to camera blur.
Odometry: 4.0m Vision: 4.5m Fused: 4.10m

Which sensor should the robot believe? Neither sensor is 100% right! Instead of blindly picking one, we mathematically blend both readings according to their relative uncertainties.


2. Solving It in Code (Java & WPILib)

First-Principles Java: 1D Kalman Sensor Fusion

// Sensor 1: Wheel Odometry (Position = 5.2m, variance = 0.09)
double odomPos = 5.20;
double odomVar = 0.09;

// Sensor 2: Vision AprilTag (Position = 4.8m, variance = 0.04)
double visionPos = 4.80;
double visionVar = 0.04;

// Optimal Bayes / Kalman Fusion:
// Fused variance: 1 / var_fused = (1 / odomVar) + (1 / visionVar)
double fusedVar = 1.0 / ( (1.0 / odomVar) + (1.0 / visionVar) );

// Fused mean: Weighted average proportional to inverse variance
double fusedPos = fusedVar * ( (odomPos / odomVar) + (visionPos / visionVar) );

System.out.printf("Fused Robot Position: %.3f m (±%.3f m)%n", fusedPos, Math.sqrt(fusedVar));
// Output: 4.923 m (closer to vision because vision is more accurate!)

3. Bridge to Machine Learning: Bayesian Inference

In machine learning and statistics:


4. Review Checkpoints

Checkpoint 1

If two identical sensors both measure distance with equal uncertainty σ = 0.40m, what weight (Kalman Gain K) is given to the second reading?

Solution: K = σ₁² / (σ₁² + σ₂²) = 0.40² / (0.40² + 0.40²) = 0.50 (50%). The algorithm takes the exact 50/50 average of the two readings!


Checkpoint 2

Why is the fused uncertainty σ = 0.179m smaller than both 0.20m and 0.40m?

Solution: Because two independent sensor readings provide more total information than one sensor alone. Combining multiple noisy perspectives always reduces overall uncertainty.


← Concept 16: Sensor Noise & Normal Dist
Module 5 Overview
Concept 18: Discrete Softmax →