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
Checkpoints · 0 of 2 (waiting for Run)
- Drive the route to the goal (waiting for Run)
- Glide through the turns: smooth and on-route (waiting for Run)
Fix a point ahead, steer at it
Your robot has a route on paper. Teach it to actually drive the line.
In lesson 7 you planned a path around the walls; now the robot has to follow it. The tempting move is to hug the line, steering by how far off it you are, but you have already felt where that leads: a hot correction rings, a soft one lags. Pure pursuit throws that framing out. Instead of chasing the nearest point, the robot fixes a single point a set distance ahead on the route, its lookahead, and simply steers toward it, tick after tick.
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. First you write the steering, then you find that distance.
Steer along the arc
Tune the lookahead that glides
▸API reference
- PurePursuit(lookahead=55, base=42)
- Built once when you press Run, from the defaults in your __init__ signature. Edit the lookahead default and Run again, and a fresh follower drives with the new value.
- 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 · ctrl/cmd+enter run