Page 1 of 1

Run IK Tool in Matlab

Posted: Mon Aug 31, 2020 11:46 am
by edooley
Hello,

I am trying to run the IK Tool by scripting with Matlab. Currently, I am getting the error that "InverseKinematicsTool Failed: Object: Cannot open file Unassigned. It may not exist or you do not have permission to read it."

I thought it might be because I didn't have the full file path assigned for the trc file, but I now do and I get the same error.

When I open the GUI and load the model specified in this script and run the IK tool using the setup file that is generated in this script, the simulation runs as anticipated and no warnings or errors appear in the GUI message window. This leads me to believe the file being written is correct.

Does anybody have any ideas why this script is throwing this error?

Code: Select all

%% Import OpenSim Libraries
import org.opensim.modeling.*;
% find geometry
ModelVisualizer.addDirToGeometrySearchPaths('I:\17_BuildOttobockWalkerModel\01_FirstPassSTLs')
ModelVisualizer.addDirToGeometrySearchPaths('C:\OpenSim 4.1\Geometry');

%% Load
model = Model('Norm09_scaled_wWalker.osim'); % load scaled model of Norm09 of human with walker
model.initSystem(); % start model

currentfolder = pwd;
markerFile = 'UVA10.trc';
trialname = regexprep(markerFile,'.trc',''); % replace the expression .trc with nothing in the markerFile string
fullMarkerFile = [currentfolder,'\',markerFile];

%% when to start and stop
% capture a little before to a little after one left gait cycle
initial_time = 1.5; % in sec
final_time = 3; % in sec

%% set up the IK tool
ikTool = InverseKinematicsTool('Setup_IK_noJCmarks.xml'); % load generic IK tool based off file that has markers enabled and weighted
ikTool.setName(trialname); % set to trial name
ikTool.setMarkerDataFileName(fullMarkerFile); % set trc to read
ikTool.setStartTime(initial_time); % when to start
ikTool.setEndTime(final_time);     % when to stop
ikTool.setOutputMotionFileName([trialname,'_IKrez.mot']); % generate file in current folder to store IK results

% save settings file
ikTool.print(['Setup_IK_',trialname,'.xml']); % generates set-up xml in current folder

%% Run Inverse Kinematics
ikTool.run();
Thanks for your help,
EAD

Re: Run IK Tool in Matlab

Posted: Mon Aug 31, 2020 12:06 pm
by aymanh
Hello,

I suggest you open the xml setup file in a text editor and see what gets printed as Unassigned and take it from there.

Please let us know what you find out,
-Ayman

Re: Run IK Tool in Matlab

Posted: Mon Aug 31, 2020 12:45 pm
by edooley
Thanks for the tip!

Both the model_file and the coordinate_file were unassigned. I guess I totally missed the iktool.setModel line in the example.

When I added that line in it ran the simulation as expected in Matlab. However, the printed xml file is still marking those two things as "Unassigned"

EAD

Re: Run IK Tool in Matlab

Posted: Mon Aug 31, 2020 1:55 pm
by aymanh
Thanks for the update, Emily.

The call to setModel doesn't necessarily set the property model_file because the Model could have been created programmatically so has no associated file or may have been modified after loading from a file. This also explains why the GUI runs without an issue since it uses the current model in the application. If you prefer you can save the model to a file e.g mymodel.osim and set the model_file property accordingly but that seems unnecessary (and a bit backwards) since you have the model handle already.

Please let us know if this or anything else doesn't behave as expected.

Best regards,
-Ayman