-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbode_plot_targeted.py
More file actions
83 lines (66 loc) · 2.2 KB
/
Copy pathbode_plot_targeted.py
File metadata and controls
83 lines (66 loc) · 2.2 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
import control as ctl
import numpy as np
import matplotlib.pyplot as plt
from control.matlab import step
plt.rcParams.update({
"font.family":
"serif", # use serif/main font for text elements
"text.usetex":
True, # use inline math for ticks
"pgf.rcfonts":
False, # don't setup fonts from rc parameters
"pgf.preamble": [
"\\usepackage{units}", # load additional packages
"\\usepackage{metalogo}",
"\\usepackage{unicode-math}", # unicode math setup
r"\setmathfont{xits-math.otf}",
r"\setmainfont{DejaVu Serif}", # serif font via preamble
]
})
def calcControl(theta, num, den):
return np.dot(theta, num)[0, 0].minreal() * den
Ts = 0.05
omega = 10
alpha = np.exp(-Ts * omega)
refModel = ctl.tf([(1 - alpha)**2], [1, -2 * alpha, alpha**2, 0], Ts)
den = [1, -1.41833, 1.58939, -1.31608, 0.88642]
num = [0.28261, 0.50666]
G=ctl.tf(num, den, Ts)
# xi = 0.05
# omegan = 0.9
# p1 = -2 * np.exp(-xi * Ts * omegan) * np.cos(omegan * Ts * np.sqrt(1- xi**2))
# p2 = np.exp(-2 * xi * omegan * Ts)
# den = [1, p1, p2]
# delta = ctl.tf([1, -1], den, Ts)
# refModel2 = refModel + 1e-2 * delta
# Control base
den = ctl.tf([1], [1, -1], Ts)
z = ctl.tf([1, 0], [1], Ts)
base = [z, 1, 1 / z, 1 / (z * z), 1 / (z * z * z), 1 / (z * z * z * z)]
baseDen = [i * den for i in base]
theta_orig = np.array([0.33324, -0.60964, 0.72401, -0.66020, 0.48204, -0.12508])
theta = 2*theta_orig
C_orig = calcControl(theta_orig, base, den)
C = calcControl(theta, base, den)
L_orig = ctl.series(C_orig, G).minreal()
L = ctl.series(C, G).minreal()
P = ctl.feedback(L).minreal()
P_orig = ctl.feedback(L_orig).minreal()
# step_t = np.arange(0, 50,
# Ts)
# step_P_y, _ = step(P_orig, step_t)
# step_P_r, _= step(P, step_t)
# plt.plot(step_t, step_P_y)
# plt.plot(step_t, step_P_r)
# plt.show()
# pdb.set_trace()
# exit(-1)
fc = 1/(2*Ts)
omega = np.linspace(0, np.pi/Ts, 500)
mag_orig, _, _=ctl.bode_plot(refModel, omega=omega, color='k',label=r'Reference model $M_r$')
mag_poisoned, _, _ = ctl.bode_plot(P, omega=omega,linestyle='--', color='0.5',label=r'Target model $M_a$')
plt.legend()
plt.savefig(
'bode_targeted.pdf',
transparent=True,
bbox_inches='tight')