Interactive course · about 4 hours

Control Systems

Setting a heater to a fixed power is not control. Control is what you need the moment the room gets colder, a window opens, or somebody asks for a different temperature. This course builds a controller out of nothing. First a switch that is only ever on or off. Then a push that grows with how far off you are, then a memory, then a sense of speed. You will tune one yourself against a score worked out from your own runs. Then you will take a good tuning apart using nothing but delay. A weight on a rail then makes momentum visible. The second half connects those experiments to the mathematics used by control engineers: differential equations, Laplace and Fourier transforms, poles, Bode plots, state-space models and distributed physics. You can take the practical path first and return to the mathematical path when you are ready.

How this works

Every line, pill and bar you will see is worked out from a simulation that reruns when you move a control. One tank of water sits underneath the whole course. Heat goes in at whatever the controller asks for. Heat leaks out to the room faster the hotter the water gets. The thermometer reports late, because a real probe has to warm up before it can tell you anything. That last detail is not a blemish on the model. It is the reason the subject exists.

What you need to know first

Arithmetic, fractions and percentages, and the idea that a letter can stand for a number. Nothing else is needed for Steps 1 to 12. The advanced path introduces its calculus and complex-number notation from pictures and arithmetic. If you want a separate foundation first, use Mathematics for Computer Science and Linear Algebra. Control is normally taught by starting with calculus; this course starts with the machine instead. Where the usual course writes an integral, this one keeps a running total and adds to it each time round the loop. Where it writes a derivative, this one subtracts the previous reading from the current one and divides by the time between them. Those are the same two ideas, done with arithmetic.

The steps

Step 1

Set a heater by hand, and find out why one setting is never right

A tank of water with a heater in it, and a number you want the water to reach. That is the whole problem. Everything later in this course is the same problem with more moving parts. The number you want is the target, and here it is 60 degrees. Engineers usually call it the setpoint, which is the same thing in an older word.

The tank and its heater are the plant: the piece of the world you are trying to boss about. The part that decides how much heat to ask for is the controller. Keeping those two words apart is worth the effort, because most arguments about a misbehaving machine turn out to be arguments about which of the two is at fault.

The simplest controller does not look at the water at all. You pick a power, and it holds that power for ever. A controller that never checks the thing it is controlling is running open loop. Open, because the information never comes back round to it. There is no feedback here: nothing measures the water and tells the controller what it found. Step 2 adds exactly that.

How do I read the chart in these labs?

Temperature up the side, time along the bottom, running left to right. The two numbers at the left-hand end are the top and bottom of the temperature scale. It is not always the same scale, because it is chosen to fit whatever the run did. So compare shapes between runs rather than heights.

The charts answer your pointer. Rest it anywhere on one and a crosshair appears, reading out every line at that moment. The small play button in a chart's top corner walks that crosshair across the whole run, so you can watch the numbers unfold in order. Some charts also carry a round handle you can take hold of and drag, and the slider it belongs to follows your hand.

The solid line is the water itself. The dashed line is what the thermometer says, and the two are not the same thing. A probe sits inside a lump of metal that has to warm up before it can report anything, so the reading trails the truth by a moment. That delay is called lag, and Step 9 is about how much trouble it causes. Three more things are drawn on there. The dashed horizontal line is the target. The pale strip either side of it is a band of close enough. The shaded area along the bottom is how hard the heater is working.

Why a tank of water? I came here for robots.

Because water is slow enough to watch. A drone runs this same loop about five hundred times a second and you cannot see any of it. Warm water does it over a minute, which means you can watch a mistake being made, spot why, and change one number.

Nothing in the course is water-specific. Step 11 swaps the tank for a weight on a rail and asks for a position instead of a temperature, using the same three sums. A motor holds a speed, a valve holds a pressure, a quadcopter holds an angle, a cruise control holds 70 miles an hour. All of them are this lesson with different units.

What does 40 per cent power even mean for a heater?

Most electric heating elements have one setting, which is fully on. Per cent power is usually built by switching quickly. On for four tenths of every short period and off for the other six tenths gives four tenths of the heat. The water is far too slow to notice the flicker. Other machines do it with a valve that can be part open, or a dimmer that passes part of the mains.

Either way, the number the controller hands over is a fraction of everything the machine has. That matters later: 100 per cent is a wall. When the sums ask for more, there is nothing there.

Lab 1 · A heater that cannot notice anything
Try this firstDrag heater power up and down. The line climbs to a different resting height for each setting, and the pill that says ends at follows it. Once you have a power you are happy with, leave it alone and drag room temperature instead.
Notice that the resting height is a balance and not a limit. Heat goes in at whatever the power setting asks for, and heat leaks out to the room faster the hotter the water gets. The line stops climbing when those two are equal. The room slider moves one side of that balance, so the answer moves, and nothing in this lab notices or minds.

Anything that shifts the answer without being asked is a disturbance: a window opening, a cold night, a cold potato dropped in the tank. The room slider is a disturbance you drive by hand. The gap between what you wanted and what you have got has a name too. The error is the target minus the measurement, so a positive error means too cold and a negative one means too hot.

Lab 2 · Hunting for the right power by hand
Try this firstPick a power, press Run this setting, and read the row that appears in the table. It records what you tried, where the water settled, and how far off that was. Try a few more, hunting for the smallest off by. Then press Now make the room colder, which reruns your last setting in a colder room.
Notice that ruining your answer took no mistake at all. The setting you found was not wrong and nothing broke. It was only ever the right answer for one room. That is the flaw in open loop, and hunting harder cannot fix it. The only fix is to let the controller look at the water, which is Step 2.
A hotel finds that 62 per cent power holds its water at 60 degrees, and writes that on a label beside the switch. For a fortnight it is perfect. Then it is too cool every morning and right every afternoon. What is the most likely explanation?
The building changed, not the machine. A fixed power setting answers one question: how much heat balances the heat leaking away right now. Mornings leak faster, so the balance lands lower. The heater is fine, the label is fine, and together they are useless, because neither one can notice anything. A drifting thermometer would be a real fault, but it would not politely wait until the afternoon to come right.
Step 2

Switch a heater on and off, and choose how much it swings

Now let the controller look. You already know how this feels, because you do it at the shower tap: feel the water, nudge the tap, feel again, nudge again, until it is right. That loop of feel and nudge is the whole idea of this course. Here the machine does it. A thermometer in the water reports a number, the controller compares that number with the target, and it decides again several times a second. One of those decisions is a tick: read the thermometer, work out what to ask for, ask for it. Everything the controller does from here on happens once per tick, and in the tank labs a tick lands every tenth of a second. Sending a decision out and getting a measurement back is feedback and a loop with feedback in it is a closed loop. The path from deciding to measuring and back to deciding joins up, and joined up is what closed means.

The cheapest closed-loop controller has two settings. Too cold: heater fully on. Too hot: heater off. Nothing in between and nothing remembered. Your kettle works like this, your fridge works like this, and so does the heating in most houses.

It cannot hold still, because it has no setting that means stay where you are. It crosses the target, keeps heating for a moment because the sensor has not caught up, drifts back down past the target, and starts again. To stop the switch clicking constantly, a real thermostat leaves a dead band around the target: a strip of temperature inside which the controller changes nothing at all.

Is this why my fridge hums in bursts instead of humming steadily?

Yes, and now you can predict the pattern. The fridge cools until the sensor says it is cold enough, then stops. It sits there warming slowly through the walls and the door seal. It starts again once it has warmed past the far edge of the dead band. The hum is one visit round that loop.

You can hear the trade being made. A freezer full of food is happy to roam a degree or two, so the dead band is wide and the compressor runs a few times an hour. A fish tank heater has a narrow band and clicks far more often, because the fish care more than the peas do.

Is a dead band just being sloppy on purpose?

It is being sloppy on purpose, and it is the right thing to do. Without it, the tiniest wobble in the reading around the target flips the heater, so the switch chatters, and chatter is the one thing that reliably breaks the hardware.

The word for the same trick elsewhere is hysteresis: the point at which a thing turns on is deliberately different from the point at which it turns off. A light switch has it mechanically, which is why it snaps rather than hovering.

What is actually wearing out when a switch clicks?

In a mechanical relay, two metal contacts slam together and pull apart. Each parting draws a tiny spark that takes a little metal with it, so contacts are rated for a number of operations, often somewhere around a hundred thousand. Divide that by the switching you can hear and you can work out how long the part will last.

A compressor is worse. Starting a motor draws several times its running current, and the motor is hottest during that start. Repeating those starts quickly is called short cycling. It wears a fridge out faster than simply running it. This is why real controllers often add a minimum on-time and a minimum off-time on top of the dead band. They refuse to switch again for a few minutes, whatever the temperature says.

Two numbers under the chart are worth naming now. One is the size of the swing, top to bottom, once it has got going. The other is the settling time: how long the water takes to get inside a narrow band around the target and stay inside it. It is measured from the last time the line left that band, not the first time it arrived. When did it first get close is a much easier question, and it flatters a controller that is still wobbling.

Lab 3 · On, off, and the size of the swing
Try this firstStart with the dead band at 0.0 and read the pill that counts how many times the heater switched. Then drag dead band, degrees up a little at a time. Watch that count and the height of the up-and-down in the line move in opposite directions.
Notice that neither end of the slider is the right answer. A narrow band holds the temperature closer and works the switch harder. A wide band leaves the switch alone and lets the temperature roam. No setting gives you both, so the choice has to be made on purpose. It is decided by what is in the tank rather than by what looks tidy on the chart.
A thermostat clicks often enough that the owner can hear it from the next room, so an engineer widens the dead band and the clicking stops. What else changed?
The room now swings wider. The dead band is the width of the strip where the controller deliberately does nothing, so widening it is precisely the instruction to let the temperature wander further before acting. That is a real fix for a real complaint and it is also a trade: quieter switch, sloppier room. The third answer has it backwards. How fast the room arrives in the first place is set by how much heat the heater can push, and the dead band does not touch that.
Step 3

Push harder when you are further away

On and off throws away nearly everything the controller knows. It has an error, a number with a size, and it answers with one of two words. A better controller uses the size. Far off, push hard; nearly there, push gently. In one line: the power asked for is the error multiplied by a fixed number. Two things are proportional when doubling one doubles the other. That is exactly what this does, so it is called proportional control and its term is the P term.

That fixed number is the gain, and this one is written Kp. Picture it at the shower tap first: it is how big your nudge is for each degree of complaint. A timid hand moves the tap a sliver per degree, a bold hand a quarter turn. Gain is worth saying slowly, because it is the word engineers use most often and explain least. A gain is a multiplier between something measured and something done about it. Here it answers one question: for each degree we are short, how much heater power should I ask for. A Kp of 2 asks for two per cent of full power per degree of error.

Something follows from that immediately. When the error is large, the multiplication comes out above 100 per cent, and a heater has no more than everything. The extra is thrown away. Asking a machine for more than it can deliver is called saturation. The word is worth having now, because Step 8 is a fault that only happens while a machine is saturated.

What are the units of a gain?

Per cent of power per degree of error, in this lab. That is worth writing down for any gain you meet, because it tells you what the number means. It also stops you carrying a value from one machine to another where it is nonsense.

A motor controller's gain might be volts per millimetre. A drone's might be motor units per degree of tilt. The same tuning number that is calm on one machine can be violent on the next, and the units are the first hint of why.

Is that all the word proportional claims?

That is all of it. Double the error and the controller asks for double the power, and no more is promised: nothing about arriving quickly, nothing about arriving accurately.

It is worth checking what fails the test. On and off, from Step 2, is not proportional to anything: at one degree off and at thirty degrees off it does exactly the same thing. That is the whole of what Step 2 was throwing away.

Is a higher gain always faster?

Up to a point, and then it stops being about speed. A higher gain asks for more power at the same distance from the target, so the early part of the run gets steeper. But past a certain gain the run is not slow, it is unstable. The controller reacts hard to a reading that is behind the truth, so the correction lands after the moment it was needed. It then feeds the swing instead of taking it out.

That boundary is not a property of the gain on its own. It depends on how quickly the plant answers and how late the measurement is, which is why Step 9 can wreck a tuning without touching a gain.

The other thing that follows is stranger, and it is the point of this step: a proportional controller settles short of the target and stays there. At exactly 60 degrees the error is zero, and zero times any gain is zero. So a controller that only multiplies the error would be asking for no heat at all, while the water cools. It has to sit below the target to justify any heat. That permanent gap is steady-state error: the error left over once everything has stopped moving. Raising the gain shrinks it and can never close it.

One more word for the pills under the chart, and you have felt it in the shower. Nudge the tap too far and the water lands too hot, so your hand swings straight back. If the line goes past the target before coming back, the amount by which it went past is the overshoot, quoted as a percentage of the target.

Lab 4 · Power in proportion to the error
Try this firstFind where the line flattens out, then read the pill that says off target by. Now drag gain (Kp) upwards one step at a time, watching that pill after each step. See how small you can make the gap, and what starts happening to the shape of the approach while you do it.
Notice that the two complaints trade against each other. A small gain is calm and leaves a wide gap. A large gain closes most of the gap and starts to overshoot and wobble, because the controller is reacting hard to a reading that trails the water. Both ends of the slider are wrong. That shape turns up everywhere from here on: gain buys speed and sells calm.
A proportional controller is holding water three degrees below its target. The engineer doubles Kp. What happens to that gap?
Smaller, never gone. The gap is whatever error is big enough, once multiplied by the gain, to ask for the power that exactly replaces the heat leaking away. Double the gain and half the error does that job, so the gap halves. Halving a number repeatedly never reaches zero, and meanwhile the loop is reacting harder to a late reading, so the arrival gets less calm. Closing the gap properly needs a term that can remember, which is Step 4.
Step 4

Close the last gap with a running total

The gap in Step 3 is there because the controller has no memory. Every tick it looks at one number, the error right now, multiplies it, and forgets. It cannot tell the difference between being a degree short for a moment and being a degree short all afternoon.

So give it a memory in the cheapest possible way. Keep one number, start it at zero, and on every tick add the current error to it. That is a running total. While the water sits below the target, every tick adds a little more, so the total climbs steadily however small the error is. Multiply that total by a gain of its own, called Ki, and add the result to what the proportional part asked for.

The running total of the error is what engineers call the integral, and Ki is the integral gain. No calculus is involved and none is needed: it is one addition per tick, exactly as the lab does it. The word only means the total of something that keeps arriving.

Is that really what an integral is? I have heard it is harder than that.

That really is what it is. An integral is the total of a quantity that keeps arriving, added up over time. If you are two degrees short for ten seconds, the total gains twenty degree-seconds. A degree-second is a unit like a kilowatt-hour: an amount multiplied by how long it lasted.

The version in a maths class asks what the total would be if you added it up in infinitely small slices, and that question needs machinery. A controller has no need of it. It has a clock ticking every tenth of a second, so it adds a slice every tenth of a second. That is both easier and what actually runs in the machine.

Why does adding up the error close the gap?

Because of what the total does when the error is small. The proportional term is happy at a small error: small error, small power, and if that power happens to balance the leak, it will sit there for ever. The total is never happy. As long as any error remains, the total keeps growing, so the power keeps rising.

The only place the total stops changing is at zero error. Everywhere else it is still moving, and moving in the direction that reduces the error. So the resting place of a controller with an integral term is the target itself, which is what you wanted all along.

What happens to the total if the water goes too hot?

The error turns negative, so the additions turn into subtractions and the total shrinks. It can go through zero and out the other side, which is how an integral term learns to hold a target that needs cooling rather than heating.

That shrinking is slow, though. The total was built up over the whole climb and it comes down at whatever rate the current error allows. A stored number that takes an age to unwind is the fault in Step 8, and it is the price of having a memory at all.

There is a bill, and the lab presents it. The total does not stop growing when the water arrives. It stops growing when the error reaches zero, and by then it is large and a large total keeps demanding heat for a tank that has already got there. So the line goes past. Overshoot is what accuracy costs.

Lab 5 · The total that closes the gap
Try this firstThe integral starts at 0.00, so this is Step 3 again: read the off target by pill before you touch anything. Now nudge integral (Ki) up in small steps, checking that pill after every nudge. Then push Ki well past the setting where the gap stopped mattering, and watch the overshoot pill instead.
Notice which pill improves and which one gets worse. Accuracy and calm are being traded against each other again, and against settling time in the middle. A small Ki gets there eventually, while a larger one gets there sooner and goes past. The integral is the only part of the controller with a memory, and a memory is the only thing that can fix an error which never changes. Any controller that has to be accurate has one, and every one of them can be pushed until it overshoots.
Two identical tanks with the same Kp. Tank A has Ki at zero, tank B has a small Ki. Both are started from cold at the same moment. Which statement is right?
The integral buys accuracy, not speed. At the start of the run the total is near zero, because it has had almost nothing added to it yet. So B behaves almost exactly like A for the first part of the climb. What the total does is refuse to let a leftover gap stand, so B is the one that ends on the target. It may well arrive later than A did, and go past first. Fewer moving parts is not the same as more accurate: A is simpler and permanently wrong.
Step 5

React to how fast the error is changing

Both terms so far look at where things are. Neither can tell that the water is arriving quickly. A controller that could would know to ease off early, the way you lift off the accelerator before the junction rather than at it.

Measuring how fast something is changing needs two readings and a clock. Take the error now, subtract the error from the previous tick, and divide by the time between the two. That is how much the error changed, per second. It is a rate, and you use rates already: 50 miles in 2 hours is 25 miles per hour, by exactly this division.

That rate of change is called the derivative, and its gain is Kd. There is no calculus in it either: one subtraction and one division per tick. While the water climbs towards the target the error is shrinking, so the rate is negative, so this term takes power off before arrival. That is where an overshoot goes.

So a derivative is a difference divided by a time?

For a controller, yes, and that is all any of them compute. The reading changed by this much, in this much time, so it is moving at that speed. Speed is the rate a position changes at. A derivative is the same question asked about any number at all.

The maths-class version asks what the answer becomes as the gap between the two readings shrinks towards nothing. A controller cannot ask that, because it only has the readings its clock gave it. Every derivative in every real machine is a subtraction and a division, which is why the tick rate is part of the design and not a detail.

Why would a sensor report anything other than the truth?

Because a sensor is a physical object in an electrically messy world. A probe's wires pick up stray voltage from the mains and from the motor next door. A bubble drifts past the tip. The circuit that turns a voltage into a number has a last digit that has to make its mind up, and sometimes it changes its mind. Nothing is broken. This is what measurement is like.

The result is that each reading is the truth plus a little rubbish, and the rubbish is different every time. Averaging several readings helps, at the cost of making them later, which by Step 9 you will recognise as a real cost rather than a free win.

Why do so many real controllers leave Kd at zero?

Because the term that reacts to speed also reacts to nonsense, and nonsense is fast. Practitioners often reach for a controller with only the first two terms, get it good enough, and stop, rather than take on a term that needs filtering to be safe.

When Kd is used, it is usually softened. The reading is smoothed before the subtraction, or the derivative is taken of the measurement rather than of the error, so that changing the target does not cause a jolt. Those are standard tricks, and both exist because of what you are about to do to the heater in this lab.

No real reading is exactly the truth. Every one of them is the truth plus a little rubbish, different each time, and that rubbish is called noise. The slider in the lab adds a controlled amount of it to what the controller sees, without touching the water at all. The tank is never actually noisy in this lab. Only the eyes are. Since a derivative term reacts to how fast its input changes, and noise changes fast, this is the one term that noise can turn against you. So the lab also reports how far the heater's power moved in total across the run. That is the number that wears out the actuator: whichever part actually does the pushing, a heater here, a valve or a motor elsewhere.

Lab 6 · Easing off before you arrive
Try this firstWith derivative (Kd) at 0.00, note the overshoot pill and the heater movement pill. Raise Kd and watch the peak of the line come down. Then leave Kd where it is and drag sensor noise up from 0.0 degrees, watching the heater movement pill after each drag.
Notice that the damage from noise shows up in the heater and not in the temperature. The line can still look respectable while the power underneath it is being yanked up and down several times a second. Somebody watching only the temperature would sign this off. An engineer who has replaced a valve shaken to pieces reads the movement number first.
Kd is often described as the term that predicts the future. What does it actually have to work with?
Two readings and a clock. The prediction amounts to assuming that whatever is happening now will carry on happening for a moment longer. That is often good enough, and it is exactly why noise ruins it. Two noisy readings in a row imply a wild speed that never existed, and the term believes them. The whole history is the integral's job. A model of the plant, used to act ahead of the error, is Step 10, and it is a different idea with a different name.
Step 6

Read the three terms separately at any moment of a run

You now have all three, and from here they go by their initials. P, for proportional, looks at how far off it is now. I, for integral, looks at every degree of error so far, added up. D, for derivative, looks at how fast the error is changing. The controller works out all three, adds them, and asks the heater for the total. That is the whole of what people call a PID controller: those three letters and nothing else.

Three numbers added together is easy to say and hard to feel, because the three take turns. Early in a run the error is large and P is nearly all of the answer. Near the end the error is small, P has almost nothing to say, and the heater is being held on by the total that I built up. Whenever the temperature is moving fast, D is the loud one.

So the lab draws four bars: the three terms and the total they add to, at whatever moment of the run you pick. The total is also where saturation shows up. If the three add to more than 100 per cent the bar says so, and reports what had to be thrown away.

Which term is supposed to be the biggest?

There is no right answer, and expecting one is a common way to get stuck. Which term dominates is a fact about the moment, not about the tuning: large error favours P, a long-standing error favours I, fast movement favours D.

What is worth checking is whether a term is doing nothing at all across an entire run. A D term that never grows is not helping. An I term that grows without limit is Step 8. A P term that is tiny throughout usually means the gain is too small to be worth having.

How can a term be negative when the heater cannot cool?

The three terms are arithmetic and arithmetic has no idea what a heater is. If the water is above the target, the error is negative, so P is negative. If the water is climbing, D is negative. Those negative numbers mean ask for less, and they are subtracted from what the other terms wanted.

Only after the three are added does the answer meet the machine. A total below zero becomes zero power, because this plant has no cooler, and the bar labels that as clipped. A machine that can push both ways, like the motor in Step 11, uses the negative half of the range instead of throwing it away.

Is PID the only way to do this?

No, and it is not always the best. It is the one worth learning first for three reasons. It needs no model of the machine. It is three numbers a person can tune by hand. It is also what sits inside most of the working equipment in the world.

Above it sit controllers that carry a model of the plant and use it to plan ahead, which is what model predictive control means. Others adjust their own gains while running. All of them still have to answer the questions this course is about. How late is my information. What happens when the machine saturates. What does the disturbance do that nobody told me about.

Lab 7 · The three terms, moment by moment
Try this firstDrag moment in the run slowly from the left-hand end. A dashed marker labelled here travels along the chart while the four bars underneath change. Stop first where the line is climbing steeply, then again where it has levelled off at the end of the run, and compare which bar is longest in each place.
Notice the handover. Early on P is nearly all of it and I is barely there. Later P has shrunk to almost nothing while I is holding the heater on by itself. Nothing switched over and no rule chose between them. The same three sums ran on every tick from beginning to end, and the shape of the run decided which of them mattered when.
Water is sitting on its target and staying there, while the heater runs at a steady 40 per cent. Which term is asking for that 40 per cent?
The stored total. On the target the error is zero, so P is zero, and the temperature is not moving, so D is zero. Meanwhile the heat leaking out to the room has not stopped, so something has to keep asking for heat, and the only term with a memory is I. Hold on to this: at rest, a PID controller's output is almost entirely its integral. It also explains Step 8, where that stored number grows past anything sensible.
Step 7

Tune a controller yourself, against a measured score

Tuning means choosing Kp, Ki and Kd for one particular machine. No formula gets it right everywhere, because the right answer depends on what the machine is for. A drinks machine may overshoot and nobody dies. A chemical reactor may not.

What tuning needs is a way to keep score, so the lab works one out from the runs themselves. Four things go into it. How long the water took to settle, how far it went past, how much error is left at the end, and how hard the heater was worked. Lower is better. One number gives you a direction to walk in, which is worth more than any amount of opinion about the shape of a line.

It also marks you on two runs rather than one. The first is a start from cold. The second is the same tuning with a draught opening half way through, which is a disturbance nobody warned the controller about. A tuning that handles the first and fails the second is the classic way to be pleased with yourself and wrong.

Is there a recipe, or is it always fiddling?

There are recipes, and they are starting points rather than answers. The best known starts with Ki and Kd turned off. Raise Kp until the loop swings past the target repeatedly without settling, like the swing in Step 2. Note both that gain and how long one swing takes. Those two measurements feed a small table that suggests all three gains. It is named after Ziegler and Nichols, who published it in the 1940s.

Every method of this kind assumes the machine will let you push it into oscillation, which rules out plenty of real plants. It also aims at a compromise nobody asked for. Practitioners use one to get into the right area and then do exactly what this lab does: change one gain, run it, look at the numbers.

Why is a draught a harder test than starting from cold?

Starting from cold is a big, honest, one-off error that every term can see coming a mile off. A draught arrives when the controller has settled and everything looks finished. The error it makes is small, and it does not go away, which is the case that finds out whether your Ki is really doing its job.

Real complaints are nearly always of the second kind. Nobody rings up about the first two minutes after switch-on. They ring up because the room goes cold when the wind is in the east.

What is heater movement doing in a score about temperature?

It is there because a score made only of temperature can be won by a tuning that destroys the hardware. Add up how far the power moved, tick by tick, across the whole run. That is a measure of how hard the actuator was worked: a valve stem sliding, a motor reversing, a relay clicking.

Real scoring functions in industry include terms like this, alongside energy used and how much the output moved. Deciding what goes into the score is the real design decision, and it is made long before anybody touches a gain.

Lab 8 · Tune it, and be marked on two runs
Try this firstMove Kp on its own, up and down, watching nothing but the score. Then leave it at its best and do the same with Ki, then with Kd. The chart shows the second run, with the moment the draught starts marked on it. The score line remembers your best so far, so you can wander without losing it.
Notice that one slider at a time is method, not tidiness. The three terms interact, so moving two at once leaves you unable to say which one helped. Notice too what the score refuses to reward. A tuning that arrives quickly by thrashing the heater scores badly, because the heater's movement is part of the score. The temperature line can look perfect while that happens.
A tuning gets the best score anyone in the room has managed. What is the honest thing to say about it?
A tuning is only as good as the tests it was scored on. A score is a measurement of two runs, not a verdict on a controller. Change the target, make the disturbance bigger, start from hot instead of cold, and the ranking can change. Machines also drift: a probe gets coated, a heater ages, a pump wears, and a tuning that was excellent becomes ordinary without anybody touching it. This is why commissioning tests a real machine and signs it off as fit for service. It uses a handful of deliberately awkward cases rather than one tidy run.
Step 8

Spot a stored total that grew too large, and limit it

This is a fault with a name, and it is the most common one in equipment that has an integral term in it. Ask the controller for a target the machine cannot reach. The heater goes flat out and stays there, saturated and the error never goes away.

Meanwhile the running total is doing exactly what it was told: adding the error on every tick. The error is large and it stays large, so the total grows and grows for as long as the impossible target is left in place. Nothing here is a mistake in the code. This is the code working.

The trouble arrives when the target comes back down to something reachable. The water is now too hot, so the error goes negative and the total starts shrinking. But it has to shrink a very long way before the controller stops demanding heat. Until it does, the heater stays on into a tank that has already gone past. The name for that is integral windup.

Where does this bite in real life?

Anywhere a machine can be asked for something it cannot do. An oven with the door propped open, told to reach 200 degrees. A car's cruise control climbing a hill too steep for the engine it has. A tank being filled by a pump that cannot keep up with the leak.

The famous cases are in aircraft. An autopilot integrating a demand it cannot meet, then meeting it suddenly and reacting to a stored number from a minute ago, has been a factor in real incidents. It is one of the reasons every serious control library has a limit on the stored total. It is also why the word windup is in the manual rather than in a lecture.

Why not just stop adding while the machine is flat out?

That is the other standard fix, and it is often the better one. If the output is already saturated and the error would push it further into the wall, stop adding to the total for that tick, because the addition cannot buy anything. It is usually called conditional integration.

The lab uses the blunter version, a hard limit on the total, because it is easier to see: one number with a ceiling. Both fixes attack the same thing, which is a memory that keeps growing while the growth can no longer change what the machine does.

How big should the limit be?

Big enough that the integral can still ask for full power on its own, and no bigger. That way an honest run, one where the target is reachable, never notices the limit at all: the total does what it always did. The limit only comes into play when the total has grown past anything it could usefully spend.

Written properly, the limit is worked out from the output range and Ki rather than picked by feel, which means it stays correct when somebody retunes Ki later. A limit chosen by feel and forgotten is how a fixed fault comes back three years on.

The fix in the lab is the blunt one: do not let the stored total past a limit. Capped, it can never grow so large that unwinding it takes an age, so the controller can turn round almost as soon as the target does. It is two lines of code.

Lab 9 · A total that grew while the heater was flat out
Try this firstThe lab opens on Unlimited stored total. Find the dashed line marked target drops to 45, look at what the temperature does after it, and read the pill for the highest temperature after the change. Now press Limit the stored total and read the same pill again.
Notice that no gain changed between the two runs. Same Kp, same Ki, same tank, same pair of targets. The only difference is a ceiling on one stored number. This fault looks like a badly tuned controller, and people spend days retuning it. The shape is worth recognising on sight: flat out for a while, then slow to respond when the demand goes the other way.
A tank overshoots badly, but only ever after being asked for a temperature it could not reach. An engineer halves Ki. What is the likely result?
You would be paying everywhere to fix one place. Halving Ki does halve how fast the total turns into demanded power, so the overshoot after an impossible target does shrink. It also makes every well-behaved run slower to close its gap, which is a real loss on the runs that were fine. A limit on the stored total costs nothing on those runs, because a run that never saturates never reaches the limit. The third answer is tempting and wrong: a smaller Ki does unwind more slowly, but it also built up less to unwind.
Step 9

Show that delay alone can wreck a good tuning

Everything difficult about control comes from one thing: the world answers late. The sensor reports where the water was a moment ago. The heater's warmth takes time to spread through the tank. By the time a controller can see the result of what it did, it has already done several more things.

The delay between the truth and the measurement is the lag. It has been in every lab so far, quietly, which is why none of the controllers on this page has been able to sit perfectly still. This step does one thing: it holds the tuning fixed and moves the lag.

Watch what that does. A controller steering by an old reading is correcting something that has already stopped being true. Its corrections land at the wrong moment, and they add to the swing instead of taking it out. With enough lag, any fixed tuning will oscillate. It swings past the target repeatedly and never settles. This time the switching rule did not ask it to.

Where does lag come from in a real machine?

From several places at once, and they add up. The sensor itself has to change temperature before it can report one. The wires and the converter take a little time. The software may average several readings before believing them. The controller only decides on its tick, so on average it sits on fresh news for half a tick before using it.

Then the plant has its own delay. Heat has to travel from the element to where the probe is. In a long pipe there is a true transport delay. What happens at one end cannot be seen at the other for some number of seconds, however good your sensor is. That kind is the worst kind, and nothing in the controller can shorten it.

Is lag the same thing as a slow tank?

No, and the difference is the point of the step. A slow tank is honest: it responds gradually and the controller can watch it respond gradually and act accordingly. Slow is not hard to control.

Lag is dishonest information. The tank may be responding right now while the measurement still shows what it was doing seconds ago, so the controller acts on a world that has moved on. Slow plus truthful is easy. Fast plus late is hard.

What do you do about lag you cannot remove?

First, lower the gains. If your news is old, hard reactions are guesses, so the honest response is to correct more gently and accept a slower loop. That is not defeat, it is arithmetic.

Beyond that there are two routes. Act on causes rather than errors, so that some of your response does not depend on the measurement at all, which is Step 10. Or carry a model of the plant, run it forward, and control the model's guess at where the plant is now rather than the stale reading. That second route is the beginning of the subject called state estimation, and its most famous tool is the Kalman filter.

Lab 10 · One tuning, more and more delay
Try this firstDrag sensor lag, seconds down to 0.0. The dashed sensor line lands on top of the solid water line and the run is calm. Now walk the lag up one notch at a time, touching nothing else, and read the overshoot pill and the settling pill after each notch.
Notice that nobody mistuned anything. The gains are fixed in this lab and you cannot reach them. The only number that changed is how late the news arrives, and that alone can take a calm controller to an oscillating one. It is why the same code, dropped onto a machine with a slower probe, behaves like a different animal. It is also why the first question about a wobbling loop is how quickly it can see.
A loop that was calm starts oscillating after its temperature probe is replaced with a heavier, slower one. Which first move is most likely to help?
Less, not more. How hard it is safe to react depends on how quickly you find out what your last reaction did. Slower news makes every correction more of a guess, so the correct response is to correct more gently. Raising Kp does the opposite and pushes the loop further into oscillation. Worth adding: the cheapest improvement in control is usually a faster measurement rather than a cleverer controller. So the real answer on the day is often to put the old probe back.
Step 10

Act before the error exists

Feedback has one limit that no amount of tuning gets past: it cannot act until there is an error to see. Something has to go wrong first, and be measured, before a feedback controller has anything to work with. Every dip in this course so far is the price of waiting for evidence.

Sometimes you know about a disturbance before the measurement does. If the window has a switch on it, the controller can be told that the window is open. It can then add the heat an open window is known to cost, at once, without waiting for the thermometer. Acting on a known cause instead of on a measured error is called feed forward.

It is not a replacement for feedback and it is not a better version of it. It is a considered guess, and it is only as good as what somebody knew. If an open window costs more today than it did when the number was measured, feed forward gets it wrong and never finds out. Feedback finds out about everything and is always late. Real machines use both.

How does the controller know what a window costs?

Somebody measured it once, and the number went into the machine. Open the window, wait for things to settle, write down how much extra power was needed to hold the target. That is the feed forward number. It is a fact about that building rather than about control theory.

Bigger systems store a table or a formula instead of one number: this much extra power per degree of outside cold, this much for that pump running. Filling in that table is unglamorous work and it is where most of the benefit lives.

Have I met feed forward already without knowing it?

Probably several times. A shower where you turn the hot tap first because you know the cold pipe is long. An oven preheated before the food goes in, since the recipe knows the food will cool it. A car with a map, easing the throttle on before the hill rather than after the speed drops.

The pattern is always the same. You know something about what is coming, so you act on the knowledge rather than waiting for the consequence. And in every case you keep an eye on the result anyway, because the knowledge might be out of date.

Can feed forward make things worse?

Easily. Too large a number and it overcorrects, so a window that used to cause a dip now causes a spike. The feedback part then has to clean up a mistake that was volunteered. Too early and it acts on a disturbance that has not started yet.

The worst case is a feed forward signal that is wrong in an unnoticed way, because it never gets checked. The feedback part will quietly compensate and everything looks acceptable, until the day the feedback part has nothing spare to compensate with. This is why the two are usually commissioned in order: feedback made good on its own first, then feed forward added and measured for what it actually improved.

Lab 11 · Told in advance, or waiting for the thermometer
Try this firstPress Feedback only and read the worst dip pill. The dashed line marked window opens is where the draught starts. Now press Tell it the window opened and read the same pill again. The three gains are identical in both runs.
Notice what is being compared. Both runs use the same controller with the same gains, and both put the dip right in the end. The only difference is when the correcting starts. Feedback corrects mistakes; feed forward avoids making them. Neither is optional in a machine that has to hold a value while the world interferes with it.
A greenhouse controller gains a feed forward term for the outside temperature, measured by a sensor on the roof. Should the feedback part be taken out now?
Keep the feedback. Feed forward handles what was listed, at the size it was measured. It cannot see a door left open, a heater losing power with age, a blocked vent, or the day the sun is on one wall only. Feedback is the part that copes with everything nobody listed, and that includes coping with the feed forward being wrong. The general shape is worth keeping: a model to act early, and a measurement to catch the model out.
Step 11

Hold a position, where the brake has to be the controller

Swap the tank for a weight sliding on a rail with a motor pushing it, and ask for a position instead of a temperature. Everything so far still applies: there is an error, there are gains, there are three terms. One thing is different, and it changes which term matters most.

Water has nowhere to go. Stop heating it and it sits there cooling gently. A weight that is moving keeps moving, because it has momentum: the tendency of a moving mass to carry on unless something stops it. A proportional term pulls hardest when the error is largest, so the weight is pulled hardest from far away, arrives at the target at speed, and sails straight past.

Nothing in P or I takes energy out of a moving mass. Pulling it back only sends it the other way, and it swings about the target instead of stopping on it. The term that leans against movement is the derivative one, because it responds to how fast the error is changing. On a moving thing, Kd is not a refinement for trimming overshoot. It is the brake.

What is momentum, more carefully?

Momentum is how much motion a thing has: its mass multiplied by its speed. A heavy trolley moving slowly and a light one moving quickly can be equally hard to stop. To change it, you have to push, and the longer you push the more it changes.

The reason this matters for control is that a moving mass carries energy that has to go somewhere before it can be still. Either something absorbs it, like friction or a controller pushing backwards, or it keeps sloshing between moving one way and moving the other. That sloshing is exactly what the lab shows with Kd at zero.

Where did the integral term go in this lab?

It has been left out so that the brake is the only thing to look at. Position loops do use one, for the same reason the tank did: friction, or gravity on a lifted arm, leaves a small steady error that only a memory can remove.

But an integral on a mass has to be handled carefully. The stored total keeps pushing after arrival, and a mass responds to a push by moving. So a careless Ki makes an arm creep past its target and hunt back and forth around it. Position loops usually run a fairly small Ki. They nearly always limit the stored total, for the reason you found in Step 8.

Which real machines are this exact problem?

Every joint of every robot arm. The read head of a hard disc, which has to move a fraction of a millimetre and stop dead, thousands of times a second. A camera gimbal on a drone. A telescope mount. A lift, where the passengers are part of the mass and the overshoot has to be zero.

They differ in what fights them. An arm has gravity pulling differently at every angle, so the same gains behave differently at each pose. A lift has a mass that changes every trip. A disc head is so light and so fast that the wobble of the arm holding it becomes part of the problem. All of them are the lab in front of you plus one honest complication.

Lab 12 · A weight, a rail, and the brake
Try this firstLeave Kd at 0.00 and look at what the line does at the target. It crosses, comes back, crosses again, and the pill reports that it is still moving at the end of the run. Now raise Kd a little at a time until that pill reports a settling time instead. Then push Kd much further and see what you paid for it.
Notice that too much brake is also a fault. With a large Kd the weight never overshoots and takes an age to arrive, because it is being braked the whole way there. The setting worth having is the one that arrives quickly and stops once. Notice as well how little else changed to get here: millimetres instead of degrees, a motor instead of a heater, and the same three sums as before.
A robot arm joint swings past its target and oscillates around it. A colleague says the gain is too high. What is the other reading of the same symptom?
It may have nothing to brake with. Lowering Kp does reduce the overshoot, by making the whole arm slow and feeble, which is why arms tuned that way feel lifeless. On a moving mass, swinging past the target is usually a missing brake rather than an excess of pull. Try it both ways in the lab. Lower Kp with Kd at zero and the crossing gets smaller and slower without going away. A high Kp with a decent Kd arrives quickly and stops. A weaker motor is the same mistake as a lower gain, paid for in hardware.
Step 12

Lay a ruler on a curve, and read its slope

The first half of this course asked you to feel a loop with your hands. The second half writes the same machine down in symbols. Between the two sits one small skill: reading how fast a curve is changing at one chosen moment. That number is the slope, and every equation in the advanced path is a sentence about slopes.

You already read slopes without naming them. A car's speedometer reads the slope of the distance. A kettle that is "heating fast" has a temperature curve with a steep slope. Steep means changing quickly, flat means holding still, and downhill means falling. The slope has units: for the tank it is degrees per second, exactly like miles per hour.

One more word makes the second half easier, and you have already met the idea. The state of a system is the shortest list of numbers you would need to restart it exactly. For the tank, one number does it: the water temperature. For the weight on the rail, you need two, position and speed, which is why two trolleys at the same spot can have different futures.

Is a slope at one moment even a real thing? The curve is curved.

Zoom in. Every smooth curve looks straight if you look at a short enough piece of it, the same way the Earth looks flat from your garden. The slope at a moment is the slope of that tiny straight piece. A ruler laid along it is called a tangent line, and the lab draws one for you.

The controller's version from Step 5 is the honest approximation: take two nearby readings, subtract, divide by the time between them. The shorter the gap, the closer that answer sits to the tangent's slope.

Why does the second half care about slopes so much?

Because physics rarely tells you where a thing will be. It tells you how fast the thing is changing right now, given where it is right now. Heat flow sets how fast temperature changes. Force sets how fast speed changes. Each law is a recipe for a slope.

An equation built out of a quantity and its slopes is called a differential equation, which is Step 13. The simulator behind every lab on this page has been solving one all along: work out the slope, take a small step along it, repeat.

Where does the slope of the warming curve come from?

From the balance you found in Step 1. Heat flows in at a rate set by the power. Heat leaks out at a rate set by how much hotter the water is than the room. The difference between the two is spare heat, and spare heat is what raises the temperature. Big difference, steep slope.

That is why the curve flattens as it climbs. The hotter the water gets, the faster it leaks, so the spare shrinks, so the slope shrinks. At the resting level the two rates are equal, the spare is zero, and the slope is zero. Not because heat stopped moving, but because the flows cancel.

And one word for what the brake did in Step 11. Anything that leans against motion and takes energy out of it is called damping. Think of catching a dropped ball: your hand gives as it catches, riding down with the ball to soak up its speed. A stiff hand lets it bounce away. Kd was a hand that gives. Step 14 turns damping into a number.

Lab 14 · A ruler on the warming curve
Try this firstDrag the marked point along the curve, or drag the moment slider, and read the slope pill. The short straight line through the point is the tangent, the ruler laid on the curve. Park the point early in the climb, then drag it out to the flat end, and watch the heat-out pill catch up with the heat-in pill.
Notice that the slope is the gap between two flows. Heat in is fixed by the power. Heat out grows with temperature. The slope pill always equals their difference divided by the tank's heat capacity, at every point you visit. That one sentence, written in symbols, is the whole of the next step.
The warming curve has gone completely flat at 68 degrees while the heater still runs. What does the zero slope tell you?
Zero slope means the flows balance. The heater is still pushing heat in, and the tank is still leaking heat to the room. At 68 degrees the two rates happen to be equal, so there is no spare heat left to raise the temperature. That is a balance, not an absence. The next step writes this balance as an equation and lets you take it one tick at a time.
Step 13

Turn a physical balance into a differential equation

The tank simulator has been using an equation since Step 1. We can now write it down. Start with one engineering rule: energy cannot vanish. During a short time, the water's stored thermal energy changes by heat from the heater minus heat leaking to the room. This is an energy balance.

Temperature is the state we track. Its rate of change is written dT/dt, read as “change in temperature divided by change in time.” Heater power is the input u. Room temperature is Troom. The model is C dT/dt = K u - H(T - Troom). C says how much energy the tank stores per degree, K converts the command into heat, and H says how readily heat escapes.

This is an ordinary differential equation, or ODE. Ordinary means that the state changes along one independent direction, time. The equation does not hand us the future temperature directly. It hands us the slope now. The simulator repeatedly uses that slope to take a small step forward.

How can I check whether an equation like this makes physical sense?

Check units before doing algebra. C has units of joules per degree. dT/dt has degrees per second, so their product is joules per second, which is watts. Both terms on the right must also be watts. If one side is metres and the other is seconds, the equation cannot describe the same quantity.

Then check directions. If the water is hotter than the room, T - Troom is positive and the minus sign makes leakage cool the tank. If the heater command rises, the positive K u term makes the slope rise. Those tests catch many sign mistakes before a simulation is run.

Is an ODE a fact about the tank or a model somebody chose?

It is a model built from a physical law plus assumptions. We assume every part of the water has one temperature, heat loss is proportional to the temperature difference, and the heater responds at once. A large tank with poor mixing violates the first assumption. Radiation and boiling violate the second. A valve or heater with its own delay violates the third.

Engineering does not require a model to contain everything. It requires the model to be accurate enough for the decision being made, and it requires the omitted effects to be named and tested.

Where is the time constant hiding?

With the heater fixed, the tank approaches its resting temperature at a speed set by C/H. That ratio is the time constant, usually written tau. After one tau, a first-order system has completed about 63 per cent of the journey to its new resting value. After about four tau it is within roughly 2 per cent.

A larger heat capacity C makes the tank slower. A larger heat-loss coefficient H makes it respond faster but also demands more heater power to hold the same temperature above the room.

Lab 15 · Balance the tank one tick at a time
Try this firstMove heater power while the starting temperature is below the target. Read the heat-in and heat-out arrows, then press Take one tick. Find a power where the reported slope is almost zero.
The resting temperature is where the two rates balance. At that point the derivative is zero, not because heat stopped moving, but because heat enters and leaves at the same rate. The equation, the arrows and the simulation are three views of that same balance.
A tank is hotter than the room and its heater is off. What sign must dT/dt have?
The slope is negative. Stored energy is not the same as changing energy. The tank contains energy, but while more leaves than enters its temperature falls. A zero derivative would mean the rates balance.
Step 14

Model motion that can store energy

A tank needs one state, temperature. A moving trolley needs at least two: position x and velocity v. Position tells us where it is. Velocity tells us where it is heading and how quickly. Two trolleys at the same position can have completely different futures if one is still and the other is moving fast.

Newton's second law says mass times acceleration equals the total force. For a mass attached to a spring and damper, m d²x/dt² + c dx/dt + kx = F. The spring term kx pulls back toward the centre. The damper term c dx/dt opposes motion. The input F pushes the mass. Because the highest derivative is the second one, acceleration, this is a second-order ODE.

Two numbers summarize much of its behaviour. Natural frequency says how quickly it would swing. Damping ratio says how strongly motion is removed. A ratio below 1 gives an oscillating response, 1 is critical damping, and above 1 returns without overshoot but more slowly.

Why does “order” count derivatives instead of parts?

The order tells us how much independent state is needed to predict the future. A first-order thermal model needs one starting value, temperature. A second-order mechanical model needs two, usually position and velocity. In general, an nth-order ODE can be rewritten as n coupled first-order equations.

This is why order matters to a controller. Each independent state may need to be measured or estimated, and each can carry an error that affects the future.

Are overshoot and oscillation always caused by too much gain?

No. Gain changes the forces, but the plant may already store and exchange energy. A spring stores energy when stretched. A mass stores kinetic energy while moving. Low damping lets energy move between those stores, so the system rings even with no controller.

Before retuning, ask whether the model has the right inertia, stiffness, friction and delay. A gain change can hide a bad model without explaining the machine.

What are underdamped, critically damped and overdamped?

Underdamped means the response crosses the final value and usually rings. Critically damped is the boundary that returns without crossing and is fastest among the non-oscillating cases. Overdamped means two slower decays dominate, so it returns without crossing but takes longer.

Critical damping is not automatically best. A camera mount may value no overshoot. A racing actuator may accept some overshoot for speed. The requirement decides.

Lab 16 · Change damping without changing the target
Try this firstSet damping ratio below 0.3 and press Disturb the mass. Then move it to 1.0 and repeat. Compare crossings, peak position and settling time. Change natural frequency only after you can describe the damping change.
Damping changes the shape; natural frequency changes the clock. Keeping those roles separate helps when a response is both too slow and too oscillatory. One number rarely fixes both.
Two masses are at x = 4 cm. One is still and the other moves right at 2 m/s. Can position alone predict their next positions?
Position alone is not enough. The moving mass carries momentum, so its future differs even though the two position readings match. A second-order model needs two initial conditions.
Step 15

Make a digital clock approximate a continuous world

The equations above describe time as continuous. A microcontroller sees only separate samples. At each tick it reads sensors, computes a command and waits for the next tick. To simulate an ODE, it can use the current slope: next state = current state + slope times dt. This is the forward Euler method.

A smaller dt follows curves more accurately, but it costs more computation and may expose more sensor noise. A larger dt is cheaper, but it adds delay and can make a perfectly stable physical model unstable in the simulation or controller. The sample time is therefore part of the design.

Sampling also creates aliasing. A fast oscillation can produce the same sample dots as a slower one. No later calculation can recover what was never measured. An analogue low-pass filter before the converter, called an anti-alias filter, removes frequencies the sampling rate cannot represent safely.

How fast must I sample?

The Nyquist rule says a sinusoid needs a sample rate greater than twice its frequency to avoid an exact alias. Control engineers usually sample much faster than that, often ten or more times the closed-loop bandwidth, because two points per cycle describe a wave badly and leave little phase room.

The correct rate also includes computation time, sensor filtering, actuator updates and timing jitter. A nominal 100 Hz loop is not a 100 Hz loop if some ticks arrive 30 ms late.

Is numerical instability a real unstable machine?

Not necessarily. Forward Euler can make a stable equation grow when dt is too large. That is a failure of the numerical method, not evidence that the real plant explodes. Shrinking dt or using a more stable integration method can separate the two.

The reverse warning also matters. A simulator can look stable because its solver smooths or clips a difficult effect. Always vary the timestep and compare against measurements.

What changes when the controller itself is converted to digital form?

Integrals become sums and derivatives become differences, as Steps 4 and 5 already used. Filters and transfer functions become recurrence equations that remember past inputs and outputs. Their coefficients depend on the chosen sample time.

Methods such as zero-order hold and the bilinear transform preserve different features of the continuous design. The important rule is to state the conversion and sample time. Copying coefficients between loop rates changes the controller.

Lab 17 · Watch a fast wave pretend to be slow
Try this firstSet the signal to 7 Hz and sampling to 10 samples per second. Compare the true curve with the sample dots and reconstructed dashed curve. Raise the sampling rate until the false slow wave disappears.
The dots are the only information a digital controller receives. Connecting them smoothly does not make them true. Filter before sampling and leave a stated timing margin.
A stable simulated plant begins to alternate and grow when dt is increased tenfold. What should be checked first?
Check the numerical method. The physical equation did not change. Forward Euler can turn a decaying mode into an alternating growing sequence when the step is too large.
Step 16

Turn derivatives into algebra with the Laplace transform

An ODE mixes a signal with its derivatives. That is awkward to rearrange. The Laplace transform describes a time signal by how strongly it contains exponential patterns. In that description, taking a derivative mostly becomes multiplication by a new variable s. An ODE can then be handled like algebra.

For a system that starts at rest, the tank equation C dT/dt + HT = Ku becomes (Cs + H)T(s) = KU(s). Dividing output by input gives T(s)/U(s) = K/(Cs + H). This ratio is the transfer function. It says how an input is changed into an output for this linear, time-invariant model.

The variable s can be complex: s = sigma + j omega. Sigma describes exponential growth or decay. Omega describes oscillation. One coordinate can therefore represent a pattern that both oscillates and changes size. You do not need to calculate complex integrals to use the map in this course.

What happened to the starting temperature?

The complete rule is L{dx/dt} = sX(s) - x(0). The starting value appears as a separate term. Transfer functions usually assume zero initial conditions so the ratio describes only the input-to-output path.

That assumption is useful, not invisible. To predict a real run from a warm start, include the initial condition or use a state-space model that carries it directly.

Does the transform change the real signal?

No. It changes the description, like switching from a street map to coordinates. The time plot is good for seeing when events happen. The s-plane is good for seeing decay, oscillation and algebraic structure.

An inverse Laplace transform returns the time signal. If two forms were transformed correctly, they describe the same behaviour and should agree when simulated.

When is a transfer function not enough?

It hides internal state and normally describes one operating point of a linear time-invariant system. Saturation, friction that changes direction, switching logic and time-varying loads do not fit one exact transfer function.

Engineers still linearise nonlinear systems near an operating point because local transfer functions are useful. They then test the design outside that local region in simulation and hardware.

Lab 18 · Rearrange an ODE into a transfer function
Try this firstMove heat capacity C and heat loss H. Watch the time constant, pole and transfer-function denominator update together. Then press Compare step response and check which change makes the tank slower.
The same ratio appears in three forms. C/H is the time constant, -H/C is the pole, and Cs + H is the denominator. They are not three unrelated facts.
Why do transfer-function derivations often state “zero initial conditions”?
The initial state is being set aside. The transform can represent it, but then the output contains both the response to the input and the response to energy already stored in the system.
Step 17

Read poles and zeros as clues about the response

A transfer function is a fraction of polynomials in s. Values of s that make its denominator zero are poles. They are the system's natural modes. A real pole at -2 gives a decay like e-2t. A complex pair gives an oscillation whose size grows or decays according to its real part.

For a continuous-time linear model, poles in the left half of the s-plane decay. Poles in the right half grow. Poles on the imaginary axis need care because they do not decay. Distance left sets decay speed; height above or below the real axis sets oscillation frequency.

Values that make the numerator zero are zeros. A zero can weaken or cancel a response pattern in a particular input-output path. It does not delete internal state safely by itself. An exact pole-zero cancellation on paper becomes imperfect when the physical parameters differ from the model.

Can I predict overshoot from a pole pair?

For a standard second-order model, the pole angle corresponds to damping ratio. Poles close to the imaginary axis decay slowly and ring. Moving the pair further left increases decay. Moving them higher increases oscillation frequency.

That shortcut applies to a dominant pair. Extra poles, zeros, delays and saturation can change the measured response, which is why prediction is followed by simulation and testing.

Does every left-half-plane pole guarantee a safe controller?

It guarantees asymptotic stability only for the stated linear model. It does not guarantee acceptable overshoot, actuator effort, noise sensitivity, constraint handling or safety under model error.

A stable aircraft that exceeds an actuator limit or loses too much altitude is still an unacceptable design. Stability is a necessary check, not the entire requirement.

What changes for a digital system?

Discrete-time systems use the z-plane. A mode is stable when its pole lies inside the unit circle. Sampling maps continuous poles into discrete poles roughly by z = es dt.

The left half of the s-plane maps inside the circle. The sample time affects where the pole lands and how accurately the digital model represents fast continuous dynamics.

Where do root locus and pole placement fit?

A root-locus plot traces where closed-loop poles move as one loop gain changes. It makes the trade between speed, damping and instability visible before a gain is chosen. Compensator poles and zeros can reshape the path.

State-space pole placement chooses feedback gains to put controllable closed-loop poles at selected locations. Both methods need sensible target locations, actuator checks and uncertainty tests. Moving a model pole is not the same as proving the hardware can produce that response.

Lab 19 · Move a pole pair and watch the time response
Try this firstSet the real part to -0.2 and the imaginary part near 3. Then move only the real part left. Watch the ringing decay faster without changing its spacing much. Finally cross into the right half-plane.
The plane is a compact prediction tool. It does not replace the time response; it tells you what shape to expect and which mode needs attention.
A continuous linear model has a pole at +0.4. What does that pole contribute?
It grows. The positive real part puts the pole in the right half-plane. Small positive is still unstable; it only takes longer to become obvious.
Step 18

Separate steady waves from transients with Fourier and Laplace

The Fourier transform asks how much of each steady sinusoidal frequency is present in a signal. It is ideal for vibration, sound, periodic disturbances, sensor noise and communication signals. A square wave, for example, is a sum of a fundamental sine wave and odd harmonics.

The Laplace transform includes exponential growth and decay as well as oscillation. Fourier analysis is closely related to evaluating a stable system along s = j omega, the vertical axis of the s-plane. Fourier tells us how a stable system responds after transients have died away. Laplace also helps explain the transients and whether they die away at all.

Neither transform is “more advanced” or a replacement for the other. Choose the view that matches the question. Use Fourier to find which vibration frequencies a controller amplifies. Use Laplace to study a step, an initial condition, pole locations or closed-loop stability.

Why are sine waves so useful?

A linear time-invariant system changes a sine wave's size and timing but not its frequency. That makes each frequency an easy test signal. Complicated signals can be split into sines, passed through the system one frequency at a time, and added back together.

This superposition rule depends on linearity. Saturation and switching create new harmonics, so their spectra reveal that the system is no longer behaving linearly.

Can Fourier analysis tell me that an unstable loop is safe?

A steady-state Fourier response assumes the relevant transients settle. If the loop is unstable, that assumption fails. Frequency-domain stability tests use the loop transfer function and conditions such as Nyquist or margins, not a casual spectrum of one finite run.

A finite FFT can still show growing energy, but it does not by itself prove closed-loop stability.

Where should I learn the transform calculation in more detail?

Frequency Domain builds the discrete Fourier transform by hand and then scales it to spectra and spectrograms. Filters connects frequency response to practical low-pass, high-pass and band-pass designs.

This course uses those ideas for loop behaviour: disturbance rejection, noise amplification, delay and stability margins.

Lab 20 · Build a square wave from harmonics
Try this firstStart with one harmonic, then add 3, 5, 7 and 9. Watch the sum approach a square wave. Change the plant bandwidth and see which sharp edges the plant can no longer follow.
Sharp changes require high frequencies. A slow plant removes those harmonics, so the output rounds off even when the low-frequency part is tracked correctly.
You need to predict how a stable motor responds to a repeating 120 Hz vibration. Which view is the most direct starting point?
Use the frequency response. The disturbance is already described by a frequency. The Laplace model can produce the same answer at s = j omega, but the Fourier question is the direct one.
Step 19

Read bandwidth and stability margin from a Bode plot

A Bode plot draws two answers against logarithmic frequency. Magnitude says how much a sine wave is enlarged or reduced. Phase says how far the output lags or leads. Decibels compress ratios: 20 log10 of a magnitude ratio. A ratio of 1 is 0 dB, 10 is 20 dB, and one tenth is -20 dB.

For loop design, find where the open-loop magnitude crosses 0 dB. That is the gain crossover frequency. Read the phase there. The distance from -180 degrees is the phase margin. Also find where phase reaches -180 degrees and read how far magnitude is below 0 dB; that is the gain margin.

Larger margins usually mean more tolerance for unmodelled delay and gain error, but there is no universal safe number. Requirements, uncertainty and standards decide. A common starting target is about 45 to 60 degrees of phase margin, followed by model variation and hardware tests.

Why does delay spend phase margin?

A pure delay changes no magnitude, but its phase lag grows with frequency. At angular frequency omega, a delay tau contributes -omega tau radians. A loop that looks safe without the sensor, computation and actuator delays can cross -180 degrees once they are included.

This is the frequency-domain version of Step 9. The controller acts on old information, and at some frequency “old” becomes close to pushing in the wrong direction.

Is bandwidth the same as sample rate?

No. Bandwidth describes how quickly the closed loop can follow and reject changes. Sample rate says how often the digital controller runs. The sample rate must be well above the bandwidth so sensing and computation do not consume the phase margin.

Raising sample rate does not make the physical actuator faster. It only reduces one source of delay and gives the digital model more points.

What if the magnitude crosses 0 dB more than once?

Then one margin number may hide the dangerous crossing. Resonances, flexible structures and filters can make several crossovers. Inspect all of them and use a Nyquist plot or direct closed-loop analysis when the simple reading is ambiguous.

Margins also describe one linearised loop at a time. Check operating points, payloads, temperatures and saturation separately.

What does a Nyquist plot add?

A Nyquist plot draws the complex loop response as frequency changes. Its encirclements of the point -1, combined with the open-loop unstable poles, determine closed-loop stability. It handles cases where one crossover and one margin are not enough.

The full rule needs careful contour and sign conventions. For this course, keep the engineering reason: Bode margins are readable summaries, while Nyquist preserves the complex path needed for a complete linear stability test.

Lab 21 · Spend phase margin with gain and delay
Try this firstRaise controller gain until the crossover moves right. Then add delay without changing gain. Read the phase-margin pill after each change and compare the time-response preview.
Faster crossover is bought with less time to react. A design is not finished when the nominal curve looks good. Vary delay and plant parameters across the bounds you expect.
A loop crosses 0 dB where its phase is -150 degrees. What is its phase margin?
It has 30 degrees. The remaining distance to -180 degrees is 30. The unit is degrees, not decibels.
Step 20

Track several states with a state-space model

Transfer functions focus on input and output. A state-space model keeps the internal state visible. Put the states in a vector x. Then write dx/dt = Ax + Bu and y = Cx + Du. A describes how states affect one another, B how inputs enter, C what sensors report, and D any direct input-to-output path.

For a trolley, choose x = [position, velocity]. Position changes at the current velocity. Velocity changes when the motor force and drag act. The same two first-order equations contain the same physics as one second-order equation, but now each state can be inspected, estimated and fed back.

Controllability asks whether the available inputs can move every important state. Observability asks whether the sensor history contains enough information to reconstruct every important state. These are structural questions. Tuning gains cannot fix an uncontrollable direction or an unobservable mode.

Why use matrices here?

A matrix is a compact table of connections. Each row says how one state changes; each column says which state or input contributes. Linear Algebra builds this picture from vectors, transformations, eigenvectors and systems of equations.

The eigenvalues of A are the state-space version of poles. State feedback changes the effective A matrix and can move controllable modes.

If I measure only position, is velocity unobservable?

Not for this trolley. A sequence of position measurements reveals how position changes, which carries velocity information. An observer combines the model, input commands and measurement error to estimate states that are not measured directly.

Noise and delay limit the estimate, so observability in the algebraic sense does not promise a useful estimate at every bandwidth.

How does this connect to Kalman filters?

A Kalman filter is an observer that propagates a state estimate and uncertainty through a linear model, then corrects them with measurements and stated noise models. It is covered in context in Autonomous Systems.

A controller and estimator are designed separately under specific linear assumptions, then combined. Their model, timing and noise assumptions still need joint testing.

What do pole placement and LQR do with the state?

State feedback uses u = -Kx plus any reference handling. Pole placement chooses K to put controllable modes at desired poles. LQR instead chooses K to minimise an accumulated quadratic cost that weighs state error against control effort.

The LQR weights are design choices, not measured physical constants. Scale states and units carefully, inspect the resulting poles and actuator demand, then test the controller outside the linear model.

Lab 22 · Control position and estimate velocity
Try this firstApply a motor pulse and watch position and velocity as separate states. Hide the velocity sensor, then step the observer. Finally disable the motor path and see why estimation does not create control authority.
Knowing and moving are different questions. An observer can estimate an unmeasured state. It cannot make an input affect a direction the actuator cannot reach.
A robot can estimate sideways drift accurately, but none of its actuators can produce a sideways force. Which property is missing?
The direction is uncontrollable. The robot knows what is happening but lacks an input path that can change it. Better sensing does not create force.
Step 21

Track temperature across space with a PDE

The tank model gave the whole tank one temperature. A long metal rod has a temperature at every position. Temperature changes with time and with distance along the rod. Its heat equation is a partial differential equation, or PDE, because it contains derivatives with respect to more than one independent variable.

In one dimension, the heat equation is partial T/partial t = alpha partial²T/partial x². The second spatial derivative measures how different a point is from its neighbours. A hot bump has cooler neighbours, so it spreads. Alpha is thermal diffusivity, which sets how quickly.

A computer replaces the continuous rod with a grid of points. Each point becomes a state and exchanges heat with its neighbours. The PDE becomes many coupled ODEs. A finer grid represents shorter spatial patterns, costs more computation, and requires a smaller stable timestep for an explicit update.

What are boundary conditions?

A PDE needs rules at the edges. A fixed-temperature end is a Dirichlet boundary. A specified heat flow, including an insulated zero-flow edge, is a Neumann boundary. A convective edge can relate flow to the difference from ambient temperature.

Changing only the boundary conditions can change the whole solution. They are part of the model, not a detail added after the equation.

Do I need a PDE for every physical controller?

No. A lumped ODE is often enough when internal differences settle much faster than the control problem. The tank worked because we assumed mixing kept one temperature. Use a distributed model when spatial shape affects sensors, actuators, stress, safety or performance.

Flexible robots, wings, long cables, batteries and buildings often need distributed models somewhere in their design, even if the final embedded controller uses a reduced model.

How is a huge PDE model used in a small controller?

Finite-difference or finite-element models may have thousands of states. Model-order reduction keeps the modes that matter in the controller's frequency range and discards weak or fast modes carefully.

Discarded flexible modes can still be excited by a controller. Check the full model and hardware for spillover, where control energy enters a neglected mode.

Lab 23 · Diffuse heat across a rod
Try this firstHeat the left end, press Run 20 ticks, and watch the temperature spread node by node. Increase diffusivity. Then make dt too large and read the stability warning before resetting.
A grid creates a coupled state model. Refining the grid changes both accuracy and the largest safe explicit timestep. Numerical choices belong in the engineering evidence.
Why can a single tank temperature fail for a long battery pack?
Spatial differences can be the hazard. An average can hide one hot region. A PDE or a network of thermal states is justified when that shape affects the decision.
Step 22

Choose a controller from the plant, constraints and evidence

PID remains common because it is understandable, cheap and effective for many single loops. Larger systems need other tools. Cascaded loops separate fast inner dynamics from slower outer goals. State feedback uses several states at once. LQR chooses feedback gains by balancing quadratic state error and control effort.

Model predictive control, MPC, predicts several future steps, chooses a sequence of inputs under constraints, applies the first one, then solves again after the next measurement. It is useful when actuator, state or path limits are central. Its model mismatch, solver time and fallback behaviour must be tested.

Modern learned models can estimate dynamics, disturbances or costs, and learned policies can propose actions. They do not remove the control problem. Training coverage, timing, uncertainty, constraints and recovery still determine whether the physical system is acceptable. Keep hard bounds, a tested fallback and an independent monitor wherever a bad action can cause harm.

How does an engineer choose among these methods?

Write the requirements first: variables to hold, disturbances, limits, timing, acceptable errors and hazards. Measure or identify the plant. Start with the simplest controller that can meet the requirements, then test nominal performance, parameter variation, noise, delay, saturation and faults.

Complexity is justified when it buys a measured capability. It also adds software, tuning, computation, monitoring and verification work.

Is system identification the same as machine learning?

System identification fits a dynamical model from input-output data. It includes classical linear methods, nonlinear grey-box models and learned neural models. The label describes the engineering job, not one algorithm family.

Excite the system safely, keep separate validation runs, check residuals and uncertainty, and repeat across operating conditions. A model that predicts the data used to fit it has not yet passed a useful test.

Where do cascaded, adaptive, uncertainty-bounded and nonlinear control fit?

Cascaded control nests a fast inner loop inside a slower outer loop, such as motor current, then speed, then position. The inner loop must be measurably faster so the outer loop can treat it as a simpler actuator.

Adaptive control changes parameters while operating under stated excitation and stability conditions. Uncertainty-bounded control designs against a stated family of models. Nonlinear methods use the real nonlinear structure instead of one linear operating point. Gain scheduling uses several local designs and rules for moving between them.

Each method answers a different failure of a simpler model. None removes the need to bound uncertainty, rate and amplitude limits, computation, faults and the region in which its guarantees apply.

Where do I continue with simulation and autonomy?

Simulating Physical Systems covers model fitting, scenario matrices, fault injection, domain randomisation, SIL and HIL. Optimisation supplies the language behind LQR and MPC. Autonomous Systems adds estimation, planning, learned policies, runtime safeguards and safety evidence.

For timing on real hardware, continue to Real-Time Systems. For physical motion, use Robotics and Drones.

Lab 24 · Match a controller to the requirement
Try this firstChoose the room heater, robot arm, chemical plant and learned drone cases in turn. The map above the buttons places the five methods by how much model they carry and how directly they handle limits, and shades the region this case calls for. Select a proposed method and read which evidence is still missing. More complicated is not automatically a better match.
Method choice follows the requirement. The final design includes the controller, estimator, timing, limits, monitor, fallback and tests. Reporting only the algorithm name leaves out most of the engineered system.
An MPC controller meets every nominal test but sometimes misses its computation deadline. What must be added before deployment?
Timing failure needs a defined response. A late optimal command is not a command for the current state. Bound solver work, monitor deadlines and transfer safely to a fallback.
Step 23

Build and test your own loop

Everything is exposed here and nothing is marked. The three gains, the sensor lag, and the limit on the stored total as a switch you can turn off. There is a knock part way through the run if you want one. The target is yours too: drag the dashed target line up and down on the chart itself, and watch the whole loop chase wherever you put it.

One suggestion for using it, because a sandbox with no plan is only sliders. Choose the lag first and leave it alone, then find gains that cope with it. That is the order the real world hands them over: the lag belongs to the machine you were given, and the gains are the part you get to choose.

Then try to break each thing you were told. Take Kd up until the heater thrashes. Turn the limit off and see whether you can make the stored total misbehave. Put the lag at its highest and find out whether any tuning is calm there.

What have I actually got in front of me?

The same tank as every other lab. Kp multiplies the error now. Ki multiplies the running total of every error so far. Kd multiplies how fast the error is changing. The three are added, and the sum is clipped to something between nothing and everything the heater has.

The sensor lag slider decides how far behind the truth the reading is. The limit button decides whether the running total has a ceiling. The knock button subtracts a lump of temperature part way through, which is a disturbance with no warning attached.

What would I change to control something else with this?

Three things, and none of them is the controller. What you measure, what you drive, and the numbers that describe how the second affects the first. Swap degrees for revolutions per minute, and heater power for throttle and the three sums are untouched.

What does change is the tuning, because the gains carry units. That is why nobody can hand you a Kp and why every course, including this one, has to hand you a method instead.

What is missing from this model?

Plenty, and it is worth knowing what, so you are not surprised by a real machine. The heater here can change power instantly, while a real valve takes time to move and cannot go faster than it goes. The plant is linear: twice the power gives twice the effect, which is untrue of nearly everything real, including a heater losing heat by radiation. The clock never stutters, and in a real machine a tick can arrive late.

Also, there is exactly one loop. Real plants have several, interfering with each other: heating one tank changes the temperature of the tank next door, so tuning one loop detunes another. That is where this subject stops being a single slider and starts being engineering.

After one practical run, describe the result using the advanced path. Name the state, input and disturbance. Say whether the dominant model is first or second order. Predict what added delay does to phase margin, and list the effects this tank model leaves out. This is how an experiment becomes model evidence.

Lab 25 · Your own loop
Try this firstDrag sensor lag to its highest setting and leave it there. Now hunt for Kp, Ki and Kd that still settle without a large overshoot. When you have something you like, press Knock it half way through and see whether your tuning survives a disturbance it was not tuned for. Then take hold of the target line on the chart and drag it: every tuning you find has to serve whatever target somebody asks for next.
Notice how much less room there is at high lag. With a fast sensor, a wide range of tunings all look fine and it is hard to tell a good one from a lucky one. With a slow sensor most tunings are bad and the good ones are narrow. Nothing you do to the gains buys back the information the delay is costing you, which is the one idea from this course most worth carrying away.
You inherit a machine that holds its value well from cold, but overshoots badly whenever somebody changes the target by a large amount. What is the first thing to check?
Look for saturation and an unlimited total first. Good from cold but bad after a large change in target is the fingerprint from Step 8. A large change sends the machine flat out, and while it is flat out the stored total grows with nothing to stop it. That costs nothing to check and the fix is small. Kp and the sensor are both worth a look afterwards, but a fault that appears only after large changes is pointing at the term with a memory.

What you can do now

  • Say which part of a machine is the plant and which part is the controller, and why the difference matters when something misbehaves.
  • Explain why a fixed setting is not control, and what a disturbance does to it.
  • Choose a dead band on purpose, knowing what you are buying and what you are selling.
  • Predict the steady-state error of a proportional controller, and say why more gain shrinks it without closing it.
  • Describe the integral term as a running total, and the derivative term as a difference divided by a time, without reaching for calculus.
  • Read a controller's output as three separate contributions and say which one is holding a machine at rest.
  • Tune a loop against a score, one gain at a time, and judge it on more than one test.
  • Recognise integral windup from its shape, and name two fixes for it.
  • Explain why lag is the thing that makes control hard, and what to do when you cannot remove it.
  • Say what feed forward can do that feedback cannot, and what it cannot do that feedback can.
  • Say why Kd is the brake on anything with momentum, and why an arm tuned without it either overshoots or feels lifeless.
  • Read the slope of a curve at one moment, name a system's state, and recognise damping as whatever takes energy out of motion.
  • Derive a first-order thermal ODE from an energy balance and check every term by its units and sign.
  • Explain why position and velocity make a second-order state, and connect damping ratio to ringing.
  • Choose a digital sample time with numerical stability, aliasing, computation and delay in mind.
  • Turn a linear ODE into a transfer function and connect its time constant, pole and step response.
  • Choose Fourier analysis for steady frequency content and Laplace analysis for modes, initial conditions and transient stability.
  • Read gain crossover and phase margin from a Bode plot, including the phase spent by delay.
  • Write a multi-state system as Ax + Bu, and keep observability separate from controllability.
  • Explain why distributed physics needs a PDE or coupled spatial states, including boundary conditions.
  • Choose among PID, state feedback, LQR, MPC and learned components from requirements and evidence rather than from novelty.

Where this goes

  • Robotics. Two wheels, some encoders, and the question of where the robot actually is. The position loop from Step 11 becomes two of them, then a path.
  • Drones. The same inner loops run on attitude and rate, where letting a response settle slowly is not an option.
  • Simulating Physical Systems. Turn the ODE, sample time and uncertainty lessons into repeatable software, hardware-in-loop and field gates.
  • Embedded Systems and Real-Time Systems. Put the loop on a real clock, measure deadline jitter and connect it to sensors and actuators.
  • Frequency Domain. Work the discrete Fourier transform by hand, then use spectra and spectrograms on measured signals.
  • Autonomous Systems. Combine estimation, planning, learned policies and runtime safeguards while keeping the low-level control contract explicit.