Page 1 of 1

MATLAB returning zero fiber lengths

Posted: Thu Jul 16, 2015 7:40 am
by csauer88
Hi,

I've been working on some code to calculate Normalized Fiber Lengths throughout a walking cycle. I've been able to set up the model to run through the motion by updating the coordinates, but whenever I call either the fiber length or normalized fiber length, a value of zero is always returned. Here's the loop that updates the coordinates:
data is matrix that contains all of the coordinates and their values for each time

Code: Select all

s = myModel.initSystem();
for ii = 1:myModel.getMuscles().getSize
   myForce = myModel.getMuscles().get(ii - 1);
   myMuscle = Muscle.safeDownCast(myForce);
   display(char(myMuscle));
   for k = 1: nFrames
       for j = 1:15
           updCoord = myModel.updCoordinateSet.get(j-1);
           updCoord.setValue(s, data(k,j)/180*2/pi);
           updCoord.setSpeedValue(s,0);
       end
       storageData(k,:) = myMuscle.getFiberLength(s);
   end
end
And when I call for the lengths this is an example of what I get:
>> myMuscle

myMuscle =

addbrev_r
>> myMuscle.getNormalizedFiberLength(s)

ans =

0
>> myMuscle.getFiberLength(s)

ans =

0

If I allow the code to run it will fill up the entire matrix with zeros for all of the muscles. I know the fiber length data is in the model; I can plot it using the GUI. Did I accidentally skip over a setting as I was writing the code?

Thanks,
Colton

EDIT: From just the initial state, I was able to return normalized fiber lengths for muscles in the torso (of which I am not concerned). These muscles are fixed because I am using the pelvis as the origin in a lower body model. Does the fact that I am changing the coordinates mean that the fiber length is lost?

Re: MATLAB returning zero fiber lengths

Posted: Mon Jul 20, 2015 10:03 am
by jimmy
Try downcasting to the Thelen type muscle model

Code: Select all

% Get the muscleType of that myForce 
muscleType = char(myForce.getConcreteClassName);
% Get a reference to the concrete muscle class in the model
eval(['myMuscle =' muscleType '.safeDownCast(myForce);'])
Always equilibrate the muscles

Code: Select all

% Set the activation and fiber length
myMuscle.setActivation( state, 1 )

% Equilibrate the forces from the activation 
myModel.equilibrateMuscles( state )

storageData(k,:) = myMuscle.getFiberLength(s);

Re: MATLAB returning zero fiber lengths

Posted: Tue Jul 21, 2015 11:55 am
by csauer88
Thanks for the help again James, but whenever I try to downcast the muscle type, I get this error.

Code: Select all

Undefined variable "Schutte1993Muscle_Deprecated" or class
"Schutte1993Muscle_Deprecated.safeDownCast".

Error in getNFL (line 63)
   eval(['myMuscle =' muscleType '.safeDownCast(myForce);'])
I was using your code as the framework for mine, which is why they are so similar. The main difference is that I manually inserted the column header names because my motion file does not include all of the coordinates that are in the model. Could this create an issue somehow?

Re: MATLAB returning zero fiber lengths

Posted: Tue Jul 21, 2015 12:21 pm
by csauer88
Also:

Code: Select all

No appropriate method, property, or field equilibriateMuscles for class
org.opensim.modeling.Model.

Error in getNFL (line 68)
   myModel.equilibriateMuscles(s)
Is there an issue with installation if these are missing?

Re: MATLAB returning zero fiber lengths

Posted: Mon Aug 03, 2015 1:28 pm
by jimmy
Your downcasting to a muscle that OpenSim doesn't support, hence the "_Deprecated". You will need to change the muscles to either Thelen or Millard types to use in scripting.

Re: MATLAB returning zero fiber lengths

Posted: Wed Aug 05, 2015 11:02 am
by csauer88
Great thank you! That would explain why the two Thelen muscles in the model are returning normalized fiber lengths but the deprecated ones are not.