Matlab moment arm error

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Alexander Barry
Posts: 5
Joined: Tue Dec 16, 2014 8:38 am

Matlab moment arm error

Post by Alexander Barry » Tue Jan 31, 2017 8:24 am

I am writing a script to iterate muscle path point locations and wrapping surface parameters in matlab. The purpose being to attempt to match the model moment arms to experimental data. The script works well some of the time, reaching my 50,000 iteration limit, but there are other times when the configuration will continue to produce a moment arm equal to zero at every joint angle. Does anyone have some insight into why the model begins to fail at this point? There does not seem to be some set of parameters that specifically produces this output, it happens seemingly at random.

Another point to note is that once the model produces this zero moment arm, no matter what I change the parameters to in the script, it will always produce zero moment arms across all joint angles. I have attempted to set the values back to a configuration that works and re-initialized, model.initsystem(), but that does not seem to work either. I wonder if there is an error with the wrapping surface which produces a java error that is not caught by matlab, and the only solution is to close and restart (which is what I would usually do in the opensim application).

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Matlab moment arm error

Post by Dimitar Stanev » Wed Feb 01, 2017 1:49 am

Moment arm is a function of the model coordinates (R(q)). So for you to assess the moment arm, you don't have to run any kind of forward or inverse simulation. I can't deduce how you assign a reference configuration q, did you re-sample the space of the coordinates? A simple procedure to calculate the moment arm is the following:

Code: Select all

load and initialize your model
for each reference configuration Q (pose)
    update the state coordinates from Q (updQ())
    realize model to position stage
    for each coordinate q
    	  for each muscle m
        	calculate R(q, m)

Hope this helps

User avatar
Alexander Barry
Posts: 5
Joined: Tue Dec 16, 2014 8:38 am

Re: Matlab moment arm error

Post by Alexander Barry » Wed Feb 01, 2017 8:08 am

I am assessing it over a range of joint angles, for example one joint from -35° to 70°, and finding the moment arm at each joint angle, example code below.

Code: Select all

import org.opensim.modeling.*

model=Model('mattest_opt.osim');
state=model.initSystem();
pip2c=model.updCoordinateSet.get('CMC1_flex');
edc=model.getMuscles().get('Ext_Pol_Longus');

for i=-35:70
        deg=deg2rad((i*1));
        pip2c.setValue(state,deg);   %pip2c is the joint
        if isnan(edc.computeMomentArm(state,pip2c))==0   %current code so matlab doesn't crash when error occurs
            maf(i+36)=edc.computeMomentArm(state,pip2c);   %Finding the moment arm of the current joint config.
            if maf(i+36)<sdp(i+36) && maf(i+36)>sdm(i+36)
                pinsdf=pinsdf+1;  %Just counting points within standard deviation lines
            end
        else
        	return
        end
 end	
        
So you're saying after I set the joint angle I should update the state variable with:

Code: Select all

state=state.updQ()
model.initSystem()

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Matlab moment arm error

Post by Dimitar Stanev » Wed Feb 01, 2017 10:16 am

After setting pip2c's coordinate value you must realize the model to position stage.

Code: Select all

model.realizePosition(state)

POST REPLY