Limiting the integral to a time window in PID controller

Would it make sense to integrate e(t) from t - c to t instead of 0 to t for the integral part of the PID controller? What are the most common deviation from classic PID controller definition?

Any question that asks "would it make sense" in control systems has the answer "that depends on your plant".

In the case of a limited time horizon integrator, you're turning your integrator from something that has infinite gain at DC into (essentially) a low-pass filter. You lose the ability to completely cancel out a constant disturbance.

I think that there are some process-control methodologies that use a finite-horizon integrator to enhance stability, but I don't know.

A similar method is to implement a so-called "leaky integrator", i.e. a single-pole low-pass filter with DC gain equal to the reciprocal of its bandwidth: $$H(s)=\frac{1}{s + \omega_0}$$. The leaky integrator "looks" like an integrator at frequencies above $$\omega_0$$, but has a bounded response.

I am outside of the area of control theory and PID design, but I came with the exact same question as you. To be precise, in classical PID design theory, the formula give is:

So the question I had was to consider a process that went on for a very long time, with multiple changes of the error. The central integral, which measured from t = 0, may be extremely large regardless of the fact that the current error, e(t), is zero. Most of the modelling situations I've seen justifying the formula have been very simple. Here is a good one.

The most sensible approach, as you say, is to integrate within a window, rather than from t = 0.

Frustratingly I have not seen a clear answer to your question, but I think this falls under the category of integral windup. There is another good reference on this here. One of the recommendations is that in general, your integral term should not always be 'on':

In this latter case, it is desirable to zero the integrator every time the error is zero or when the error changes sign. A convenient and robust method to determine when the error changes sign or is equal to zero is to multiply the current error by the previous error. (The previous error would be available if a derivative term is also being used.) If the product is zero or negative then the integrator should be zeroed.

I have also seen an ad-hoc fix of this via the post here.

I used a running sum for my error, but with the current sum cut down by a % each loop, so that the more recent error has more “weight”. You also get the advantage of not having to keep and manage an error array for a time window.

// Integral control
Integral_Sum = (Integral_Sum *995) / 1000 + Err;
Integral_Counter = (Integral_Counter *995) / 1000 + 1;

Iout = Ki * (Integral_Sum / Integral_Counter);


Using this, every loop the current sum and number of sums is multiplied by 0.995, or cut down a half a percent, then the current sum is added. The average error of the old sum stays the same since the count is reduced too. The current sum gets added while all the old sums get repeatedly reduced.

Sums from 38 loops (1 second) ago to now make up 17% of the running sum.
0.995^38 = 0.827

Sums from 114 loops (3 seconds) ago to now make up 43% of the running sum.
0.995^114 = 0.565

Sums from 191 loops (5 seconds) ago to now make up 62% of the running sum.
0.995^191 = 0.384

Sums from 382 loops (10 seconds) ago make up 85% of the running sum.
0.995^382 = 0.147

Sums from 763 loops (20 seconds) ago make up 98% of the running sum.
0.995^763 = 0.022


You can change the 0.995 to make your running sum more recent or keep older sums more important.

I haven’t seen this online anywhere, I don’t know what it’s called or if it even works yet, but it made sense to me. If anyone sees anything wrong with it let me know.

None of these are solutions, but I think the lesson is that the classical PID formula is largely applicable only for the specific case of a very simple scenario. In anything that is run for long time, where the integral term may be doing funny things, people will have to implement some way of limiting the time window.

• As long as the loop remains closed, a loop with integral action can run forever. Where you may want to limit integral action would be if you don't want the integrator to wind up during start-up or fault conditions -- but integrator anti-windup is well treated in the practical literature, and is usually implemented as a nonlinearity in the controller rather than by limiting the integrator's horizon. (Being a nonlinearity, integrator anti-windup doesn't get introduced into academic discussions until you're well advanced -- no matter that it's a practical necessity). Jul 28, 2022 at 15:28