Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Romain LEBERRE
- Posts: 12
- Joined: Fri Feb 24, 2012 11:47 am
Post
by Romain LEBERRE » Thu Nov 08, 2012 9:28 am
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
-
Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Post
by Ayman Habib » Thu Nov 08, 2012 12:12 pm
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