Page 1 of 1

MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Fri Apr 16, 2021 12:35 pm
by nathanknodel
Hello,

I am trying to write a MATLAB script that will be able to calculate specific muscles' unit vectors and moment arms throughout a specific motion. To do this, I need the muscles' path points. I'm new to scripting in OpenSim's API, and during some searches on the forum came across this thread:

viewtopicPhpbb.php?f=91&t=7723&p=0&star ... 4c70db5cbd

I copied and pasted the example code that Thomas provided and upon running it received the following error:

Check for missing argument or incorrect argument data type in call to function 'getLocation'. I received this error several times beforehand when trying my own scripts, which is what led me to searching for and finding the above thread in the first place. I'm not really sure where to go from here. I'm assuming I'm missing something obvious but being new to this process, I can't seem to figure out what it is. Any help would be appreciated.

For reference, I've run into this issue on both Mac and Windows, and in versions 4.0 and 4.1 of OpenSim.

Thank you,
Nathan

Re: MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Fri Apr 16, 2021 4:39 pm
by tkuchida
The documentation for the PathPoint::getLocation() method can be found here: https://simtk.org/api_docs/opensim/api_ ... a0e2258120. The argument is a State.

Re: MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Fri Apr 16, 2021 5:19 pm
by nathanknodel
Hi Thomas,

Thank you for the reply. Does that mean that the method has changed since my previously mentioned post and that the line should read

locInBody = pathPoint.getLocation(state);

instead? If so, are there many other instances like this where methods' arguments have changed (specifically from that example)?

Thank you again,
Nathan

Re: MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Sat Apr 17, 2021 6:43 am
by tkuchida
Method signatures sometimes change from one version to the next. You can find upgrade notes in the "What's New..." pages in the documentation: https://simtk-confluence.stanford.edu/p ... Id=3376255. You can also check the CHANGELOG.md file on GitHub for a more detailed list of changes to the API: https://github.com/opensim-org/opensim- ... ANGELOG.md.

Re: MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Mon Apr 19, 2021 7:16 am
by nathanknodel
Got it, thank you for the references. I do have a follow up question regarding my overall goal.

I mentioned in my original post that I would like to obtain this information throughout an exercise (i.e. at each time step). If I have the IK results for an exercise using a marker set, how can I accomplish this? I'm assuming that I need to update the state based on the current coordinates for each time step, but I'm not sure how to go about that. Would you be able to provide a simple example to demonstrate how this is done?

Thank you,
Nathan

Re: MATLAB error with 'getLocation' while trying to get muscle path points

Posted: Tue Apr 20, 2021 9:53 am
by nathanknodel
Hello,

I have since made some progress on my previous question after finding the following forum link:

viewtopicPhpbb.php?f=91&t=6480&p=31950&start=0&view=

However, when implementing this example into my MATLAB program:

Code: Select all

%% Import opensim modeling library - load model and initialize state
import org.opensim.modeling.*

% Load model 
[pathname,filename] = uigetfile('*.osim', 'Select an OpenSim Model File');
modelpath = fullfile(filename,pathname);
model = Model(modelpath);
numCoords = model.getNumCoordinates();

% Initialize state
state = model.initSystem();
q = state.getQ();

%% Store motion file
clear pathname filename modelpath
[pathname,filename] = uigetfile('*.mot', 'Select an OpenSim Motion File');
motionpath = fullfile(filename,pathname);
motion = Storage(motionpath);

%% Loop through motion
for i = 0:(motion.getSize()-1)
   inputModelStateVector = motion.getStateVector(i).getData(); 
   for j = 0:(numCoords-1)
       coordValue = inputModelStateVector.get(j);
       model.updCoordinateSet().get(j).setValue(state, coordValue);
   end
end
I get the error "Array index out of bounds" for the "coordValue = inputModelStateVector.get(j);" line. After a bit of investigation, my "inputModelStateVector" only contains the coordinate values of initially non-zero coordinates from the motion file. For reference, I'm using the gait2392_simbody.osim model and normal.mot motion file from the first OpenSim tutorial. This means that the vector only contains 17 components while numCoords is 23.

Why would it recognize that there are 23 coordinates but only read in 17 of the values? I'm not sure how to get around this. Any advice on how to remedy this issue?

Thank you,
Nathan