AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
plotGenericErrorDivided.m
1 function plotGenericErrorDivided(pathName, fileName, strNorm)
2 
3 legFontSize = 19;
4 titleFontSize = 18;
5 ylabFontSize = 17;
6 xlabFontSize = 17;
7 
8 
9 errors = importMatrices(pathName);
10 errorsSqueezed = squeeze(errors);
11 nStep = size(errors, 3);
12 
13 global sControlLoop
14 totSecondPassed = sControlLoop*(nStep-1);
15 seconds = 0:sControlLoop:totSecondPassed;
16 
17 global secInsertion
18 
19 figure('Renderer', 'painters', 'Position', [0 0 710 550])
20 subplot(2,1,1);
21 hold on;
22 if strcmp(strNorm,'yes')
23  plot(seconds, vecnorm(errorsSqueezed(1:3,:)) );
24  grid on;
25  xlim([0,10]);
26  ylim([0, 0.03]);
27 else
28  plot(seconds, errorsSqueezed(1:3,:));
29 end
30 %vertical line to show where insertion begin
31 %plot([secInsertion; secInsertion], [ylim]', '--m');
32 %text([secInsertion+2], [5.6], {'\rightarrow Inside the hole'}, 'Color','magenta', 'FontSize',14);
33 %ylim([-5.5,1]);
34 hold off;
35 xlab1 = xlabel('time [s]');
36 
37 
38 if strcmp(fileName,'realgoal_Tool_error')
39  if strcmp(strNorm,'yes')
40  ylab1 = ylabel('norm of error [m]');
41  tq1 = title("Norm of Linear error between goal (real) and tool");
42  else
43  ylab1 = ylabel('errors [m]');
44  tq1 = title("Linear error between goal (real) and tool");
45  leg1 = legend('$x$','$y$', '$z$');
46  set(leg1, 'Interpreter', 'latex', 'FontSize' , legFontSize);
47  end
48 elseif strcmp(fileName, 'Tracking_error')
49  if strcmp(strNorm,'yes')
50  ylab1 = ylabel('norm [m]');
51  tq1 = title("Norm of Linear error between real pose and estimated one");
52  end
53 else
54  ylab1 = ylabel('errors [m]');
55  tq1 = title("Cartesian Linear Error");
56  leg1 = legend('$x$','$y$', '$z$');
57  set(leg1, 'Interpreter', 'latex', 'FontSize' , legFontSize);
58 end
59 
60 
61 subplot(2,1,2);
62 hold on;
63 if strcmp(strNorm,'yes')
64  plot(seconds, vecnorm(errorsSqueezed(4:6,:)));
65  xlim([0,10]);
66  ylim([0, 0.15]);
67  grid on;
68 else
69  plot(seconds, errorsSqueezed(4:6,:) );
70 end
71 %vertical line to show where insertion begin
72 %plot([secInsertion; secInsertion], [ylim]', '--m');
73 %text([secInsertion+2], [0.037], {'\rightarrow Inside the hole'}, 'Color','magenta', 'FontSize',14);
74 hold off;
75 xlab2 = xlabel('time [s]');
76 
77 if strcmp(fileName,'realgoal_Tool_error')
78  if strcmp(strNorm,'yes')
79  ylab2 = ylabel('norm of error [rad]');
80  tq2 = title("Norm of Angular error between goal (real) and tool");
81  %ylim([0,0.05]);
82 
83  else
84  ylab2 = ylabel('errors [rad]');
85  tq2 = title("Angular error between goal (real) and tool");
86  leg2 = legend('$roll$', '$pitch$', '$yaw$');
87  set(leg2, 'Interpreter', 'latex', 'FontSize' , legFontSize);
88  end
89  elseif strcmp(fileName, 'Tracking_error')
90  if strcmp(strNorm,'yes')
91  ylab2 = ylabel('norm [rad]');
92  tq2 = title("Norm of Angular error between real pose and estimated one");
93  end
94 else
95  ylab2 = ylabel('errors [rad]');
96  tq2 = title("Cartesian Angular Error");
97  leg2 = legend('$roll$', '$pitch$', '$yaw$');
98  set(leg2, 'Interpreter', 'latex', 'FontSize' , legFontSize);
99 end
100 
101 
102 set(ylab1, 'Interpreter', 'latex', 'FontSize' , ylabFontSize);
103 set (tq1, 'Interpreter', 'latex', 'FontSize' , titleFontSize);
104 set(ylab2, 'Interpreter', 'latex', 'FontSize' , ylabFontSize);
105 set (tq2, 'Interpreter', 'latex', 'FontSize' , titleFontSize);
106 set (xlab1, 'Interpreter', 'latex', 'FontSize', xlabFontSize);
107 set (xlab2, 'Interpreter', 'latex', 'FontSize', xlabFontSize);
108 
109 
110 
111 
112 
113 
114 %% plot vel norm
115 % figure
116 % hold on;
117 % for i = 1:nRow
118 % a(:) = norms(i,1,:);
119 % plot(seconds, a);
120 % end
121 % xlabel('time [s]');
122 % ylab = ylabel('norms');
123 %
124 % tq = title("Norms (lin, ang) of Cartesian Error between the two coincident pipes");
125 %
126 % leg = legend('Linear', 'Angular');
127 % set(leg, 'Interpreter', 'latex', 'FontSize' , legFontSize);
128 % set(ylab, 'Interpreter', 'none', 'FontSize' , ylabFontSize);
129 %
130 % set (tq, 'Interpreter', 'latex', 'FontSize' , titleFontSize);
131 % hold off