Menu

PID Is Not a Guess

PID Is Not a Guess: Tuning a Control Loop in Simulation First

Notes · Motors and motionNovember 19, 202611 min readSenova Systems Research

A PID controller is three knobs: now, always, and what's coming. Guessing them burns motors. Ziegler–Nichols (1942) still works, Tyreus–Luyben trades speed for zero overshoot, and the whole argument is settled in simulation before anything moves.

First, a simple picture

You are driving, and you want to hold exactly 60 miles an hour.

Your foot is the controller. Your eyes are the sensor. The speedometer is the measurement. The gap between 60 and where you are, that is the error.

Now imagine three different drivers:

  • The first driver looks at the speedometer, sees 50, and presses the pedal in proportion to the gap. Ten under, ten of pedal. Two under, two of pedal. Simple, fast, but when the road levels out, they settle at 57, not 60, and stay there forever. They never quite close the gap.
  • The second driver keeps a running tally. Every second spent below 60 adds to a mental pile, and they press harder the longer the gap has lasted. They get to 60 exactly, but they have been pressing so long that they sail past it to 68 before they notice.
  • The third driver watches the rate of change. The speed is climbing fast? Ease off now, before it overshoots. The speed is falling? Press early, before it drops.

A PID controller is all three drivers at once, in one piece of code, making the decision hundreds of times a second. P, I, and D are three knobs, and tuning is choosing their numbers. Guess the numbers and the machine oscillates, overshoots, or burns its motor out. Tune them in simulation first, before anything moves, and you know the answer before you risk the hardware.

That last line is not a slogan. It is the site's own rule: "control loops modelled and tuned in simulation before anything moves."

The loop, and the three knobs

A control loop is a circle: the controller reads the sensor, compares the reading with the setpoint (where you want to be), and pushes the actuator (the motor, the heater, the valve) to close the gap. Then it reads again. And again. The loop never stops; it only gets the error smaller.

The PID controller's output is one line of arithmetic, and it is worth reading slowly:

output=Kp×error+Ki×(error added up over time)+Kd×(how fast the error is changing)\text{output} = \text{Kp} \times \text{error} + \text{Ki} \times \text{(error added up over time)} + \text{Kd} \times \text{(how fast the error is changing)}
  • P, proportional. Push in proportion to the error right now. Big gap, big push. Small gap, small push. P is fast and simple, and it is the only knob that can react instantly. Its failure is built in: as the error shrinks, the push shrinks, and the system stops just short of the target. That leftover gap is called steady-state error (or offset). P alone never closes it, our own simulation below measures it at a third of the step, forever.
  • I, integral. Keep a running total of the error over time, and push in proportion to the total. The longer the gap has lasted, the harder I pushes. I is the knob that kills the offset: it will not rest until the error is zero. Its failure is windup: if the actuator is already at full power (saturated, the valve fully open, the motor at max), the total keeps growing anyway, and when the target is finally reached, the stored-up push sails the system far past it. The fix is anti-windup, stop adding to the total while the actuator is saturated. Always implement it in a real system.
  • D, derivative. Push against the rate of change. If the error is closing fast, D eases off early, it is the driver who lifts off before the overshoot. D is the damper: it calms oscillation and cuts settling time. Its failure is noise: D reacts to how fast the measurement changes, so a jittery sensor makes D jitter the actuator, wearing valves and motors. The fixes are standard: put D on the measurement (not the error) so a setpoint change doesn't cause a derivative kick, and filter the measurement first.

Three facts that frame everything else:

  • PID is the most widely deployed controller in industry, over 95% of industrial control loops use some form of PID, and about 90% of those run PI (P plus I, no D). Derivative is useful on slow, smooth processes and actively harmful on noisy ones.
  • The idea is old: Elmer Sperry built it for ship autopilots in 1911; Nicolas Minorsky formalised it mathematically in 1922. It has survived a century because it is simple, and because it works.
  • Four numbers describe any step response: rise time (how long from 10% to 90% of the target), overshoot (how far past the target it goes, in percent), settling time (how long until it stays within 2% of the target), and steady-state error (the gap that never closes). Every tuning decision is a trade between these four.

Why guessing fails

Guessing fails for a reason that is easy to state and hard to feel until you have watched it: the three knobs fight each other.

Turn P up and the loop gets faster, and then it overshoots, then oscillates, then goes unstable. Turn I up and the offset vanishes, and then the loop hunts, slowly swinging above and below the target. Turn D up and the swinging calms, and then the sensor noise starts hammering the actuator.

There is a second reason, quieter and more expensive: dead time. Dead time (also called transport delay) is the gap between moving the actuator and seeing any change at all, the heater warming up, the fluid travelling down a pipe. It is not lag; lag is the process easing toward a new value, dead time is nothing happening.

The ratio of dead time to the process time constant, L/T, predicts how well PID can work before you touch a single knob. If the dead time is longer than the time constant, PID is the wrong tool: use feedforward, dead-time compensation, or change the process. No amount of knob-turning fixes a loop that cannot see what it just did.

And the third reason is the one that costs hardware: tuning on the real machine means the bad tunes happen on the real machine. An oscillating loop on a heater is a ruined batch. An oscillating loop on a motor is a burnt winding. The simulation exists so the bad tunes happen on a screen.

The 1942 method that still works: Ziegler–Nichols

In 1942, John Ziegler and Nathaniel Nichols published a paper, Optimum Settings for Automatic Controllers, Transactions of the ASME, that gave the field its first systematic tuning rule. It is still the starting point most engineers learn first, and it works like this:

  1. Set I and D to zero. P only.
  2. Turn P up slowly until the system oscillates with a steady, regular rhythm, not growing, not shrinking. That gain is the ultimate gain (Ku), and the period of the oscillation is the ultimate period (Pu). You have just found the edge of stability, on purpose.
  3. Calculate the three gains from two numbers:
    • P-only: Kp = 0.5 × Ku
    • PI: Kp = 0.45 × Ku, Ti = Pu / 1.2
    • PID: Kp = 0.6 × Ku, Ti = Pu / 2, Td = Pu / 8, in the parallel form engineers code: Ki = 2 × Kp / Pu, Kd = Kp × Pu / 8.

The classic Ziegler–Nichols PID is deliberately aggressive: it is designed for roughly 25% overshoot and fast disturbance rejection. If that is too much overshoot for your machine, the same paper's family gives you gentler variants: a low-overshoot setting (Kp = 0.33 × Ku, about 5% overshoot) and a no-overshoot setting (Kp = 0.2 × Ku, under 1% overshoot, slower). The method assumes a roughly linear process, and it needs the real machine, or a good model of it, to find Ku and Pu.

Finding Ku on hardware means deliberately driving the loop to the edge of oscillation, which is exactly why you do it in simulation first.

The gentler alternative: Tyreus–Luyben, and lambda

Ziegler–Nichols is not the only rule, and for many machines it is the wrong one. Two alternatives, both published and both in use:

  • Tyreus–Luyben: Kp = Ku / 3.2, Ti = 2.2 × Pu, Td = Pu / 6.3. Much gentler. It trades speed for stability, in a published MATLAB comparison (IJIREEICE, 2014), Tyreus–Luyben gave 0% overshoot against Ziegler–Nichols' 31.7%, but took 76 seconds to settle against Ziegler–Nichols' 24.3. The same study measured the untuned, guessed PID at 63.3% overshoot and 85 seconds to settle, the cost of guessing, in numbers.
  • IMC / lambda tuning: you build a simple model of the process (first-order plus dead time) and pick a single number, λ (lambda), that sets the speed. λ ≈ 1–3 × the dead time is a good start. The result is no overshoot by design, and the speed is your choice. This is the method for loops that must not overshoot, level and pressure control, and anything where an overshoot breaks something.

Three ways to find the numbers (published MATLAB comparison, IJIREEICE 2014, one test system)

MethodOvershootSettling timeCharacter
Untuned (guessed)63.3%85 sWild and slow
Ziegler–Nichols (1942)31.7%24.3 sFast, overshoots
Tyreus–Luyben0%76 sNo overshoot, slow
IMC / lambdaAbout 0%You chooseλ sets the speed

One motor, three tunes: actually simulated

This is not a sketch. The curves below were produced by a real simulation, run for this article: a first-order plant (gain 1, time constant 5 seconds, dead time 1 second), a step setpoint from 0 to 1 at t = 0, a discrete PID with derivative on measurement and anti-windup, 60 seconds of simulated time. The same plant, the same step, three different tunes. The numbers are the simulation's measurements, not illustrations.

Step 1, Find the edge. P only, I and D at zero, Kp raised until the loop holds a steady oscillation. The simulation measures Ku = 8.27 and Pu = 3.81 seconds. (The analytical value for this plant is about 8.6, the simulation and the theory agree, which is the check that the model is honest.)

Step 2, The guessed tune (Kp = 6, Ki = 1.5, no D). A plausible guess: strong P, a middling I, no D because "D is scary." The result: 80.9% overshoot, the motor sails to 1.81 on a target of 1.0, and it takes 25.9 seconds to settle. The loop rings like a bell. The guess was not crazy. It was still wrong, because no one had measured the edge.

Step 3, Ziegler–Nichols (Kp = 4.96, Ki = 2.60, Kd = 2.36). From the measured Ku and Pu, by the 1942 formulas. The result: 53.6% overshoot, settling in 9.7 seconds. Fast, the fastest of the three, and still a big overshoot. The textbook says Ziegler–Nichols typically gives about 25% overshoot; on this plant it gives 54%, which is the honest lesson: the rule is a starting point, not a promise. The numbers depend on the plant. The pattern does not.

Step 4, Tyreus–Luyben (Kp = 2.58, Ki = 0.31, Kd = 1.56). The gentle rule. The result: 0% overshoot, settling in 15.6 seconds. No drama at all, and six seconds slower than Ziegler–Nichols. If the machine cannot tolerate an overshoot, those six seconds are cheap. If it can, they are wasted.

Step 5, And P alone, for the record. Kp = 2, no I, no D: the loop settles at 0.667 and stays there, a steady-state error of a third of the step, forever. That is what P alone buys: fast, stable, and permanently wrong by a third. It is the clearest picture of why I exists.

00.511.5051015202530Time (s)Output (setpoint = 1)
One motor, three tunes, the same step (first-order plant, gain 1, time constant 5 s, dead time 1 s). Simulated at 1 ms steps: guessed tune overshoots 77% and settles in 23 s; Ziegler–Nichols 49% in 10 s; Tyreus–Luyben 0% in 17 s.

The decision test

Four questions. They sort the jobs that need a tune from the jobs that need something else:

  1. Does the loop oscillate, overshoot, or settle short? Yes, the tune is the problem, and simulation is the fix. No, look elsewhere.
  2. Is the dead time longer than the time constant? Yes, PID is the wrong tool. No amount of tuning fixes a loop that cannot see what it just did. Feedforward, dead-time compensation, or change the process.
  3. Is the sensor noisy? Yes, fix the measurement before you touch D. D amplifies noise, and a noisy D wears the actuator out.
  4. Can the machine tolerate an overshoot? Yes, Ziegler–Nichols is a fair starting point. No, Tyreus–Luyben or lambda, and the slower settling time is the price, stated up front.

If the answer to all four is "the tune is the problem and the machine can take a little overshoot," the job is a simulation and a morning. If the answer to question 2 is yes, the job is a redesign, and the honest thing is to say so before anyone pays for a tune.

"But we tune by feel", and two more fair doubts

"Our engineer has tuned loops for twenty years." Then the simulation will confirm what they know in an afternoon, and it will write it down. The risk is not that your engineer is wrong. The risk is that the knowledge lives in one person's head, the next loop is tuned from scratch, and the day they are on holiday, the loop has no tuner. A model and a method outlive a memory.

"Simulation never matches the real machine." A bad model, no. A good model, built from a step test on the real machine, with the dead time measured, not assumed, matches closely enough to pick the tune, and the tune is then verified on the hardware at low power. The simulation's job is not to replace the machine. It is to make the bad tunes happen on a screen, so the first tune on the machine is already close.

"PID is old tech. Shouldn't we use something smarter?" PID is the most widely deployed controller in industry for a reason: it is simple, it is understood, and it works on the loops it fits. Smarter controllers, model-predictive, adaptive, learning-based, earn their keep on loops PID cannot handle: heavy dead time, strong nonlinearity, multiple interacting variables. If your loop is a single variable with a modest dead time, PID is the right tool, and the smart move is to tune it properly rather than replace it fashionably.

Sources

  1. Ziegler, J. G. & Nichols, N. B. (1942), "Optimum Settings for Automatic Controllers"
    What we used

    Transactions of the ASME, 64, 759–768, the closed-loop method: Ku and Pu, PID at Kp = 0.6 Ku, Ti = Pu / 2, Td = Pu / 8; P-only at 0.5 Ku; PI at 0.45 Ku, Ti = Pu / 1.2

  2. All About Circuits, "Embedded PID Temperature Control, Part 6: Ziegler–Nichols Tuning"
    What we used

    Worked example: Ku = 110, Tu = 55 s gives PID Kp = 64.7, Ti = 27.5, Td = 6.9; no-overshoot variant Kp = Ku / 5, Ti = Tu / 2, Td = Tu / 3

  3. Compu-Tools PID calculator
    What we used

    Classic ZN PID intentionally produces ~25% overshoot; low-overshoot variant Kp = 0.33 Ku (~5%); no-overshoot variant Kp = 0.2 Ku (<1%)

  4. IJIREEICE (2014), "Performance Analysis of PID Tuning Techniques" (MATLAB/Simulink)
    What we used

    Untuned PID: 63.3% overshoot, 85 s settling, 0.4 steady-state error; Ziegler–Nichols: 31.7%, 24.3 s, 0; Tyreus–Luyben: 0%, 76 s, 0; modified Z–N: 6.84%, 25.7 s, 0

  5. TecXSkill, "Control System Fundamentals"
    What we used

    Over 95% of industrial control loops use some form of PID; rise time t_r ≈ 1.8/ωn; overshoot Mp = e^(−πζ/√(1−ζ²)); settling time t_s ≈ 4/(ζωn) for ±2%; integral windup and anti-windup clamping; derivative-on-measurement to avoid derivative kick

  6. VideoPhysics PID simulator
    What we used

    PID in over 95% of industrial loops; Sperry ship autopilot 1911, Minorsky formalised 1922; Cohen-Coon, lambda tuning, software optimisation as modern approaches

  7. NRTechStudio PID closed-loop simulator
    What we used

    Live P vs PI vs PID on the same plant: P-only stalls at 0.667 with 0.333 steady-state error; PI reaches 1.000 with 0 error; PID adds damping; derivative kick at first output

  8. Pro-InstControl, "Control & tuning"
    What we used

    90% of industrial loops run PI; derivative useful on slow smooth processes, harmful on noisy ones; six tuning methods (manual, Z–N closed loop, Z–N open loop, Cohen-Coon, IMC/lambda); λ ≈ 1–3 × dead time; if dead time exceeds the time constant, PID is the wrong tool; starting points by loop type (flow, level, temperature)

  9. Our simulation, run for this article
    What we used

    Agreement checks the model). Guessed tune (Kp 6, Ki 1.5, no D): 80.9% overshoot, 25.9 s settling. Ziegler–Nichols (Kp 4.96, Ki 2.60, Kd 2.36): 53.6% overshoot, 9.7 s settling. Tyreus–Luyben (Kp 2.58, Ki 0.31, Kd 1.56): 0% overshoot, 15.6 s settling. P-only (Kp 2): final 0.667, steady-state error 0.333. Full curves in fig1

More in motion and sensing

Robot arm controlA robot arm runs one loop, sense, decide, move, and the human is the gate before the risky move. ISO 10218:2025 (Feb 2025) folds the old ISO/TS 15066 limits into the standard and makes force validation mandatory: a chest takes 140 N before it hurts, a face 65 N, and a 20 kg arm moving toward a chest must stay under 0.24 m/s. The safe speed costs 2.55 seconds a move, and the log is what proves the arm asked.14 minThe Arm That FeelsFour ways to make a robot arm touch things without breaking them, direct force control, impedance, admittance, and hybrid position/force, with a real contact simulation on a bench arm.22 minThe Axis That Doesn't BacklashA linear axis misses position, whips at speed, or drops its load on power loss, and the fault is usually the architecture, not the motor. Ball screw vs lead screw vs belt vs rack vs linear motor, the five numbers that decide, and a worked Z-axis sizing.16 minThe Drive StageA BLDC driver is five sections, six switches, and one rule that matters more than the rest: the two devices in a half-bridge must never conduct together. This is how the drive stage works, how it dies, and the arithmetic that keeps it alive, with a worked 48 V design.30 minThe Encoder Is the LoopAn encoder is the sensor that tells the controller where the shaft is, that is the whole job. Incremental counts pulses and forgets everything on power loss; absolute reads a unique code for every angle and knows where it is the instant power returns. This is what resolution buys, why it is not accuracy, why velocity comes from differentiating position and gets noisy at low speed, and what Example Labs' bench arm needs on each of its four joints.24 min