Best Ever Introduction into Baye's Filter In Robotics
May 22, 2026·6 min read

Best Ever Introduction into Baye's Filter In Robotics

T
Tambu Precious
HWIVC Contributor
Robotics

Finally Understanding Kalman Filters Through Code and Animations

Simultaneous Localization and Mapping (SLAM) is one of the most elegant problems in robotics. How does a robot figure out where it is while simultaneously building a map of an unknown environment? The answer lies at the heart of probabilistic robotics — and the Kalman Filter (or more generally, the Bayes Filter) is the superstar algorithm that makes it possible.

In this blog, I’ll take you on a visual, step-by-step journey from basic state estimation to a full working filter. No heavy mathematical proofs — just clear intuition, beautiful diagrams, and cool animations that make the concepts stick.

The Big Idea: Belief and Uncertainty

Robots never know exactly where they are. Instead, they maintain a belief — a probability distribution over possible positions.

Starting with Zero Knowledge

In a simple 1D world, the robot begins completely lost:

Every position has equal probability. This is pure uncertainty.

First Hint of Information

After receiving some initial data, the belief becomes a Gaussian centered around a likely position:

The width of this bell curve (controlled by σ) represents how uncertain the robot is.

Predict Step: Motion Introduces More Uncertainty

When the robot moves, it uses its motor commands (odometry) to predict the new position. But real motion is noisy.

Key Formula (Motion Model):

bel(xt) = ∫ p(xt | ut, xt-1) * bel(xt-1) dxt-1

This is the prediction step. Notice how the curve gets wider and shorter with each movement — uncertainty grows.

But when sensor Correction is added,  the uncertainty reduces.  

The sensor data and the data from wheel sensors are fused together for correction.  But if the sensor is damaged it starts giving wrong readings, making the estiamte wrong

Code Snippet (from 2_motion_model_prediction_step1.py):

Summary:
  - PREDICT step:
                  bel_bar(xt) = ∫ p(xt | ut, xt-1) * bel(xt-1) dxt-1
                                                         [what motion says]      [what we knew before]
    - belief SPREADS (less certain)

  - CORRECT step:
                bel(xt) = η * p(zt | xt) *  bel_bar(xt)
                                        [what sensor says]    [what motion gave us]
  - belief SHARPENS (more certain)
  - So the correction is literally just multiplying the two together:
            prediction × sensor reading = corrected belief
    - (where we think we are) × (where we seem to be) = (best estimate of where we are)
  - Neither one alone is enough:
    - Prediction only → uncertainty grows forever
    - Sensor only → too noisy, no memory
    - Combined → best of both worlds ✓
  - η makes sure total probability is 1.
  - If the sensor reading is bad, the correction may be far from what is real.
 
Now let us do exactly the same,  but this time in 2D. 

From 1D to 2D: Odometry Motion Model

Real robots operate in 2D space with position (x, y) and orientation θ.  

Below shows that. The countours around the robot is also how gaussian is represented in 2D.

Animated Prediction in 2D


Watch the uncertainty cloud grow as the robot drives:

Code Snippet (from 5_odometry_motion_model_prediction_step2D.py):

Correct Step: Sensors Save the Day

Prediction alone leads to drift. Sensors (especially LiDAR) provide the crucial correction.

Key Formula (Correction / Update):

bel(x_t) = η · p(z_t | x_t) · bel(\bar{x}_t)
  • Wide curve = motion prediction
  • Sharp likelihood = sensor reading
  • Multiplication = sharp, confident belief
Summary of the Loop:
• Predict: Belief spreads (less certain)
• Correct: Belief sharpens (more certain)

This Predict-Correct cycle is the essence of the Kalman Filter.  The sensor model is responsible for adding correction to prediction.
Just like the motion model, there are many sensor models. So we have to select one and go with it.  For the motion model, we selected the odometry motion model as seen above. 

Sensor Models: How Robots “See” the World

Chosen sensor Model: Beam-Endpoint Model (great for LiDAR)

Used with LiDAR sensors. It only considers the endpoints where the laser beams hit obstacles. When used on a map, it creates a likelihood map (see image below) — bright areas around walls show how likely the current scan is from a certain position.  


Bright areas indicate positions where the current scan matches well:

 
    Using this model on a map results in a likelihood map (see below) where each endpoint has a Gaussian around it.

Live Laser Interaction:

 

The Full Bayes / Kalman Filter

Everything comes together in one beautiful loop:

You can clearly see:

  • Uncertainty growing during motion
  • The belief collapsing back to high confidence when sensor data arrives
  • The robot staying accurately localized over time

Code Snippet (core of 7_full_Bayes_filter_kalman_filter.py):

This is Kalman Filter intuition at its finest — elegant, visual, and practical.

From Theory to Real-World Robots

These concepts scale beautifully. The same principles power self-driving cars, drone navigation, and vacuum robots.

I’ve taken this knowledge and applied it to a real Roomba-style robot in a physical room. The transition from 1D animations to real hardware is incredibly rewarding.

See the github Link Below

Final Thoughts

Kalman Filters aren’t scary once you see them in action. They are simply a smart way of answering:

“What does my motion tell me?” × “What does my sensor tell me?” = “Where am I most likely now?”

By starting simple (1D), moving to 2D, adding realistic sensor models, and watching the animations, you build real intuition that no textbook alone can give.

If you want to truly understand SLAM and Kalman Filters, don’t just read — visualize, animate, and implement.

The journey from researcher to engineer mindset is worth every line of code.

More from the Blog

How to Install Fusion 360 that doesn't expire
Sep 27, 2026·2 min read

How to Install Fusion 360 that doesn't expire

Want to use Fusion 360 for free without the 30-day limit? Learn how to legally download and install the official, non-expiring Fusion 360 personal license.

T
Tambu Precious
Read →
How to Train and Test An AI model on edge Impulse
May 27, 2026·4 min read

How to Train and Test An AI model on edge Impulse

This blog includes how to train an Object Localization Model on Edge impulse. We will train this model to recognize cubes of different colors. The blog will also include some tips to getting better Test Results from your model.

T
Tambu Precious
Read →
3D Modelling & Printing – Step by Step
May 12, 2026·3 min read

3D Modelling & Printing – Step by Step

TDesign cubes that will be used to Train a basic Edge impulse AI model to classify Cubes (Further Used with Robotic Arm) - Skills: 3D modelling, 3D printing

T
Tambu Precious
Read →