I hope all is well.
I'm trying to calculate a set of muscle properties such as muscle moment arm and strength using OpenSim 4.4 API in MATLAB (for custom static optimization).
Here is the script:
Code: Select all
% q2 ==> Kinematics_q.sto file (2D array [time,coordinate])
% u2 ==> Kinematics_u.sto file (2D array [time,coordinate])
model = Model('subject01_simbody.osim');
state = model.initSystem();
muscles = model.updMuscles();
nMuscles = muscles.getSize();
coordinates = model.getCoordinateSet();
nCoordinates = coordinates.getSize();
for i=1:frameTime
Q = Vector(); Q.resize(nCoordinates);
U = Vector(); U.resize(nCoordinates);
for j=1:nCoordinates
Q.set(j-1, q2(i,j));
U.set(j-1, u2(i,j));
end
state.setQ(Q);
state.setU(U);
% model.realizePosition(state);
% model.realizeVelocity(state);
% model.equilibrateMuscles(state);
model.realizeDynamics(state);
for j=1:nMuscles
muscle = Millard2012EquilibriumMuscle.safeDownCast(muscles.get(j-1));
muscle.set_ignore_activation_dynamics(true); % disable activation dynamics
muscle.set_ignore_tendon_compliance(true); % disable tendon compliance
% muscle.computeFiberEquilibrium(state);
% muscle.computeEquilibrium(state);
% muscle.computeActuation(state);
model.equilibrateMuscles(state);
L(i,j) = muscle.getLength(state);
FL(i,j) = muscle.getFiberLength(state);
TL(i,j) = muscle.getTendonLength(state);
OFL(j) = muscle.getOptimalFiberLength();
TSL(j) = muscle.getTendonSlackLength();
TL(i,j) = muscle.getTendonLength(state);
MIF(j) = muscle.getMaxIsometricForce();
FF(i,j) = muscle.getFiberForce(state);
AFF(i,j)= muscle.getActiveFiberForce(state);
PFF(i,j)= muscle.getPassiveFiberForce(state);
TF(i,j) = muscle.getTendonForce(state);
muscle.setActivation(state, 1);
S(i,j) = muscle.getFiberForce(state); % muscle strength
% for k=1:nCoordinates
% coordinate = coordinates.get(k-1);
% coordinate.setValue(state, q2(i,k))
% MA(i,k,j) = muscle.computeMomentArm(state, coordinate);
% end
end
end
Here are the complete files: Any help is much appreciated.
Regards,
Mohammadreza