Page 1 of 1

reporting Fiber force using Matlab API

Posted: Mon May 19, 2014 12:42 am
by porsasina
Hi all
I am trying to report fiber active and passive forces using matlab API. Here is my code:

Code: Select all

% load model
osimModel = Model('test.osim');

% initiate states and set proper values
defaultStates = osimModel.initSystem();
  ...
% geting the fiber force
fiberForce = muscle.getFiberForce(defaultStates)
But it returns an error:
Error using findFiberLength (line 37)
Java exception occurred:
java.lang.RuntimeException: Exception caught in
Thelen2003Muscle::calcMuscleDynamicsInfo
of ercspn_r
Exception caught in Thelen2003Muscle::calcFiberVelocityInfo
of ercspn_r
SimTK Exception thrown at State.cpp:2080:
State Cache entry was out of date at Stage Position. This entry depends on
version 11 of Stage Position but was last updated at version 0.

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

at org.opensim.modeling.Muscle.getFiberForce(Muscle.java:557)

Is there anyway to realize the system into a new stage?

Thanks
Sina

Re: reporting Fiber force using Matlab API

Posted: Tue May 27, 2014 3:45 pm
by jimmy
Hi Sina,

the problem may be in the '...', perhaps there is a change in the model or states and system picks up on it.

You could also use computeStateVariableDerivatives() to force a realize up to accelerations.

hope that helps,
-james

Re: reporting Fiber force using Matlab API

Posted: Wed Apr 01, 2015 10:04 pm
by saxbyd
Hey Guys,

I've experienced the same error as Sina.

I am moving a model (2392) through the complex knee flexion/extension range and am interested in the force-length relationship.

Code: (model already initialized, moved into x gen coordinate and state updated)

muscleOfInterest = Muscle.safeDownCast(model.getMuscles().get('myMuscle'));

% set activation to 1
muscleOfInterest.setActivation(state, double(1.0));

% compute fiber force
muscleOfInterest_FiberForce = muscleOfInterest.getFiberForce(state);


Then the same error as Sina.

Is this an issue with Thelen class muscles? Have I really updated the states?

Or is there something more fundamentally wrong with what I am asking OpenSim to do?

Best,

David

Re: reporting Fiber force using Matlab API

Posted: Wed Apr 01, 2015 10:12 pm
by jimmy
Here is some example code that works.

https://github.com/jimmyDunne/stackJimm ... ceLength.m

-j

Re: reporting Fiber force using Matlab API

Posted: Sun Apr 05, 2015 8:26 pm
by saxbyd
James,

Thanks for this reply. I'm going to update my code with your section and let you know how it goes.

Best,

David