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

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

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

Build a 2D Occupancy Grid

A robot has driven round a room with a laser scanner, and you know exactly where it was at every scan. The room is still invisible: all you have are lists of distances.

You will turn them into a map a planner can use, with walls, free space and unknown space, and then see what happens when the poses are not exact.

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 geometry: which cells does a beam cross? It is graded by properties (connectivity, count, closeness), so any correct tie-breaking passes. Stage 2 is the log-odds update of M3-T1, graded on three outcomes a planner cares about: walls found, no phantom walls, free space known. Stage 3 holds the code fixed and degrades only the poses, to show that the map is as good as the localisation behind it. The room and the true cell occupancy stay in the simulator.

    Theory for this lab

    Mapping and State Estimation labs

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

    Educational simplification: a 20 cm grid, exact poses in stages 1 and 2, a 360° scanner with Gaussian noise and 4% random dropouts, and independent cells. Production mappers (Cartographer, SLAM Toolbox, GMapping) use scan matching to correct poses, probabilistic hit/miss tables, submaps and much finer, sparse grids.

    Get the next lab

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