73 Integral and Derivative Control
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
For Beginners: Integral and Derivative Control
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)
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 \]
Putting Numbers to It
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.
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
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:
- Eliminates steady-state error: System reaches exact set point
- Compensates for disturbances: Overcomes constant external forces
- Automatic adjustment: No manual reset needed
Cautions with Integral:
- Integral Windup: Integral can accumulate excessively during large errors
- Slower Response: Can slow down initial response
- Overshoot: Can cause overshoot if Ki too large
- Requires Careful Tuning: Ki must be chosen carefully
73.3 Derivative Control (D)
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} \]
Putting Numbers to It
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.
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
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:
- Reduces overshoot: Dampens aggressive P and I responses
- Improves stability: Prevents oscillations
- Faster settling: Reaches steady state more quickly
- Better response to changing conditions: Anticipates trends
Cautions with Derivative:
- Noise sensitivity: Amplifies high-frequency noise in sensor readings
- Difficult to tune: Kd selection is challenging
- Rarely used alone: Almost always combined with P and/or I
- May prevent reaching target: Excessive Kd can slow response too much
73.4 PID Control Summary
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.
Response 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
73.6 Visual Reference Gallery
Visual: Feedback System with Example
Visual: Drone Flight Control System
Visual: PID Derivative Action
For Kids: Meet the Sensor Squad!
Integral and Derivative are like having a memory and a crystal ball!
73.6.1 The Sensor Squad Adventure: The Balloon Height Challenge
The Sensor Squad was flying a drone-balloon at a science fair. They had to keep it at EXACTLY 2 meters high – not higher, not lower!
Sammy the Sensor used a distance sensor to check the balloon’s height. Max the Microcontroller controlled the fan that pushed the balloon up.
At first, Max only used P control (the “right now” helper). When the balloon was at 1.5 meters, P said “blow harder!” When it reached 1.9 meters, P said “blow a little.” But a breeze kept pushing the balloon down, and it always hovered at 1.8 meters – close but never quite 2 meters!
“We need I control – the memory helper!” said Lila the LED. “I’ll remember that we’ve been 0.2 meters too low for a LONG time. That means we need MORE fan power!” The I term kept adding up all those tiny errors. Slowly, the extra power pushed the balloon up to exactly 2 meters!
But then a gust of wind pushed the balloon up FAST toward 2.5 meters! “SLOW DOWN!” shouted D control – the future predictor. “The balloon is rising too quickly! Cut the fan power NOW before we go too high!” D saw the balloon speeding upward and applied the brakes just in time.
“P watches the present, I remembers the past, D predicts the future,” sang Bella the Battery. “Together, they’re the PERFECT team!”
73.6.2 Key Words for Kids
| Word | What It Means |
|---|---|
| Integral (I) | The “memory” – adds up all past mistakes to fix long-term problems |
| Derivative (D) | The “predictor” – sees how fast things are changing and acts early |
| Windup | When the memory gets TOO full and overreacts (like eating too much candy!) |
| Damping | Slowing things down gently so they don’t bounce around |
73.6.3 Try This at Home!
The Paper Airplane Challenge: Throw a paper airplane and try to make it land on a target. Your first throw shows P (aim based on distance). If you keep missing left, your brain’s I term says “aim more right next time.” If the plane is diving fast, your D term says “angle it up!” You naturally use PID every time you throw!
Worked Example: Preventing Integral Windup in an Oven Controller
Scenario: You are building a smart oven controller that heats from room temperature (20°C) to setpoint (180°C). The oven uses a 2 kW heating element (max capacity) controlled by PWM. You implement PI control with Kp = 5 and Ki = 0.1. The oven has a 10-minute thermal time constant.
Step 1: Calculate Expected Behavior Without Anti-Windup
During the initial 10-minute warm-up period:
- Error over time: Starts at 160°C (180 - 20), drops to 0°C as oven heats
- Integral accumulation: ∫(160 to 0) over 10 minutes = approximately 48,000 °C-seconds (area under error curve)
- Integral output: Ki × 48,000 = 0.1 × 48,000 = 4,800 (output units)
- Proportional output (when error reaches 0): Kp × 0 = 0
Problem: At t = 10 minutes, oven reaches 180°C (error = 0), but integral term commands 4,800 units of heating. Even though the heater is already saturated at 100%, the integral keeps growing because error was positive for 10 minutes. When error finally reaches 0, the controller maintains 100% heat due to the massive accumulated integral.
Result without anti-windup:
- Oven overshoots to 210°C (30°C overshoot)
- Takes 15 additional minutes to cool back to 180°C
- Overshoots in opposite direction to 160°C
- Oscillates for 40+ minutes before settling
- Total settling time: 50+ minutes
Step 2: Implement Anti-Windup Clamping
Method 1: Conditional Integration (stop integrating when saturated)
float integral = 0;
float output_limit = 100; // Max heater PWM percentage
float pid_output = kp * error;
// Only integrate if output is not saturated
if (pid_output < output_limit && pid_output > 0) {
integral += error * dt;
}
float i_output = ki * integral;
float total_output = pid_output + i_output;
total_output = constrain(total_output, 0, output_limit);Method 2: Back-Calculation (reduce integral when saturating)
float integral = 0;
float output_limit = 100;
float p_output = kp * error;
float i_output = ki * integral;
float total_output = p_output + i_output;
// Calculate how much we're saturating
float saturation_error = total_output - output_limit;
// If saturating, reduce integral
if (saturation_error > 0) {
integral -= saturation_error / ki; // Back-calculate to unsaturate
i_output = ki * integral;
total_output = output_limit;
}
total_output = constrain(total_output, 0, output_limit);Method 3: Integral Clamping (limit integral accumulation directly)
float integral = 0;
float integral_limit = 1000; // Cap integral at ±1000
integral += error * dt;
// Clamp integral to prevent excessive accumulation
integral = constrain(integral, -integral_limit, integral_limit);
float p_output = kp * error;
float i_output = ki * integral;
float total_output = constrain(p_output + i_output, 0, 100);Step 3: Compare Results
| Metric | No Anti-Windup | Method 1 (Conditional) | Method 2 (Back-Calc) | Method 3 (Clamping) |
|---|---|---|---|---|
| Peak overshoot | 210°C (+30°C) | 185°C (+5°C) | 183°C (+3°C) | 186°C (+6°C) |
| Settling time | 50+ minutes | 15 minutes | 12 minutes | 16 minutes |
| Steady-state error | 0°C (eventually) | 0°C | 0°C | 0°C |
| Complexity | Simple (broken) | Easy | Moderate | Easy |
Step 4: Calculate Integral Limit for Method 3
Rule of thumb: Integral limit should produce enough output to overcome the largest expected sustained disturbance.
For the oven: - At steady-state 180°C, heater runs at approximately 40% to compensate for heat loss - Maximum expected disturbance: Door opened for 30 seconds (drops 10°C) - Integral needed: 40 / Ki = 40 / 0.1 = 400 units to maintain steady-state - Integral limit: Set to 2-3× steady-state need = 1,000 units (allows disturbance compensation plus margin)
Result with Method 2 (Back-Calculation):
- Oven reaches 180°C in 10 minutes
- Overshoots by only 3°C to 183°C
- Returns to 180°C within 2 minutes
- Total settling time: 12 minutes (4× faster than without anti-windup)
- No oscillation
Key lesson: Integral windup occurs during any prolonged saturation period (startup, setpoint change, large disturbance). Always implement anti-windup protection when using the integral term. Back-calculation (Method 2) typically gives the best performance, but simple clamping (Method 3) is easier to implement and works well for most applications.
Key Takeaway
The Integral term is the “memory” of PID control – it accumulates past errors and keeps increasing its output until the error reaches exactly zero, which is why PI control eliminates steady-state offset that P-only cannot fix. The Derivative term is the “predictor” – it detects how fast error is changing and applies braking to prevent overshoot. The biggest practical danger is integral windup (when the integral accumulates excessively during actuator saturation), solved by anti-windup clamping. For most IoT applications, PI control (no D) is the best starting point because derivative amplifies sensor noise.
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
1. Applying Integration to Unstable or Near-Integrating Processes
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.
2. Not Filtering the Derivative Input
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.
3. Disabling Derivative Entirely to Avoid Noise
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.
4. Confusing Integral Windup with Integral Saturation
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:
Integral Control (I): Accumulates error over time to eliminate steady-state error that P-only control cannot address
Integral Windup: A dangerous condition where the integral accumulates excessively during prolonged errors - requires anti-windup mechanisms
Derivative Control (D): Responds to the rate of error change, providing predictive braking to reduce overshoot
D Term Limitations: Sensitive to sensor noise and difficult to tune - often omitted in favor of PI control
Configuration Selection: PI is most common for general-purpose control; full PID only needed when minimal overshoot is critical
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 |