PID Controller
ContinuousThe PIDController block implements an industrial-grade continuous-time Proportional-Integral-Derivative feedback controller. It combines immediate error correction (proportional action), steady-state offset elimination (integral action), and anticipatory damping of error transients (derivative action with first-order high-frequency filtering). The block includes integrated anti-windup clamping, configurable parallel or ideal series topologies, optional individual component output ports, and an external reset port for bumpless initialization.
Video tutorial
Mathematical Model
In the standard parallel formulation, the continuous Laplace domain transfer function relating error to control command is:
where is kp, is ki, is kd, and is the derivative filter coefficient (n).
In the time domain, the controller is realized using two continuous ODE states: an integrator state and a filtered derivative state :
The raw unsaturating control signal is:
The final output is clamped between saturation bounds:
When the output saturates (), the integrator state is clamped ( if ), preventing integrator windup and long recovery delays.
In series (ideal) form (form = "series"), the controller parameters relate via interaction terms: .
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | error |
Error | number | Required |
| → In | reset |
Reset | number | Optional |
| ← Out | out |
Output | number | Output |
| ← Out | p |
P | number | Output |
| ← Out | i |
I | number | Output |
| ← Out | d |
D | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
kp |
Proportional Gain (Kp) | number | 1 |
Controls immediate response to error |
ki |
Integral Gain (Ki) | number | 0.1 |
Eliminates steady-state error over time |
kd |
Derivative Gain (Kd) | number | 0.1 |
Dampens oscillations by responding to error rate of change |
n |
Filter Coefficient (N) | number | 100 |
Derivative filter cutoff frequency. Higher = less filtering |
form |
PID Form | select | parallel |
Parallel: u = Kp·e + Ki·∫e + Kd·de/dt. Series: u = Kp·(1 + 1/(Ti·s) + Td·s)·e |
min |
Saturation Min | number | -1000000000000000 |
Lower output limit for anti-windup protection |
max |
Saturation Max | number | 1000000000000000 |
Upper output limit for anti-windup protection |
showComponents |
Show P/I/D Outputs | boolean | false |
Expose individual Proportional, Integral, and Derivative term outputs |
Usage Examples
Example 1: Closed-Loop DC Motor Speed Control with Anti-Windup
Regulating motor shaft angular velocity under fluctuating mechanical loads. Configuring kp = 2.5, ki = 8.0, kd = 0.05, and n = 150 with output limits min = -24.0 V and max = 24.0 V. In response to a 1000 RPM step command, the controller delivers maximum initial voltage to accelerate the armature without integrator over-accumulation, settling cleanly within with zero steady-state error.
Example 2: Thermal Heat Exchanger Temperature Regulation
Controlling temperature in a fluid heat exchanger. Because thermal systems exhibit large time constants and sensor noise, configuring kp = 1.2, ki = 0.02, kd = 10.0, and n = 10 with limits min = 0.0% and max = 100.0% (valve position). The low filter coefficient filters out high-frequency thermocouple noise while derivative lead action anticipates slow thermal drift.
Remarks & Best Practices
- Anti-Windup Protection: Clamping the output limits automatically stops integrator accumulation whenever an actuator saturates, preventing huge overshoot transients when returning to the linear operating region.
- Derivative Noise Filtering: Pure mathematical differentiation () amplifies high-frequency measurement noise infinitely. The parameter caps derivative gain to at high frequencies, ensuring physical stability.
- Continuous State Integration: Formulated with continuous ODE states in Rust/WASM, enabling compatibility with both explicit (RK4, RK45) and stiff implicit (TR-BDF2) numerical simulation solvers.
- External Reset and Mode Switching: While the optional
resetinput is high () the integrator is held at zero, so the I term reads zero and the block acts as a PD controller. Releasing the reset restarts integration from zero. The derivative filter keeps tracking the error throughout, so neither edge of the reset produces a derivative kick.
Frequently Asked Questions (FAQ)
Q: How does PID anti-windup clamping work and when should I use back-calculation?
Clamping (conditional integration) halts integration whenever the actuator output saturates AND the control error has the same sign as the saturated output. This prevents the integrator state from accumulating error that cannot be physically actuated. Back-calculation continuously discharges the integrator state via a feedback gain proportional to the difference between demanded and saturated control output (). Clamping is ideal for hard physical limits (valves, PWM duty cycle) to eliminate severe overshoot upon setpoint recovery.
Q: What is the derivative filter coefficient N in the PID block?
An ideal derivative term has infinite high-frequency gain, amplifying sensor noise and causing actuator chatter. BlockWerk implements a real, band-limited derivative filter: . The parameter (typically chosen between 8 and 20) places a low-pass roll-off pole at frequency rad/s, providing derivative phase lead at control frequencies while attenuating high-frequency noise.
Related Components
- Online PID Simulator & Tuner: Free browser-based PID simulator with live step response, Bode margins and auto-tuning.
- Integrator: Continuous-time state accumulation.
- Derivative: Filtered differentiator ().
- Saturation: Clamps signals to defined lower and upper bounds.
- SecondOrderSystem: Second-order dynamic plant model.