Run IK Tool in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Evan Dooley
Posts: 25
Joined: Fri Sep 27, 2019 8:36 am

Run IK Tool in Matlab

Post by Evan Dooley » Mon Aug 31, 2020 11:46 am

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

Tags:

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: Run IK Tool in Matlab

Post by Ayman Habib » Mon Aug 31, 2020 12:06 pm

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

User avatar
Evan Dooley
Posts: 25
Joined: Fri Sep 27, 2019 8:36 am

Re: Run IK Tool in Matlab

Post by Evan Dooley » Mon Aug 31, 2020 12:45 pm

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

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: Run IK Tool in Matlab

Post by Ayman Habib » Mon Aug 31, 2020 1:55 pm

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

POST REPLY