-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfigure-2.9-secord_stepresp.py
More file actions
93 lines (73 loc) · 2.27 KB
/
figure-2.9-secord_stepresp.py
File metadata and controls
93 lines (73 loc) · 2.27 KB
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
# figure-2.9-secord_stepresp.py - step responses for second order systems
# RMM, 21 Jun 2021
#
# Responses to a unit step change in the reference signal for different
# values of the design parameters \omega_c and \zeta_c. The left column
# shows responses for fixed \zeta_c = 0.707 and \omega_c = 1, 2, and 5. The
# right figure column responses for \omega_c = 2 and \zeta_c = 0.5, 0.707,
# and 1. The process parameters are a = b = 1. The initial value of the
# control signal is kp.
#
import numpy as np
import matplotlib.pyplot as plt
import control as ct
# Process model
b = 1; a = 1
P = ct.tf([b], [1, a])
# Set the simulation time vector
time = np.linspace(0, 6, 100)
#
# Omega sweep
#
# Choose gains to use
wc_list = [1, 2, 5]
zc = 0.707
for wc in wc_list:
kp = (2 * zc * wc - a) / b
ki = wc**2
C = ct.tf([kp, ki], [1, 0])
Gyr = P*C / (1 + P*C)
Gur = C / (1 + P*C)
t, y = ct.step_response(Gyr, time)
t, u = ct.step_response(Gur, time)
if 'w_y_ax' not in locals():
w_y_ax = plt.subplot(3, 2, 1)
plt.ylabel('Output $y$')
plt.title(r"Sweep $\omega_c$, $\zeta_c = %g$" % zc)
w_y_ax.plot(t, y)
if 'w_u_ax' not in locals():
w_u_ax = plt.subplot(3, 2, 3)
plt.ylabel('Input $u$')
plt.xlabel(r'Normalized time $\omega_c t$')
w_u_ax.plot(t, u, label=r"$\omega_c = %g$" % wc)
# Label the omega sweep curves
w_u_ax.legend(loc="upper right")
#
# Zeta sweep
#
# Figure out frequency of critical damping
wc = 2
zc_list = [0.5, 0.707, 1]
# Plot results for different resonate frequencies
for zc in zc_list:
kp = (2 * zc * wc - a) / b
ki = wc**2
C = ct.tf([kp, ki], [1, 0])
Gyr = P*C / (1 + P*C)
Gur = C / (1 + P*C)
t, y = ct.step_response(Gyr, time)
t, u = ct.step_response(Gur, time)
if 'z_y_ax' not in locals():
z_y_ax = plt.subplot(3, 2, 2)
plt.ylabel('Output $y$')
plt.title(r"Sweep $\zeta_c$, $\omega_c = %g$" % wc)
z_y_ax.plot(t, y)
if 'z_u_ax' not in locals():
z_u_ax = plt.subplot(3, 2, 4)
plt.ylabel('Input $u$')
plt.xlabel(r'Normalized time $\omega_c t$')
z_u_ax.plot(t, u, label=r"$\zeta_c = %g$" % zc)
# Label the zeta sweep curves
z_u_ax.legend(loc="upper right")
# Overalll figure labeling
plt.tight_layout()