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 01
Differential drive
Checkpoints · 0 of 3 (waiting for Run)
- Roll dead straight (waiting for Run)
- Spin in place (waiting for Run)
- Park on the green goal (waiting for Run)
How two wheels steer
Your robot has two wheels and no idea how to use them. Over this lesson you teach it to roll, spin, and park, the three moves every later lesson stands on.
There is no steering wheel here, just the two wheels. Match their speeds and the robot rolls dead straight. Speed up one wheel and it arcs toward the slower side. Spin the wheels in opposite directions and it pirouettes on the spot. Every path the robot ever drives is some mix of those.
The two sliders below the sim are a sandbox: drag them and feel the mapping before you write a line. They drive the robot until your code compiles, and then your code owns the wheels. Checkpoints only count for the code. Your drive function gets the clock and the bearing to the goal, and returns a (left, right) speed each tick.
▸Go deeper: how two wheels are enough
A car needs a steering rack because its wheels only ever point the same way. This robot does not: each wheel spins on its own, so the two speeds already carry both things you want. Their average is how fast the body goes forward, and their difference is how fast it turns. Feed in any forward speed and any turn rate, and there is exactly one pair of wheel speeds that produces it.
That is the whole trick, and it is why every phase in this lesson is just a choice of those two numbers. Straight is all average, no difference. A spin is all difference, no average. Parking on the goal is a steady average with a difference that leans on the bearing. Every controller you write after this, all the way to the capstone, is still just picking a forward speed and a turn.
Make it roll
Make it spin
Head for the goal
▸API reference
- drive(t, goal_bearing)
- Called every tick. t = seconds since Run; goal_bearing = angle to the goal in radians (+ = the goal is to your left). Return a (left, right) tuple.
- wheel speeds (-100..100)
- Equal speeds roll straight; opposite speeds spin in place; unequal speeds arc toward the slower wheel.
- the sliders
- A sandbox: before your first Run they drive the robot so you can feel the mapping. Once your code compiles, it owns the wheels. Checkpoints only count for the code.
space pause · r reset · ctrl/cmd+enter run
Simulator
Sandbox: the sliders drive the robot until your first Run. After that your code owns the wheels, and only code earns checkpoints.