Control Systems
The closed-loop control structure of a plant is shown below, where $G(s)$ is the plant transfer function and $C(s)$ is the controller. The plant transfer function is given by,$G(s) = \displaystyle\frac{G_0}{1 + \displaystyle\frac{s}{Q\,\omega _0} + \left(\displaystyle\frac{s}{\omega _0}\right)^2}$,
with $G_0=10$, $Q=2$, $\omega _0=100$.
- Plot the frequency response of the plant. Determine the phase margin and gain cross-over frequency.
- Determine the phase margin for the loop transfer function $C(s)G(s)$ for $C(s)=10$.
- Design a lead-lag controller $C(s) = k\,\displaystyle\frac{1+(s/\omega _z)}{1+(s/\omega _p)}$ to achieve a phase margin of $45^{\circ}$ at a gain cross-over frequency of $500\,$rad/s. Plot the loop transfer function and verify your design.
- Apply a step input ($x(t)$ in the figure) and observe the output.
InĀ [1]:
from IPython.display import Image
Image(filename =r'control_1_fig_1.png', width=320)
Out[1]:
InĀ [2]:
import control as ct
import matplotlib.pyplot as plt
import numpy as np
import sys
G0 = 10.0
Q = 2.0
w0 = 100.0
# see bode3.py for xfer fn using ct.
# The leftmost number in the np arrays corresponds to the highest power of s.
#num = np.array([G0])
#den = np.array([(1.0/(w0*w0)), (1.0/(Q*w0)), 1.0])
a0 = G0
b0 = 1.0
b1 = (1.0/(Q*w0))
b2 = (1.0/(w0*w0))
print('coefficients for G(s):')
print('a0:', "%11.4E"%a0)
print('b0:', "%11.4E"%b0)
print('b1:', "%11.4E"%b1)
print('b2:', "%11.4E"%b2)
num = np.array([a0])
den = np.array([b2, b1, b0])
G = ct.tf(num, den)
gm, pm, wcg, wcp = ct.margin(G)
print("G(s):")
print("Phase margin:", "%10.3e"%pm, "deg")
print("gain cross-over frequency:", "%10.3e"%wcp, "rad/s")
ct.bode_plot(G)
plt.grid()
plt.suptitle("Bode plot for G(s)")
plt.show()
coefficients for G(s): a0: 1.0000E+01 b0: 1.0000E+00 b1: 5.0000E-03 b2: 1.0000E-04 G(s): Phase margin: 9.485e+00 deg gain cross-over frequency: 3.296e+02 rad/s
InĀ [3]:
num = 10.0*(np.array([G0]))
den = np.array([(1.0/(w0*w0)), (1.0/(Q*w0)), 1.0])
G1 = ct.tf(num, den)
gm, pm, wcg, wcp = ct.margin(G1)
print("C(s)*G(s) with C(s)=10:")
print("Phase margin:", "%10.3e"%pm, "deg")
print("gain cross-over frequency:", "%10.3e"%wcp, "rad/s")
C(s)*G(s) with C(s)=10: Phase margin: 2.878e+00 deg gain cross-over frequency: 1.004e+03 rad/s
InĀ [4]:
k = 0.8 # to be changed by user
wz = 300.0 # to be changed by user
wp = 2000.0 # to be changed by user
num = k*(np.array([(1/wz),1.0]))
den = (np.array([(1/wp),1.0]))
C = ct.tf(num, den)
H = C*G
gm, pm, wcg, wcp = ct.margin(H)
print("C(s)*G(s) with lead-lag controller:")
print("Phase margin:", "%10.3e"%pm, "deg")
print("gain cross-over frequency:", "%10.3e"%wcp, "rad/s")
ct.bode_plot(H)
plt.grid()
plt.suptitle("Bode plot for C(s)*G(s) with lead-lag controller")
plt.show()
C(s)*G(s) with lead-lag controller: Phase margin: 4.864e+01 deg gain cross-over frequency: 3.638e+02 rad/s
InĀ [5]:
# step response of C*G/(1 + C*G)
# construct C*G/(1 + C*G):
H1= ct.feedback(H, 1)
t = np.linspace(0,100.0e-3,200)
t1, y1 = ct.step_response(H1,t)
plt.plot(t1, y1)
plt.grid()
plt.show()
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.