Page 1 of 1

Ligament moment arm in Matlab API

Posted: Thu Nov 08, 2012 9:28 am
by romleberre
Hi,

I want to estimate some knee ligaments properties through an optimization process using API in Matlab.

First, I need to obtain the knee ligaments moment arms using the "ComputeMomentArm" method in the "Ligament" class.
My code to get the moment arms in the default pose is:

Code: Select all

myModel = Model('myModel.osim')
aLigament = Ligament();  
aLigament.assign(myModel.getForceSet.get('aLigament'));
state = myModel.initSystem();
aCoord = myModel.getCoordinateSet.get('aCoord')
momentArm_aCoord = Lig.computeMomentArm(state,aCoord) 
But the following error is displayed:
??? Java exception occurred:
java.lang.RuntimeException: ModelComponent::isCacheVariableValid:
ERR- name not found.
for component '' of type GeometryPath

at
org.opensim.modeling.opensimModelJNI.GeometryPath_computeMomentArm(Native
Method)

at
org.opensim.modeling.GeometryPath.computeMomentArm(GeometryPath.java:172)
I don't understand what is exactly the cacheVariable and how it should be managed in this particular case. Does anybody can clarify this for me?

Thanks for your help

Romain

Re: Ligament moment arm in Matlab API

Posted: Thu Nov 08, 2012 12:12 pm
by aymanh
Hi Romain,

Your code makes a fresh copy of the Ligament rather than gets a reference to the Ligament that lives in the model and so it causes problems downstream. To get a reference to the Ligament in the model you should call model.getForceSet() then get the individual Force (A Ligament lives in the ForceSet). Since the reference you get is to the base class "Force" while you need to use a method of the subclass Ligament, you'd need to tell Matlab to treat the Force as a Ligament (by calling safeDownCast as explained below):

Code: Select all

myModel = Model('myModel.osim')
state = myModel.initSystem()
myForce =myModel.getForceSet().get('aLigament')
myLigament = Ligament.safeDownCast(myForce )
aCoord = myModel.getCoordinateSet.get('aCoord')
momentArm_aCoord = myLigament.computeMomentArm(state,aCoord) 
 
Hope this helps and please let me know how it goes.

Best regards,
-Ayman

Re: Ligament moment arm in Matlab API

Posted: Fri Nov 09, 2012 4:10 pm
by romleberre
It works now. Thanks Ayman.