AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
plotForcesTorquesWorld.m
1 function plotForcesTorquesWorld(rootPath, robotName, strNorm)
2 
3 legFontSize = 19;
4 titleFontSize = 18;
5 ylabFontSize = 17;
6 xlabFontSize = 17;
7 
8 coordName = 'Coordinator/';
9 vecFor = importMatrices(strcat(rootPath, robotName, '/forces.txt'));
10 vecTor = importMatrices(strcat(rootPath, robotName, '/torques.txt'));
11 fileName = "wTt.txt";
12 wTt = importMatrices(strcat(rootPath, coordName, fileName));
13 nStep = min( size(vecFor, 3), size(wTt, 3));
14 
15 %project in world
16 w_vecFor =zeros(3,nStep);
17 w_vecTor =zeros(3,nStep);
18 for i=1:nStep
19  w_vecFor (:,i) = wTt(1:3,1:3,i) * vecFor(:,:,i);
20  w_vecTor (:,i) = wTt(1:3,1:3,i) * vecTor(:,:,i);
21 end
22 
23 %millisecond indicated in missionManager
24 global sControlLoop
25 totSecondPassed = sControlLoop*(nStep-1);
26 seconds = 0:sControlLoop:totSecondPassed;
27 
28 global secInsertion
29 
30 % plot force
31 figure('Renderer', 'painters', 'Position', [0 0 710 550])
32 subplot(2,1,1)
33 hold on;
34 if strcmp(strNorm, 'yes')
35  plot(seconds, vecnorm(w_vecFor));
36  ylab = ylabel('norm of force [N]');
37  tq = title("Norm of force vector projected in world");
38  xlim([0,180]);
39  ylim([0,2]);
40 else
41  plot(seconds, w_vecFor);
42  leg = legend('x','y', 'z');
43  ylab = ylabel('forces [N]');
44  tq = title(strcat("forces projected in world"));
45  set(leg, 'Interpreter', 'latex', 'FontSize' , legFontSize);
46  xlim([0,200]);
47 end
48 grid on;
49 xlab = xlabel('time [s]');
50 plot([secInsertion; secInsertion], [0,15], '--m');
51 text([secInsertion+2], [14], {'\rightarrow Inside the hole'}, 'Color', 'magenta', 'FontSize',14);
52 hold off
53 
54 
55 %% torque
56 subplot(2,1,2)
57 hold on;
58 if strcmp(strNorm, 'yes')
59  plot(seconds, vecnorm(w_vecTor));
60  ylab2 = ylabel('norm of torque [N*m]');
61  tq2 = title('Norm of torque vector projected in world');
62  xlim([0,180]);
63  ylim([0,0.4]);
64 
65 else
66  plot(seconds, w_vecTor);
67  leg2 = legend('x','y', 'z');
68  ylab2 = ylabel('torques [N*m]');
69  tq2 = title(strcat("torques projected in world"));
70  set(leg2, 'Interpreter', 'latex', 'FontSize' , legFontSize);
71  %xlim([0,170]);
72 
73 end
74 grid on;
75 xlab2 = xlabel('time [s]');
76 
77 plot([secInsertion; secInsertion], [ylim]', '--m');
78 text([secInsertion+2], [18.7], {'\rightarrow Inside the hole'}, 'Color', 'magenta', 'FontSize',14);
79 hold off
80 
81 set (tq, 'Interpreter', 'latex', 'FontSize' , titleFontSize);
82 set (ylab, 'Interpreter', 'latex', 'FontSize', ylabFontSize);
83 set (xlab, 'Interpreter', 'latex', 'FontSize', xlabFontSize);
84 set (tq2, 'Interpreter', 'latex', 'FontSize' , titleFontSize);
85 set (ylab2, 'Interpreter', 'latex', 'FontSize', ylabFontSize);
86 set (xlab2, 'Interpreter', 'latex', 'FontSize', xlabFontSize);
87 
88 
89