Difference between results from OpenSIM GUI and MATLAB

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Difference between results from OpenSIM GUI and MATLAB

Post by In Bae Chung » Tue Jun 25, 2019 8:02 am

Hi, all.

I used MATLAB to get the moment arm and tendon force of the muscles as below.

Code: Select all

import org.opensim.modeling.*

%% Read data
activations = STOFileAdapter.read('musclenumber.sto');
% force = STOFileAdapter.read('arm26_StaticOptimization_force.sto');
motion = STOFileAdapter.read('orig.mot');
%% Instantiate a model
model = Model('C:\Users\In Bae Chung\Desktop\Arm swing simulation data (1)\arm_swing\scaledmodel.osim');
% Get a reference to the state
s = model.initSystem();
% Get the number of data rows
nt = motion.getNumRows();
% get the number of coordinates
nc = model.getNumCoordinates;
% Get a reference to the muscle set
ms = model.getMuscles();
% nm = ms.getSize();
nm = 9;
% Get Muscle names from the activation file
muscleNames = activations.getColumnLabels();

%% Make some default matrices to store results
ma = zeros(nt,nm);

%% Iterate through each row, set the model pose and activation, get force
for i = 0 : nt - 1
    model.getCoordinateSet().get('elbow_flexion').setValue(s, deg2rad(motion.getDependentColumnAtIndex(38).get(i) ));
    coord = model.getCoordinateSet().get('elbow_flexion');
 
    model.realizePosition(s)
    
    % Get the computed moment arm from each muscle
    for u = 0 : nm - 1 
        % Get a muscle
        m = ms.get( char(muscleNames.get(u)));
        % Compute moment arm
        ma(i+1,u+1) = m.computeMomentArm(s, coord);
    end
end

Code: Select all

import org.opensim.modeling.*

%% Read data
activations = STOFileAdapter.read('musclenumber.sto');
% force = STOFileAdapter.read('arm26_StaticOptimization_force.sto');
motion = STOFileAdapter.read('orig.mot');
%% Instantiate a model
model = Model('C:\Users\In Bae Chung\Desktop\Arm swing simulation data (1)\arm_swing\scaledmodel.osim');
% Get a reference to the state
s = model.initSystem();
% Get the number of data rows
nt = motion.getNumRows();
% get the number of coordinates
nc = model.getNumCoordinates;
% Get a reference to the muscle set
ms = model.getMuscles();
% nm = ms.getSize();
nm = 9;
% Get Muscle names from the activation file
muscleNames = activations.getColumnLabels();

%% Make some default matrices to store results
mf = zeros(nt,nm);

%% Iterate through each row, set the model pose and activation, get force
for i = 0 : nt - 1
    model.updCoordinateSet().get('elbow_flexion').setValue(s, deg2rad(motion.getDependentColumnAtIndex(38).get(i) ));
    coord = model.getCoordinateSet().get('elbow_flexion');

    model.realizeDynamics(s);
    
    % Get the computed force from each muscle
    for u = 0 : nm - 1 
         % Get a muscle
        m = ms.get( char(muscleNames.get(u)));
        % Compute muscle force
        mf(i+1,u+1) = m.getTendonForce(s);
    end
end
I compared the results from the code with the results from OpenSIM4.0 > Tool > Plot > Moment arm / Tendon force, and both of them were different.
(Moment arm values were different but seemed to be in a similar range while Tendon force values were hard to be seen as similar values.)
I was wondering if there's something wrong with my code that led to the differences in the results. If so, is there a better way to compute these values?

Thanks in advance.
Last edited by In Bae Chung on Thu Jun 27, 2019 4:39 am, edited 1 time in total.

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Difference between results from OpenSIM GUI and MATLAB

Post by jimmy d » Tue Jun 25, 2019 10:39 am

When do you ever set the muscle activations?

POST REPLY