2

The I in PID (Proportional Integral Derivative) is the sum of the last few previous errors, weighted only by it's gain.

Using error(-1) to mean the previous error, error(-2) to mean the error before that etc... 'I' can be described as:

I = (error(-1) + error(-2) + error(-3) + error(-4) etc...) * I_gain

Why when PID was designed was 'I' not instead designed to slope off in importance into the past, for example:

I = (error(-1) + (error(-2) * 0.9) + (error(-3) * 0.81) + (error(-4) * 0.729) + etc...) * I_gain

edit: reworded

alan2here
  • 3,223
  • 6
  • 37
  • 62
  • 3
    I think this is off-topic here. Try http://math.stackexchange.com/ – CesarGon Mar 20 '11 at 23:02
  • 3
    I think the sum of the last few errors is the integral. Derivative is the change in error, not the sum. Derivative "dampens" the system, if it is too low there is a danger that the system will become unstable, thus your integral will never taper off. – Faken Mar 20 '11 at 23:03
  • Thanks, your right, corrected. Annoyingly it could go in either stack site, I may repost in the maths site if I don't get the answer here. Are you saying that the reason that the integral doesn't weight the errors in decreasing importance into the past is because of the effects of D? – alan2here Mar 20 '11 at 23:14
  • Both the effects of D and P will affect I and vice versa. If your I is not tapering off (ie, the result is not settling to zero) it could be because your P is too large and your D is too small. Large P causes the system to get to zero faster but also causes it to overshoot if your D is not large enough to dampen it. Thus your system is unstable and I will just keep increasing as oscillations get worse and worse. – Faken Mar 20 '11 at 23:27
  • You title and question do not match. What is the question? – phkahler Mar 21 '11 at 00:50
  • Iv'e fixed the title as well now. – alan2here Mar 21 '11 at 00:54
  • I'm not asking about how to make PID work. I'm implementing it at the moment but I'm sure it will work, the question is when PID was designed why did they design 'I' in this way, to be the sum of the last few errors and not instead design 'I' to mean the sum of the last few errors weighted by how previous each error was. – alan2here Mar 21 '11 at 00:57
  • 1
    You're confusing FIR filters with PID controllers. The integral is not weighted at all - it is the sum of all past errors. – phkahler Mar 21 '11 at 00:59
  • I know it is not weighted as I described, it's only weighted by it's gain. I'm asking why it was not designed as I described in the question. – alan2here Mar 21 '11 at 01:03

1 Answers1

3

The integral term is the sum of ALL the past errors. You simply add the error to the "integrator" at each time step. If this needs to be limited, clamp it to a min or max value if it goes out of range. Then copy this accumulated value to your output and add the proportional and derivative terms and clamp the output again if necessary.

The Derivative term is the difference in the present and previous error (the rate of change in the error). P of course is just proportional to the error.

err = reference - new_measurement
I += kI * err
Derivative = err - old_err
output = I - kD * Derivative + kP * err
old_err = err

And there you have it. Limits omitted of course.

Once the controller reaches the reference value, the error will become zero and the integrator will stop changing. Noise will naturally make it bounce around a bit, but it will stay at the steady state value required to meet your objective, while the P and D terms do most of the work to reduce transients.

Notice that in a steady state condition, the I term is the ONLY thing providing any output. If the control has reached the reference and this requires a non-zero output, it is provided solely by the integrator since the error will be zero. If the I term used weighted errors, it would start to decay back to zero and not sustain the output as needed.

BSMP
  • 4,596
  • 8
  • 33
  • 44
phkahler
  • 5,687
  • 1
  • 23
  • 31
  • I didn't think it meant all previous errors, after some number of previous errors you stop counting, for example the previous 20 errors, we have been instructed to use the last 4 errors in our 'I'. – alan2here Mar 21 '11 at 01:24
  • 1
    Who instructed you to do that? – phkahler Mar 21 '11 at 12:24
  • It's not the last 4, I've reasked and it's the last 10 seconds of values (so more like hundreds), but everyone is saying not to have 'I' go back forever as this is not a sensible way of doing PID. – alan2here Mar 21 '11 at 20:32