PIDController Block
Standard PID (Proportional-Integral-Derivative) controller for closed-loop control
Open PIDController in BlockWerk →Description
The PID Controller block implements a standard Proportional-Integral-Derivative controller for closed-loop feedback control. It combines three control terms to regulate a process: proportional correction for immediate response, integral for eliminating steady-state error, and derivative for damping overshoot.
Mathematical Model
P term: p(t) = Kp × e(t)
I term: i(t) = Ki × ∫₀ᵗ e(τ) dτ
D term: d(t) = Kd × N × s/(s+N) × e(t) (filtered derivative)
Output: u(t) = p(t) + i(t) + d(t)
Saturated: u = clamp(u, u_min, u_max)
Discrete approximation:
I[n] = I[n-1] + Ki × e[n] × Δt (Forward Euler)
D[n] = (Kd × N × (e[n] - e[n-1]) + D[n-1]) / (1 + N × Δt) (Backward Euler filter)
The derivative filter transfer function is Kd × N × s / (s + N), where N is the filter coefficient. This low-pass filters the derivative action to reduce noise amplification. Higher N means less filtering (N → ∞ gives pure derivative). Typical values: N = 10–100.
Parameters
proportionalGain (Kp)
Proportional gain. Controls immediate response to error.
- Type: number
- Symbol: Kp
- Range: 0 to 10000
- Default: 1.0
- Tooltip: Controls immediate response to error
integralGain (Ki)
Integral gain. Eliminates steady-state error by accumulating error over time.
- Type: number
- Symbol: Ki
- Range: 0 to 1000
- Default: 0.1
- Tooltip: Eliminates steady-state error over time
derivativeGain (Kd)
Derivative gain. Dampens oscillations by responding to error rate of change.
- Type: number
- Symbol: Kd
- Range: 0 to 1000
- Default: 0.0
- Tooltip: Dampens oscillations by responding to error rate of change
filterCoefficient (N)
Derivative filter coefficient. Controls the cutoff frequency of the derivative low-pass filter.
- Type: number
- Symbol: N
- Range: 1 to 10000
- Default: 100
- Tooltip: Derivative filter cutoff frequency. Higher = less filtering
saturationMin
Lower output limit for anti-windup protection.
- Type: number
- Default: -10
- Tooltip: Lower output limit for anti-windup protection
saturationMax
Upper output limit for anti-windup protection.
- Type: number
- Default: 10
- Tooltip: Upper output limit for anti-windup protection
reset (optional)
Reset trigger. Set > 0 to reset the controller state.
- Type: number
- Required: false
Anti-Windup Behavior
The anti-windup mechanism prevents integral accumulation when the output would saturate:
- Before updating the integral, a candidate output is computed with the new integral value
- If this candidate output would exceed the saturation limits AND the error drives it further into saturation, the integral update is blocked
- If the error drives the output *away* from saturation (unwinding), integration is always allowed
- This ensures fast recovery when the setpoint changes direction
Examples
Temperature Control (1 second)
Setpoint = 50°C, measured temperature ramps from 20°C. PID controller outputs heating signal, reducing error over time.
Motor Speed Regulation
Reference speed vs measured speed error fed to PID. Output drives motor command signal.
Remarks
- Tuning: Start with Kp only (Ki=0, Kd=0), tune P for good response, add I to remove offset, add D for stability
- Anti-Windup: Uses conditional integration — integral only accumulates when doing so would not cause or worsen saturation
- Derivative Filter: The filtered derivative avoids noise amplification inherent in pure differentiation
- Sample Rate: All gains work correctly independent of simulation sample time (Δt is handled internally)
- Error Input: Connect (reference - measured) or similar error signal
- Classic Control: Foundation for most industrial feedback systems
See Also
- Derivative: D-term computation
- Integrator: I-term alternative
- Saturation: Output limiting
- Subtraction: Error signal generation (reference - measured)