Click & WhirrAll lessons

Integration · Lesson 10

The gauntlet

This is the written walk-through of the lesson: the idea, stage by stage, plus the deeper asides. The interactive version, where you write real Python in the browser and drive a simulated robot, lives on the lesson page.

Everything, at once. Here’s the route you planned, and somebody left crates on it. One controller has to do it all: follow the route with pure pursuit (L8), see the crates with your distance rays (L6), and switch between those behaviors with a state machine (L9), because a follower that never looks up plows straight into the first crate, and a dodger that never looks back loses the route. This time you’re scored: the clock runs from reset, crashes send you back to the start, and the clock doesn’t care.

One controller, all of it

Everything your robot has learned, at once, against the clock. This is the robot you built, and for the first time it runs on the library you built.

Here is the route you planned, and somebody left crates on it. One controller has to do it all: follow the route with the PurePursuit you wrote in lesson 8, imported straight from mybot; see the crates with the three distance rays from lesson 6; and switch between those behaviors the way lesson 9 taught you, with a mode latched on self.state from tick to tick.

Neither behavior survives out there alone. A follower that never looks up plows straight into the first crate, and a dodger that never looks back loses the route. And this time you are scored: the clock starts at reset, a crash sends you back to the start, and the clock does not care.

Read the skeleton in the editor. The import line pulls three pieces from your library; if one is missing, the banner above the editor offers the vetted reference, so nothing blocks you. The glue builds your PurePursuit in __init__ and starts in follow mode. The only thing it cannot do yet is change its mind.

Switch to dodge when a crate looms

Press Run on the untouched starter and watch: it follows the route beautifully, straight into crate number one, forever. The pursuit is perfect, and it does not matter, because the follower never looks up.

Give it the nerve to change modes. Two transitions, written at the top of step. First, while following, watch the front ray: when a crate reads close ahead (about 55 px works), latch self.state to "dodge", pick the open side by comparing the left and right rays, and start a timer. Second, while dodging, count the timer down; at zero, latch back to "follow" and let the pursuit reel the route back in.

The dodge itself is already written below your transitions: a gentle arc toward the open side. Your latches decide when it fires. Once both are in, the bot swerves past the first crate, and that swerve is the gate here.

Reach the finish pad

Now let it run the whole gauntlet. Watch the MODE readout on the scoreboard flip as it goes: follow along the straights, dodge as each crate looms, follow again as the pursuit reels the route back in. Three crates, three swerves, and the finish pad waits at the end of the last straightaway.

Reaching the pad latches this gate, scuffed or not. Getting there without a scratch is the next beat.

Finish without a crash

A finish is not a clean finish. The scoreboard counts every crash, and each one sends the bot back to the start with the clock still running. This gate wants zero.

If a run keeps clipping a crate, watch where. Clipping the crate it is dodging means the swerve starts too late: raise the trigger distance in your transition so the front ray reacts sooner. Drifting into a crate on the way back means the dodge is too hot for the speed: ease the base default in __init__ down a notch and Run again.

Clean run under 14 seconds

One gate left: a clean run under 14 seconds. Speed lives in the code now. The base default in __init__ is the tuning surface, and the editor highlights it.

The shipped base=70 makes the bar with a little to spare. Feel the edges anyway: ease it down and the run turns safe and slow, the clock drifting past 14. Push it up and the laps get faster until, somewhere past 90, the dodge cannot save you and the crashes start. Each Run builds a fresh controller from your source, so the new value drives from the first tick. Press r for a clean timed run.

Find the base you would sign your name to and let the clean lap land. That is the course: a robot that rolls, senses, plans, follows, and decides, all of it running out of your own library.

Ready to build it? The interactive lesson is where you write the code and watch the robot run.