place/ball_im.py
changeset 0 0efde00f9229
equal deleted inserted replaced
-1:000000000000 0:0efde00f9229
       
     1 #!/usr/bin/python 
       
     2 # 9.9
       
     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_im import pp_im
       
    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 a = sp.array([[0, 1, 0], [a21, 0, a23], [0, 0, a33]])
       
    32 b = sp.array([[0], [0], [b3]])
       
    33 c = sp.array([1, 0, 0])
       
    34 d = 0
       
    35 
       
    36 # Transfer functions
       
    37 G = signal.lti(a, b, c, d)
       
    38 Ts = 0.01
       
    39 B, A, k = myc2d(G,Ts)
       
    40 
       
    41 # Transient specifications
       
    42 rise = 0.15
       
    43 epsilon = 0.05
       
    44 phi = desired(Ts, rise, epsilon)
       
    45 
       
    46 # Controller design
       
    47 Delta = sp.array([1, -1])
       
    48 Rc, Sc, Tc, gamm = pp_im(B, A, k, phi)
       
    49 
       
    50 # Setting up simulation parameters for basic
       
    51 st = 0.0001 # desired change in h, in m.
       
    52 t_init = 0  # simulation start time
       
    53 t_final = 0.5 # simulation end time
       
    54 
       
    55 # Setting up simulation parameters for c_ss_cl
       
    56 N_var = 0
       
    57 xInitial = [0 0 0]
       
    58 N = 1
       
    59 C = 0 
       
    60 D = 1