-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_replay.py
More file actions
72 lines (56 loc) · 1.49 KB
/
graph_replay.py
File metadata and controls
72 lines (56 loc) · 1.49 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
import re
import numpy as np
import matplotlib.pyplot as plt
import sys
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.3, hspace=0.8)
f = open(sys.argv[1],"r")
lines = f.readlines()
y = [] #time
x1 = [] #pole angle
x2 = [] #cart position
x3 = [] #pole velocity
x4 = [] #cart velocity
x5 = [] #force applied
# x1 = np.array()
read_numbers = False
for l in lines:
if(not read_numbers):
if(l.rstrip("\n") == "SIMULATION BEGIN"):
read_numbers = True
else:
print(l.rstrip("\n"))
elif(read_numbers):
numbers = re.findall(r"[-+]?\d*\.\d+|\d+",l)
y.append(float(numbers[0]))
x1.append(float(numbers[1])*180/np.pi)
x2.append(float(numbers[2]))
x3.append(float(numbers[3])*180/np.pi)
x4.append(float(numbers[4]))
x5.append(float(numbers[5]))
plt.suptitle(sys.argv[1], fontsize=16)
plt.subplot(2,2,1)
plt.plot(y, x1, 'b')
plt.title('pole angle')
plt.xlabel('time(s)')
plt.ylabel('angle (deg)')
plt.subplot(2,2,2)
plt.plot(y, x2, 'g')
plt.xlabel('time (s)')
plt.title('cart position')
plt.ylabel('position (m)')
plt.subplot(2,2,3)
plt.plot(y, x3, 'r')
plt.xlabel('time (s)')
plt.title('pole velocity')
plt.ylabel('velocity (deg/s)')
plt.subplot(2,2,4)
plt.plot(y, x4, 'y')
plt.xlabel('time (s)')
plt.title('cart velocity')
plt.ylabel('velocity (m/s)')
# plt.subplot(3,2,5)
# plt.plot(y, x5, 'm')
# plt.xlabel('time (s)')
# plt.title('force applied')
# plt.ylabel('force (N)')
plt.show()