Skip to content
UPEEC

PID Controllers

Proportional, integral and derivative actions combined — the most widely used controller in industry.

Intermediate
Comments 0

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

  • P — reacts to the present error; alone it leaves a steady-state error.
  • I — removes steady-state error; too much causes overshoot and oscillation.
  • D — reacts to the rate of change, adding damping; sensitive to noise (filter it).
float pid_update(PID *c, float setpoint, float measured, float dt) {
    float error = setpoint - measured;
    c->integral += error * dt;
    if (c->integral > c->i_max) c->integral = c->i_max;      // anti-windup clamp
    if (c->integral < -c->i_max) c->integral = -c->i_max;
    float derivative = (error - c->prev_error) / dt;
    c->prev_error = error;
    return c->kp * error + c->ki * c->integral + c->kd * derivative;
}

Tuning: manual (raise KpK_p until it oscillates, back off, then add KiK_i and KdK_d), Ziegler–Nichols or auto-tune. Implement anti-windup whenever the actuator can saturate.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.