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
(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.