PID

PID Controller

Continuous
运行在线示例 免费 · 无需注册 · 直接在浏览器中运行

PIDController 方块实现了用于闭环反馈控制的标准比例-积分-微分(PID)控制器。它结合了三个并联的控制项以精确调节过程:比例作用用于快速响应,积分作用用于消除稳态误差,微分作用用于阻尼超调。

视频教程

数学模型

u(t)=Kp e(t)+Ki∫0te(τ) dτ+Kd ddte(t)u(t) = K_p \, e(t) + K_i \int_{0}^{t} e(\tau) \, d\tau + K_d \, \frac{d}{dt} e(t)

离散数值近似:

I[n] = I[n-1] + Ki × e[n] × Δt                              (前向欧拉法)
D[n] = (Kd × N × (e[n] - e[n-1]) + D[n-1]) / (1 + N × Δt)  (后向欧拉滤波)

微分滤波器的传递函数为 Kd × N × s / (s + N),其中 NN 为滤波系数。该低通滤波器可防止测量噪声被过度放大。较大的 NN 意味着更少的滤波(N→∞N \to \infty 退化为纯微分环节)。常用取值范围为 N=10–100N = 10\text{–}100。

输入与输出

Direction ID Label 类型 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

参数

参数 Label 类型 默认值 描述
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

使用示例

烤箱温度控制

设定值 (200°C) → [+]
                   \
测量温度       → [-] → 误差 → PIDController (Kp: 2, Ki: 0.05, Kd: 1) → 加热执行器

伺服电机位置控制

针对阶跃位置目标,引入 Kd>0K_d > 0 能有效防止电机越过目标位置并在其附近发生震荡。

说明与最佳实践

  • 工业基石: 工业中绝大多数连续控制回路均基于 PID 控制原理构建。
  • 参数整定 (Tuning): 可使用属性面板中的 Auto-Tune 按钮在您的超调上限和安全裕度内自动计算 Kp,Ki,KdK_p, K_i, K_d,也可先只调 KpK_p,再依次加入 KiK_i 和 KdK_d。
  • 仿真步长: 各项增益的计算均在内部根据仿真步长 Δt\Delta t 进行了归一化,与时间步长无关。

常见工程问题解答 (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 KtK_t proportional to the difference between demanded and saturated control output (u−usatu - u_{sat}). 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 D(s)=Kd⋅sD(s) = K_d \cdot s has infinite high-frequency gain, amplifying sensor noise and causing actuator chatter. BlockWerk implements a real, band-limited derivative filter: D(s)=Kd⋅s1+sKdND(s) = \frac{K_d \cdot s}{1 + s \frac{K_d}{N}}. The parameter NN (typically chosen between 8 and 20) places a low-pass roll-off pole at frequency ωp=N/(Kd/Kp)\omega_p = N / (K_d / K_p) rad/s, providing derivative phase lead at control frequencies while attenuating high-frequency noise.

相关模块