Click & Whirr needs a wider screen
Open it on a laptop or desktop (1280px or wider recommended). The Learn · Code · Watch workspace needs the room to breathe.
Lesson 08
Follow the route
In L7 you planned a route; now drive it. Pure pursuit is the trick: instead of hugging the line, the robot fixes a point a set distance ahead on the route, its lookahead, and simply steers toward it, again and again. That one distance is the whole personality of the follower. Look too close and it oversteers and snakes (a hot Kp all over again); look too far and it cuts the corners, rounding them off and sliding wide (too much damping). Somewhere between is a lookahead that glides.
Checkpoints
- Drive the route to the goal (waiting for Run)
- Glide through the turns: smooth and on-route (waiting for Run)
Press Run ▸ to start checking your code.
The stub ignores aim entirely. Write the steering arc, then play the lookaheadslider: pull it down tight and the bot fights itself; push it too far and it cuts the corners. It’s the Kp/Kd trade-off again, in space.
Steps
- 1
Steer along the arc
aimis the angle to the lookahead point. Bend toward it:steer = self.base * math.sin(aim) * (55 / self.L): the same angle bends you harder whenLis small. - 2
Glide through the turns
▸API reference
- PurePursuit(lookahead, base)
- Your class is built once when you press Run, with the two slider values as constructor args. Moving a slider rebuilds it with the new values.
- step(aim_at)
- Called every tick with the aim_at sensor function. Return a (left, right) wheel-speed tuple.
- aim_at(L) (callable)
- Angle (radians) from your heading to the point L px ahead on the route; + = to your left. The same function is available as robot.sensors.aim_at(L). The reading runs on a slightly delayed pose: that lag is why a too-tight lookahead rings.
space pause · r reset