-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_plots.m
741 lines (607 loc) · 19.3 KB
/
generate_plots.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
%% Generates and saves the plots needed for the project report
% Check if 'figs/' and its subdirectories exist
if exist('figs', 'dir') ~= 7
mkdir('figs');
end
gen_pdf = 'no';
fig_path = [pwd '/figs/'];
%% Trajectory plots (Pick Phase)
for i = 1 : length(pick)
% Position trajectory
fig = figure;
P = transl(pick{i}.TC);
plot(P);
title(['Task ' num2str(i) ' - Pick - Translational Trajectory']);
legend('x', 'y', 'z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'pick' num2str(i) '_traj_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_traj_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
fig = figure;
R = tr2rpy(pick{i}.TC);
plot(R);
title(['Task ' num2str(i) ' - Pick - Rotational Trajectory']);
legend('roll', 'pitch', 'yaw');
xlabel('Time Steps');
ylabel('RPY angles [rad]');
savefig(fig, [fig_path 'pick' num2str(i) '_traj_rot']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_traj_rot'], 'pdf');
end
close;
end
%% Trajectory plots (Place Phase)
for i = 1 : length(place)
% Position trajectory
fig = figure;
P = transl(place{i}.TC);
plot(P);
title(['Task ' num2str(i) ' - Place - Translational Trajectory']);
legend('x', 'y', 'z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'place' num2str(i) '_traj_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_traj_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
fig = figure;
R = tr2rpy(place{i}.TC);
plot(R);
title(['Task ' num2str(i) ' - Place - Rotational Trajectory']);
legend('roll', 'pitch', 'yaw');
xlabel('Time Steps');
ylabel('RPY angles [rad]');
savefig(fig, [fig_path 'place' num2str(i) '_traj_rot']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_traj_rot'], 'pdf');
end
close;
end
%% Trajectory Error IK (Pick Phase)
for i = 1 : length(pick)
% Forward kinematics trajectory (from IK)
fig = openfig([fig_path 'pick' num2str(i) '_traj_pos']);
hold on;
P = transl(robot.fkine(pick{i}.ik.no_opt.q(:,:)));
plot(P);
hold off;
title(['Task ' num2str(i) ' - Pick - IK Transl. Trajectory Error']);
legend('Ideal x', 'Ideal y', 'Ideal z', 'IK x', ...
'IK y', 'IK z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'pick' num2str(i) '_trajVsik_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_trajVsik_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
% fig = openfig([fig_path 'pick' num2str(i) '_traj_rot']);
% hold on;
%
% R = tr2rpy(robot.fkine(pick{i}.ik.no_opt.q(:,:)));
%
% plot(R);
% hold off;
% title(['Task ' num2str(i) ' - Pick - IK Rot. Trajectory Error']);
% legend('Ideal roll', 'Ideal pitch', 'Ideal yaw', 'IK roll', ...
% 'IK pitch', 'IK yaw');
% xlabel('Time Steps');
% ylabel('RPY angles [rad]');
% savefig(fig, [fig_path 'pick' num2str(i) '_trajVsik_rot']);
% if strcmp(gen_pdf, 'yes')
% saveas(fig, [fig_path 'pick' num2str(i) '_trajVsik_rot'], 'pdf');
% end
% close;
end
%% Trajectory Error IK (Place Phase)
for i = 1 : length(place)
% Forward kinematics trajectory (from IK)
fig = openfig([fig_path 'place' num2str(i) '_traj_pos']);
hold on;
P = transl(robot.fkine(place{i}.ik.no_opt.q(:,:)));
plot(P);
hold off;
title(['Task ' num2str(i) ' - Place - IK Transl. Trajectory Error']);
legend('Ideal x', 'Ideal y', 'Ideal z', 'IK x', ...
'IK y', 'IK z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'place' num2str(i) '_trajVsik_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_trajVsik_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
% fig = openfig([fig_path 'place' num2str(i) '_traj_rot']);
% hold on;
%
% R = tr2rpy(robot.fkine(place{i}.ik.no_opt.q(:,:)));
%
% plot(R);
% hold off;
% title(['Task ' num2str(i) ' - Place - IK Rot. Trajectory Error']);
% legend('Ideal roll', 'Ideal pitch', 'Ideal yaw', 'IK roll', ...
% 'IK pitch', 'IK yaw');
% xlabel('Time Steps');
% ylabel('RPY angles [rad]');
% savefig(fig, [fig_path 'place' num2str(i) '_trajVsik_rot']);
% if strcmp(gen_pdf, 'yes')
% saveas(fig, [fig_path 'place' num2str(i) '_trajVsik_rot'], 'pdf');
% end
% close;
end
%% Trajectory Error CLIK (Pick Phase)
for i = 1 : length(pick)
% Forward kinematics trajectory (from CLIK)
fig = openfig([fig_path 'pick' num2str(i) '_traj_pos']);
hold on;
P = transl(robot.fkine(pick{i}.clik.no_opt.q(:,:)));
plot(P);
hold off;
title(['Task ' num2str(i) ' - Pick - CLIK Transl. Trajectory Error']);
legend('Ideal x', 'Ideal y', 'Ideal z', 'CLIK x', ...
'CLIK y', 'CLIK z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'pick' num2str(i) '_trajVsclik_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_trajVsclik_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
% fig = openfig([fig_path 'pick' num2str(i) '_traj_rot']);
% hold on;
%
% R = tr2rpy(robot.fkine(pick{i}.clik.no_opt.q(:,:)));
%
% plot(R);
% hold off;
% title(['Task ' num2str(i) ' - Pick - CLIK Rot. Trajectory Error']);
% legend('Ideal roll', 'Ideal pitch', 'Ideal yaw', 'CLIK roll', ...
% 'CLIK pitch', 'CLIK yaw');
% xlabel('Time Steps');
% ylabel('RPY angles [rad]');
% savefig(fig, [fig_path 'pick' num2str(i) '_trajVsclik_rot']);
% if strcmp(gen_pdf, 'yes')
% saveas(fig, [fig_path 'pick' num2str(i) '_trajVsclik_rot'], 'pdf');
% end
% close;
end
%% Trajectory Error CLIK (Place Phase)
for i = 1 : length(place)
% Forward kinematics trajectory (from CLIK)
fig = openfig([fig_path 'place' num2str(i) '_traj_pos']);
hold on;
P = transl(robot.fkine(place{i}.clik.no_opt.q(:,:)));
plot(P);
hold off;
title(['Task ' num2str(i) ' - Place - CLIK Transl. Trajectory Error']);
legend('Ideal x', 'Ideal y', 'Ideal z', 'CLIK x', ...
'CLIK y', 'CLIK z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'place' num2str(i) '_trajVsclik_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_trajVsclik_pos'], 'pdf');
end
close;
% Rotation trajectory (RPY angles)
% fig = openfig([fig_path 'place' num2str(i) '_traj_rot']);
% hold on;
%
% R = tr2rpy(robot.fkine(place{i}.clik.no_opt.q(:,:)));
%
% plot(R);
% hold off;
% title(['Task ' num2str(i) ' - Place - CLIK Rot. Trajectory Error']);
% legend('Ideal roll', 'Ideal pitch', 'Ideal yaw', 'CLIK roll', ...
% 'CLIK pitch', 'CLIK yaw');
% xlabel('Time Steps');
% ylabel('RPY angles [rad]');
% savefig(fig, [fig_path 'place' num2str(i) '_trajVsclik_rot']);
% if strcmp(gen_pdf, 'yes')
% saveas(fig, [fig_path 'place' num2str(i) '_trajVsclik_rot'], 'pdf');
% end
% close;
end
%% Trajectory Error Without Cart (ikcon)
% Pick Phase
fig = openfig([fig_path 'pick1_traj_pos']);
hold on;
P = transl(arm.fkine(pick{1}.q_no_cart(:,:)));
plot(P);
hold off;
title('Task 1 (6 DoF) - Pick - ikcon Transl. Trajectory Error');
legend('Ideal x', 'Ideal y', 'Ideal z', 'ikcon x', ...
'ikcon y', 'ikcon z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'pick1_trajVsikcon_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick1_trajVsikcon_pos'], 'pdf');
end
close;
% Place Phase
fig = openfig([fig_path 'place1_traj_pos']);
hold on;
P = transl(arm.fkine(place{1}.q_no_cart(:,:)));
plot(P);
hold off;
title('Task 1 (6 DoF) - Place - ikcon Transl. Trajectory Error');
legend('Ideal x', 'Ideal y', 'Ideal z', 'ikcon x', ...
'ikcon y', 'ikcon z');
xlabel('Time Steps');
ylabel('Distance [m]');
savefig(fig, [fig_path 'place1_trajVsikcon_pos']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place1_trajVsikcon_pos'], 'pdf');
end
close;
%% Ellipsoids
% Pick phase initial pose velocity ellipsoid
% Translational velocity
fig = figure;
grid on;
J_tmp = robot.jacob0(qn);
J_tmp = J_tmp(1:3, :);
plot_ellipse(J_tmp * J_tmp');
title('Pick - Initial Pose Translational Velocity Ellipsoid');
xlabel('x [m/s]');
ylabel('y [m/s]');
zlabel('z [m/s]');
savefig(fig, [fig_path 'ellips_pick_transl']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'ellips_pick_transl'], 'pdf');
end
close;
% Rotational velocity
fig = figure;
grid on;
J_tmp = robot.jacob0(qn);
J_tmp = J_tmp(4:6, :);
plot_ellipse(J_tmp * J_tmp');
title('Pick - Initial Pose Rotational Velocity Ellipsoid');
xlabel('x [rad/s]');
ylabel('y [rad/s]');
zlabel('z [rad/s]');
savefig(fig, [fig_path 'ellips_pick_rot']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'ellips_pick_rot'], 'pdf');
end
close;
% Place phase initial pose velocity ellipsoids
for i = 1 : length(place)
% Translational velocity
fig = figure;
grid on;
% We consider the value of the joint variables for the closed-loop
% inverse kinematics because gives the lowest error
J_tmp = robot.jacob0(place{i}.clik.no_opt.q(end,:));
J_tmp = J_tmp(1:3, :);
plot_ellipse(J_tmp * J_tmp');
title(['Task ' num2str(i) ...
' - Place - Translational Velocity Ellipsoid']);
xlabel('x [m/s]');
ylabel('y [m/s]');
zlabel('z [m/s]');
savefig(fig, [fig_path 'ellips_place' num2str(i) '_transl']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'ellips_place' num2str(i) '_transl'], 'pdf');
end
close;
% Rotational velocity
fig = figure;
grid on;
J_tmp = robot.jacob0(place{i}.clik.no_opt.q(end,:));
J_tmp = J_tmp(4:6, :);
plot_ellipse(J_tmp * J_tmp');
title(['Task ' num2str(i) ...
' - Place - Rotational Velocity Ellipsoid']);
xlabel('x [rad/s]');
ylabel('y [rad/s]');
zlabel('z [rad/s]');
savefig(fig, [fig_path 'ellips_place' num2str(i) '_rot']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'ellips_place' num2str(i) '_rot'], 'pdf');
end
close;
end
%% Manipulability analysis CLIK (Pick)
for i = 1 : length(pick)
man_opt = cell(1,3);
man_noopt = zeros(1,N);
% Actual number of active optimizations
for k = 1 : 2
man_opt{k} = zeros(1,N);
for j = 1 : N
man_opt{k}(j) = robot.maniplty(pick{i}.clik.opt{k}.q(j,:));
end
end
for j = 1 : N
man_noopt(j) = robot.maniplty(pick{i}.clik.no_opt.q(j,:));
end
fig = figure;
plot(1:N, man_noopt);
hold on;
% Actual number of active optimizations
for k = 1 : 2
plot(1:N, man_opt{k});
end
title(['Manipulability - Task ' num2str(i) ' - Pick CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. est. exact');
xlabel('Time Step');
ylabel('Manipulability value');
savefig(fig, [fig_path 'pick' num2str(i) '_clik_manip']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_clik_manip'], ...
'pdf');
end
close;
end
%% Manipulability analysis CLIK (Place)
for i = 1 : length(place)
man_opt = cell(1,3);
man_noopt = zeros(1,N);
% Actual number of active optimizations
for k = 1 : 2
man_opt{k} = zeros(1,N);
for j = 1 : N
man_opt{k}(j) = robot.maniplty(place{i}.clik.opt{k}.q(j,:));
end
end
for j = 1 : N
man_noopt(j) = robot.maniplty(place{i}.clik.no_opt.q(j,:));
end
fig = figure;
plot(1:N, man_noopt);
hold on;
% Actual number of active optimizations
for k = 1 : 2
plot(1:N, man_opt{k});
end
title(['Manipulability - Task ' num2str(i) ' - Place CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. est. exact');
xlabel('Time Step');
ylabel('Manipulability value');
savefig(fig, [fig_path 'place' num2str(i) '_clik_manip']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_clik_manip'], ...
'pdf');
end
close;
end
%% Joint limits plots CLIK (Pick)
for i = 1 : length(pick)
j_mid = mean([robot.qlim(:,1) robot.qlim(:,2)], 2);
dist_noopt = zeros(1, N);
dist_opt = cell(1,4);
% Actual number of active optimizations
for k = 1 : 2
dist_opt{k} = zeros(1, N);
for j = 1 : N
dist_opt{k}(j) = (1 / (2*robot.n)) * sumsqr( ...
(pick{i}.clik.opt{k}.q(j,:)' - j_mid) ./ (robot.qlim(:,2) - ...
robot.qlim(:,1)));
end
end
for j = 1 : N
dist_noopt(j) = (1 / (2*robot.n))*sumsqr( ...
(pick{i}.clik.no_opt.q(j,:)' - j_mid) ./ (robot.qlim(:,2) - ...
robot.qlim(:,1)));
end
fig = figure;
plot(1:N, dist_noopt);
hold on;
% Actual number of active optimizations
for k = 1 : 2
plot(1:N, dist_opt{k});
end
hold off;
title(['Joint Medium Distance - Task ' num2str(i) ' - Pick CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. sym', ...
'Grad. sym exact');
xlabel('Time Step');
ylabel('Squared medium distance [m]')
savefig(fig, [fig_path 'pick' num2str(i) '_clik_dist']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_clik_dist'], 'pdf');
end
close;
end
%% Joint limits plots CLIK (Place)
for i = 1 : length(place)
j_mid = mean([robot.qlim(:,1) robot.qlim(:,2)], 2);
dist_noopt = zeros(1, N);
dist_opt = cell(1,3);
% Actual number of active optimizations
for k = 1 : 2
dist_opt{k} = zeros(1, N);
for j = 1 : N
dist_opt{k}(j) = (1 / (2*robot.n)) * sumsqr( ...
(place{i}.clik.opt{k}.q(j,:)' - j_mid) ./ (robot.qlim(:,2) - ...
robot.qlim(:,1)));
end
end
for j = 1 : N
dist_noopt(j) = (1 / (2*robot.n))*sumsqr( ...
(place{i}.clik.no_opt.q(j,:)' - j_mid) ./ (robot.qlim(:,2) - ...
robot.qlim(:,1)));
end
fig = figure;
plot(1:N, dist_noopt);
hold on;
% Actual number of active optimizations
for k = 1 : 2
plot(1:N, dist_opt{k});
end
hold off;
title(['Joint Medium Distance - Task ' num2str(i) ' - Place CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. sym', ...
'Grad. sym exact');
xlabel('Time Step');
ylabel('Squared medium distance [m]')
savefig(fig, [fig_path 'place' num2str(i) '_clik_dist']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_clik_dist'], 'pdf');
end
close;
end
%% Plane distance plots CLIK (Pick)
for i = 1 : length(pick)
dist_opt = cell(1,4);
dist_noopt = zeros(1, N);
% Actual number of active optimizations
for k = 1 : 2
dist_opt{k} = zeros(1, N);
for j = 1 : N
dist_opt{k}(j) = dist_plane(robot, pick{i}.clik.opt{k}.q(j,:));
end
end
for j = 1 : N
dist_noopt(j) = dist_plane(robot, pick{i}.clik.no_opt.q(j,:));
end
fig = figure;
plot(1:N, dist_noopt);
hold on;
% Actual number of active optimizations
for k = 1 : 2
plot(1:N, dist_opt{k});
end
hold off;
title(['Plane Medium Distance - Task ' num2str(i) ' - Pick CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. sym', ...
'Grad. sym exact');
xlabel('Time Step');
ylabel('Squared medium distance [m]')
savefig(fig, [fig_path 'pick' num2str(i) '_clik_plane']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick' num2str(i) '_clik_plane'], 'pdf');
end
close;
end
%% Plane distance plots CLIK (Place)
for i = 1 : length(place)
dist_opt = cell(1,4);
dist_noopt = zeros(1, N);
% Actual number of active optimizations
for k = 1 : 2
dist_opt{k} = zeros(1, N);
for j = 1 : N
dist_opt{k}(j) = dist_plane(robot, place{i}.clik.opt{k}.q(j,:));
end
end
for j = 1 : N
dist_noopt(j) = dist_plane(robot, place{i}.clik.no_opt.q(j,:));
end
fig = figure;
plot(1:N, dist_noopt);
hold on;
for k = 1 : 2
plot(1:N, dist_opt{k});
end
hold off;
title(['Plane Medium Distance - Task ' num2str(i) ' - Place CLIK']);
legend('No opt.', 'fminunc', 'Grad. est.', 'Grad. sym', ...
'Grad. sym exact');
xlabel('Time Step');
ylabel('Squared medium distance [m]')
savefig(fig, [fig_path 'place' num2str(i) '_clik_plane']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'place' num2str(i) '_clik_plane'], 'pdf');
end
close;
end
%% Plot the joint positions obtained by q0 for a specific task
q_pos = cell(robot.n,1);
q_pos{1} = zeros(N-1, 3);
q_pos{2} = zeros(N-1, 3);
q_pos{3} = zeros(N-1, 3);
q_pos{4} = zeros(N-1, 3);
q_pos{5} = zeros(N-1, 3);
q_pos{6} = zeros(N-1, 3);
q_pos{7} = zeros(N-1, 3);
q_pos{8} = zeros(N-1, 3);
for i = 1 : N-1
for j = 1 : robot.n
q_pos{j}(i, :) = transl(robot.A(j, ...
pick{1}.clik.opt{1}.q0(i,:)));
end
end
fig = figure;
hold on;
for i = 1 : robot.n
scatter3(q_pos{i}(:,1), q_pos{i}(:,2), q_pos{i}(:,3));
end
legend('q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8');
plot_robot(robot, qn, fruit{1}, 'r');
hold off;
title('Manip. Optimal Solutions - Task 1 - Pick CLIK');
savefig(fig, [fig_path 'pick1_manip_sol']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick1_manip_sol'], 'pdf');
end
close;
%% Plot a specific joint configuration with the robot
q_pos = zeros(robot.n, 3);
for j = 1 : robot.n
q_pos(j, :) = transl(robot.A(j, ...
pick{1}.clik.opt{1}.q0(100,:)));
end
fig = figure;
hold on;
for i = 1 : robot.n
scatter3(q_pos(i,1), q_pos(i,2), q_pos(i,3), '*');
end
legend('q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8');
plot_robot(robot, qn, fruit{1}, 'r');
hold off;
title('Joint Distance Optimal Solution - Task 1 - Pick CLIK');
savefig(fig, [fig_path 'pick1_manip_sol']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'pick1_manip_sol'], 'pdf');
end
close;
%% Workspace Analysis plots
% Cloud of points
fig = figure;
scatter3(scatter(:,1), scatter(:,2), scatter(:,3), '.');
hold on
for i = 1: length(work_manipl)
if (work_manipl(i,1) < 0.5)
scatter3(scatter(i,1), scatter(i,2), scatter(i,3), '.', 'r');
end
end
hold off;
savefig(fig, [fig_path 'workspace_cloud']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'workspace_cloud'], ...
'pdf');
end
close;
% Convex hull
fig = figure;
dela = delaunay(scatter(:,1), scatter(:,2), scatter(:,3));
tsearchn(scatter, dela, [-1.5 -2.5 0]);
trisurf(dela, scatter(:,1),scatter(:,2), scatter(:,3));
savefig(fig, [fig_path 'workspace_convex']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'workspace_convex'], ...
'pdf');
end
close;
% Workspace manipulability
fig = figure;
histogram(work_manipl(:,1));
savefig(fig, [fig_path 'workspace_manip']);
if strcmp(gen_pdf, 'yes')
saveas(fig, [fig_path 'workspace_manip'], ...
'pdf');
end
close;