-
Notifications
You must be signed in to change notification settings - Fork 1
/
jet_engine
executable file
·106 lines (85 loc) · 4.53 KB
/
jet_engine
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
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from control.models.jet_engine import JetEngine
from control.controller import Controller
INITIAL_CONDITIONS = [5.37, JetEngine.YtoX2(5.37, 0.34)]
T_FINAL = 3
if __name__ == "__main__":
###############################################################################################
################################# Figure #1 Replication #######################################
###############################################################################################
# construct JetEngine class
print("Constructing jet engine model.")
model = JetEngine(INITIAL_CONDITIONS)
print ("Constructing periodic controller.")
controller = Controller(model, model.calculateCommand)
print("Simulating...")
# get the periodic response
t_periodic, r_periodic = controller.execute(T_FINAL, model.periodicCondition)
# get the self-triggered response
t_trigger, r_trigger = controller.execute(T_FINAL, model.triggerCondition)
t_trigger_clean = t_trigger # save for future plots
# also get the analog "perfect world" respone
t_perfect, r_perfect = model.analogResponse(T_FINAL, INITIAL_CONDITIONS, t_periodic)
# plot the response
plt.figure("Jet Engine State Response")
plt.plot(t_perfect, r_perfect[:, 0], 'b')
plt.plot(t_perfect, r_perfect[:, 1], 'r')
plt.plot(t_periodic, r_periodic[:, 0], 'b*', markersize = 1)
plt.plot(t_periodic, r_periodic[:, 1], 'r*', markersize = 1)
plt.plot(t_trigger, r_trigger[:, 0], 'b+', markersize = 5)
plt.plot(t_trigger, r_trigger[:, 1], 'r+', markersize = 5)
plt.xlabel("Time (s)")
plt.ylabel("State")
plt.legend(["x1 (perfect)", "x2 (perfect)", "x1 (periodic)", "x2 (periodic)", "x1 (trigger)", "x2 (trigger)"])
plt.xlim([0, T_FINAL])
plt.grid(True)
###############################################################################################
################################# Figure #2 Replication #######################################
###############################################################################################
# plot the inter-execution times
plt.figure("Inter-execution Times")
plt.plot(t_periodic[1:], np.diff(t_periodic), 'b')
plt.plot(t_trigger[1:], np.diff(t_trigger), '--r')
plt.xlabel("Time (s)")
plt.legend(["periodic", "self-triggered"])
plt.xlim([0, T_FINAL])
plt.grid(True)
###############################################################################################
################################# Figure #3 Replication #######################################
###############################################################################################
# get the system response with noise and perturbations
model = JetEngine(INITIAL_CONDITIONS, 0.05)
controller = Controller(model, model.calculateCommand)
# get the responses with a perturbation around ~0.7 seconds
t_periodic, r_periodic = controller.execute(T_FINAL, model.periodicCondition, [0.7, 200])
t_trigger, r_trigger = controller.execute(T_FINAL, model.triggerCondition, [0.7, 200])
# plot the noisy / perturbed response
plt.figure("Jet Engine Perturbed Response")
plt.plot(t_periodic, r_periodic[:, 0], 'b')
plt.plot(t_periodic, r_periodic[:, 1], 'r')
plt.plot(t_trigger, r_trigger[:, 0], '--b')
plt.plot(t_trigger, r_trigger[:, 1], '--r')
plt.xlabel("Time (s)")
plt.ylabel("State")
plt.legend(["x1 (periodic)", "x2 (periodic)", "x1 (trigger)", "x2 (trigger)"])
plt.xlim([0, T_FINAL])
plt.grid(True)
###############################################################################################
################################# Figure #4 Replication #######################################
###############################################################################################
# get the system response with no noise and perturbation
model = JetEngine(INITIAL_CONDITIONS)
controller = Controller(model, model.calculateCommand)
# get the responses with a perturbation around ~0.7 seconds
t_trigger, r_trigger = controller.execute(T_FINAL, model.triggerCondition, [0.7, 200])
# plot the inter-execution times
plt.figure("Noisy Inter-execution Times")
plt.plot(t_trigger[1:], np.diff(t_trigger), 'b')
plt.plot(t_trigger_clean[1:], np.diff(t_trigger_clean), '--r')
plt.xlabel("Time (s)")
plt.legend(["disturbance at t=0.7s", "no disturbance"])
plt.xlim([0, T_FINAL])
plt.grid(True)
plt.show()