Kc = 0.05 # plant model G = 3 * (-2 * s + 1) / ((10 * s + 1) * (5 * s + 1)) # Controller model K = Kc * (10 * s + 1) * (5 * s + 1) / (s * (2 * s + 1) * (0.33 * s + 1)) # closed-loop transfer function L = G * K # magnitude and phase of L plt.figure('Figure 2.19') bode(L, -2, 1) # From the figure we can calculate w180 # w180 = 0.44 GM, PM, wc, wb, wbt, valid = marginsclosedloop(L) print('GM:', np.round(GM, 2)) print('PM:', np.round(PM * np.pi / 180, 2), "rad or", np.round(PM, 2), "deg") print('wb:', np.round(wb, 2)) print('wc:', np.round(wc, 2)) print('wbt:', np.round(wbt, 4)) # Response to step in reference for loop shaping design # y = Tr, r(t) = 1 for t > 0 # u = KSr, r(t) = 1 for t > 0 plt.figure('Figure 2.20') T = feedback(L, 1) S = feedback(1, L) u = K * S step_response_plot(T, u, 50, 0)
[Kc, Taui, Ku, Pu] = ControllerTuning(G, method='ZN') print 'Kc:', np.round(Ku/2.2, 3) print 'Taui:', np.round(Pu/1.2, 3) print 'Ku:', np.round(Ku, 3) print 'Pu:', np.round(Pu, 3) K1 = Kc * (1 + 1 / (Taui * s)) K = K1[0] # use this code to remove array L = G * K T = feedback(L, 1) S = feedback(1, L) u = S * K plt.figure('Figure 2.8') step_response_plot(T, u, 80, 0) plt.show() plt.figure('Figure 2.14') bodeclosedloop(G, K, -2, 1, margin=True) plt.show() GM, PM, wc, wb, wbt, valid = marginsclosedloop(L) print 'GM:' , np.round(GM, 2) print "PM: ", np.round(PM, 1) , "deg or", np.round(PM / 180 * np.pi, 2), "rad" print 'wb:' , np.round(wb, 2) print 'wc:' , np.round(wc, 2) print 'wbt:' , np.round(wbt, 2) if valid: print "Frequency range wb < wc < wbt is valid" else: print "Frequency range wb < wc < wbt is not valid"