-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_time.py
176 lines (138 loc) · 5.98 KB
/
plot_time.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
import time
import numpy as np
import pickle
import argparse
import matplotlib.pyplot as plt
from pyquaternion import Quaternion
from scipy import interpolate
from utils import *
Panda = TrajectoryClient()
def average(lst):
return sum(lst) / len(lst)
def region(ax, start_marg, end_marg):
ax.axvspan(start_marg, end_marg, color='#a1d99b')
def get_idx(X):
idx_1 = len(X[X <= x_margin_1])
idx_2 = idx_1 + len(X[(X > x_margin_1) & (X <= x_margin_2)])
idx_3 = idx_2 + len(X[(X > x_margin_2) & (X < x_margin_3)])
return idx_1, idx_2, idx_3
def mean_error(arr, base):
error = np.mean(abs(base - arr) / len(arr))
return np.round(100 * error, 3)
def quat_error(R):
diff = []
for r in R:
diff.append(Quaternion.absolute_distance(Panda.rot2quat(R_desire), Panda.rot2quat(r)))
return np.array(diff)
def compute_time(var, t, t_total):
t_active = 0
idcs = np.argwhere(np.abs(np.diff(var)) > 0.0008) + 1
idcs_flat = idcs.flatten('F').tolist()
for idx in idcs_flat:
t_active += (t[idx] - t[idx-1])
return 100 * t_active / t_total
X = {}
Y = {}
Z = {}
Quat = {}
n = 9
for method in ["GUI", "local", "global"]:
x = {}
t_y = {}
t_z = {}
t_quat = {}
for user_n in range(1, n+1):
filename = "data/demos/user_" + str(user_n) + "_" + method + ".pkl"
file = open(filename, "rb")
data = pickle.load(file)
R = data["rotation matrix"]
time = data["time"]
ee = data["ee positions"]
points = np.array(ee).T
t_total = time[-1] - time[0]
x["user_" + str(user_n)] = points[0,:]
marg_1_idx, marg_2_idx, marg_3_idx = get_idx(points[0, :])
if method == "GUI":
t_z["user_" + str(user_n)] = compute_time(points[2,:][:marg_1_idx], time[:marg_1_idx], t_total)
t_quat["user_" + str(user_n)] = compute_time(quat_error(R[marg_1_idx:marg_2_idx]), time[marg_1_idx:marg_2_idx], t_total)
t_y["user_" + str(user_n)] = compute_time(points[1,:][marg_2_idx:marg_3_idx], time[marg_2_idx:marg_3_idx], t_total)
elif method == "global":
t_z["user_" + str(user_n)] = compute_time(points[2,:][:marg_1_idx], time[:marg_1_idx], t_total)
t_y["user_" + str(user_n)] = compute_time(points[1,:][marg_1_idx:marg_2_idx], time[marg_1_idx:marg_2_idx], t_total)
t_quat["user_" + str(user_n)] = compute_time(quat_error(R[marg_2_idx:marg_3_idx]), time[marg_2_idx:marg_3_idx], t_total)
elif method == "local":
t_quat["user_" + str(user_n)] = compute_time(quat_error(R[:marg_1_idx]), time[:marg_1_idx], t_total)
t_z["user_" + str(user_n)] = compute_time(points[2,:][marg_1_idx:marg_2_idx], time[marg_1_idx:marg_2_idx], t_total)
t_y["user_" + str(user_n)] = compute_time(points[1,:][marg_2_idx:marg_3_idx], time[marg_2_idx:marg_3_idx], t_total)
X[method] = x
Y[method] = t_y
Z[method] = t_z
Quat[method] = t_quat
### user feature times ###
GUI_h_time = Z["GUI"].values()
GUI_orien_time = Quat["GUI"].values()
GUI_dist_time = Y["GUI"].values()
global_h_time = Z["global"].values()
global_dist_time = Y["global"].values()
global_orien_time = Quat["global"].values()
local_orien_time = Quat["local"].values()
local_h_time = Z["local"].values()
local_dist_time = Y["local"].values()
### plot time bars ###
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12,4))
fig.suptitle('\n')
# set width of bar
barWidth = 0.25
# Set position of bar on X axis
br1 = np.arange(n)
br2 = [x + barWidth for x in br1]
br3 = [x + barWidth for x in br2]
plt.setp((ax1, ax2, ax3),
xticks=br1+barWidth, xticklabels=br1+1,
xlabel='Users', ylabel='Percent Time')
# plot distance time
ax1.bar(br1, GUI_dist_time, color ='#d9d9d9', width = barWidth, label ='GUI')
ax1.bar(br2, local_dist_time, color ='#b3de69', width = barWidth, label ='Local')
ax1.bar(br3, global_dist_time, color ='#ff7f00', width = barWidth, label ='Global')
ax1.title.set_text('Distance From User')
# plot height time
ax2.bar(br1, GUI_h_time, color ='#d9d9d9', width = barWidth, label ='GUI')
ax2.bar(br2, local_h_time, color ='#b3de69', width = barWidth, label ='Local')
ax2.bar(br3, global_h_time, color ='#ff7f00', width = barWidth, label ='Global')
ax2.title.set_text('Height From Table')
# plot orientation time
ax3.bar(br1, GUI_orien_time, color ='#d9d9d9', width = barWidth, label ='GUI')
ax3.bar(br2, local_orien_time, color ='#b3de69', width = barWidth, label ='Local')
ax3.bar(br3, global_orien_time, color ='#ff7f00', width = barWidth, label ='Global')
ax3.title.set_text('End-Effector Orientation')
handles, labels = ax1.get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center', ncol=3)
plt.tight_layout()
plt.savefig("results_plot/users_time.png")
### user mean feature times ###
GUI_dist_time_mean = average(list(GUI_dist_time))
GUI_h_time_mean = average(list(GUI_h_time))
GUI_orien_time_mean = average(list(GUI_orien_time))
GUI_mean = [GUI_dist_time_mean, GUI_h_time_mean, GUI_orien_time_mean]
local_dist_time_mean = average(list(local_dist_time))
local_h_time_mean = average(list(local_h_time))
local_orien_time_mean = average(list(local_orien_time))
local_mean = [local_dist_time_mean, local_h_time_mean, local_orien_time_mean]
global_dist_time_mean = average(list(global_dist_time))
global_h_time_mean = average(list(global_h_time))
global_orien_time_mean = average(list(global_orien_time))
global_mean = [global_dist_time_mean, global_h_time_mean, global_orien_time_mean]
fig = plt.figure()
features = ['Distance','Height','Orient']
# Set position of bar on X axis
barWidth = 0.3
br1 = np.arange(len(features))
br2 = [x + barWidth for x in br1]
br3 = [x + barWidth for x in br2]
plt.bar(br1, GUI_mean, width = barWidth, color ='#d9d9d9', label = 'GUI')
plt.bar(br2, local_mean, width = barWidth, color ='#b3de69', label = 'Local')
plt.bar(br3, global_mean, width = barWidth, color ='#ff7f00', label = 'Global')
plt.xticks(br2, features)
plt.ylabel('Percent Time')
plt.legend()
plt.savefig("results_plot/users_mean_time.png")