-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaperFigures.m
395 lines (347 loc) · 13.3 KB
/
PaperFigures.m
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
clearvars; clc; close all; addpath("data"); addpath("figures"); addpath("functions"); addpath("modeling");
set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultAxesTickLabelInterpreter','latex'); set(groot,'defaultLegendInterpreter','latex');
%% ---------------- learning 1D suction cup dynamics ----------------- %%
%% Constants and Settings
set(groot,'defaultAxesFontSize',10)
%Load the data
load('data/processedData.mat')
load("data/meanAndStdData.mat")
data = processedData;
exps = fieldnames(expStats);
fn = fieldnames(data);
%Settings
lineWidth = 2; % The linewidth
Nsigma = 3; % the # of std the confidence interval is plotted at
doSave = false;
initHyperParGrouping = "init_D600";
%0.16kg","0.306kg","0.452kg",'0.642kg',"0.714kg","0.784kg","0.974kg","1.181kg","1.581kg","2.187kg
% Colors used for the masses
% colors = 1/255*...
% [0 0 123
% 93 85 0
% 149 211 79
% 162 129 0
% 15 98 106
% 201 169 128
% 110 0 0
% 246 169 1
% 150 0 0
% 25 85 60];
colors = 1/255*...
[122,70,57
220,217,208
84,11,14
46,68,75
182,174,163
181,219,247
51,92,103
224,159,62
231,224,208
201,174,145];
haags = [46,68,75]/255;
dadel = [201,174,145]/255;
herfst = [122,70,57]/255;
%Computations
for i = 109% 1:Nexps
exp = data.(fn{i});
fprintf(append("Used mass: ", string(exp.mass), " kilograms.\n"))
t = exp.time*1000;
h = exp.h;
dh = exp.dh;
ddh = exp.ddh;
s = exp.s;
ds = exp.ds;
dds = exp.dds;
a = exp.a;
da = exp.da;
dda = exp.dda;
end
masses = [];
z0s = [];
for i = 1:length(fn)
z0 = data.(fn{i}).z(1)*1000;
z0s = [z0s;z0];
m = data.(fn{i}).mass;
masses = [masses; m];
end
massesSorted = sort(unique(masses));
z0mean = [];
z0std = [];
for m = massesSorted'
ix = find(masses == m);
z0mean = [z0mean; mean(z0s(ix))];
z0std = [z0std; std(z0s(ix))];
end
%For the releases
mass_2 = [];
for i = 1:length(exps)
mass_2 = [mass_2; expStats.(exps{i}).mass];
end
maxmass = max(mass_2);
minmass = min(mass_2);
for i = 1:length(exps)
mass = expStats.(exps{i}).mass;
position_obj(:,i) = expStats.(exps{i}).h_avg;
velocity_obj(:,i) = expStats.(exps{i}).dh_avg;
accelera_obj(:,i) = expStats.(exps{i}).ddh_avg;
position_rel(:,i) = expStats.(exps{i}).z_avg;
velocity_rel(:,i) = expStats.(exps{i}).dz_avg;
accelera_rel(:,i) = expStats.(exps{i}).ddz_avg;
position_arm(:,i) = expStats.(exps{i}).a_avg;
velocity_arm(:,i) = expStats.(exps{i}).da_avg;
accelera_arm(:,i) = expStats.(exps{i}).dda_avg;
end
time = [0:length(position_obj)-1]/360;
time = time*1000;
% Plot zm, zdm for all masses at same times
N = length(exps);
for ti = 1:length(time)
for i = 1:N
z(i,ti) = expStats.(exps{i}).z_avg(ti);
zd(i,ti) = expStats.(exps{i}).dz_avg(ti);
m(i) = expStats.(exps{i}).mass;
end
end
% Simulating releases
sim_result = simulateFunc(initHyperParGrouping, true);
%% Plot the figures
%Check if figures directory exists, if not, it will create one.
if ~isfolder('figures')
mkdir('figures');
end
%Create a plot grid
sizex = 456;
sizey = 250;
px = (0:7)*(sizex+10)+10;
py = (0:4)*(sizey+40)+45;
for ii = 1:length(px)
for jj = 1:length(py)
pp{jj,ii} = [px(ii) py(jj)];
end
end
%%
close all
set(groot,'defaultAxesFontSize',11)
figure('rend','painters','unit','centimeters','pos',[0.238125,1.164167,6.25,6]);
ha = tight_subplot(1,1,[.05 .04],[.14 .03],[0.19 0.13]); %[gap_h gap_w] [lower upper] [left right]
axes(ha(1));
for ti=1:length(time); plot3(m'.*z(:,ti)*1000, m'.*zd(:,ti), time(ti)*ones(1,N),'color',[.4, .4, .4],'HandleVisibility','off'); hold on; end; hold on;
for ii=1:N; plot3(m(ii)*z(ii,:)*1000, m(ii)*zd(ii,:), time, 'LineWidth',lineWidth,'color',colors(ii,:)); hold on; end;
grid on
axis square
% L1 = legend({"0.16kg","0.306kg","0.452kg",'0.642kg',"0.714kg","0.784kg","0.974kg","1.181kg","1.581kg","2.187kg"},'NumColumns',5,'location','northeast');
% L1.Position(2) = 0.90;
% L1.Position(1) = 0.5-(L1.Position(3)/2);
% L1.FontSize = 9;
xlabel("$mz$ [kg mm]",'Position',[50,3,0])
ylabel({"\quad $m\dot{z}$";"[kg m/s]"},'Position',[-30,1.5,0])
zlabel("Time [ms]")
view(205,25)
if doSave
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig,'figures/mz-mzd-t-expmean.pdf','-dpdf','-painters')
end
%%
figure('rend','painters','unit','centimeters','pos',[7,1.164167,6.25,6]);
ha = tight_subplot(1,1,[.05 .04],[.14 .03],[0.19 0.13]); %[gap_h gap_w] [lower upper] [left right]
axes(ha(1));
for ti=1:length(time); plot3(z(:,ti)*1000, zd(:,ti), time(ti)*ones(1,N),'color',[.4, .4, .4],'HandleVisibility','off'); hold on; end; hold on;
for ii=1:N; plot3(z(ii,:)*1000, zd(ii,:), time, 'LineWidth',lineWidth,'color',colors(ii,:)); hold on; end;
grid on
axis square
% L1 = legend({"0.16kg","0.306kg","0.452kg",'0.642kg',"0.714kg","0.784kg","0.974kg","1.181kg","1.581kg","2.187kg"},'NumColumns',5,'location','northeast');
% L1.Position(2) = 0.90;
% L1.Position(1) = 0.5-(L1.Position(3)/2);
% L1.FontSize = 9;
xlabel("$mz$ [kg mm]",'Position',[70,1.4,0])
ylabel({"\quad $m\dot{z}$";"[kg m/s]"},'Position',[43,0.7,0])
zlabel("Time [ms]")
view(205,25)
if doSave
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig,'figures/z-zd-t-expmean.pdf','-dpdf','-painters')
end
%% Plot typical release
figure('rend','painters','unit','centimeters','pos',[7,1.164167,8.75,8.6349]); %-25.876250000000002,5.053541666666668,10.054166666666669,9.921875000000002
ha = tight_subplot(3,1,[.05 .04],[.09 .03],[0.12 0.03]); %[gap_h gap_w] [lower upper] [left right]
axes(ha(1));
plot(t, (exp.a-exp.z)*1e3, "LineWidth", lineWidth,'color',haags, "DisplayName","package"); hold on; grid on;
plot(t, s*1e3, "LineWidth", lineWidth,'color',dadel, 'DisplayName','suction cup')
ylabel("Height [mm]")
xlim([0 140]);
ylim([30 110])
yticks(linspace(30,110,5))
axes(ha(2));
plot(t, dh, "LineWidth", lineWidth,'color',haags); hold on;
plot(t, ds, "LineWidth", lineWidth,'color',dadel); grid on;
ylabel("Velocity [m/s]")
xlim([0 140]);
ylim([-1.5 0.5])
yticks(linspace(-1.5,0.5,5))
axes(ha(3));
plot(t, ddh, "LineWidth", lineWidth,'color',haags); hold on;
plot(t, dds, "LineWidth", lineWidth,'color',dadel); grid on;
ylabel("Acceleration [m/s$^2$]")
xlabel("Time [ms]")
xlim([0 140]);
ylim([-15 45])
yticks(linspace(-15,45,5))
% L1 = legend({'package','suction cup'},'NumColumns',2,'location','northeast');
% L1.Position(2) = 0.94;
% L1.Position(1) = 0.5-(L1.Position(3)/2);
% L1.FontSize = 9;
if doSave
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig,'figures/typicalrelease.pdf','-dpdf','-painters')
end
%% Plot masses vs elongation
figure('rend','painters','units','centimeter','pos',[37,15.5,7.5,3.9474]); %10.054166666666667,5.291666666666668
ha = tight_subplot(1,1,[.05 .04],[.26 .04],[0.16 0.02]); %[gap_h gap_w] [lower upper] [left right]
axes(ha(1));
plot(masses,z0s,'.','color',dadel); hold on; grid on;
plot(massesSorted, z0mean,'color',haags,'LineWidth',1.2)
plot(massesSorted, z0mean + Nsigma*z0std,'color',herfst,'LineStyle','--','LineWidth',1.2)
plot(massesSorted, z0mean - Nsigma*z0std,'color',herfst,'LineStyle','--','LineWidth',1.2)
xlabel("Object mass [kg]")
ylabel("$z(t_0)$ [mm]")
ylim([49, 54]);
xlim([0 2.3]);
xticks([0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 2.25])
yticks(-flip([-54 -53.5 -53 -52.5 -52 -51.5 -51 -50.5 -50 -49.5 -49]))
yticklabels({'49','49,5','50','50,5', '51', '51,5', '52', '52,5', '53', '53,5', '54'})
% L1 = legend({'datapoints','mean','3$\sigma$ interval'},'NumColumns',3,'location','northeast');
% L1.Position(2) = 0.9;
% L1.Position(1) = 0.5-(L1.Position(3)/2)+0.06;
% L1.FontSize = 9;
if doSave
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig,'figures/SCrestLength.pdf','-dpdf','-painters')
end
%% Plot the position velocity and acceleration of object and tool arm
set(groot,'defaultAxesFontSize',11)
figure('rend','painters','units','centimeter','pos',[0.238125,15.45166666666667,12.5,6.614583333333334]);
ha = tight_subplot(3,2,[.04 .1],[.13 .02],[0.09 0.01]); %[gap_h gap_w] [lower upper] [left right]
axes(ha(1));
for ii = 1:width(position_obj); plot(time, position_obj(:,ii)*1000,'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
set(gca,'xticklabel',[])
ylabel('$h$ [mm]')
axes(ha(3));
for ii = 1:width(position_obj); plot(time, velocity_obj(:,ii),'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
set(gca,'xticklabel',[])
ylabel('$\dot{h}$ [m/s]')
ylim([-1.1 0.1]);
axes(ha(5));
for ii = 1:width(position_obj); plot(time, accelera_obj(:,ii),'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
ylabel('$\ddot{h}$ [m/s$^2$]')
xlabel("Time [ms]")
ylim([-17.1 8.4]);
axes(ha(2));
for ii = 1:width(position_obj); plot(time, position_arm(:,ii)*1000,'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
set(gca,'xticklabel',[])
ylabel('$a$ [mm]')
ylim([139 141]);
axes(ha(4));
for ii = 1:width(position_obj); plot(time, velocity_arm(:,ii),'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
set(gca,'xticklabel',[])
ylabel('$\dot{a}$ [m/s]')
ylim([-0.032 0.037]);
axes(ha(6));
for ii = 1:width(position_obj); plot(time, accelera_arm(:,ii),'LineWidth',lineWidth,'color',colors(ii,:)); hold on; drawnow; end
hold on
grid on
xlim([0 142]);
ylabel('$\ddot{a}$ [m/s$^2$]')
xlabel("Time [ms]")
ylim([-2 2]);
% L1 = legend({"0.160kg","0.306kg","0.452kg",'0.642kg',"0.714kg","0.784kg","0.974kg","1.181kg","1.581kg","2.187kg"},'NumColumns',5,'location','northeast');
% L1.Position(2) = 0.86;
% L1.Position(1) = 0.5-(L1.Position(3)/2);
% L1.FontSize = 9;
if doSave
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];
print(fig,'figures/ReleaseResults.pdf','-dpdf','-painters')
end
%% Simulation results
% close all
fnsim = fieldnames(sim_result);
for ii = 1:length(fnsim)
res = sim_result.(fnsim{ii});
FontSize = 10;
if ii == 1 || ii == 4 || ii ==8
figure('rend','painters','units','centimeter','pos',[37,15.5,4.5,5]);
ha = tight_subplot(3,1,[.04 .12],[.18 .05],[0.22 0.03]); %[gap_h gap_w] [lower upper] [left right]
else
figure('rend','painters','units','centimeter','pos',[37,15.5,4,5]);
ha = tight_subplot(3,1,[.04 .12],[.18 .05],[0.15 0.03]); %[gap_h gap_w] [lower upper] [left right]
end
axes(ha(1));
plot(res.time_exp*1000, res.h_exp*1000,'color',haags,'LineWidth',1); hold on; grid on;
plot(res.time_exp*1000, res.h_sim*1000,'color',dadel,'LineWidth',1)
plot(res.time_exp*1000, (res.h_exp + res.Nsigma*res.h_exp_std)*1000,'--','color',herfst)
plot(res.time_exp*1000, (res.h_exp - res.Nsigma*res.h_exp_std)*1000,'--','color',herfst)
if ii == 1 || ii == 4 || ii ==8; ylabel("$h$",'FontSize',FontSize); end
xlim([0 140])
ylim([30 100])
ax = gca;
set(ax,'xticklabel',[])
% lgd = legend({'Exp. mean','Simulation','3$\sigma$ on exp.'}, 'Location', 'southwest','FontSize',9);
axes(ha(2));
plot(res.time_exp*1000, res.dh_exp,'color',haags,'LineWidth',1); hold on; grid on;
plot(res.time_exp*1000, res.dh_sim,'color',dadel,'LineWidth',1)
plot(res.time_exp*1000, res.dh_exp + res.Nsigma*res.dh_exp_std,'--','color',herfst)
plot(res.time_exp*1000, res.dh_exp - res.Nsigma*res.dh_exp_std,'--','color',herfst)
if ii == 1 || ii == 4 || ii ==8; ylabel("$\dot{h}$",'FontSize',FontSize); end
xlim([0 140])
ylim([-1.1 0])
ax = gca;
set(ax,'xticklabel',[])
axes(ha(3));
plot(res.time_exp*1000, res.ddh_exp,'color',haags,'LineWidth',1); hold on; grid on;
plot(res.time_exp*1000, res.ddh_sim,'color',dadel,'LineWidth',1)
plot(res.time_exp*1000, res.ddh_exp + res.Nsigma*res.ddh_exp_std,'--','color',herfst)
plot(res.time_exp*1000, res.ddh_exp - res.Nsigma*res.ddh_exp_std,'--','color',herfst)
if ii == 1 || ii == 4 || ii ==8; ylabel("$\ddot{h}$",'FontSize',FontSize); end
xlabel("Time [ms]",'FontSize',FontSize)
xlim([0 140])
if ii == 1 || ii ==2 || ii == 3
ylim([-21 15]);
elseif ii == 4 || ii ==5 || ii == 6
ylim([-15 1]);
else
ylim([-15 1]);
end
if doSave
ax = gcf;
exportgraphics(ax,append('figures/',string(res.m*1000),'gram.pdf'))
end
end