Moment arm calculation help needed

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ben Bolen
Posts: 10
Joined: Wed Jan 17, 2018 6:23 pm

Moment arm calculation help needed

Post by Ben Bolen » Tue Oct 23, 2018 4:16 pm

Hello,

I'm trying to calculate the moment arms in Matlab with wrapping point coordinates copied from OpenSim and my values are not matching up. The methodology I'm using is from Hoy, et al.: http://e.guigon.free.fr/rsc/article/HoyEtAl90.pdf
"We calculated the moment arm as the cross product between the vector connecting the joint center to the origin (insertion), and the unit vector connecting the origin (insertion) to the insertion (origin), using actual origin and insertion coordinates, except when effective ones exist."

Is this how it is calculated in OpenSim? Can someone provide an equation, a link to the source code, and a link to API documentation?

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Moment arm calculation help needed

Post by Dimitar Stanev » Wed Oct 24, 2018 2:43 am

You can compute the moment arm of a muscle wrt to a coordinate using the API function:

Code: Select all

coord = model.getCoordinateSet().get(coordinate_name)
model.getMuscles().get(muscle_name).computeMomentArm(state, coord)
make sure that you have changed the pose of the model for each coordinate i

Code: Select all

model.updCoordinateSet().get(coordinate_names[i]).setValue(state, q[i])
and that the state is realized to a position level before computing the moment arm

Code: Select all

model.realizePosition(state)
Relative publication of the OpenSim implementation:
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4404026/

User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Re: Moment arm calculation help needed

Post by In Bae Chung » Thu Jun 13, 2019 7:10 am

Hi, Dimitar.
I found your post very helpful for my research.
I was able to compute the moment arm of a muscle at the initial state of the model.
However, I didn't get the part where you mentioned how to change the pose of the model for each coordinates.

Code: Select all

model.updCoordinateSet().get(coordinate_names[i]).setValue(state, q[i])
I'm wondering if I can load a .mot file by

Code: Select all

motion = osim.Storage("orig.mot")
and then compute the moment arm at each pose in the motion file. Could you let me know how this would be possible?
Thank you in advance :)

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Moment arm calculation help needed

Post by Dimitar Stanev » Sun Jun 16, 2019 12:59 am

One option is to get the column names from the Storage object. Then for each column name find the coordinate in the coordinate set and update its value. However, I think that there is an easier way to update the generalized coordinates from storage directly. Maybe you can search in the opensim-core GitHub repository and examples

https://github.com/opensim-org/opensim- ... ectory.cpp

User avatar
In Bae Chung
Posts: 19
Joined: Mon Jan 14, 2019 11:46 pm

Re: Moment arm calculation help needed

Post by In Bae Chung » Tue Jun 18, 2019 6:52 am

I created an empty trajectory of states and restored continuous state variable values from a .sto file by doing this:

Code: Select all

sto = osim.Storage("orig.sto")
states = osim.StatesTrajectory()
states = states.createFromStatesStorage(model, sto, True)
but when I try to get the Moment Arm by doing

Code: Select all

muscle = model.getMuscles().get('rect_fem_r')
coord = model.getCoordinateSet().get('elbow_flexion')
print muscle.computeMomentArm(states[3], coord)
it gives me "NaN." I wonder if it doesn't have all the variables it needs to calculate the moment arm because I ignored the missing columns in the .sto file by allowmissingcolumns=True ? If so, is it necessary to use a .sto file without any missing columns or would there be another way to solve this?

Also, I tried getting the Tendon force of the muscle by doing

Code: Select all

muscle = model.getMuscles().get('rect_fem_r')
print muscle.getTendonForce(states[3])
but it gives me an error saying

RuntimeError: std::exception in 'double OpenSim::Muscle::getTendonForce(SimTK::State const &) const': Exception caught in Thelen2003Muscle::calcMuscleDynamicsInfo
of rect_fem_r
Exception caught in Thelen2003Muscle::calcMuscleLengthInfo
of rect_fem_r
SimTK Exception thrown at state.cpp:974:
Error detected by Simbody method getCacheEntry: State Cache entry was out of date at Stage Instance. This entry depends on version 1 of Stage Instance but was last updated at version 0.
(Required condition 'version == m_dependsOnVersionWhenLastComputed' was not met.)


I have no idea what 'dependsOnVersionWhenLastComputed' means... Is there an easy way to get the Tendon Force at a certain state?
I would really appreciate someone's help on this :)

Best,
In Bae Chung

POST REPLY