73  Integral and Derivative Control

In 60 Seconds

Integral control eliminates steady-state error by accumulating past errors over time, but risks integral windup when the actuator saturates. Derivative control reduces overshoot by responding to the rate of change, providing damping that can cut settling time by 40-60% in temperature and motor control applications.

73.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Derive Integral Control Behavior: Explain how integral control accumulates past errors to eliminate steady-state offset
  • Diagnose Integral Windup: Identify windup conditions and implement clamping, back-calculation, or conditional integration
  • Evaluate Derivative Control: Assess how derivative control reduces overshoot through predictive braking action
  • Compare PID Configurations: Contrast P-only, PI, and PID response characteristics for specific system requirements
  • Select Appropriate Configuration: Justify PI vs full PID selection based on sensor noise, process speed, and precision needs

This chapter covers foundational concepts for designing IoT systems at scale. Think of IoT system design like city planning – you need to consider where devices go, how they communicate, where data is stored, and how everything stays secure. Reference architectures and design principles help you create systems that work reliably and can grow over time.

73.2 Integral Control (I)

Diagram showing integral control addition to system with error signal being accumulated over time through integration, multiplied by integral gain Ki to produce output that grows continuously until error reaches zero, eliminating persistent steady-state offset that proportional control alone cannot fix
Figure 73.1: Diagram showing addition of integral control action to eliminate steady-state error by accumulating error over time

The Integral term accumulates error over time and provides control action based on the total accumulated error. This eliminates steady-state error that P-only control cannot handle.

\[ u_i(t) = K_i \cdot \int_{0}^{t} e(\tau) \, d\tau \]

Consider \(K_i = 0.3\) with a persistent 0.5°C error over 60 seconds:

  • Accumulated error: \(\int_0^{60} 0.5 \, dt = 30\) °C·s
  • Integral output: \(u_i = 0.3 \times 30 = 9\) (9% additional power)

Even though P-term only gives \(5 \times 0.5 = 2.5\)% (too weak), the I-term adds 9%, totaling 11.5% — enough to overcome heat loss and eliminate the offset. If error persists another 60s, integral grows to \(0.3 \times 60 = 18\)%, driving error to zero.

Line chart showing integral control response: error starts positive, and as the integral term accumulates the error over time, the controller output steadily increases, driving the measured value up to the setpoint and eliminating the steady-state offset that P-only control leaves behind
Figure 73.2: Integral: accumulates error until steady-state offset eliminated

Integral Control Mechanism: Accumulates error over time. Even small persistent errors grow the integral, increasing control output until error reaches exactly zero. Eliminates steady-state offset that P-only cannot fix.

How Integral Control Works:

  • Accumulates error over time: \(\int e(t) dt\)
  • If error persists (even small error), integral grows
  • Integral keeps increasing until error becomes zero
  • Also called “automatic reset” - resets bias until error eliminated
Analogy: Lane Change with Crosswind (Need for Integral)

Continuing the driving analogy, now add a crosswind (disturbance):

Comparison diagram of P-only versus PI control under a constant crosswind disturbance: P-only settles at an offset below setpoint because its output is too weak to overcome the wind, while PI control accumulates the persistent error and raises output until the car reaches exactly the target lane center with zero steady-state error
Figure 73.3: P-only vs PI: integral eliminates crosswind-caused offset

Integral Term Necessity with Disturbances: P-only control settles with offset when constant disturbance (crosswind) opposes control action. Integral term accumulates persistent error and increases output until exactly compensating for disturbance, achieving zero steady-state error.

P-Only Response to Crosswind:

  • Initial steering (Kp times error) moves car toward target
  • Crosswind counteracts steering
  • Car settles with persistent offset (steady-state error)
  • Driver maintains constant steering, but never reaches center

PI Response to Crosswind:

  • P term provides initial response (Kp times error)
  • Crosswind creates persistent error
  • I term accumulates this error over time
  • Integral output increases until steering overcomes crosswind
  • Car reaches exact center of lane
  • Error becomes zero, integral stops growing

Mathematical Intuition:

The integral accumulates (sums) all past errors:

Time | Error | Proportional | Integral Accumulated | Total Output
-----|-------|-------------|---------------------|-------------
0s   | +3C   | Kp×3 = 1.5  | 0                   | 1.5
1s   | +2C   | Kp×2 = 1.0  | Ki×(3+2) = 0.5      | 1.5
2s   | +1C   | Kp×1 = 0.5  | Ki×(3+2+1) = 0.6    | 1.1
3s   | +1C   | Kp×1 = 0.5  | Ki×(3+2+1+1) = 0.7  | 1.2
4s   | 0C    | Kp×0 = 0    | Ki×(3+2+1+1+0) = 0.7| 0.7
5s   | 0C    | Kp×0 = 0    | Ki×(3+2+1+1+0+0)=0.7| 0.7

Kp = 0.5, Ki = 0.1

Key Observations:

  • Even when P term drops to zero (error = 0), I term maintains output
  • This compensates for disturbances requiring sustained control action
  • Integral prevents steady-state error

Benefits of Adding Integral:

  1. Eliminates steady-state error: System reaches exact set point
  2. Compensates for disturbances: Overcomes constant external forces
  3. Automatic adjustment: No manual reset needed

Cautions with Integral:

  1. Integral Windup: Integral can accumulate excessively during large errors
  2. Slower Response: Can slow down initial response
  3. Overshoot: Can cause overshoot if Ki too large
  4. Requires Careful Tuning: Ki must be chosen carefully
Integral Windup Problem

If a large error persists for a long time (e.g., system startup, actuator saturation), the integral can accumulate to very large values. This is called integral windup.

Consequences:

  • When error finally reverses, huge accumulated integral causes massive overshoot
  • System may oscillate wildly or become unstable

Solutions:

  • Limit integral accumulation (clamping)
  • Reset integral when actuator saturates
  • Anti-windup algorithms in modern controllers

73.3 Derivative Control (D)

Diagram showing derivative control addition to system with error rate of change being calculated, multiplied by derivative gain Kd to produce damping output that opposes rapid changes, reducing overshoot by providing predictive braking action when system approaches setpoint quickly, preventing oscillation
Figure 73.4: Diagram showing addition of derivative control action to reduce overshoot and improve stability by responding to rate of error change

The Derivative term provides control action based on the rate of change of error. It anticipates future error trends and provides damping to prevent overshoot.

\[ u_d(t) = K_d \cdot \frac{de(t)}{dt} \]

With \(K_d = 2.0\), if temperature approaches setpoint rapidly (error drops from 3°C to 1°C in 10 seconds):

  • Rate of change: \(\frac{de}{dt} = \frac{1 - 3}{10} = -0.2\) °C/s
  • Derivative output: \(u_d = 2.0 \times (-0.2) = -0.4\) (reduces power by 0.4%)

When combined with P-term (\(5 \times 1 = 5\)%) and I-term (say 3%), total becomes \(5 + 3 - 0.4 = 7.6\)% instead of 8%. This “braking” prevents overshoot. If approaching slowly (\(-0.05\) °C/s), D contributes only \(-0.1\)%, preserving fast response when safe.

Line chart showing derivative control action: when error decreases rapidly (system approaching setpoint fast), the derivative term produces a negative output that reduces total control action, acting as a predictive brake to prevent overshoot; when error changes slowly the derivative contribution is small
Figure 73.5: Derivative: rate of change provides predictive braking

Derivative Control Mechanism: Measures rate of error change. Rapid error decrease (approaching target fast) produces negative D output, reducing control action preemptively to prevent overshoot. Acts as predictive damping brake.

How Derivative Control Works:

  • Measures how fast error is changing: \(\frac{de}{dt}\)
  • If error decreasing rapidly, derivative is negative
  • Negative derivative reduces control action (anticipates reaching target)
  • Provides damping effect to prevent overshoot
  • Acts as predictive brake
Analogy: High-Speed Lane Change (Need for Derivative)

Now consider changing lanes at high speed where momentum causes overshoot:

Comparison diagram of PI versus PID lane-change control at high speed: PI control without derivative overshoots the target lane due to momentum and then oscillates, while PID control detects rapid error decrease (large negative de/dt) and reduces steering preemptively, achieving smooth arrival at the target lane without overshoot
Figure 73.6: PI vs PID: derivative prevents high-speed overshoot

Derivative Term Prevents Overshoot: PI control without D term overshoots at high speed due to momentum, causing oscillation. PID control’s D term detects rapid approach (large negative de/dt), reduces control action preemptively, achieving smooth arrival without overshoot.

Without Derivative (PI only at high speed):

  1. Large error leads to strong steering (P + I)
  2. Car accelerates toward target lane
  3. Momentum carries car past target (overshoot)
  4. Must steer back (oscillation)
  5. May oscillate several times before settling

With Derivative (PID at high speed):

  1. Large error leads to strong steering (P + I + D)
  2. As car approaches target, error decreases rapidly
  3. Derivative detects rapid error change: \(\frac{de}{dt} < 0\)
  4. Derivative produces negative output, reducing total control
  5. Steering reduced proportionally to approach speed
  6. Car smoothly reaches target without overshoot

Derivative Calculation Example:

Time | Error | Error Change | P Output | I Output | D Output | Total
-----|-------|--------------|----------|----------|----------|------
0s   | +5C   | —            | 2.5      | 0        | 0        | 2.5
1s   | +4C   | -1C/s        | 2.0      | 0.45     | -0.3     | 2.15
2s   | +2C   | -2C/s        | 1.0      | 0.55     | -0.6     | 0.95
3s   | +0.5C | -1.5C/s      | 0.25     | 0.6      | -0.45    | 0.4
4s   | 0C    | -0.5C/s      | 0        | 0.6      | -0.15    | 0.45
5s   | 0C    | 0C/s         | 0        | 0.6      | 0        | 0.6

Kp = 0.5, Ki = 0.05, Kd = 0.3
Error Change = (Current Error - Previous Error) / Δt

Key Observations:

  • When error decreases rapidly (large negative de/dt), D term is negative
  • Negative D term reduces total output, slowing approach
  • As approach slows (de/dt approaches 0), D term reduces to zero
  • D acts as damping, preventing overshoot from P and I

Benefits of Adding Derivative:

  1. Reduces overshoot: Dampens aggressive P and I responses
  2. Improves stability: Prevents oscillations
  3. Faster settling: Reaches steady state more quickly
  4. Better response to changing conditions: Anticipates trends

Cautions with Derivative:

  1. Noise sensitivity: Amplifies high-frequency noise in sensor readings
  2. Difficult to tune: Kd selection is challenging
  3. Rarely used alone: Almost always combined with P and/or I
  4. May prevent reaching target: Excessive Kd can slow response too much

73.4 PID Control Summary

Complete PID control system diagram showing setpoint and measured value feeding into error calculation, error splitting into three parallel control paths (proportional for present error, integral for accumulated past error, derivative for predicted future error), all three terms summing to produce optimal combined control output driving process plant
Figure 73.7: Complete PID control system showing all three control actions working together: P (immediate response), I (eliminates offset), D (reduces overshoot)
Block diagram of complete PID controller showing three parallel signal paths from the error signal: the P path multiplies current error by Kp for immediate response, the I path integrates accumulated error and multiplies by Ki to eliminate offset, the D path differentiates error rate and multiplies by Kd for damping; all three outputs sum to produce the final control signal sent to the plant
Figure 73.8: Complete PID: P (present), I (past), D (future) combined

Complete PID Controller Architecture: Error drives three parallel control actions. P term addresses present error (fast), I term corrects accumulated past error (accuracy), D term anticipates future trends (stability). Combined output creates optimal control signal.

PID Term Summary
Term Reacts To Purpose Issue to Watch
P Current error magnitude Provide proportional response Steady-state error, overshoot
I Accumulated error over time Eliminate steady-state error Integral windup, slow response
D Rate of error change Dampen overshoot, predict future Noise amplification, hard to tune

Simplified Summary:

  • P corrects present error
  • I corrects past accumulated error
  • D corrects future predicted error

Response Comparison:

Step response comparison chart showing three curves: P-only control reaches steady state quickly but with persistent offset below setpoint, PI control eliminates the offset but shows moderate overshoot before settling, and full PID control combines fast response with minimal overshoot and zero steady-state error for optimal performance
Figure 73.9: P vs PI vs PID: performance trade-off comparison

PID Configuration Performance Comparison: P-only provides fast response but leaves steady-state error. PI eliminates error but may overshoot. Full PID combines fast response, zero error, and minimal overshoot for optimal performance.

73.5 Interactive: Integral Windup Visualizer

See how the integral term grows over time and how clamping prevents windup. Adjust the error and Ki to observe accumulation dynamics.

When to Use Each Configuration:

  • P Only: Simple systems, fast response needed, some error acceptable
  • PI: Most common, general-purpose control, steady-state accuracy required
  • PID: High-performance applications, minimal overshoot critical
  • PD: Rare, fast servos with no steady-state error concerns
Common Misconception: “Higher Gains Always Mean Better Control”

The Myth: Many beginners believe that increasing all PID gains (Kp, Ki, Kd) will result in faster, more accurate control. Reality proves otherwise.

Real-World Example: A commercial smart greenhouse ventilation system experienced catastrophic oscillations after technicians “optimized” the temperature controller by doubling all PID gains.

What Happened:

  • Original tuning: Kp=2.0, Ki=0.5, Kd=1.0 led to smooth control, plus-minus 0.3C stability, 5-minute settling time
  • “Optimized” tuning: Kp=4.0, Ki=1.0, Kd=2.0 led to severe oscillations, plus-minus 4C swings, vent motors cycling every 30 seconds
  • Motor damage: $8,500 in burnt-out actuators from excessive cycling (12,000 cycles/day vs. rated 5,000 cycles/day)
  • Crop loss: $45,000 in heat-stressed tomato plants due to temperature instability

Why Aggressive Tuning Fails:

  1. Excessive Kp leads to overshoot and oscillation. Temperature overshoots target by 5-8C, system corrects aggressively in opposite direction, creating sustained oscillation.
  2. Excessive Ki leads to integral windup. During startup, integral accumulates massive value while system heats up slowly. When finally reaching setpoint, huge integral term causes 10C+ overshoot taking 30+ minutes to correct.
  3. Excessive Kd leads to noise amplification. Sensor noise (plus-minus 0.1C measurement variation) gets amplified by derivative term, causing actuator “chatter” - rapid on/off cycling that wears mechanical components.

The Truth About PID Tuning:

  • Balanced gains create stable control with acceptable response time
  • Conservative tuning (slightly slower) is more robust to disturbances and noise
  • Field conditions (sensor noise, actuator delays, thermal lag) limit achievable performance
  • Diminishing returns: Gains beyond optimal provide marginal speed improvement but dramatic stability degradation

Correct Approach:

  • Start with conservative gains (low values)
  • Gradually increase Kp until seeing slight overshoot
  • Add Ki slowly to eliminate steady-state error
  • Add minimal Kd only if overshoot remains problematic
  • Accept that 10-15% overshoot with 2-5 minute settling time is often optimal for real systems

Measured Impact (from greenhouse case study): - Reverting to original conservative tuning reduced motor cycling from 12,000 to 400 cycles/day (30x reduction) - Temperature stability improved from plus-minus 4C to plus-minus 0.3C (13x improvement) - System operated reliably for 3+ years with no further actuator failures

Key Concepts

  • Integral Action: The PID mechanism that accumulates past error to eliminate steady-state offset — without integral, a proportional controller always has residual error equal to the disturbance divided by the open-loop gain
  • Integrator Windup: The condition where the integral term grows without bound during actuator saturation because the controller cannot reduce error — prevented by anti-windup strategies that clamp or back-calculate the integral
  • Integral Time Constant (Ti): The equivalent integral tuning parameter expressing how long the integral takes to contribute a correction equal to the proportional term for a constant error — smaller Ti means faster integral action
  • Derivative Action: The PID mechanism that responds to the rate of error change, providing predictive damping before the process variable reaches the setpoint — reduces overshoot at the cost of noise amplification
  • Derivative Time Constant (Td): The equivalent derivative tuning parameter expressing how far ahead the derivative predicts based on current rate of change — larger Td gives stronger predictive damping but amplifies more noise
  • Derivative Kick: The large spike in controller output caused by applying differentiation to the error signal when the setpoint steps — eliminated by differentiating only the process variable measurement instead of the error
  • Noise Sensitivity: The tendency of the derivative term to amplify high-frequency sensor measurement noise into large, rapid control output changes — mitigated by first-order low-pass filtering of the derivative input

Common Pitfalls

Adding integral action to processes that already behave like integrators (e.g., liquid level with inlet flow controlled, position control). Double integration creates 180° phase lag at all frequencies, making any feedback gain potentially unstable. Use PI carefully and check phase margins explicitly.

Differentiating raw sensor measurements without a low-pass filter. A 12-bit ADC with 1 LSB (0.8 mV) noise at 100 Hz sampling produces derivative noise of 0.08 V/s — multiplied by Kd, this creates actuator chatter. Filter derivative input with a time constant of Td/5 to Td/10.

Setting Kd=0 on all PIDs to avoid noise amplification, sacrificing the damping benefit of derivative action. Instead of disabling, implement proper derivative filtering. A well-filtered derivative term dramatically reduces overshoot and settling time without noise amplification.

Treating output clamping (preventing the final PID output from exceeding actuator limits) as anti-windup. Clamping the output does not prevent the integral accumulator from continuing to grow. Anti-windup must separately clamp or reset the integrator state itself.

73.7 Summary

This chapter covered the Integral and Derivative components of PID control:

Key Takeaways:

  1. Integral Control (I): Accumulates error over time to eliminate steady-state error that P-only control cannot address

  2. Integral Windup: A dangerous condition where the integral accumulates excessively during prolonged errors - requires anti-windup mechanisms

  3. Derivative Control (D): Responds to the rate of error change, providing predictive braking to reduce overshoot

  4. D Term Limitations: Sensitive to sensor noise and difficult to tune - often omitted in favor of PI control

  5. Configuration Selection: PI is most common for general-purpose control; full PID only needed when minimal overshoot is critical

  6. Tuning Philosophy: Conservative, balanced gains outperform aggressive tuning in real-world conditions

73.8 What’s Next?

In the next chapter, we’ll explore hands-on PID implementation with labs, Arduino/ESP32 code examples, and production-ready frameworks.

Continue to PID Implementation and Labs

Previous Current Next
PID Control Fundamentals Integral and Derivative Control PID Implementation and Labs