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?
Moment arm calculation help needed
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Moment arm calculation help needed
You can compute the moment arm of a muscle wrt to a coordinate using the API function:
make sure that you have changed the pose of the model for each coordinate i
and that the state is realized to a position level before computing the moment arm
Relative publication of the OpenSim implementation:
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4404026/
Code: Select all
coord = model.getCoordinateSet().get(coordinate_name)
model.getMuscles().get(muscle_name).computeMomentArm(state, coord)
Code: Select all
model.updCoordinateSet().get(coordinate_names[i]).setValue(state, q[i])
Code: Select all
model.realizePosition(state)
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4404026/
- In Bae Chung
- Posts: 19
- Joined: Mon Jan 14, 2019 11:46 pm
Re: Moment arm calculation help needed
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.
I'm wondering if I can load a .mot file by
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
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])
Code: Select all
motion = osim.Storage("orig.mot")
Thank you in advance
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Moment arm calculation help needed
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
https://github.com/opensim-org/opensim- ... ectory.cpp
- In Bae Chung
- Posts: 19
- Joined: Mon Jan 14, 2019 11:46 pm
Re: Moment arm calculation help needed
I created an empty trajectory of states and restored continuous state variable values from a .sto file by doing this:
but when I try to get the Moment Arm by doing
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
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
Code: Select all
sto = osim.Storage("orig.sto")
states = osim.StatesTrajectory()
states = states.createFromStatesStorage(model, sto, True)
Code: Select all
muscle = model.getMuscles().get('rect_fem_r')
coord = model.getCoordinateSet().get('elbow_flexion')
print muscle.computeMomentArm(states[3], coord)
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])
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