-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathID_app.m
85 lines (66 loc) · 3.06 KB
/
ID_app.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
function [ID_RESULTS_PATH, EXLOAD_PATH]=ID_app(MOT_FILE,TRC_FILE, path, IK_results_path, leg, FP_used, setupIDname, initial_time, final_time)
% tic
import org.opensim.modeling.*
% Load the model and initialize
model = Model([path,'\scaled_matlab.osim']);
model.initSystem();
%TRC work around
% Create name of trial from .trc file name
trialname = erase(erase(MOT_FILE, [path,'/']), '.mot');
markerPath =TRC_FILE;
% Get trc data to determine time range
markerData = MarkerData(markerPath);
% Get initial and final time to compute
initial_time = markerData.getStartFrameTime(); % simply get from the loaded trc file the start frame/ time
final_time = markerData.getLastFrameTime(); %simply get from the loaded trc file the end frame/ time
% Create path and Name for Coordinate File (IK File)
fullpathIKFile =IK_results_path;
idTool = InverseDynamicsTool([cd, '/', setupIDname]);
idTool.setName(['ID_' trialname]); % set name for the ID tool
% Tell Tool to use the loaded model
idTool.setModel(model); % set the model to the ID object
% Get the name of the file for this trial
grfFile = MOT_FILE;
% create and prepare external forces xml file
if strcmp(leg, 'Right') && FP_used==1
external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup_FP1_Right.xml'],1); %this is the stupid fore file
elseif strcmp(leg, 'Right') && FP_used==2
external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup_FP2_Right.xml'],1); %this is the stupid fore file
elseif strcmp(leg, 'Left') && FP_used==1
external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup_FP1_Left.xml'],1); %this is the stupid fore file
elseif strcmp(leg, 'Left') && FP_used==2
external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup_FP2_Left.xml'],1); %this is the stupid fore file
else
external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup_FP3_Right.xml'],1); %this is the stupid fore file
end
%external_loads = ExternalLoads([cd, '/', 'ExternalForce_Setup.xml'],1); %this is the stupid fore file
external_loads.setDataFileName(MOT_FILE);
% externalforce =ExternalForce ()
% externalforce.set_data_source_name(fullpathGRFFile)
% external_loads.adoptAndAppend(externalforce)
extLoadsName = ['Setup_force_',trialname,'.xml'];
lowpassfilter= 6;
external_loads.print([path,'/', extLoadsName]);
EXLOAD_PATH = [path,'/', extLoadsName];
idTool.setName(trialname);
idTool.setModelFileName([path,'/' ,'scaled_weighted_matlab.osim']);
%Set file containing IK data
idTool.setCoordinatesFileName(fullpathIKFile);
%Set start and end time
idTool.setStartTime(initial_time);
idTool.setEndTime(final_time);
%Set output file and folder
idTool.setOutputGenForceFileName([ path,'\ID_RESULTS_' trialname '.sto' ]);
ID_RESULTS_PATH = [ path,'\ID_RESULTS_' trialname '.sto' ];
idTool.setResultsDir([path, '/']);
% Set file containing External Loads information
idTool.setExternalLoadsFileName([path, '\' ,extLoadsName]);
%%
idTool.setLowpassCutoffFrequency(lowpassfilter);
% Save the settings in a setup file
outfileID = [path, '/Setup_ID_' trialname '.xml' ];
idTool.print(outfileID);
idTool.run();
%
% toc
end