Part 3 · How robots are controlled

22Proportional control: push harder the further you are

Two copies of the same arm run the same simple rule: push harder the further you are from the target. The only difference is how hard, and that one number decides how far each arm sags, how far a knock sends it, and how it shivers back.

This assumes: Open loop, closed loop: the idea of feedback, Gravity and momentum: why arms sag and overshoot. About 9 minutes of reading.

Picture driving down a straight road. When the car drifts a little toward the edge of the lane, you turn the wheel a little. When it has drifted a lot, you turn it a lot. When it is in the middle, you hold the wheel straight. You never worked out a plan for the whole road. You looked at how far off you were, and how hard you steered came from that.

That is the simplest closed loop there is, and it is the rule inside the servos this course's arms have been using all along. This module opens one up, puts a knob on it, and runs two copies side by side with the knob set differently.

The rule

The last module ended with the error: the gap between where a machine wants to be and where its sensors say it is. A controller has to turn that gap into an action. The rule you used on the road is proportional control: push in proportion to the error. Twice the gap gets twice the push. Half the gap gets half. No gap gets no push at all.

The rule needs one number to be complete, and that number is the gain: how much push the controller gives for each unit of error. For a robot joint, the push is a torque and the error is an angle, so a gain is so many newton meters of torque for every radian of gap. A radian is about 57 degrees, which makes the numbers easier to feel in degrees. A gain of 5 is a bit under a tenth of a newton meter for each degree. A gain of 40 is eight times that, about 0.7 of a newton meter for each degree.

In the module on gravity, a servo like this behaved like a spring pulling the arm toward its target, harder the further it was stretched. The gain is how stiff that spring is. A low gain is a soft spring, and a high gain is a stiff one. Everything in the box follows from that.

Two arms

The box holds two copies of the SO-101 arm from the modules on motors and on gravity, with the same servo at the shoulder lift and the elbow and wrist held straight, so each arm is one long lever with the hand on the end. Both have been told to hold the shoulder at 0 degrees, which points the arm forward and about 35 degrees above level. On this joint, bigger numbers tip the arm down. The servo in the module on gravity ran at a gain of 15, so the two arms here are one softer than it and one stiffer.

The left arm runs at gain 5 and the right at gain 40. Each side has its own Gain knob, a Payload knob that puts a weight in the hand, a Step button that sends the target to minus 30 degrees and back, and a Shove button that knocks the arm downward.

The chart on each side has two panels. The top one shows the target, dashed, and the angle. The bottom one shows two torques. The P push is what the rule asks for: the gain times the gap. The motor torque is what the motor actually gives. The line under the chart says how far the arm is from its target and what the motor is giving.

Low gain

Loading the simulation. The robot runs in your browser, so the first one takes a few seconds to arrive.

High gain

Loading the simulation. The robot runs in your browser, so the first one takes a few seconds to arrive.

This is easier on a larger screen, but it works here too.

Why the sag depends on the gain

In this pose, gravity twists the shoulder downward with about 0.6 newton meters. To hold the arm still, the motor must twist back with the same amount. Neither arm has a choice about that; it is what holding the arm up costs.

The rule can only produce a push from a gap. So each arm sinks until the gap is exactly big enough to earn 0.6 newton meters, and stops there. The soft spring on the left gives under a tenth of a newton meter a degree, so it needs about 7 degrees of gap. The stiff one on the right gives 0.7 a degree, so it needs less than one. Divide the push the load needs by the gain, and you have the sag.

That leftover gap has a name. The steady-state error is the error that is left once everything has stopped moving. Under proportional control, there is always one whenever something has to be held against a load, because the gap is how the controller knows how hard to push. The sag you measured in the module on gravity was this, and so was the error the last module said a servo is pushing against the whole time.

A load makes it bigger in proportion. Set Payload to 500 g on both sides and the left arm sinks to about 26 degrees below its target, the right one to about 3 degrees below: each gap has grown about four times, because half a kilogram in the hand has made the push the arm needs about four times bigger. The ratio between the two sides does not change, the left gap still about eight times the right one, because the right gain is eight times the left.

Moving

Holding still is half of a servo's job. The other half is getting somewhere.

At the start of the step, both gaps were 30 degrees or more, and by the rule both arms asked for more torque than the motor has, the right one about seven times more. This is saturation: the controller asks for more than the motor can give, so the motor gives all it has, and nothing more. All it has is 2.94 newton meters standing still, and less as the arm speeds up; the module on motors showed why. While a joint is saturated, the gain makes no difference. Both motors were flat out, so both arms rose at the same speed. Turning the gain up does not make a saturated arm any faster.

The difference comes near the target, where the gaps shrink and the pushes fall back below the motor's limit. From there, the rule is in charge again. The arm is moving fast by then, and as the module on gravity showed, a moving arm carries momentum that takes a force applied for a time to remove. The only brake is the rule itself: past the target, the gap is on the other side, and the push reverses. The soft spring on the left brakes gently, so the arm sails a long way past before it is stopped, and swings back slowly. The stiff spring on the right brakes hard as soon as it crosses, so it goes less far past. On the way back the same thing happens: the stiff spring pulls harder at every degree, so it gets the arm back across the target sooner. Each swing takes less time, which is why the right arm shivers where the left arm sways, and why half a dozen quick swings are over about as soon as two slow ones.

Being pushed

In the last module a disturbance was anything that pushes a machine away from what its commands would have done: an oily wheel, a gust. Shove is one for the arm, a sharp knock downward.

Neither arm knew a shove was coming, and neither needed to. Each saw a gap and pushed against it, as it always does. The stiffer spring pushes harder for every degree it is knocked, so the same knock sends it less far.

It is less far by about half, though, not by eight times, as the sag was. A shove is not a steady load. It sets the arm moving, and what stops it is the brake, the push growing as the gap grows. The right arm's push asks for everything the motor has once the gap is about 4 degrees; the left arm's would need a gap of more than 30. Once a motor is braking with everything it has, that is saturation again, and more gain adds nothing. So the stiff arm gets to full braking sooner, which saves it some distance, but from there the two are stopped by the same motor.

So why not turn it all the way up?

The two ends of the knob show what gain does. Drag the left arm's Gain all the way down to 0 and the arm falls until it rests on the table, because with no gain, no gap is ever worth any push. Drag the right arm's up to 60 and set its Payload to 500 g, and the sag shrinks to about 2 degrees. More gain makes the gap smaller, but no amount of gain makes it zero.

In this box, a high gain looks like it costs almost nothing. The right arm sags less, is knocked less, and settles as soon as the left. Its only fault is the shiver. That is the simulation being kind in two ways.

First, the controller here sees the arm's angle perfectly and instantly. A real one reads a sensor that is a little noisy and a little late. A stiff spring reacts strongly to every degree, including degrees that are not really there, and it reacts strongly to where the arm was a moment ago rather than where it is now. A push that arrives late can arrive when the arm has already turned round, and then it adds to the next swing instead of stopping it. Turn the gain up far enough on a real robot and that shiver grows into a shake that does not stop. A later module in this part adds that delay to the box and lets you watch it happen.

Second, however high the gain, the steady-state error never quite goes away, and a heavier load always makes it bigger. A controller that only looks at the present gap cannot do better. The next module gives it a memory of the gaps it has seen, so that a gap that lingers is pushed against harder and harder until it is gone.

What the simulation leaves out

The box's rule runs two hundred times a second on an exact reading of the angle. The motor gives exactly what it is asked for, up to its limit, and nothing is added to it: every newton meter it gives comes from the gap. Many real servos are set up the same way, with their gain chosen at the factory; better ones let you change it, and the people who tune robots spend a lot of their time doing exactly what you have done here, turning that one number and watching how the arm sags, swings and shivers.

Watch

PID Tuning — ROBOTISAMERICA (2:24 of it, starting at 2:39)

Why this video
This is the job the end of this module describes, done by a real person on a real robot servo. An engineer from ROBOTIS, a company that makes robot servos, has one servo swinging a weighted arm, and he turns its gain down from the factory setting, one step at a time, watching a graph of where the arm really went after each change. You see measured motion, not a drawing: at the factory gain the arm overshoots and shivers around each target, at lower gains it moves more gently and overshoots less, and when the arm is held level, with the most weight hanging off the joint, it stops short of its target, the same sag as the soft arm in the box.
What to watch for
The line on the graph is the servo's measured position, and each flat step is a new target. From 2:49, at the factory gain of 800, look at the corners of each step: the line shoots past and wobbles before it settles. He then tries 700 (3:41), 600 (3:53) and 400 (4:02); by 400 the wobble has mostly gone and the moves are gentler. At 4:20 a slide highlights part of the graph where the arm is held level and never quite reaches its target: that is steady-state error, and he says the "I gain" will fix it, which is what the next module adds. His gain numbers are the servo's own units, not newton meters per degree, so compare them with each other, not with the box.

Words introduced

proportional control
A closed-loop rule that pushes in proportion to the error. Twice the gap gets twice the push, and no gap gets no push at all.
gain
How much push a controller gives for each unit of error. In proportional control it is the one number you can change, and it works like the stiffness of a spring pulling toward the target.
steady-state error
The error that is left once everything has stopped moving. Under proportional control, it is whatever gap is needed to earn the push that holds the load.
saturation
When a controller asks for more than the motor can give. The motor gives all it has, and until the request falls back within reach, changing the controller changes nothing.

Where next

Suggested next: 23. Push, 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.