Part 3 · How robots are controlled

21Open loop, closed loop: the idea of feedback

Two rovers set off for the same beacon. One drives straight ahead for three seconds, because that is where the beacon was when someone measured. The other keeps looking at the beacon and steers toward it. Put oil under a wheel and only one of them still arrives.

This assumes: Odometry: where am I, and why wheels lie. About 8 minutes of reading.

A toaster has a dial. Turn it to three and it heats the bread for a set time, then pops, whether the bread went in frozen or warm, thick or thin. Most mornings that works. Now picture a person making toast under a grill: they look at it, see it getting golden, and take it out. They did not need to know how thick the bread was. They watched, and they stopped when it was right. This module is about the difference between those two, which is the most important idea in how machines are controlled.

Two ways to get somewhere

The toaster works in open loop: it follows a plan made in advance, and never checks along the way whether the plan is working. The plan might be very good. Someone at the factory tried dozens of slices to choose how long "three" should be. But once the dial is turned, nothing that happens to this slice can change what the toaster does.

The person at the grill works in closed loop: act, measure what happened, use the measurement to decide the next action, and go round again until the job is done. The measurement has a name. Feedback is a measurement of what a machine's actions have actually done, fed back into the decision about what to do next. The toast's color is feedback. So is the reading on a scale while you pour flour onto it.

The words "open" and "closed" come from drawing it. Draw a box for the brain, an arrow from it to the wheels, and an arrow from the wheels into the world. In open loop the arrows stop there. In closed loop a sensor draws one more arrow, from the world back into the brain, and the path becomes a loop. It is the sense-think-act loop from the first module, and the point of this module is what that last arrow buys.

A closed loop needs one more word. The error is the gap between where the machine wants to be and where its sensors say it is: how far the toast is from golden, how many grams short of the recipe the scale reads. In control, error means only that gap. Nobody has made a mistake. A closed-loop machine is always doing the same thing underneath: measuring its error and acting to shrink it.

Two rovers

The box below holds two copies of the rover from the earlier modules, starting side by side in two identical rooms, facing a beacon about a meter ahead.

The left rover works in open loop. Its whole brain is one plan: both wheels forward at cruising speed for three seconds, then stop. Someone worked that plan out on this floor. At this speed the rover covers about 85 centimeters in three seconds, which leaves it just short of the beacon. It does not look at the beacon, the distance sensors on its nose or anything else. The status line under it says how far it ends up from the beacon, but that number is yours, not the rover's.

The right rover works in closed loop. Its brain is the one from the first module, with the obstacle rules left idle because the room is empty. Many times a second it reads which way the beacon lies compared with its nose. That angle is its error: zero means the beacon is dead ahead. It speeds up one wheel and slows the other to turn toward the beacon, harder the further off it is, and it stops when the beacon is 20 centimeters away. It has no plan for how far or how long to drive. It keeps shrinking the error until there is nothing left to shrink.

Driving for three seconds

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

Watching the beacon

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.

When the world behaves the way it did when the plan was made, open loop is hard to beat. It needs no sensor, so it costs less and has one less part to fail. It does exactly the same thing every time, which makes it easy to predict. And it never waits for a measurement before acting. Washing machines, microwaves, traffic lights on a timer and most hobby 3D printers all work this way. A printer's motors move in small fixed steps, one for each electrical pulse they are sent; the printer counts the pulses it sent and assumes the print head went where they say. Nothing measures where it actually went, which is why a bump can shift every layer after it.

A disturbance

A disturbance is anything that pushes a machine away from what its commands would have done on their own: a slippery floor, a gust of wind, a load heavier than expected. The plan was made without it, so an open-loop machine carries on as if it were not there.

In the module on odometry you put oil under the rover's left wheel and watched its dead reckoning come apart from the truth. Each side of the box has that button too. With the oil on, the left wheel still turns as fast as it is told, but as the rover sets off it slides on the oil instead of gripping, so the left side of the rover covers less floor than the right. One side covering more floor than the other is what turns a rover, as in the module on wheels, so it swings toward the oily side. Once the rover is rolling at a steady speed, the wheels need hardly any grip to keep it rolling; grip is for speeding up, slowing down and turning. So the oily wheel rolls along with the other one, and the rover goes straight again, pointing wherever the swing left it.

The left rover did nothing wrong. It carried out its plan perfectly. The oil turned the rover in the first half second. After that, driving straight was driving straight in the wrong direction, and every centimeter took it further from the beacon's line. That is how open-loop mistakes usually behave. A small error early on grows the longer the plan runs, because nothing ever measures it.

Could the left rover have checked its wheels? Both of its wheels turned exactly the same amount, about 17 radians each. The odometry from the earlier module would add those up and report about 85 centimeters straight ahead. That sum is honest about what the wheels did and wrong about where the rover went, because the oil is between the wheel and the floor, where the wheel sensors cannot see it. Measuring your own motors is not the same as measuring the world. Feedback that can catch a slippery floor has to come from outside the wheels, like the beacon's direction.

The right rover never knew about the oil either. Nobody told its brain, and its brain has no rule about slippery floors. It did not need one. The oil turned its nose, which moved the beacon off to one side, which was an error, and shrinking errors is all it does. A closed loop corrects for disturbances nobody predicted. That is why it is worth the cost of a sensor.

When the loop is cut

A closed loop is only as good as its measurement. The right side has one extra button, Sensing, which cuts the arrow from the world back to the brain.

Two costs of closed loop are visible in the box. The first is that it only corrects an error once the error is there. Both rovers were turned by the oil. The closed loop could not prevent that; it could only undo it, and it arrived late because of it. The second is that it depends on its sensor. With sensing off it stopped correcting anything. A noisy sensor, like the jittery distance sensors in the module on noise, would feed its noise straight into the steering.

Almost everything is both

Real machines mix the two. A robot arm told to move its hand works out in advance roughly how hard to push each joint, which is open loop, and then corrects using the sensors that measure each joint's angle, which is closed loop. The servos in this course's robot arms, the motors that are given an angle to go to, have each been a small closed loop: a servo measures its own angle and pushes toward the target, harder the further away it is. That is why the arm in the module on gravity sagged a little under a weight. The servo only pushes when there is a gap, so it settles where the gap is just big enough to earn a push that holds the weight up. The sag was an error the servo was pushing against the whole time.

The next modules open that servo up and look at the rule inside: how hard to push for a given error, and what happens when you push too hard, too late, or not quite enough.

What the simulation leaves out

The right rover is handed the beacon's direction exactly, many times a second. A real robot would have to work it out from a camera, a radio or a light sensor, with noise and a little delay. The oil is a single slippery setting under one wheel, the same from the first moment, where a real spill is a patch the robot drives onto and off. And the left rover's three seconds were chosen for this exact floor and this exact starting spot. Move the beacon, or start the rover somewhere else, and the plan would have to be worked out again. That is the deepest problem with open loop: every plan is a guess about the world, made before the world has been looked at.

Watch

Disturbance Input to Open and Closed-Loop System — Ryan Krauss (2:17 of it, starting at 0:00)

Why this video
A real robot on a real board, with a black line painted down the middle as its road, running the same test as the two rovers on this page, one robot driven twice. The board is tilted, so gravity pulls the robot sideways the whole way: a disturbance nobody put in the plan, just like the oil under the rover's wheel. Driven open loop, with the same power to both motors, it has no way of feeling the pull and drifts off the road. Driven closed loop, a sensor on its nose watches the line, and the robot pushes one side harder than the other to stay on it. That line is feedback from the world, not from the robot's own wheels, which is the kind of feedback that can catch a disturbance.
What to watch for
At 0:47 he explains the setup: one edge of the board is propped up on blocks of wood, so the road leans. At 1:23 the open-loop run starts, with no talking: both motors get the same power, so watch the robot slide off toward the low side of the board. At 1:30 comes the closed-loop run, the same robot on the same leaning board, now with a line sensor on its front (1:34). From 1:57 he says what it does with that measurement: more power to the lower wheel, less to the upper one. Watch it keep turning back toward the line instead of sliding off it. When he says "voltage," he means how hard each motor is driven.

Words introduced

open loop
Doing something by following a plan made in advance, without checking along the way whether it is working.
closed loop
Doing something by acting, measuring what happened, and using that measurement to decide the next action, over and over until the job is done.
feedback
A measurement of what a machine's actions have actually done, fed back into the decision about what to do next.
error
The gap between where a machine wants to be and where its sensors say it is. In control, "error" means only that gap, not a mistake.
disturbance
Anything that pushes a machine away from what its commands would have done on their own, such as a slippery floor, a gust of wind, or a heavier load than expected.

Where next

Suggested next: 22. Proportional 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.