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 02b
Smooth it out
The if/else bot always jerks the wheels by the same amount, and that’s why it wobbles. Proportional control scales the correction by how far off it is: steer = Kp × error. Tune the gain Kp: too low and it drifts off the curves, too high and it oscillates wildly. Find the gain that glides.
Checkpoints
- Reach the end of the line (waiting for Run)
- Reach it smoothly (low wobble) (waiting for Run)
Press Run ▸ to start checking your code.
Write the one-line law, Run, then slide Kp (it flows in live) and feel the trade-off. If it still shivers at every gain, ease the base speed down too: the sensor lags, and speed makes lag hurt. Smooth and on the line to the flag is the win.
Steps
- 1
Scale the correction by the offset
Big error, big steer; tiny error, tiny nudge. And the steer must flip sides with the sign of
offset. - 2
Let Kp set the strength
- 3
Find the gain that glides
▸API reference
- follow_line(offset, kp, base)
- Called every tick. offset = signed cross-track px (+ = right of the line, already sensor-delayed); kp and base are the current slider values. Return a (left, right) tuple (clamped to ±100).
- kp / base (live)
- Slider moves flow straight into the next tick's call: tune the gain while it drives. The lesson: the default kp starts HOT (wobbly); find the gain that glides.
space pause · r reset