FixTheRobot Explore Robotics / Navigation / M6 / M6-L2

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

Navigation · Local Planning and Obstacle Avoidance · M6-L2 · Intermediate

Implement the Dynamic Window

16:30. In the supply aisle Scout drives straight at a rolling shelf, brakes hard at the last moment, and stops with its bumper touching the shelf. The log says every command was "collision free". The shelf was seen 1.2 m ahead; the robot was doing 1 m/s and cannot stop in less than 1 m.

You will build the velocity chooser in three steps: which velocities the motors can reach in one control period, how far an arc is free of obstacles, and which of the candidates can still be stopped in time.

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

    The dynamic window approach chooses a velocity pair (v, w) every control cycle. Stage 1 builds the window of velocities that the motors can actually reach, clipped to the robot's limits. Stage 2 measures how far Scout can drive along an arc before touching an obstacle, which needs a fine enough step. Stage 3 scores a grid of candidates by heading, clearance and speed, and keeps only those that are admissible: the robot must be able to stop before the first contact.

    Grading is result-based: your functions are run on hidden situations, and the chosen velocity is checked against the window, against the stopping distance computed independently by the simulator, and against the best admissible candidate.

    Theory for this lab

    Local Planning and Obstacle Avoidance labs

    1. M6-L1: Escape the Local Minimum
    2. M6-L2: Implement the Dynamic Window: this lab.
    3. M6-L3: Avoid a Moving Obstacle
    4. M6-L4: Pass Without Colliding: ORCA

    Educational simplification: a circular robot, circular obstacles of known position, exact arcs, one decision per situation (your function is called once with a batch of situations instead of every tick), and a score with fixed weights. Real planners also account for sensor latency, odometry error and a footprint that is not round (lesson M6-T7).

    Get the next lab

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