File: pendule.dem

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (134 lines) | stat: -rw-r--r-- 2,470 bytes parent folder | download | duplicates (2)
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
xselect();xbasc();wdim=xget('wdim')
mode(1)

//
getf('SCI/demos/pendulum/simulation.sci')
getf('SCI/demos/pendulum/graphics.sci')
//
x_message('the cart')
// ----------------
//
 xselect();
 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];
// y=ode(y0,0,0.03*(1:180),ivpd);
 y=read('SCI/demos/pendulum/yy',4,180,'(e12.6)');
 xbasc();
 anim(y(1,:),y(3,:));
//
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);ssprint(pe)
//
x_message('checking the result');
//
 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];
 norm(f-f1,1)+norm(g-g1,1)+norm(h-h1,1)+norm(j,1)
 
x_message('analysis');
//---------
//stability (unstable system !)
//
 spec(f)
//
//controlability
//
 n=contr(f,g)
//
//observability
//
 m1=contr(f',h(1,:)')
//
 [m2,t]=contr(f',h(2,:)')
 
//
x_message('synthesis of a stabilizing controller');
//-------------------------------------------------
//
//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('linear system  pendulum-observer-compensator')
//---------------------------------------------
//
//state: [x x-z]
//
 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
 // black(pr,0.01,100,['position','theta'])
 g_margin(pr(1,1))
 
 
//
x_message('sampled system')
//---------------
//
 t=to/5;
 prd=dscr(pr,t);
 spec(prd(2))
 
//
x_message('impulse response')
//-----------------
//
 x0=[0;0;0;0;0;0;0;0];
 u(1,180)=0;u(1,1)=1;
 y=flts(u,prd,x0);

 draw(0)

//
x_message('compensation of the non linear system');
//--------------------------------------
//
//simulation
//
 t0=0;t1=t*(1:125);
 x0=[0 0 0.4 0   0 0 0 0]';   //
 yd=ode(x0,t0,t1,regu);
//
 x_message('non linear simulation')
 draw(1)
mode(0)
x_message('The end')
xbasc()
xset('wdim',wdim(1),wdim(2))