FixTheRobot Explore Robotics / Navigation / M2 / M2-L2

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

Navigation · Maps and Costmaps · M2-L2 · Intermediate

Compute a Distance Field

11:20. The pharmacy corridor has two doors, a narrow one on the straight line and a wide one a few metres away. Scout takes the narrow one every time and scrapes the frame. Facilities want the robot to prefer wide doors when it costs little.

For that, the planner needs to know how far every cell is from the nearest wall. You will compute that field with a two-pass sweep, use it to find the widest route, and then turn it into a direction that nudges the robot away from obstacles.

Your task

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

    Plain Python with math and heapq. Your code runs in a background worker: an endless loop is stopped after a few seconds and the page stays usable. It runs in your browser and is never sent anywhere.

    Hints

    What this lab teaches

    Stage 1 is the chamfer distance transform: two sweeps over the grid replace a search against every obstacle for every cell. Stage 2 uses the field to find a route by a max-min version of Dijkstra's algorithm. Stage 3 takes the gradient of the field with central differences and handles the zero-gradient case on a ridge.

    Grading is result-based on the practice map and on freshly generated hidden maps.

    Theory for this lab

    Maps and Costmaps labs

    1. M2-L1: Build an Inflated Costmap
    2. M2-L2: Compute a Distance Field: this lab.
    3. M2-L3: Find the Ghost Obstacles

    Educational simplification: the chamfer distance (weights 1 and square root of 2) overestimates the Euclidean distance by up to about 8%; distances are in cells; moves are 8-connected; the map is static and fully known.

    Get the next lab

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