The aim of this post is to explain and demonstrate how to calculate a simple PI controller for a first-order system. Let’s assume that the system is given by its transfer function G. The closed loop system is given by the following diagram:

C is the system controller we'll design in the following.

The transfer function of the closed-loop system is given by:

$$ \frac{y}{y_c} = \frac {CG}{1+CG} $$

as \(G\) is assumed to be a first-order system, its equation is given by:

$$ G=\frac{b}{z-a} = \frac{b} { z-e^{-\Delta/\tau} } $$

where \( \Delta \) is the sampling time, and \( \tau \) the time constant of the open loop system.

\( C \) is the PI controller, its equation is given by:

$$ C=K . \frac{z-a}{z-1} $$

The transfer function of the closed loop system is now given by:

$$ \frac{y}{y_c} = \frac { K \frac{z-a}{z-1} \frac{b}{z-a} }{1+ K \frac{z-a}{z-1} \frac{b}{z-a}} $$

Previous equation can be simplified:

$$ \frac{y}{y_c} = \frac { K \frac{b}{z-1} }{1+ K \frac{b}{z-1} } $$

The new transfer function is given by:

$$ \frac{y}{y_c} = \frac { Kb }{ z -1 + Kb } $$

Let's consider the response of the closed loop system when the input is a unity step ( \( \frac{z}{z-1} \) ):

$$ y(z) = \frac { zKb }{ (z -1 + Kb)(z-1) } $$

According to the final value theorem for Z-transforms, the static gain of the system is given by :

$$ \lim\limits_{z \to 1} (z-1).y(z) = \lim\limits_{z \to 1} \frac { zKb(z-1) }{ (z -1 + Kb)(z-1) } = \lim\limits_{z \to 1} \frac { zKb }{ (z -1 + Kb) } = 1 $$

The static gain of the system is equal to 1, the static error will be equal to zero.

The closed loop system is also a first-order :

$$ \frac{y}{y_c} = \frac { Kb }{ z -1 + Kb } = \frac { Kb }{ z - e^{-\Delta/\tau_c} }$$

where \( \Delta \) is the sampling time, and \( \tau_c \) the time constant of the closed loop system. Note that \( \tau_c \) can be less than \( \tau \) (the time constant of the open loop system). If \( \tau_c<\tau \) the system is more reactive (but is also more energy consuming). In practice, \( \tau_c=\tau/2 \) is a good compromise. From the previous equation :

$$ 1-Kb = e^{-\Delta/\tau_c} $$

and:

$$ K= \frac {1-e^{-\Delta/\tau_c}} {b} $$

To get the same response time in closed and open loop, the previous equation becomes :

$$ K= \frac {1-a} {b} $$

The system is stable if all the poles are located inside the unity circle. Here, as the system is a first-order, there is one pole : \( 1-Kb \). The system is stable if:

$$ -1 < 1-Kb < 1 $$

The previous equation can be rewritten as:

$$ 0 < Kb < 2 $$

and:

$$ 0 < K < \dfrac{2}{b} $$

Note that if \( K \) is calculated from \( \tau_c \) ( \( K = \dfrac {1-e^{-\Delta / \tau_c}}{b} \) ), the term \( e^{-\Delta / \tau_c} \) is included in the range [0,1[ and the system is necessarely stable because it leads to \( 0 < Kb < 1 \).

The transfert function of the controller expressed in the discrete-time domain is given by:

$$ \frac{u(z)}{\epsilon(z)} = K . \frac{z-a}{z-1} $$

The previous can be rewritten as:

$$ (z-1)u(z) = K(z-a)\epsilon(z) $$ $$ z.u(z) - u(z) = K.z.\epsilon(z) -K.a.\epsilon(z) $$ $$ z.u(z) = K.z.\epsilon(z) - K.a.\epsilon(z) + u(z) $$

Let's expressed the previous equation in the discrete-time domain:

$$ u_{n+1}= K\epsilon_{n+1} - K.a.\epsilon_n + u_{n} $$

or :

$$ u_{n}= K\epsilon_{n} - K.a.\epsilon_{n-1} + u_{n-1} $$

Here is a MATLAB script for simulating the system response:

- Dynamic model of an inverted pendulum (part 1)
- Dynamic model of an inverted pendulum (part 2)
- Dynamic model of an inverted pendulum (part 3)
- Dynamic model of an inverted pendulum (part 4)
- Dynamic model of an inverted pendulum (part 5)
- Dynamic model of an inverted pendulum (part 6)
- Equation of closed and open loop systems

Last update : 01/24/2021