1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
mode(-1)
path=get_absolute_file_path('pendule.dem');
//
getf(path+'simulation.sci')
getf(path+'graphics.sci')
//
xselect();wdim=xget('wdim')
//mode(1)
dpnd()
//
// equations
//----------
//state =[x x' theta theta']
//
mb=0.1;mc=1;l=0.3;m=4*mc+mb; //constants
//
x_message(['Open loop simulation'
' '
' y0 = [0;0;0.1;0]; //initial state [x x'' theta theta'']'
' t = 0.03*(1:180); //observation dates'
' y = ode(y0,0,0.03*(1:180),ivpd); //differential equation integration'
' //Display'
' P = initialize_display(y0(1),y0(3))'
' for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end'])
//
y0=[0;0;0.1;0];
y=ode(y0,0,0.03*(1:180),ivpd);
P=initialize_display(y0(1),y0(3));
for k=1:size(y,2), set_pendulum(P,y(1,k),y(3,k));end
//
x_message(['Linearization'
' '
' x0=[0;0;0;0];u0=0;'
' [f,g,h,j]=lin(pendu,x0,u0);'
' pe=syslin(''c'',f,g,h,j);'
' // display of the linear system'
' ssprint(pe)'])
//
mode(1)
x0=[0;0;0;0];u0=0;
[f,g,h,j]=lin(pendu,x0,u0);
pe=syslin('c',f,g,h,j);
ssprint(pe)
mode(-1)
//
x_message(['Checking the result'
' //comparison with linear model computed by hand';
''
' f1=[0 1 0 0'
' 0 0 -3*mb*9.81/m 0'
' 0 0 0 1'
' 0 0 6*(mb+mc)*9.81/(m*l) 0];'
' '
' g1=[0 ; 4/m ; 0 ; -6/(m*l)];'
' '
' h1=[1 0 0 0'
' 0 0 1 0];'
' '
' err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)'])
//
mode(1)
f1=[0 1 0 0
0 0 -3*mb*9.81/m 0
0 0 0 1
0 0 6*(mb+mc)*9.81/(m*l) 0];
g1=[0 ; 4/m ; 0 ; -6/(m*l)];
h1=[1 0 0 0
0 0 1 0];
err=norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)
mode(-1)
x_message(['Linear system properties analysis'
' spec(f) //stability (unstable system !)'
' n=contr(f,g) //controlability'
' '
' //observability'
' m1=contr(f'',h(1,:)'') '
' [m2,t]=contr(f'',h(2,:)'')'])
//---------
mode(1)
spec(f) //stability (unstable system !)
n=contr(f,g) //controlability
//observability
m1=contr(f',h(1,:)')
[m2,t]=contr(f',h(2,:)')
mode(-1)
//
x_message(['Synthesis of a stabilizing controller using poles placement'
' '
'// only x and theta are observed : contruction of an observer'
'// to estimate the state : z''=(f-k*h)*z+k*y+g*u'
' to=0.1; '
' k=ppol(f'',h'',-ones(4,1)/to)'' //observer gain'
'// compute the compensator gain'
' kr=ppol(f,g,-ones(4,1)/to)'])
//-------------------------------------------------
//
//pole placement technique
//only x and theta are observed : contruction of an observer
//to estimate the state : z'=(f-k*h)*z+k*y+g*u
//
to=0.1; //
k=ppol(f',h',-ones(4,1)/to)' //observer gain
//
//verification
//
// norm( poly(f-k*h,'z')-poly(-ones(4,1)/to,'z'))
//
kr=ppol(f,g,-ones(4,1)/to) //compensator gain
//
x_message(['Build full linear system pendulum-observer-compensator'
' '
' ft=[f-g*kr -g*kr'
' 0*f f-k*h]'
' '
' gt=[g;0*g];'
' ht=[h,0*h];'
''
' pr=syslin(''c'',ft,gt,ht);'
''
'//Check the closed loop dynamic'
' spec(pr.A)'
' '
'//transfer matrix representation'
' hr=clean(ss2tf(pr),1.d-10)'
' '
'//frequency analysis'
' black(pr,0.01,100,[''position'',''theta''])'
' g_margin(pr(1,1))'])
//---------------------------------------------
//
//state: [x x-z]
//
mode(1)
ft=[f-g*kr -g*kr
0*f f-k*h];
gt=[g;0*g];
ht=[h,0*h];
pr=syslin('c',ft,gt,ht);
// closed loop dynamics:
spec(pr(2))
//transfer matrix representation
hr=clean(ss2tf(pr),1.d-10)
//frequency analysis
clf()
black(pr,0.01,100,['position','theta'])
g_margin(pr(1,1))
mode(-1)
//
x_message(['Sampled system'
' '
' t=to/5; //sampling period'
' prd=dscr(pr,t); //discrete model'
' spec(prd.A) //poles of the discrete model'])
//---------------
//
mode(1)
t=to/5;
prd=dscr(pr,t);
spec(prd(2))
mode(-1)
//
x_message(['Impulse response'
' '
' x0=[0;0;0;0;0;0;0;0]; //initial state'
' u(1,180)=0;u(1,1)=1; //impulse'
' y=flts(u,prd,x0); //siscrete system simulation'
' draw1()'])
//-----------------
//
mode(1)
x0=[0;0;0;0;0;0;0;0];
u(1,180)=0;u(1,1)=1;
y=flts(u,prd,x0);
draw1()
mode(-1)
//
x_message(['Compensation of the non linear system with'
'linear regulator'
''
' t0=0;t1=t*(1:125);'
' x0=[0 0 0.4 0 0 0 0 0]''; // initial state'
' yd=ode(x0,t0,t1,regu); //integration of differential equation'
' draw2()'])
;
//--------------------------------------
//
//simulation
//
mode(1)
t0=0;t1=t*(1:125);
x0=[0 0 0.4 0 0 0 0 0]'; //
yd=ode(x0,t0,t1,regu);
draw2()
mode(-1)
x_message('The end')
|