I don't understand Integral part of PID controller

user561838 picture user561838 · Nov 24, 2012 · Viewed 16.6k times · Source

I dont understand integral part of PID controller. Let's assume this pseudocode from Wikipedia:

previous_error = 0
integral = 0 
start:
  error = setpoint - measured_value
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error
  wait(dt)
  goto start

Integral is set to zero in the beginning. And then in the loop it's integrating the error over the time. When I make a (positive) change in measured value or setpoint, the error will become positive and integral will "eat" the values over the time (from the beginning). But what I dont understand is, when error stabilizes back to zero, the integral part will still have some value (integrated errors over time) and will still contribute to the output value of controller, but it should not.

Can somebody explain me that please?

Answer

Dave X picture Dave X · Jun 9, 2014

Think of the output at steady state... You want the measured_value to be setpoint, the error to be zero, and the output to be whatever it takes to hold the process steady at the measured value. (Could be zero in some cases, but the output may not always need to be zero -- e.g.: you need a heater set to mark 6.5 to keep a room at 72F.)

If the error is zero, then the proportional error term doesn't contribute anything to the output.

If the process is at steady state, then the error-previous_error is zero, and the derivative term contributes nothing.

If the output is the appropriate setting that is holding the process at steady state, then the integral term has to be the sole term providing the output value. It has accumulated the proper memory of the errors, as measured in measurement units times the observation times, that can be converted into output units by the Ki term, which is in units of outputUnits/(error*measurementTime).

As a thermostat example, if the output is in the 0-11 units on the knob of an electric heater in a room, and you are measuring the degrees F in the room versus a setpoint of 72F every 1 minute, then the integral sums up the degreesFtooCold*minute that you've been recording, and the Ki term would convert the sum of the observed errors into the units on the dial.

It is perfectly fine and expected for the integral to be non-zero at steady state.