-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrenchForceReader.m
72 lines (67 loc) · 4.04 KB
/
wrenchForceReader.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
% Copyright: (C) 2023 Department of COgNiTive Architecture for Collaborative Technologies
% Istituto Italiano di Tecnologia
% Author: Alessandro Tiozzo
% email: [email protected]
% Permission is granted to copy, distribute, and/or modify this program
% under the terms of the GNU General Public License, version 2 or any
% later version published by the Free Software Foundation.
%
% A copy of the license can be found at
% http://www.robotcub.org/icub/license/gpl.txt
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details
function cuttedSynchWrenchDataSet = wrenchForceReader(numPerson, initialPosDataSet, posStart, posEnd, handInvolved, BaselineFilesParameters)
% Function used to read and sinch the data from the /wholeBodyDynamics/involved_arm/cartesianEndEffectorWrench:o
tic
fprintf("\n .Force transformation error evaluation...")
if numPerson == -2
wrenchDataSet = readtable(strjoin([BaselineFilesParameters(4),"\wrench\leftArm\",BaselineFilesParameters(1),"\data.log"],""));
else
if numPerson == -1
wrenchDataSet = readtable(strjoin([BaselineFilesParameters(4),"\wrench\rightArm\",BaselineFilesParameters(2),"\data.log"],""));
else
if strcmp(handInvolved,"R") == 1
if numPerson < 10
wrenchDataSet = strjoin(["..\iCub_InputData\wrench\leftArm\P_0000",num2str(numPerson),"\data.log"],'');
else
wrenchDataSet = strjoin(["..\iCub_InputData\wrench\leftArm\P_000",num2str(numPerson),"\data.log"],'');
end
else
if numPerson < 10
wrenchDataSet = strjoin(["..\iCub_InputData\wrench\rightArm\P_0000",num2str(numPerson),"\data.log"],'');
else
wrenchDataSet = strjoin(["..\iCub_InputData\wrench\rightArm\P_000",num2str(numPerson),"\data.log"],'');
end
end
end
end
wrenchDataSet = renamevars(wrenchDataSet,["Var1","Var2","Var3","Var4","Var5","Var6","Var7","Var8"], ...
["Counter","Time","Fx","Fy","Fz","Tx","Ty","Tz"]);
%% Synchronizing wrench forces signal with position
% Find the initial delay between the two sampled signals
initialTimeDelay = initialPosDataSet.Time(1)-wrenchDataSet.Time(1);
if initialTimeDelay >= 0
% If the wrench forces have more samples than position, than it has smaller starting time,
% and a positive difference with the position one, so it needs to be back-shifted
synchWrenchDataSet = wrenchDataSet(wrenchDataSet.Time>=initialPosDataSet.Time(1),:);
else
% The opposite situation, so it will be forward-shifted using some zeros
zeroMatrix = array2table(zeros(sum(wrenchDataSet.Time(1)>initialPosDataSet.Time),size(wrenchDataSet,2)));
zeroMatrix = renamevars(zeroMatrix,["Var1","Var2","Var3","Var4","Var5","Var6","Var7","Var8"], ...
["Counter","Time","Fx","Fy","Fz","Tx","Ty","Tz"]);
synchWrenchDataSet = [zeroMatrix;wrenchDataSet];
end
tmpCuttedSynchWrenchDataSet = zeros(posEnd-posStart+1,8);
for j = 2:9
% Now the wrench forces have to be interpolated in the position time stamp in order
% to set the same start and stop point
tmpSynchWrenchDataSet = interp1(1:height(synchWrenchDataSet),table2array(synchWrenchDataSet(:,j)),1:height(initialPosDataSet));
% Remove greetings and closing
tmpCuttedSynchWrenchDataSet(:,j-1) = tmpSynchWrenchDataSet(posStart:posEnd)';
end
cuttedSynchWrenchDataSet = array2table(tmpCuttedSynchWrenchDataSet);
cuttedSynchWrenchDataSet = renamevars(cuttedSynchWrenchDataSet,1:width(cuttedSynchWrenchDataSet),["Counter","Time","Fx","Fy","Fz","Tx","Ty","Tz"]);
end