Solutions of Exercise 7.3

Contents

Solutions of Exercise 7.3#

Assume you designed the following control law:

\[ U(s) = 2 \frac{10s + 1}{s + 1} E(s) \]
  1. Discretize it using the trapezoidal method with a sampling frequency of \(10\) Hz.


Solution#

Question 1#

First, let’s start by noting that a sampling frequency of \(10\) Hz corresponds to a sampling period of \(T = \frac{1}{10} = 0.1\) seconds.

To discretize the control law, the bilinear formula is applied

(39)#\[ s \gets \frac{1}{T} \cdot \frac{1 - q^{-1}}{\alpha + (1 - \alpha) q^{-1}} \]

Rembember that:

In this case, with \(\alpha = \frac{1}{2}\), the bilinear transformation (39) reads

(40)#\[ s \gets \frac{2}{T} \, \frac{1-q^{-1}}{1 + q^{-1}} \]

where \(T=0.1\) is the sampling time and \(q^{-1}\) is the time-shift operator, meaning that \(q^{-1} x_k = x_{k-1}\).

To proceed, we apply (40) to our control law. This results in:

\[\begin{split} \begin{aligned} u_k &= 2 \frac{10 \cdot 20 \frac{1-q^{-1}}{1 + q^{-1}} + 1}{20 \cdot \frac{1-q^{-1}}{1 + q^{-1}} + 1} e_k \\ &= 2 \frac{\frac{200(1-q^{-1}) + 1 + q^{-1}}{\cancel{1 + q^{-1}}}}{\frac{20 (1-q^{-1}) + 1 + q^{-1}}{\cancel{1 + q^{-1}}}} e_k \\ &= 2 \frac{201 - 199 q^{-1}}{21 - 19 q^{-1}} e_k \end{aligned} \end{split}\]

If we now multiply both sides by \((21 - 19 q^{-1})\) we get

\[ (21 - 19 q^{-1}) u_k = (402 - 398 q^{-1}) e_k \]

Because of the meaning of the time-shift operator, this expression is equivalent to

\[ 21 u_k - 19 u_{k-1} = 402 e_k - 398 e_{k-1} \]

Isolating \(u_k\) we retrieve the discrete-time control law:

(41)#\[ \boxed{ u_k = \frac{19}{21} u_{k-1} + \frac{402}{21} e_k - \frac{398}{21} e_{k-1}} \]

Implementation

The discretized control law (41) can be easily implemented with, e.g., a python function invoked that gets called every \(T\) seconds

def control_law(u_prev: float, e_current: float, e_prev: float) -> float:
    """
    This function implement the discretized control law and 
    should be invoked every T = 0.1 seconds.

    Arguments:
        u_prev (float): The control input at the previous step, i.e. u_{k-1}
        e_current (float): The currently-measured error, i.e. e_k
        e_prev (float): The previously measured error. i.e. e_{k-1}
    
    Returns:
        u_current (float): The control action to be applied to the actuator
    """

    return 19.0 / 21.0 * u_prev + 402.0 / 21.0 * e_current - 398.0 / 21.0 e_prev