Vaclav Kosar's face photo
Vaclav Kosar
Software, Machine Learning, & Business

PID Controller: A Simple Control Loop Mechanism

Proportional–integral–derivative controller calculates feedback to reduce the error in the next step.

When to use PID controller?

  • measured value (process variable) is a time series
  • ideal value (setpoint) is known
  • can correct via a feedback in the next steps
  • tuning (training) data is available
  • cannot model of the process
  • in non-linear systems may not work
  • example: cruise control
    • process variable = speed
    • setpoint = ideal speed
    • error = ideal speed - actual speed
    • feedback = gas pedal

What is PID controller?

  • is sometimes called three-term controller
  • tool to stay close to the ideal (control loop mechanism)
  • uses distance from setpoint (error) to produce feedback
    • error = setpoint - process variable
  • defined as sum of 3 terms:
    • proportional term
      • current error
      • corrects for error in the previous step
    • integral term
      • sum of errors till now
      • corrects for error in the same direction in the past
    • derivative
      • current derivative of the error
      • can cause instability and not used often
      • or low pass filtering
      • corrects for sudden change in error
  • mathematical form:
    • error: \( e(t) \)
    • proportional coefficient: \( K_p \)
    • integral coefficient: \( K_i \)
    • derivative coefficient: \( K_d \)
    • time: \( t \)
    • feedback value (control function): \( u(t) \)
    • equation: \( u(t) = K_p e(t) + K_i \int_0^t e(t) dt + K_d \frac{de(t)}{dt} \)

Demo

  • grey dots represent setpoint
    • here: constantly zero
  • blue represents original process variable
    • uncontrolled process variable
  • red represents process variable after corrective feedback
    • here: process variable minus feedback
  • try changing the input function
  • Find the demo source below

  sine input function
Kp:
Kd:
Ki:

Self-tuning PID using Kalman filter

  • Kalman filter uses linear relationship between measured values
  • to estimate true values and uncertainty
  • in the paper relationship between the PID parameters defines the Kalman filter tuning

Demo Source Code

Created on 21 May 2021.

Let's connect





Privacy Policy How many days left in this quarter? Twitter Bullet Points to Copy & Paste