-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost_TS_test_log.py
184 lines (157 loc) · 6.96 KB
/
post_TS_test_log.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import pickle
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import cassie
import time
from tempfile import TemporaryFile
FILE_PATH = "./hardware_logs/aslip_unified_10_v6/"
FILE_NAME = "2020-01-26_15:19_logfinal"
logs = pickle.load(open(FILE_PATH + FILE_NAME + ".pkl", "rb")) #load in file with cassie data
# data = {"time": time_log, "output": output_log, "input": input_log, "state": state_log, "target_torques": target_torques_log,\
# "target_foot_residual": target_foot_residual_log}
time = logs["time"]
states_rl = logs["input"]
states = logs["state"]
nn_output = logs["output"]
trajectory_steps = logs["trajectory"]
numStates = len(states)
rom_input = np.zeros((len(states_rl), 18)) # COM vel command input
vels = np.zeros((numStates, 3))
pelvis = np.zeros((numStates, 3))
motors = np.zeros((numStates, 10))
joints = np.zeros((numStates, 6))
torques_mea = np.zeros((numStates, 10))
ff_left = np.zeros((numStates, 6))
ff_right = np.zeros((numStates, 6))
foot_pos_left = np.zeros((numStates, 6))
foot_pos_right = np.zeros((numStates, 6))
# trajectory_log = np.zeros((numStates, 10))
states_rl = np.array(states_rl)
print(states_rl.shape)
j=0
for s in states:
rom_input[j, :] = states_rl[j,-18:64]
vels[j, :] = s.pelvis.translationalVelocity[:]
pelvis[j, :] = s.pelvis.position[:]
motors[j, :] = s.motor.position[:]
joints[j, :] = s.joint.position[:]
torques_mea[j, :] = s.motor.torque[:]
ff_left[j, :] = np.reshape(np.asarray([s.leftFoot.toeForce[:],s.leftFoot.heelForce[:]]), (6))
ff_right[j, :] = np.reshape(np.asarray([s.rightFoot.toeForce[:],s.rightFoot.heelForce[:]]), (6))
foot_pos_left[j, :] = np.reshape(np.asarray([s.leftFoot.position[:],s.leftFoot.position[:]]), (6))
foot_pos_right[j, :] = np.reshape(np.asarray([s.rightFoot.position[:],s.rightFoot.position[:]]), (6))
# trajectory_log[j, :] = trajectory_steps[j][:]
j += 1
# Save stuff for later
SAVE_NAME = FILE_PATH + FILE_NAME + '.npz'
# np.savez(SAVE_NAME, time = time, motor = motors, joint = joints, torques_measured=torques_mea, left_foot_force = ff_left, right_foot_force = ff_right, left_foot_pos = foot_pos_left, right_foot_pos = foot_pos_right, trajectory = trajectory_log)
np.savez(SAVE_NAME, time = time, motor = motors, joint = joints, torques_measured=torques_mea, left_foot_force = ff_left, right_foot_force = ff_right, left_foot_pos = foot_pos_left, right_foot_pos = foot_pos_right)
##########################################
# Plot everything (except for ref traj)
##########################################
row = 7
col = 1
#Plot Motor Positions
ax1 = plt.subplot(row,col,1)
motors = np.rad2deg(motors)
ax1.plot(time[:], motors[:, 0], label='left-hip-roll' )
# ax1.plot(time[:], motors[:, 1], label='left-hip-yaw' )
ax1.plot(time[:], motors[:, 2], label='left-hip-pitch' )
ax1.plot(time[:], motors[:, 3], label='left-knee' )
# ax1.plot(time[:], motors[:, 4], label='left-foot' )
ax1.plot(time[:], motors[:, 5], label='right-hip-roll' )
# ax1.plot(time[:], motors[:, 6], label='right-hip-yaw' )
ax1.plot(time[:], motors[:, 7], label='right-hip-pitch')
ax1.plot(time[:], motors[:, 8], label='right-knee' )
# ax1.plot(time[:], motors[:, 9], label='right-foot' )
# ax1.set_xlabel('Time')
ax1.set_ylabel('Motor Position [deg]')
ax1.legend(loc='upper left')
ax1.set_title('Motor Position')
# measured torques
ax3 = plt.subplot(row,col,2, sharex=ax1)
ax3.plot(time, torques_mea[:, 0], label='left-hip-roll' )
# ax3.plot(time, torques_mea[:, 1], label='left-hip-yaw' )
ax3.plot(time, torques_mea[:, 2], label='left-hip-pitch' )
ax3.plot(time, torques_mea[:, 3], label='left-knee' )
# ax3.plot(time, torques_mea[:, 4], label='left-foot' )
ax3.plot(time, torques_mea[:, 5], label='right-hip-roll' )
# ax3.plot(time, torques_mea[:, 6], label='right-hip-yaw' )
ax3.plot(time, torques_mea[:, 7], label='right-hip-pitch')
ax3.plot(time, torques_mea[:, 8], label='right-knee' )
# ax3.plot(time, torques_mea[:, 9], label='right-foot' )
# ax3.set_xlabel('Time')
ax3.set_ylabel('Measured Torques [Nm]')
ax3.legend(loc='upper left')
ax3.set_title('Measured Torques')
#Plot Joint Positions
ax4 = plt.subplot(row,col,3, sharex=ax1)
joints = np.rad2deg(joints)
ax4.plot(time, joints[:, 0], label='left-knee-spring' )
# ax4.plot(time, joints[:, 1], label='left-tarsus')
# ax4.plot(time, joints[:, 2], label='left-foot' )
ax4.plot(time, joints[:, 3], label='right-knee-spring' )
# ax4.plot(time, joints[:, 4], label='right-tarsus')
# ax4.plot(time, joints[:, 5], label='right-foot' )
# ax4.set_xlabel('Time')
ax4.set_ylabel('Joint Position [deg]')
ax4.legend(loc='upper left')
ax4.set_title('Joint Position')
# foot force
ax5 = plt.subplot(row,col,4, sharex=ax1)
# ax5.plot(time, ff_left[:, 0], label='left-X' )
# ax5.plot(time, ff_left[:, 1], label='left-Y' )
ax5.plot(time, ff_left[:, 2], label='left-Z' )
# ax5.plot(time, ff_right[:, 0], label='right-X' )
# ax5.plot(time, ff_right[:, 1], label='right-Y' )
ax5.plot(time, ff_right[:, 2], label='right-Z' )
# ax5.set_xlabel('Time')
ax5.set_ylabel('Foot Force [N]')
ax5.legend(loc='upper left')
ax5.set_title('Foot Forces')
# foot pos
ax6 = plt.subplot(row,col,5, sharex=ax1)
# ax6.plot(time, foot_pos_left[:, 0], label='left-X' )
# ax6.plot(time, foot_pos_left[:, 1], label='left-Y' )
ax6.plot(time, foot_pos_left[:, 2], label='left-Z' )
# ax6.plot(time, foot_pos_right[:, 0], label='right-X' )
# ax6.plot(time, foot_pos_right[:, 1], label='right-Y' )
ax6.plot(time, foot_pos_right[:, 2], label='right-Z' )
# ax6.set_xlabel('Time')
ax6.set_ylabel('Foot Pos [m]')
ax6.legend(loc='upper left')
ax6.set_title('Foot Pos')
# pelvis translational vel
ax7 = plt.subplot(row,col,6, sharex=ax1)
ax7.plot(time, vels[:, 0], label='X' )
ax7.plot(time, vels[:, 1], label='Y' )
ax7.plot(time, vels[:, 2], label='Z' )
ax7.set_xlabel('Time')
ax7.set_ylabel('m / s')
ax7.legend(loc='upper left')
ax7.set_title('Pelvis translational velocity')
# rom input
ax8 = plt.subplot(row,col,7, sharex=ax1)
ax8.plot(time, rom_input[:, 15], label='COM X Vel' )
ax8.plot(time, rom_input[:, 16], label='COM Y Vel' )
ax8.plot(time, rom_input[:, 17], label='COM Z Vel' )
ax8.set_xlabel('Time')
ax8.set_ylabel('m / s')
ax8.legend(loc='upper left')
ax8.set_title('ROM Library input')
# plt.tight_layout()
# plt.show()
plt.savefig(SAVE_NAME + '_full_log.png')
# plot them side by side
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')
# 1 m/s constant x velocity
x_offset = np.linspace(0, 10, num=pelvis.shape[0])
x_offset = foot_pos_left[:, 0]
ax.plot(pelvis[:, 0] + x_offset, pelvis[:, 1], pelvis[:, 2], label='pelvis')
ax.plot(pelvis[:, 0] + x_offset + foot_pos_left[:, 0], pelvis[:, 1] + foot_pos_left[:, 1], pelvis[:, 2] + foot_pos_left[:, 2], label='true left foot pos')
ax.plot(pelvis[:, 0] + x_offset + foot_pos_right[:, 0], pelvis[:, 1] + foot_pos_right[:, 1], pelvis[:, 2] + foot_pos_right[:, 2], label='true right foot pos')
ax.axis('equal')
plt.show()
plt.savefig(SAVE_NAME + '_TS_pose.png')