This blog post explains why PID control gains need to be positive. It is important to understand how PID controller works first. The post will consider stability analysis of each control action, i.e. proportional, integral and derivative control individually. Examples and figures are used to demonstrate the result. Tuning of PID controller will be left for a future blog post.

- Proportional controller

Suppose an error system is as follows

where *e* is the error, *A* is the system parameter and *u* is the control input. A proportional controller is given below

The closed loop system of (1) and (2) is

The solution of the ordinary differential equation in (3) is well known and can be represented as

*t _{0}* is the initial time and

*e(t*is the the initial value of the error. Depending on the sign of

_{0})*A-K*in the exponential term, (4) will be exponentially unstable if

_{p}*A-K*is positive and exponentially stable if

_{p}*A-K*is negative.

_{p}For example, if *A-K _{p}=1 * in (3), i.e.

then (4) becomes

For * t _{0}=0, e(0)=1,* (6) becomes

Simulation results of both systems (5) and (7) are given in the plot below

Figure 1 shows the error is unstable due to closed-loop control gain *A-K _{p}> 0*. If

*A-K*is negative, then (3) becomes

_{p}=-1

and (4) becomes

For *t _{0}=0, e(0)=1,* simulation of the systems (8) and (9) are shown as follows

Figure
2 shows the error is stable due to closed-loop control gain * A-K _{p}< 0.
*

It has been demonstrated that the control gain *K _{p}* in (2) needs to be selected such that the closed loop system gain

*A-K*in (3) is negative in order for the closed loop system to be stable.

_{p}< 0*K*therefore needs to be a positive value.

_{p}2. Integral controller

Suppose the controller (2) now has an integral term as below

The closed-loop system (1) and (10) becomes

To analyse the stability of (11), let’s introduce a Lyapunov function

It is easy to see *V > 0* is positive for any non-zero *e(t)*, and a negative value of *V̇ < 0* will ensure *V→ 0* and *e(t)→ 0* eventually. Taking the derivative of (12)

substitute (11) into (13)

For the first term in (14), *2e(t)(A-K _{p})e(t) < 0 * for

*A-K*. It has been shown in previous section that

_{p}< 0*A-K*is required for the solution (4) to converge to zero. We now only look at the second integral term. It follows that if

_{p}< 0*e(0)=0*then

In discrete time the term *-2K _{i}e(s)ė (s) * in (15) can be expressed

where *e(k)* is the value at current time step and *e(k-1)* is the value at the previous time step, *T _{s}* is the simulation discrete step size and is a positive value. The sign of (16) can be found out as follows:

Assume *K _{i} > 0*, then

It has just been shown above that (16) will always be negative when *|e(k)|> |e(k-1)| * or *e(k)* and *e(k-1)* are of different sign. If *|e(k)|< |e(k-1)|*, the error approaches to zero from either positive or negative side. Reformulating (15) there always exists a positive value * Ω _{i}(K_{i})> 0 * for

*K*that

_{i}> 0It has been shown that both terms in (14) are negative, and

Solution of (18) can be presented similarly to (4)

if *A-K _{p}-Ω_{i}(K_{i})t<0 * for

*t=0*, then as time

*t*becomes larger,

*A-K*will become more negative and

_{p}-Ω_{i}(K_{i})t*V→ 0*in (19) and hence

*e(t)→ 0*. It is now clear to see that the integral control gain

*K*is required for the error to be reduced. The integral term minimizes the steady state error as time becomes larger.

_{i}>0A simulation of the closed loop system (11) with *A+K _{p}=-1* and

*K*is shown below

_{i}=-1It is shown in the figure that the closed loop system (11) shows an initial overshoot at 2 seconds and then converges to zero as time becomes larger. Between 8 seconds and 20 seconds the steady state error decreases due to integral control.

3. Differential controller

The controller (10) with an additional differential term is

The closed-loop system (1) with (20) becomes

The derivative of the Lyapunov function

is

Substitute (21) into (23)

We now only analyse the derivative term. It turns out the derivative term with *K _{d}* in (24) can be analysed like (16) but without the integral term in (17). There exists a

*Ω*such that

_{d}(K_{d})>0Compare (25) and (17), the derivative control energy does not increase with time unlike integral control, but it has a larger control gain at the beginning of the control. Figure 4 shows control performance between P, PI and PID control for a step input. How to tune PID for a specific application would require more techniques to achieve desired control performance. A future post will be written to explain that aspect in more detail.

In summary, it has been shown why all PID control gains need to be positive in order to stabilize a system, otherwise the system will be unstable as shown.

**Written by: Xiaoran Han – Project Engineer**

**Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion.**