Part 3 · How robots are controlled
23Push, patience and a brake: what PID stands for
The rule inside almost every robot joint is called PID, three letters for three pushes added together. You met the first one last time. This module adds the other two, one switch at a time, and shows what each one does to an arm lifting a weight.
This assumes: Proportional control: push harder the further you are. About 8 minutes of reading.
Ask almost any robot builder what rule keeps a joint where it is told to be, and the answer will be three letters: PID. It is inside the servos of the arms in this course, inside the motor controllers of drones and 3D printers, and inside the cruise control of a car. The letters put people off, and they should not, because each one is a plain idea you already use with your own arm.
PID control stands for proportional, integral, derivative. It is three pushes added together. This module takes them one at a time.
P: the push you already know
P is for proportional, and it is the whole of the last module. Push toward the target, harder the further away you are: twice the gap, twice the push. It works, and it has one fault you measured there. When the arm has to hold something up, it settles a little below its target and stays there, because a gap is the only thing that earns it a push. Turning the gain up shrinks that gap. Nothing about P ever closes it.
I: patience
Hold a full shopping bag out at arm's length. Your arm dips. You do not know how heavy the bag is, but you notice that your arm has been low for a while, and without deciding anything you push a little harder, and a little harder again, until it is back where you meant it to be. The longer it stays low, the harder you push.
I is for integral, and that is the idea. An integral is a total that keeps adding up over time. The controller adds up the gap, moment by moment, for as long as there is one: a big gap adds a lot each moment, a small gap a little, and the total only stops growing when the gap is gone. If the arm ever goes past its target, the gap counts the other way and the total shrinks again. The push it makes is in proportion to that total. So a gap that lasts gets pushed against harder and harder until it closes. In this course, that push is called patience.
The patience push has a memory. When the gap is finally closed, the total does not go back to zero; it keeps everything it added up, and goes on giving that push. That is how it holds the bag up with no gap left: it has learned, over time, how hard holding this load takes.
D: the brake
Now walk toward a closed door. You slow down a few steps before you reach it. You are not reacting to how far away the door is, but to how fast you are closing in on it.
D is for derivative, and that is the idea. A derivative is how fast something is changing right now. For a joint, that is its speed. The push made from it leans against the movement, harder the faster the joint moves, whichever way it is going. It is a brake. A joint that is not moving gets no push from it at all, so the brake never changes where the arm settles, only how it gets there: it takes the swing out of arriving.
The box
The box holds one SO-101 arm from the last module, with the elbow and wrist held straight and 300 grams fixed in its hand, the rust-colored ball. The shoulder is under PID control with a switch for each of the three pushes, and no knobs: the size of each push is fixed, with P at a gain of 10, between the soft arm and the stiff arm of the last module. P starts on, and I and D start off, so at first this is a proportional arm like those.
Until you press Run, the arm is only asked to hold the angle it starts at. The gold star is where Run sends it: 30 degrees higher. Run does the same thing every time. It puts the arm back at its start, wipes the controller's memory, and moves the target to the star. You flip switches and press Run, and watch what changed.
Under the switches, the bars show what each push is giving right now, as a bar toward the target or away from it: P in blue, I in red, D in green, and underneath them, in orange, the total the motor gives. The dashed mark on every bar is what holding the arm still takes at this moment. Whichever bar reaches the mark is the one doing the holding. Below the bars, a chart draws where the arm has been over the last few seconds against its target, and a line under the chart says where the arm is now and how far past the target it went on the last run. Before you press anything, P is the only bar lit and it reaches the dashed mark: it is holding the whole weight, and the line under the chart says the arm is about 9 degrees below its target, which is the gap it needs to earn that push.
This is easier on a larger screen, but it works here too.
Adding patience
The gap is gone, as promised. The price was the longer swinging, and it came from the memory. All the way up, the arm was below the star, so the total kept adding up. When the arm reached the star, the patience push was still there, still pushing up, and it could only shrink by the arm spending time above the star, where the gap counts the other way. Every swing above the star unwound some, every swing below wound some back, and it took three seconds to find the amount that holds the weight and no more.
Adding the brake
The brake is on from the moment the arm starts to move. Far from the star, P is big and the brake is small beside it, so the arm still goes up briskly, and it keeps speeding up for as long as P pushes up harder than gravity and the brake together pull it back, which is nearly all the way. Near the star, the gap and the P push have shrunk, but the arm is moving at its fastest, so the brake is at its strongest and takes over. The arm slows before it gets there, like you at the door, and there is no momentum left to carry it past.
Now switch on all three and press Run. The arm goes about 5 degrees past the star, comes back, and is still within a second, exactly on it. Patience holds the weight, the brake took most of the overshoot and all of the swinging, and P did the lifting.
The arm still went a little past, where with the brake alone it went none. That is patience again: the total wound up on the way up and was still pushing at the star. The brake cut how far it went past from 11 degrees to 5, and then stopped the rocking that unwinding it would otherwise have taken, so the total settled in one swing instead of a dozen.
That is the whole recipe. P gets you there and holds you roughly. I removes the sag that P alone leaves, and on its own makes the arm swing longer. D takes the swing out, and on its own does nothing about the sag. Together they lift the weight to the star and stop there. And with all three switched off, Run lifts nothing: nothing pushes at all, and the arm falls until its hand rests on the table.
What each one costs
Each push fixes one fault and can cause another, and choosing how strong to make each one is called tuning. In this box the sizes are chosen for you. Too little patience and the sag takes a long time to close; too much and it runs away. The patience push is always a little behind: when the arm crosses the star going up, the total is still full and takes time to unwind, so it is still pushing up while the arm is above the star. Make it stronger and that leftover push throws the arm further above the star than P can turn it around, the longer swing back below winds the total up more than before, and every swing is bigger than the last. Too little brake and the swinging stays; too much and the arm creeps up so slowly it seems stuck. People who build robots spend a lot of their time on those three numbers, watching a joint do what you have just watched it do.
What the simulation leaves out
The box's controller sees the arm's exact angle and speed two hundred times a second. A real one works the speed out by comparing two angle readings a moment apart, and an angle sensor jitters a little: a wobble of a tenth of a degree between two readings a two-hundredth of a second apart looks like 20 degrees a second, so the brake reacts hard to jitter that P would barely notice, and real brakes are kept gentler than this box would let you have. Real controllers also cap the patience total. When a motor is already giving all it has, the gap lingers, and the total goes on growing with nothing to show for it; every bit of that has to be unwound afterward, which is a long swing, so the cap stops it building up past what the motor could ever give. And the reading here arrives instantly. The next module lets it arrive late, and shows what that does to a controller that is always acting on old news.
Watch
PID Control with Arduino: Lecture 6 (Propeller Arm Demonstration) — Nabil Mohammad (2:12 of it, starting at 1:54)
- Why this video
- This is the box's Shove, done by hand to a real arm. The maker has built an arm on a pivot with a propeller on its end, and a PID controller holds it at 45 degrees against gravity, much like the SO-101's shoulder holding its angle. He knocks it with his hand in three runs, turning the D gain down and then up between them. You see the brake at work on a real machine: with too little D the arm keeps swinging after each knock ("oscillating", in his word), and with more D, as he puts it, "it rejects disturbances a lot better".
- What to watch for
- Keep your eyes on the arm, and on the wiggly line on the monitor behind it, which is the arm's measured angle; the three gains are printed in the top-left corner. From about 2:14 he knocks the arm with the D gain he started with. From about 2:48 he has lowered D: after each knock, count the swings and watch how long the line on the monitor keeps waving. From 3:24 he raises D to 0.811, and from about 3:43 he knocks it again: compare how quickly it comes to rest. The memory (the I gain) is on in every run, so this is the whole PID controller, not P and D alone.
Words introduced
- PID control
- Control by adding three pushes together, proportional, integral and derivative. P pushes toward the target, harder the further away; I adds patience, pushing harder the longer a gap has lasted; D is a brake, pushing against movement.
- integral
- A total that keeps adding up over time. In a controller, the integral of the error is a running total of how far off the joint has been and for how long, and the push made from it grows for as long as any gap lasts.
- derivative
- How fast something is changing right now. In a controller, the derivative is the joint's speed, and the push made from it leans against the movement, harder the faster the joint is moving.
Where next
Suggested next: 24. Stability: when control goes wrong
