Part 3 · How robots are controlled
26Balancing something that wants to fall
The cart-pole is back, and the four pushes that keep its pole up are yours to switch off. Each one missing brings the pole down its own way: straight over, whipped over, walked off the rail, or swayed into a bumper.
This assumes: Stability: when control goes wrong. About 9 minutes of reading.
Two modules ago you balanced a broom on your hand through a laggy video call, and it fell because your hand was late. That module was about when the catch arrives. This one is about what the catch is made of. Nothing here is late. The same cart-pole comes back with its four pushes out in the open, and you take them away one at a time to see what each was doing.
First, why a broom needs catching. Balance one on your open palm, bristles up, and stop moving your hand. It is down in about a second. Now hold it by the tip of its handle, bristles hanging, and stop. It hangs, and if you nudge it, it swings a little and comes back to hanging.
The difference is which way a lean pulls. Gravity pulls the broom straight down. Standing exactly upright, all of that pull runs down through your hand and none of it tips the broom; as it leans, a share of the pull falls to one side of your hand, and that sideways share is what tips it. Hanging, the same share pulls the broom back toward the middle, so every wobble dies on its own. Standing, it pulls the broom further over, and it grows as the lean grows: at one degree it is tiny, at ten degrees it is ten times that, and once the broom is well over, nothing your hand does will get it back. Anything held up like this, balanced above the point that supports it, is an inverted pendulum: the broom, the pole on the cart, a person standing, a robot on two legs, a rocket on its own engine. Every one of them has to be caught again and again, because the moment the catching stops the falling starts. The arm of the proportional control module sagged when its push was too weak. This pole does not sag. It goes.
Four numbers, four pushes
The cart on its two-meter rail, the 12 newton motor, the half-meter pole on its free pivot: as before. The pole's sensor reports its lean and how fast that lean is changing; the cart's reports where it is and how fast it is moving. Those four numbers are the rig's state: everything about where it is and how it is moving at this instant, and everything the controller has to go on.
The controller makes one push from each number. Two are the PID module's P and D aimed at the pole: a push in proportion to the lean, which this box calls the lean push, and a brake in proportion to how fast the pole is going over, the lean brake. The other two are P and D aimed at the cart: a pull in proportion to how far the cart is from the middle of the rail, the cart pull, and a brake in proportion to the cart's speed, the cart brake. The four are added up and handed to the motor, which gives what it is asked for up to its 12 newtons. And remember the last module's strange sign: all four push the lean push's way. To bring the cart home, the controller first sends it a little further out, so that the pole leans toward home, and then the lean push carries the cart back under it. The cart brake works the same roundabout way: it nudges the cart on in the direction it is already moving, which tips the pole back against the motion, and the lean push then slows the cart under the leaning pole. Both act through the pole, because pushing the cart straight against the pole is what tips it over.
Last time the sizes of these pushes were fixed and you turned only the delay. Here each push has a switch.
The box
The four switches across the top are the four pushes, all on to begin with. Off, a push is gone. Run stands the pole back up with the cart at the middle. Knock the pole gives the pole the same flick as in the last module, and Knock it hard gives it a flick three times as fast. The bars show what each push is asking for right now, in newtons, left or right, and the bottom bar what the motor is giving: the four added together, never more than 12. Under the bars, the chart draws the pole's lean and the motor's force, as before, and the line under it says which way the pole leans, where the cart is, the biggest lean since the last knock, and whether the controller has given up.
This is easier on a larger screen, but it works here too.
That is a well-tuned balance. To see what each push does, take it away and leave the other three on: how it fails tells you what the missing one was for.
The lean push: going under the lean
Switch off Lean push and press Run. The pole tips one way, then the other, each tip bigger than the last, and is over within about two seconds, the cart lurching back and forth under it to end against a bumper.
Without the lean push, nothing puts the cart under a leaning pole. The lean brake helps a little, since it pushes the cart the way the pole is falling; but it answers how fast the pole is going over, not how far it has gone, so a leaning pole that is for a moment still gets nothing from it. The lean push does the balancing; the other three tidy up after it.
The lean brake: not overdoing the catch
Switch Lean push back on, switch off Lean brake, and press Run. The cart charges under the lean, and the pole swings through upright and straight over the other side, in about a second.
The lean push grows with the lean and does not care which way the pole is moving. So it pushes the cart as hard while the pole is swinging back toward upright as while it was going over, and the cart arrives under the pole with speed the pole cannot use. Out the other side, the lean push turns round and pushes the other way, harder because the lean is now bigger, and the second swing is bigger than the first. That is the PID module's P without its D, on a machine that cannot afford one overshoot. The lean brake reads how fast the pole is moving and leans against it, so the catch eases off as the pole comes back, and the pole arrives at upright nearly still.
The cart pull: coming home
A cart that only catches the pole ends up wherever the last catch left it. Nothing about the pole says where the cart is, so nothing brings it back. The catch was even a little tighter, 6 degrees against 8, because the cart pull's job is to lean the pole a little extra so the cart comes home, and nobody was doing it. On a two-meter rail, three knocks the same way is all it takes; a balancing robot in a room would wander into the furniture.
The cart brake: coming home without overshooting
Switch Cart pull back on, switch off Cart brake, press Run, and watch the cart. It begins to sway along the rail, a couple of centimeters at first, then five, then fifteen, one sweep every four or five seconds, the pole tilting a degree or two at each turn, until after about twenty seconds a sweep reaches the bumper and the pole goes over.
That growing sway is the lean brake's story, a floor lower. The cart pull brings the cart home through the pole, but the cart arrives at the middle with speed and carries on past; the pull brings it back from the other side, further; and so on. The cart brake reads the cart's speed and, through the pole, leans against it, so each return arrives slower than it set off. An oscillation that grows every swing is the stability module's unstable system. There the cause was lateness; here nothing is late, and a missing brake is enough.
Two pulls and two brakes, then. The pulls, on the lean and on the cart's position, bring the rig back where it should be. The brakes, on the pole's speed and the cart's, stop each return becoming the next departure. Switch all four off, press Run, and the pole is down in a second, as with no controller at all.
The point of no return
No setting of the switches fixes this fall. A leaning pole is caught by getting the cart back under it before the top comes down, and the further the pole leans, the harder the cart has to accelerate to get there, because the sideways share of gravity tipping it has grown. The motor's 12 newtons give the cart only so much acceleration, and the rail is only so long, so there is a lean past which no run of the cart gets under the pole in time: for this rig, about 27 degrees. Past it, the motor can give everything it has and the pole still gains. That is the saturation of the proportional control module again, and here it is final. The soft knock leaned the pole 8 degrees, well inside the line; the hard one threw it past it before the cart had moved a hand's width. A stronger motor moves the line out, and 20 newtons would have caught this knock; nothing moves it away. Every balancing robot is built to stay well inside it.
Tuning
The four pushes' sizes were found by tuning: trying a size, giving the pole the same knock, measuring how far it leaned and how long the rig took to settle, and adjusting. Every push has a window: half the lean brake and the catch overshoots into a bigger lean the other way, and the pole is lost; a cart brake half again as strong holds the cart still when the pole needs it to move, and it is lost that way. The sizes here sit near the middle of each window, the margin the last module said a real controller keeps.
This is everywhere
The drone of the flying module is kept level by the same shape of rule: its tilt is a lean, and its controller tilts it back and steadies it while another push holds its place over the floor. A robot on two legs is an inverted pendulum whose cart is its feet, kept up by the same four ideas hundreds of times a second. The dog of the legs and balance module did none of this: it stood on four stiff legs on a wide base and survived a shove by stiffness alone. Two legs cannot be stiff enough; they have to balance.
What the simulation leaves out
The sensors here are exact. A real one jitters, and both brakes read speeds, which jitter makes worse. The motor here answers in the instant it is asked; a real one takes a moment, the last module's latency, and that eats into the margin. And this rig never has to get the pole up: Run stands it there. A real cart-pole must swing its pole up from hanging first, a harder trick than anything on this page.
Watch
How to Visually Tune PID Control Loops — upgrdman (3:56 of it, starting at 13:20)
- Why this video
- This is a real balancing robot, two wheels and a body that is its own pole, with the size of each push on a knob and a live chart of what each one is giving, driven by the person who built it. He turns the brake up from nothing and you watch the same robot stop jumping and overshooting when he pushes it, then turns it too far up and you can hear it hunting. And it has no wheel sensors, so it has no cart pull, and he says so: it drifts across the floor and cannot come back, which is the third of the box's four failures on a real floor.
- What to watch for
- At 13:31 he raises the brake, and at 13:47 says it no longer jumps when he gives it an input and is smooth when he lets go: that is the lean brake doing its job. At 13:43 and again at 17:04 he says it drifts because it has no wheel sensors, which is the cart pull missing. At 14:38 the brake is far too high and the robot hunts, moving all over the place and audibly chattering, and at 15:41 he explains why: the brake reads the change between one measurement and the next, so it amplifies the sensor's noise. At 16:31 he turns it down and it settles.
Words introduced
- inverted pendulum
- Anything balanced above the point that holds it up, so that a lean pulls it further over instead of back. A broom on your palm, a pole on a cart, a person standing, a rocket on its engine. Keeping one up is a job that never ends.
- state
- The handful of numbers that say everything about where a system is and how it is moving right now. For the cart-pole there are four, the pole's lean and how fast it is changing, and the cart's position and speed.
- tuning
- Choosing the sizes of a controller's pushes, by trying a size, watching what happens and adjusting. Too small and a push does not do its job; too big and it fights the others.
Where next
Suggested next: 27. Stiff or soft: holding an egg without breaking it
