FixTheRobot Explore Robotics / Localization & SLAM / M3 / M3-L4

This lab works on phones, but writing code is much easier on a laptop.

Localization & SLAM · Mapping and State Estimation · M3-L4 · Intermediate

Explore Particle-Filter Localization

A particle filter is a crowd of guesses. Each is a possible pose, each is judged by how well the laser scan fits, and the crowd changes to follow the evidence. When the robot is picked up and moved, the whole crowd is wrong.

You write the two pieces of the filter that are easy to get subtly wrong, resampling and weighting, and then discover what it takes to survive a kidnapping.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math and, for matrices, slamkit (matmul, transpose, solve, inverse, identity). The data arrive as the dictionary D. There is no NumPy, random, json or copy in the browser runtime. Your code runs locally and never leaves this page.

    Hints

    What this lab teaches

    Stage 1 is the resampling and effective sample size of M3-T8, tested on weights with zeros, a dominant particle and a uniform set. Stage 2 is the weight computation, with a trap that real filters fall into: a full 200-beam scan multiplies so many small numbers that the likelihood underflows. Stage 3 runs a complete filter with a built-in sensor model and lets you change the number of particles, the noise, the resampling rule and the random injection to survive a kidnapping. The true pose stays in the simulator.

    Theory for this lab

    Mapping and State Estimation labs

    1. M3-L1: Build a 2D Occupancy Grid
    2. M3-L2: Fix a Misaligned Map
    3. M3-L3: Diagnose Scan-Matching Failure
    4. M3-L4: Explore Particle-Filter Localization: this lab.
    5. M3-L5: Implement a Simplified EKF-SLAM

    Educational simplification: a known 2D map, 18 beams in the filter run (200 in the weighting stage), a simple beam model with a random-reading floor, brute-force ray casting, and a kidnapping at a fixed step. Production filters (ROS nav2_amcl) add likelihood fields, adaptive particle counts (KLD sampling) and augmented-MCL recovery.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.