-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot.py
More file actions
38 lines (33 loc) · 1.31 KB
/
Copy pathPlot.py
File metadata and controls
38 lines (33 loc) · 1.31 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
import numpy as np
import matplotlib.pyplot as plt
with open ('data (1).txt',"r") as f:
lines = f.readlines()[1:]
#f.close()
angle =[round(float(line.split(sep=",")[0]),2) for line in lines]
pidout =[round(float(line.split(sep=",")[1]),2) for line in lines]
speed =[round(float(line.split(sep=",")[2]),2) for line in lines]
fps =[round(float(line.split(sep=",")[3]),4) for line in lines]
elapsed = [round(float(line.split(sep=",")[4]),2) for line in lines]
pidout = [x/10 for x in pidout]
st = elapsed[0]
elapsed=[x-st for x in elapsed]
#print(fps)
x = np.linspace(70,110,len(angle))
fig = plt.figure()
#fig2 = plt.figure()
#ay1 = fig2.add_subplot(111)
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.plot(elapsed,angle, c='r', label='Pendulum Angle',linewidth=2.0)
ax1.set_ylabel('Angle (deg)',color = 'r')
ax1.set_xlabel('Time (s)')
ax1.tick_params('y',colors='r')
ax2.plot(elapsed,pidout, c='g',linewidth=2.0, label='PID Output')
ax1.set_ylim([80,100])
ax2.set_ylabel('PID Output (%)',color = 'g')
ax2.tick_params('y',colors='g')
#ax3.plot(elapsed,fps, c='r', label='FPS')
plt.text(1, -100, 'FPS ~ 64\nKp=00\nKi=00\nKd=00', style='italic',
bbox={'facecolor':'w', 'alpha':0.5, 'pad':10})
plt.title('Inverted Pendulum \n Computer Vision Control \nHSV Colour Thresholding')
plt.show()