Muscle parameters

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mohammadreza Rezaie
Posts: 408
Joined: Fri Nov 24, 2017 12:48 am

Muscle parameters

Post by Mohammadreza Rezaie » Wed Sep 28, 2022 5:12 am

Hi,

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
Any guide is greatly appreciated.

Regards,
Mohammadreza

Tags:

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Muscle parameters

Post by Thomas Uchida » Wed Sep 28, 2022 9:45 am

- In general, the value of all coordinates must be set before computing moment arms because muscles can span more than one coordinate. Also, when using the Coordinate::setValue() method, you should pass "False" for the third argument when setting all coordinates except the last one (please see topic 14709: viewtopicPhpbb.php?f=91&t=14709).
- The computeMomentArm() method uses the provided state (first argument) to set the pose of the model; the second argument is used to indicate the Coordinate (ModelComponent) with respect to which the moment arm is calculated.

User avatar
Mohammadreza Rezaie
Posts: 408
Joined: Fri Nov 24, 2017 12:48 am

Re: Muscle parameters

Post by Mohammadreza Rezaie » Wed Sep 28, 2022 3:56 pm

Dear Dr. Uchida,

I appreciate your response. I think the problem was solved. I implemented your suggestion and put it at the beginning of the loop. It seems that there was no need to put joint angles and velocities into state.

Code: Select all

for i=1:frame
    for j=1:nCoordinates
        model.updCoordinateSet().get(j-1).setValue(state, q2(i,j), false)
        model.updCoordinateSet().get(j-1).setSpeedValue(state, u2(i,j))
    end
    model.assemble(state)
    model.realizeVelocity(state);
Do you think getFiberForce works with this method or needs an updated state (by setQ and setU)?

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Muscle parameters

Post by Thomas Uchida » Thu Sep 29, 2022 6:52 pm

Do you think getFiberForce works with this method or needs an updated state (by setQ and setU)?
You are already setting the state when you call setValue() and setSpeedValue(). However, you will need to change realizeVelocity() to realizeDynamics() or higher (https://simtk.org/api_docs/opensim/api_ ... 7def5f54be).

User avatar
Mohammadreza Rezaie
Posts: 408
Joined: Fri Nov 24, 2017 12:48 am

Re: Muscle parameters

Post by Mohammadreza Rezaie » Fri Sep 30, 2022 5:18 pm

Dear Dr. Uchida,

I really appreciate your help.

POST REPLY