3
exec(SCI+'/demos/control/scheme.dem');
4
s=poly(0,'s');z=poly(0,'z');
5
x_message(['Simple example of SISO LQG Design';
6
'Demo is in file '+SCI+'/demos/control/lqg.dem';
7
'Computes the LQG compensator and plots response'])
8
n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
16
str='(s-1)/(s^2-5*s+1)';
17
rep=x_dialog('Nominal plant?',str)
18
if rep==[] then return,end
20
Plant=syslin('c',Plant);
25
str='(z+1)/(z^2-5*z+2)'
26
rep=x_dialog('Nominal plant?',str)
27
if rep==[] then return,end
29
Plant=syslin('d',Plant);
34
P22=tf2ss(Plant); //...in state-space form
36
x_message('Now enter weighting matrices');
37
rep=x_matrix('x-weighting matrix',eye(nx,nx))
38
if rep==[] then return,end
40
rep=x_matrix('u-weighting matrix',eye(nu,nu));
41
if rep==[] then return,end
44
rep=x_matrix('x-noise covariance matrix',eye(nx,nx))
45
if rep==[] then return,end
47
rep=x_matrix('y-noise covariance matrix',eye(ny,ny))
48
if rep==[] then return,end
51
[Plqg,r]=lqg2stan(P22,bigQ,bigR); //LQG pb as a standard problem
52
Klqg=lqg(Plqg,r); //LQG compensator
54
disp(spec(h_cl(Plqg,r,Klqg)),'closed loop eigenvalues:'); //Check internal stability
55
[Slqg,Rlqg,Tlqg]=sensi(P22,Klqg); //Sensitivity functions
57
disp(clean(ss2tf(Slqg)),'Sensitivity function');
58
disp(clean(ss2tf(Tlqg)),'Complementary sensitivity function');
60
x_message('Closed-loop response');
62
resp=['Frequency response';'Time response'];
64
n=x_choose(resp,'Select response(s)');
67
disp("LQG demo stops!");break;
70
xbasc(0);xset("window",0);xselect();bode(Tlqg);xend()
76
title='Enter Sampling period and Tmax';
77
rep=x_mdialog(title,['Sampling period?';'Tmax?'],defv)
78
if rep==[] then break,end
80
dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
82
n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
85
xbasc(1);xset("window",1);xselect();
86
plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')]);xend()
88
xbasc(1);xset("window",1);xselect();
89
plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t']);xend()
92
elseif Plant(4)=='d' then
96
rep=x_mdialog(title,['Tmax='],defv)
97
if rep==[] then break,end
100
n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
106
u=ones(1,Tmax);u(1)=0;
107
xbasc(1);xset("window",1);xselect();
108
plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
113
u=zeros(1,Tmax);u(1)=1;
114
xbasc(1);xset("window",1);xselect();
115
plot2d((1:Tmax)',(dsimul(Tlqg,u))')
122
clear s z n str rep Plant P22 ny nu nx Qx Qu bigQ Rx Ry bigR Plqg r
123
clear Klqg Slqg Rlqg Tlqg resp title dttmax dt t n1 defv Tmax n2 u