I have a loop that compute fiber force, length and muscle moment arm. I'm dealing with these issues and wondering if anyone could guide me.
1. computeMomentArm doesn't get joint angles from state and I have to put them in coordinate that makes the code extremely slow. Without coordinate, the outputs are different.
2. The output of getFiberForce and getFiberLength with and without the computeMomentArm in the loop are different.
Here is the code (q2 and u2 are 2D arrays of joint angles and angular velocities)
Code: Select all
for i=1:frame
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.realizeVelocity(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
model.equilibrateMuscles(state);
FL(i,j) = muscle.getFiberLength(state);
FF(i,j) = muscle.getFiberForce(state);
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
Regards,
Mohammadreza