|
1 #!/usr/bin/python |
|
2 # 9.1 |
|
3 import os, sys |
|
4 sys.path += [os.getcwdu() + os.sep + ".." + os.sep + "python"] |
|
5 |
|
6 import scipy as sp |
|
7 from scipy import signal |
|
8 from myc2d import myc2d |
|
9 from pp_basic import pp_basic |
|
10 from desired import desired |
|
11 |
|
12 # Magnetically suspended ball problem |
|
13 # Operating conditions |
|
14 |
|
15 M = 0.05 |
|
16 L = 0.01 |
|
17 R = 1 |
|
18 K = 0.0001 |
|
19 g = 9.81 |
|
20 |
|
21 #Equilibrium conditions |
|
22 hs = 0.01 |
|
23 i = sqrt(M*g*hs/K) |
|
24 |
|
25 |
|
26 # State space matrices |
|
27 a21 = K*i**2/M/hs**2 |
|
28 a23 = - 2*K*i/M/hs |
|
29 a33 = - R/L |
|
30 b3 = 1/L |
|
31 a1 = sp.array([[0, 1, 0], [a21, 0, a23], [0, 0, a33]]) |
|
32 b1 = sp.array([[0], [0], [b3]]) |
|
33 c1 = sp.array([1, 0, 0]) |
|
34 d1 = 0 |
|
35 |
|
36 # Transfer functions |
|
37 G = signal.lti(a1, b1, c1, d1) |
|
38 Ts = 0.01 |
|
39 B, A, k = myc2d(G, Ts) |
|
40 |
|
41 #polynomials are returned |
|
42 num, den = G.num, G.den |
|
43 |
|
44 # Transient specifications |
|
45 rise = 0.15 |
|
46 epsilon = 0.05 |
|
47 phi = desired(Ts, rise, epsilon) |
|
48 |
|
49 # Controller design |
|
50 Rc, Sc, Tc, gamm = pp_basic(B, A, k, phi) |
|
51 |
|
52 # Setting up simulation parameters for basic |
|
53 st = 0.0001 # desired change in h, in m. |
|
54 t_init = 0 # simulation start time |
|
55 t_final = 0.5 # simulation end time |
|
56 |
|
57 # Setting up simulation parameters for c_ss_cl |
|
58 N_var = 0 |
|
59 xInitial = [0 0 0] |
|
60 N = 1 |
|
61 C = 0 |
|
62 D = 1 |