Interactive Animation: PID Controller

By |

The following animation illustrates the operation of a PID controller using the example of a water level control system. Control behavior, manipulated variable, and disturbance influence are visualized in real time.

Links

Animation Description

The animation shows a water tank with a percentage scale (0–100%) on the left side. Water flows in from the top (the manipulated variable – the strength of the blue water jet indicates how far the valve is open). Water flows out at the bottom (the disturbance variable – adjustable via the outflow slider). The desired water level (setpoint) is marked as a dashed red line in the tank. The PID controller compares the current water level with this marking and adjusts the inflow so that the water level reaches the red line.

A real-time graph shows the time history of the setpoint and process value, allowing the transient response, overshoot, and steady-state accuracy to be observed directly.

The manipulated variable \( u(t) \) of the PID controller is calculated from three components:

\[ u(t) = K_p \cdot e(t) + K_i \cdot \int e(t)\,dt + K_d \cdot \frac{de(t)}{dt} \]

Where the control error is \( e(t) = w(t) – x(t) \), with \( w \) being the setpoint and \( x \) the process value.

Interactive Controls

The following parameters can be adjusted using the sliders:

  • Setpoint w (10–90%): Desired water level of the tank
  • Outflow (Disturbance) (0–100%): Simulates an external disturbance through variable outflow
  • Kp (0–10): Proportional gain – responds to the current control error
  • Ki (0–2): Integral gain – eliminates steady-state error
  • Kd (0–10): Derivative gain – dampens rapid changes and reduces overshoot

The simulation can be paused using the Pause button and reset to its initial state using the Reset button.

Physical Background

The PID controller is the most widely used controller type in automation engineering. It combines three modes of action: The P component responds proportionally to the control error. The I component accumulates the error over time and eliminates steady-state offset. The D component responds to the rate of change and dampens overshoot.

The water tank example clearly demonstrates the interplay of these components: A pure P controller (\( K_i = 0, K_d = 0 \)) leaves a residual steady-state error – in the animation, this is visible as a persistent gap between the blue process-value line and the red dashed setpoint line in the graph, and the water level in the tank stays below the red marking. Adding the I component eliminates this error, but may cause overshoot – the blue line then shoots above the red line before settling. The D component can reduce this overshoot and improve the transient response.

A Brief History of Automatic Control

The idea of automatic feedback control is far older than electronics. One of the earliest and most famous examples is the centrifugal governor on James Watt’s steam engine (1788): two rotating weights that automatically throttle the steam supply when the engine runs too fast. This purely mechanical device is, in essence, a proportional controller.

The mathematical foundations of PID control were laid by Nicolas Minorsky in 1922, who analyzed the steering of large ships and showed that combining proportional, integral, and derivative action produces superior control. In 1942, John G. Ziegler and Nathaniel B. Nichols published their famous tuning rules, which gave engineers a systematic method for setting PID parameters – still widely taught today.

With the advent of microcontrollers, the PID algorithm moved from pneumatic and analog hardware into software. Today, it is estimated that over 90 % of all industrial control loops use some form of PID control – from chemical plants and power stations to household appliances and consumer electronics.

The Three Components in Detail

Each of the three PID components addresses a different aspect of the control problem. The following sections explain them individually and suggest slider settings for the animation so that the effect of each component can be observed directly.

P – The Proportional Component

The P component produces an output that is directly proportional to the current control error: the larger the error, the stronger the corrective action. It provides an immediate response but, on its own, cannot bring the error to zero in the presence of a sustained disturbance – there will always be a residual steady-state error.

A high \( K_p \) makes the controller more aggressive: the response becomes faster, but if \( K_p \) is set too high, the system begins to oscillate.

Try it: Set \( K_p = 5 \), \( K_i = 0 \), \( K_d = 0 \) and move the outflow slider to about 50%. In the tank, the water level rises but stops below the red setpoint line. In the graph on the right, the gap between the blue process-value curve and the red dashed setpoint line remains – this is the steady-state error that a pure P controller cannot eliminate. The inflow jet at the top of the tank stays constant, since the P component only reacts to the current difference.

I – The Integral Component

The I component accumulates the control error over time. Even a small persistent error will cause the integral to grow steadily, increasing the corrective action until the error is eliminated. This is what makes a PI or PID controller capable of achieving zero steady-state error.

The downside: if \( K_i \) is too large, the accumulated integral can overshoot the setpoint significantly before the controller corrects back. In extreme cases, this leads to sustained oscillation. Another known problem is integral windup, where the integral grows excessively during large setpoint changes or saturation of the actuator.

Try it: Set \( K_p = 3 \), \( K_i = 0.5 \), \( K_d = 0 \) and set the outflow to about 50%. In the graph, the blue process-value curve reaches the red setpoint line after some time – the steady-state error disappears. However, the blue curve first overshoots above the red line before settling down. Now increase \( K_i \) to 2: the blue curve begins to oscillate noticeably around the red line, and in the tank the water level can be seen repeatedly rising above and falling below the red marking.

D – The Derivative Component

The D component reacts to the rate of change of the error. When the error is decreasing quickly (e.g., the process value is approaching the setpoint fast), the D component applies a braking force that reduces overshoot and improves the transient response.

In practice, pure derivative action amplifies high-frequency noise, which is why real-world implementations always include a low-pass filter on the D term. In the animation, this effect is less visible because the simulation is noise-free.

Try it: Set \( K_p = 3 \), \( K_i = 0.5 \), \( K_d = 3 \). Compared to the PI setting (\( K_d = 0 \)), the graph shows that the blue curve overshoots far less above the red setpoint line and settles more quickly. The D component acts like a brake: as the water level approaches the setpoint rapidly, it reduces the inflow before the setpoint is exceeded. The difference is easiest to see by first running the PI setting briefly, then pressing Reset and starting with the PID setting.

Tuning Methods and Common Pitfalls

Finding good PID parameters is both science and craft. Several established methods exist:

Manual Tuning

A widely used step-by-step approach:

  1. Set \( K_i = 0 \) and \( K_d = 0 \). Gradually increase \( K_p \) while watching the graph: the blue curve should approach the red line quickly without repeatedly overshooting it. If the blue curve begins to oscillate, \( K_p \) is too high.
  2. Slowly increase \( K_i \) while watching the graph: the gap between the blue and red lines should close. Stop before the blue curve overshoots significantly above the red line.
  3. If the blue curve still overshoots above the red line, add \( K_d \) – in the graph you will see the overshoots diminish and the blue curve settle more quickly.

Ziegler–Nichols Method

A classic systematic approach from 1942: increase \( K_p \) (with \( K_i = 0 \), \( K_d = 0 \)) until the system exhibits sustained, uniform oscillation. In the animation, this point is reached when the blue curve in the graph oscillates evenly around the red setpoint line with constant amplitude, neither growing nor decaying. The value of \( K_p \) at this point is the critical gain \( K_u \), and the period of oscillation is \( T_u \). The PID parameters are then calculated as:

Controller\( K_p \)\( K_i \)\( K_d \)
P only\( 0.5 \cdot K_u \)00
PI\( 0.45 \cdot K_u \)\( 0.54 \cdot K_u / T_u \)0
PID\( 0.6 \cdot K_u \)\( 1.2 \cdot K_u / T_u \)\( 0.075 \cdot K_u \cdot T_u \)

Common Pitfalls

  • Integral windup: When the actuator reaches its physical limit (e.g., valve fully open), the integral term keeps growing. Upon recovery, this causes a large overshoot. Countermeasure: anti-windup clamping. The animation includes such a clamp internally. You can still observe the effect: set \( K_i = 2 \) and the setpoint to 90% with the outflow at 0%. The manipulated variable is capped at 100% (valve fully open), and when you lower the setpoint, the graph shows a pronounced undershoot.
  • Derivative noise: In real systems, sensor noise is amplified by the D term, leading to erratic actuator behavior. Countermeasure: low-pass filter on the derivative.
  • Aggressive tuning: Setting \( K_p \) too high can push the system into instability. For example, set \( K_p = 10 \), \( K_i = 0 \), \( K_d = 0 \) and watch the graph: the blue curve begins to oscillate violently around the red line. In the tank, the water level jumps up and down erratically and the inflow jet changes constantly.

The Feedback Control Loop

The PID controller operates within a standard feedback control loop. Understanding this loop is key to understanding any controlled system, not just the water tank in this animation:

ElementSymbolIn this animation
Setpoint (reference)\( w(t) \)Desired water level (red dashed line)
Process value (measurement)\( x(t) \)Current water level
Control error\( e(t) = w – x \)Difference between desired and actual level
ControllerPIDCalculates required inflow adjustment
Manipulated variable\( u(t) \)Inflow rate (valve position)
Plant (controlled system)Water tank
Disturbance\( d(t) \)Outflow (drain)

The loop works continuously: the controller reads the error, computes a corrective action, the plant responds, the new process value is measured, and the cycle repeats. This closed-loop feedback is what enables the system to reject disturbances and track the setpoint automatically.

Comparison: P, PI, and PID Controller

The following table compares the three most common controller configurations. Use the suggested slider settings to observe each behavior directly in the animation:

FeatureP onlyPIPID
Steady-state errorYes (residual offset)No (eliminated by I)No
OvershootLowCan be significantControlled by D
Response speedProportional to \( K_p \)ModerateFast and well-damped
Stability riskLow (unless \( K_p \) very high)Oscillation from high \( K_i \)Best if well-tuned
Suggested settings\( K_p=5,\; K_i=0,\; K_d=0 \)\( K_p=3,\; K_i=0.5,\; K_d=0 \)\( K_p=3,\; K_i=0.5,\; K_d=3 \)

Practical Applications

PID controllers are found in virtually every area of modern technology. The following examples illustrate how the same control principle is applied across very different domains:

  • Cruise control (Tempomat): The setpoint is the desired speed. The controller measures the actual speed and adjusts the throttle. When driving uphill, the error grows – the I component increases the throttle until the speed recovers. The D component prevents abrupt acceleration when cresting the hill.
  • Drone flight stabilization: A quadcopter uses multiple PID loops simultaneously – one for each axis of rotation (roll, pitch, yaw) and one for altitude. The gyroscope provides the process value; the controller adjusts motor speeds dozens of times per second. Without PID control, a drone would be unflyable.
  • Industrial temperature control: In furnaces, extruders, and chemical reactors, temperature must be held within narrow tolerances. The large thermal inertia of these systems makes the I component particularly important for eliminating drift, while the D component reacts to sudden disturbances (e.g., when a furnace door is opened).
  • 3D printer nozzle temperature: The extruder nozzle of a 3D printer is heated to a precise temperature (e.g., 200 °C for PLA). The PID controller in the printer firmware adjusts the heating element to maintain this temperature despite changing heat losses as the nozzle moves.
  • Self-balancing robots (Segway principle): An inverted pendulum system that uses an accelerometer and gyroscope as sensors. The PID controller must react extremely quickly to keep the robot upright – a textbook application where the D component is critical for stability.

Further Resources

For those who wish to explore the topic further:

  • Brian Douglas – Control Systems LecturesYouTube – Excellent video series on control theory, including PID control
  • Åström & Murray: Feedback SystemsFree online textbook (Caltech) – Comprehensive introduction to feedback control
  • PID ControllerWikipedia – Detailed article covering theory, tuning, and applications
  • MATLAB PID TunerMathWorks – Interactive PID tuning tool documentation

Overview

TitlePID Controller
Target AudienceTeachers and Lecturers
FeaturesFull-screen mode
Lossless scaling
Large screens and projectors supported
LicenseMIT