| name | pid-controller |
| description | PID controller design — transfer function, Ziegler-Nichols tuning, stability margins, root locus, integral windup, anti-windup, discretization, implementation. |
| metadata | {"priority":7,"promptSignals":{"phrases":["PID controller","PID tuning","proportional integral derivative","Ziegler-Nichols","controller gain","integral windup"],"minScore":3}} |
PID Controller Design — Complete Skill
PID Transfer Function
Time domain:
u(t) = K_p [e(t) + (1/T_i)∫e(t)dt + T_d de(t)/dt]
Frequency domain (s-domain):
C(s) = K_p [1 + 1/(T_i s) + T_d s]
= K_p (T_i T_d s² + T_i s + 1) / (T_i s)
Parallel form: C(s) = K_p + K_i/s + K_d s
K_p = proportional gain; K_i = K_p/T_i; K_d = K_p T_d
Ideal derivative (with filter):
C(s) = K_p + K_i/s + K_d s/(τ_f s + 1)
τ_f = T_d/N, N = 5–20 (derivative filter constant; prevents high-freq amplification)
Effect of Each Term
Proportional (K_p): reduces error; too high → overshoot, instability
Integral (K_i): eliminates steady-state error; too high → slow oscillation, windup
Derivative (K_d): dampens overshoot, improves speed; sensitive to noise
Ziegler-Nichols Tuning Methods
Step Response Method (Open-loop)
Apply step to plant; measure S-shaped response
L = apparent dead time (lag); T = time constant (63.2% of response); a = L/T
| Controller | K_p | T_i | T_d |
|---|
| P | T/aT | ∞ | 0 |
| PI | 0.9T/aL | L/0.3 | 0 |
| PID | 1.2T/aL | 2L | 0.5L |
Frequency Response Method (Closed-loop)
Increase K_p until sustained oscillation → K_u (ultimate gain), T_u (period)
| Controller | K_p | T_i | T_d |
|---|
| P | 0.5 K_u | ∞ | 0 |
| PI | 0.45 K_u | T_u/1.2 | 0 |
| PID | 0.6 K_u | T_u/2 | T_u/8 |
Ziegler-Nichols note: aggressive starting point; expect further manual tuning
Stability Margins
Phase margin (PM): PM = 180° + ∠G(jω_gc) at gain crossover (ω where |G|=0 dB)
Desired: PM ≥ 45° (good); PM ≥ 30° (minimum)
Gain margin (GM): GM = 1/|G(jω_pc)| at phase crossover (ω where ∠G = -180°)
Desired: GM ≥ 6 dB (factor of 2); ≥ 12 dB for conservative
Bandwidth: ω_BW ≈ ω_gc for unity feedback system
IMC-Based Tuning (Internal Model Control)
Simple, robust tuning for first-order-plus-dead-time (FOPDT) plants:
G(s) = K_plant × e^(-θs) / (τ s + 1)
IMC-PID (Rivera 1986):
K_p = τ / (K_plant (λ + θ))
T_i = τ
T_d = 0 (for PI); or T_d = θ/2 (for PID approximation)
λ = closed-loop time constant (tuning knob): λ > 0.8θ (stability); λ = 2θ (typical robust)
Increase λ for more robustness (slower); decrease for faster (less robust)
Integral Windup
When actuator saturates, integrator accumulates error → large overshoot on recovery
Back-calculation anti-windup:
u_s = saturated(u)
extra term: K_aw × (u_s - u) added to integrator input
K_aw = 1/T_t where T_t = tracking time constant ≈ √(T_i T_d) or = T_i
Conditional integration:
Freeze integration when actuator saturated
Simple to implement; effective for position control
Derivative Kick
Step change in setpoint causes derivative spike (du/dt → ∞)
Solution: apply derivative only to measurement, not error:
u(t) = K_p e(t) + K_i∫e dt - K_d dy/dt
(Derivative on measurement avoids setpoint bump)
Discretization (Digital Implementation)
Sampling period T_s; rule: T_s < T_i/10 and T_s < T_d/3
Tustin (bilinear) transform: s → 2/T_s × (z-1)/(z+1)
More accurate than Euler; avoids frequency warping
Velocity (incremental) form:
Δu[k] = K_p (e[k]-e[k-1]) + K_i T_s e[k] + K_d/T_s (e[k]-2e[k-1]+e[k-2])
u[k] = u[k-1] + Δu[k]
Benefits: automatic anti-windup; no bumpless transfer issue
Feedforward
Improves setpoint tracking without sacrificing disturbance rejection:
u = C(s) × e + G_ff(s) × setpoint
G_ff = 1/G_plant (approximate plant inverse) for perfect tracking
Practical: G_ff = (τ₁s+1)/(τ₂s+1) lead-lag for smooth feedforward
Output
Provide: K_p, K_i [1/s], K_d [s], PM [deg], GM [dB], bandwidth [Hz], anti-windup method, sampling rate recommendation, closed-loop step response characteristics (overshoot %, settling time).