Page 1 of 1

Getting Joint Location in Matlab

Posted: Mon Apr 04, 2016 10:17 am
by msarens
Hi everybody,

I'm trying to get the joint location of an .osim model. My ultimate goal is calculating the length of a bone, for instance the tibia. For example I want to know the joint location of the right foot of the .osim model. I try to do this by :

clc
close all
clear all

import org.opensim.modeling.*

osimModel= Model(modelFile1);
osimModel.getJointSet().get("ankle_r").getLocationInParent();

While runnig this piece of code in Matlab I get the next error :
No method 'getLocationInParent' with matching signature found for class 'org.opensim.modeling.Joint'.

Can some one help me with this error?

Greetings Maarten

Re: Getting Joint Location in Matlab

Posted: Mon Apr 04, 2016 5:15 pm
by bradh
Try this:

Code: Select all

import org.opensim.modeling.*

osimModel= Model(modelFile1);
p=Vec3();   % This creates an empty opensim vector which will contain the location in the parent frame
osimModel.getJointSet().get("ankle_r").getLocationInParent(p);

%Now convert into native MATLAB double
pval(1)=p.get(0);
pval(2)=p.get(1);
pval(3)=p.get(2);
And take a look at "Working with Vectors" info here: http://simtk-confluence.stanford.edu:80 ... g+Commands

If the documentation for an API function has a "Vec3" argument (https://simtk.org/api_docs/opensim/api_ ... c459c37081), that's what you will need to do.

Brad

Re: Getting Joint Location in Matlab

Posted: Mon Apr 04, 2016 11:59 pm
by msarens
Thank you very much for your help !
I now understand what I did wrong !

Re: Getting Joint Location in Matlab

Posted: Sat Jun 10, 2017 2:21 pm
by y_ammouche
Dear all,

Sorry to revive this topic, but it seems this manipulation doest not work now, as the function getLocationInParent has to have a VEC3 and a "rLocation" argument but i don't know to create this kind of object in matlab.

Any ideas ?

Thank you

Re: Getting Joint Location in Matlab

Posted: Sat Jun 10, 2017 9:45 pm
by tkuchida
it seems this manipulation doest not work now
What version of OpenSim are you using?

Re: Getting Joint Location in Matlab

Posted: Sun Jun 11, 2017 2:07 am
by y_ammouche
OpenSim 3.3. For information, I use matlab 2015 and both are in 32 bits.

Re: Getting Joint Location in Matlab

Posted: Sun Jun 11, 2017 1:03 pm
by tkuchida
Sorry to revive this topic, but it seems this manipulation doest not work now, as the function getLocationInParent has to have a VEC3 and a "rLocation" argument but i don't know to create this kind of object in matlab.
I did not encounter any issues using the getLocationInParent() method. I think there is confusion about the doxygen for this method (https://simtk.org/api_docs/opensim/api_ ... c459c37081):

Code: Select all

void OpenSim::Joint::getLocationInParent ( SimTK::Vec3 & rLocation ) const
There is only one argument; "SimTK::Vec3 &" is its type and "rLocation" is the name of the variable used in the implementation. Here is an example of how to use this method in MATLAB:

Code: Select all

import org.opensim.modeling.*

model = Model('arm26.osim');
state = model.initSystem();

elbow = model.getJointSet().get('r_elbow');
locInParent = Vec3(0);
elbow.getLocationInParent(locInParent);
locInParent
The following will be printed to the MATLAB Command Window:

Code: Select all

locInParent =
 
~[0.0061,-0.2904,-0.0123]

Re: Getting Joint Location in Matlab

Posted: Sun Jun 11, 2017 1:42 pm
by y_ammouche
Thanks for the answer !

I know what went wrong.