Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology

Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

Exercise 7
“State Space Controller, Optimal Control,
Controllability and Observability”

OBJECTIVE
The objective of this exercise is designing a state space controller based on optimal
control theory by taking into considerations the controllability and observability of the
system. We present the plant in state space and introduce the state variable, input and
vectors, as well as system parameters. Then the controllability and observability of the
plant is examined, without which Linear Quadratic Regulator (LQR) methodology can not
be applied. Finally the optimal matrix gain based on LQR will be calculated, sytem will be
simulated and the response parameters checked against design requirements.

REQUIREMENTS
Prerequisite knowledge:
You are expected to know the following topics:
1. Definition of state and observation equations for linear systems,
2. Presentation of mathematical model in state space,
3. Definition of controllability, observability, controllability matrix and observability
matrix
4. Principles of Optimal control and Linear Quadratic Regulator (LQR)

To find basic information on optimal control theory, students may read the following file:
“Chapter 5 – Optimal Control.pdf” available on-line:
http://www.pg.gda.pl/~ghaemi/student/pdf/MCDS/Chapter5 - Optimal Control.pdf.

LAYOUT
1. Recall Example of Exercise 2 and present the mathematical model of the plant in
state space, expressing matrices A, B, C and D.
2. Define the input, output and state variable vectors and system parameters.
3. Check the controllability of the plant. Give the rank of controllability matrix.
4. Check the observability of the plant. Give the the rank of observability matrix.
5. Define the performance index.
6. Adjust the weighting matrices Q, R and S.
7. Calculate the optimal gain matrix.
8. Simulate the system response.

MATLAB/SIMULINK
The following new MATLAB commands and functions are necessary to be understood and
applied in this exercise:
ctrb
obsv
rank
lqr

REPORT
In addition to those points mentioned under Layout, your report should include:
1. calculation of:
• Steady state error,
• Maximum overshoot,
• Damping ratio,
• Natural frequency.

51
Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology
Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

2. Comparison of the results for 3 different selected set of weighting matrices.


3. A proposition to improve the response quality by decreasing the steady state
error, if there is any.

EXAMPLE
Recall the example of Exercise 2:
( )
m ⋅ &x&(t ) + z ⋅ x& (t ) − d& (t ) + k ⋅ ( x(t ) − d (t ) ) = f (t )

Step 1: Presenting the open loop system in state space:

The following tricky process introduces this system in state space:

&x&(t ) = −
z
m
( )k 1
⋅ x& (t ) − d& (t ) − ⋅ ( x(t ) − d (t ) ) + f (t )
m m
then
z  k 1 
x& (t ) = − ⋅ ( x(t ) − d (t ) ) + ∫ − ⋅ ( x(t ) − d (t ) ) + f (t ) dt
m  m m 

Let us introduce a new variable N (t ) :


z
x& (t ) = − ⋅ ( x(t ) − d (t ) ) + N (t )
m
where
k 1
N& (t ) = − ⋅ ( x(t ) − d (t ) ) + f (t )
m m

Now, we define the state variables:


 x1 (t ) = x(t )

 x 2 (t ) = N (t )
and we get
 z
 x&1 (t ) = x& (t ) = − m ⋅ ( x(t ) − d (t ) ) + N (t )

 x& (t ) = N& (t ) = − k ⋅ ( x(t ) − d (t ) ) + 1 f (t )
 2 m m

By taking into account:


u1 (t ) = f
u 2 (t ) = d
y (t ) = x(t )

Definition of the open system in state space is now completed:


 z z
 x&1 (t ) = − m ⋅ x1 (t ) + x 2 (t ) + m ⋅ u 2 (t )

 k 1 k
 x& 2 (t ) = − ⋅ x1 (t ) + ⋅ u1 (t ) + ⋅ u 2 (t )
 m m m
 y (t ) = x1 (t )

52
Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology
Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

The matrices A, B, C and D of state and observation equations are as follows:


 z   z
− 1 0 m
A= m  B= C = [1 0] D = [0]
k 1 k
− 0  
 m  m m
We put the open system into MATLAB:
» m=100;k=200;z=50;
» A=[-z/m 1 ; -k/m 0];
» B=[0 z/m ; 1/m k/m];
» C=[1 0];
» D=[0];
» open_sys=ss(A,B,C,D);

Step 2: Structure of the control system using Linear Quadratic Regulator (LQR):

In a typical feedback control system, the output is fed back to the summing junction. We
change the topology of design. Instead of feeding back the system output we feed back
all state variables. If each state variable is fed back to the control u , through a gain k i ,
that could be adjusted to yield the required closed-loop pole values. This is represented
in the following figure by the feedback matrix K (t ) .

+ u(t) .
x x(t)
r(t) +
B(t)
+

-

A(t)

K(t)

If the system is stationary, then K is not function of time and comprises constant
elements.

Step 3: Checking the controllability and observability of the open system:

To apply LQR method it is necessary to check the controllability and observability of the
system. In case system is not controllable, some elements of gain matrix K will not take
part in control process, because they do not affect the input. Similarly, if the system is
not observable, the control of those state variables which do not affect the output will be
meaningless. If system is not controllable or observable we may not apply LQR method
and there is no guarantee that our system is optimally controlled. Practically, it means
that optimal gain is not available, because the Matrix Riccati Equation remains
unsolvable.

Let us check at first controllability:


» CO=ctrb(open_sys);
» rank(CO)
ans =
2
Since the rank of controllability matrix is equal to the order of open loop system (or the
length of matrix A), i.e. 2, the open loop system is controllable.

53
Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology
Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

Then we check observability of the open loop system:


» OB=obsv(open_sys);
» rank(OB)
ans =
2
It means that the open loop system is observable, too, because the rank of observability
matrix is equal to the order of open loop system (or the length of matrix A), i.e. 2.

Step 4: Calculation of gain matrix K :

Assume that the initial time and the initial state vector are specified. The problem is
minimizing the performance index (or cost function)
tf
J = θ [x(t f ), t f ] + ∫t0
φ [x(t ), u(t ), t ] dt
for the system described by
x& = f [ x(t ), u(t ), t ] ; x(t 0 ) = x 0
where t0 is fixed and where, at the unspecified terminal time t = t f , the q–dimensional
vector of terminal manifold equation is given by
N [x(t f ), t f ] = 0

For instance, it is desired to find the control which minimizes the performance index J,
for
θ [x(t f ), t f ] = 12 x T (t f ) S x(t f )
φ [x(t ), u(t ), t ] = x T (t ) Q(t ) x(t ) + u T (t ) R (t ) u(t )

The choice of weighting matrices S, Q and R can affect optimality of the system. The
choice of Q, S and R matrices to minimize J is somewhat arbitrary and, if is possible, can
be done by experimentation. It can be accomplished only when the knowledge of
possible disturbances has been obtained and driving the system off the nominal
trajectory may be realized. It is necessary to ensure that the stability criterion is
satisfied. There is no loss of generality in assuming weighting matrices to be symmetric.
They have to be semi-positive, too.

Having the weighting matrices, the gain matrix can be calculated by solving the Matrix
Riccati Equation:
P& = −P (t ) A(t ) − A T (t ) P(t ) + P(t ) B(t ) R −1 (t ) B T (t ) P(t ) − Q(t )
with a terminal condition given by
P(t f ) = S
Then the Matrix Riccati Equation may be solved backward in time from tf to t0, for storing
the matrix
K (t ) = R −1 (t ) B T (t ) P(t )
and then obtaining a closed-loop control from
u(t ) = − K (t ) x(t )

As a result for the closed loop control system we have:


x& (t ) = A ⋅ x(t ) + B ⋅ u(t ) = A ⋅ x(t ) + B ⋅ [r (t ) − K (t ) ⋅ x(t )] = ( A − B ⋅ K ) ⋅ x(t ) + B ⋅ r (t )
y (t ) = C ⋅ x(t ) + D ⋅ u(t )

54
Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology
Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

Consider that S=0 and final time is not a parameter for optimization process. Moreover,
assume that Q and R are diagonal matrices:
q 0
Q =  11 
 0 q 22 
r 0
R =  11 
 0 r22 

For a second order system, as in our case, the performance index will be as follows:
J = ∫ [(q11 ⋅ x1 +q 22 ⋅ x 2 ) + (r11 ⋅ u1 + r22 ⋅ u 2 )] dt
2 2 2 2

It means that by selecting the elements of weighting matrices we decide about the
weight (significance degree) of each state variable and each input signal.

Here, the output of system is x1 and therefore the importance degree of this state
variable could be considered as much as possible high in comparison with x2 , which is
mass speed. Let us consider a range of 1 to 10 for weighting the elements of weighting
matrices. We give x1 , which is displacement of the mass, the highest possible related
weight, i.e. q11 =10. For x 2 , in comparison with x1 , for example, we can select q 22 =2. u1
is the control variable and u 2 is the disturbance signal. We can consider the same value
both for r11 and r22 , for example r11 = r22 = 1 (these are also weighted using the same
scale, i.e. from 1 to 10).

Therefore:
10 0 1 0 
Q=  and R= 
 0 2 0 1 

Now, we introduce the weighting matrices and calculate the optimal gain matrix:
» Q=[1 0 ; 0 2];
» R=[1 0 ; 0 1];
» K=lqr(A,B,Q,R)
K=

-0.0001 0.0071
2.3166 1.4078
where:
u1 = k11 ⋅ x1 + k12 ⋅ x 2
u 2 = k 21 ⋅ x1 + k 22 ⋅ x 2

The closed-loop system can be defined as:


» An=A-B*K;
» Bn=B;
» Cn=C;
» Dn=D;
» cl_sys=ss(An,Bn,Cn,Dn);

Then by introducing the input signals (control variable and disturbance) we make
simulation:
Time=0:.01:10;

55
Gdansk University of Technology, Faculty of Ocean Engineering and Ship Technology
Modeling and Control of Dynamic Systems, Laboratory, M. H. Ghaemi

» R1(1:length(Time))=0;
» R2(1:length(Time))=0.1;
» R=[R1;R2]';
» [Y,X]=lsim(An,Bn,Cn,Dn,R,Time);
» X1=X(:,1);
» X2=X(:,2);
» plot(Time,Y,'b',Time,X1,'-.c',Time,X2,'-y')
» title('Response of the closed loop system with optimal gain matrix');
» xlabel('Time [s]');
» ylabel('System response (y), displacement (x1) [m] and speed (x2) [m/s] of …
the mass')
» legend('y: blue', 'x1: dot red', 'x2: green')

Response of the closed loop system with optimal gain matrix


0.08
System response (y), displacement (x1) [m] and speed (x2) [m/s] of the mass

0.07
y: blue
x1: dot red
0.06 x2: green

0.05

0.04

0.03

0.02

0.01

-0.01
0 1 2 3 4 5 6 7 8 9 10
Time [s]

As it is visible from this figure, the system response is settled after 2.3 seconds, and the
overshoot is 0.66%, which gives damper ratio equal 0.13 (These values can be calculated
as follows:
» OS=(max(Y)-Y(length(Y)))/Y(length(Y));
» maxOS=100*OS
» zeta=-log(maxOS)/(sqrt(pi^2+log(maxOS)^2))

Therefore, our design is enough satisfactory. The only point which has to be improved is
steady state error, which is not zero, at the moment. Using this optimal control system,
for a disturbance equal 10 cm we have 3 cm displacement in steady state condition.

How could we decrease the steady state error for this design?
***

56

You might also like