FreeThe loop, P and D🔒 In the workshopLate sensor, Motor limitsAn algorithm has no housing to open. What we take apart is its loop: the blocks it is made of and the numbers flowing between them, next to the motion they produce in 3D (drag to turn it). A teaching model; every number's source is in sources.md.
The teardown opens on its “P and D” mode, which shows this principle. Drag to turn it.
One step at a time
Step by step
PD control
Step 1 of 5
Measure the error
The wanted tilt is 0; the robot is at θ.
In words
P alone is a spring: it pulls back in proportion to the lean, but nothing removes energy, so it swings. D is a shock absorber: it resists speed and lets the robot settle in the middle.
Too much P swings hard and shakes; too much D feels sluggish and amplifies sensor noise (see derivatives). In the teardown, take P and D apart one at a time.
The formula
u = −Kp·θ − Kd·dθ/dt
Where you meet this in a robot
This is the heart of the “balance before walking” workshop. The teardown's “P and D” mode shows what each term does.