-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPIDgraphplot.py
More file actions
58 lines (43 loc) · 1.5 KB
/
Copy pathPIDgraphplot.py
File metadata and controls
58 lines (43 loc) · 1.5 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
import numpy as np
import matplotlib.pyplot as plt
results = np.loadtxt('PIDcontroldata.txt')
t = results[:, 0]
altitude = results[:, 4]
SP = results[:, 1]
PV = results[:, 2]
throttle = results[:, 3]
fig, (ax1, ax3) = plt.subplots(2, 1, figsize=(10, 8))
# First plot - time based
ax1.set_xlabel('time (s)')
ax1.set_ylabel('Velocity')
ax1.plot(t, SP, label='Setpoint (m/s)')
ax1.plot(t, PV, label='Process Variable (m/s)')
ax1.tick_params(axis='y',)
color = 'tab:green'
ax2 = ax1.twinx() # instantiate a second Axes that shares the same x-axis
ax2.set_ylabel('throttle') # we already handled the x-label with ax1
ax2.plot(t, throttle, label='throttle', color=color)
ax2.tick_params(axis='y')
# Combine legends from both axes
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
ax1.legend(h1+h2, l1+l2, loc='upper left')
ax1.set_title('PID Response vs Time')
# Second plot - altitude based
ax3.set_xlabel('Altitude (m)')
ax3.set_ylabel('Velocity (m/s)')
ax3.plot(altitude, SP, label='Setpoint')
ax3.plot(altitude, PV, label='Process Variable')
ax3.invert_xaxis() # Invert x-axis to show 1000-0
# Add throttle on secondary y-axis
ax4 = ax3.twinx()
ax4.set_ylabel('Throttle')
ax4.plot(altitude, throttle, label='Throttle', color=color)
# Combine legends
h3, l3 = ax3.get_legend_handles_labels()
h4, l4 = ax4.get_legend_handles_labels()
ax3.legend(h3+h4, l3+l4, loc='upper left')
ax3.set_title('PID Response vs Altitude')
plt.suptitle('PID Control System Response')
plt.tight_layout()
plt.show()