How to get Moment Arm of a Body on Matlab ?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Alper Ayaz
Posts: 6
Joined: Tue Jan 16, 2018 1:27 am

How to get Moment Arm of a Body on Matlab ?

Post by Alper Ayaz » Fri Mar 02, 2018 3:19 am

Hello everyone,

Currently working on Arm26 model, considering only 2 muscles (BRA and TRIlat) on Matlab. I need to obtain the moment arm of the forearm body (elbow joint to the center of mass) of the model as a Matlab double numeric type. I tried to use MomentArmSolver(model).solve(state, CoordinateElbow, ForeArm) method, where ForeArm is the body considered. But this method doesn't seem to work for Bodies. How can I get this Moment Arm ?

Below an example of what I am looking for, the red line.
http://exerciseeducation.com/wp-content ... ntarn1.jpg

Thanks,

Alper

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

Re: How to get Moment Arm of a Body on Matlab ?

Post by Dimitar Stanev » Sat Mar 03, 2018 3:50 am

This is a python code for calculating the moment arm of the BIClong muscle as a function of the elbow flexion:

Code: Select all

import opensim
import numpy as np

model = opensim.Model('arm26.osim')
state = model.initSystem()

coordinate = 'r_elbow_flex'
elbowFlexion = np.arange(0, 1.57, 0.1)
muscle = 'BIClong'
BIClongMA = []

for q in elbowFlexion :
    model.updCoordinateSet().get(coordinate).setValue(state, q)
    model.realizePosition(state)
    BIClongMA .append(model.getMuscles().get(muscle).computeMomentArm(state, coordinate))
https://simtk.org/api_docs/opensim/api_ ... 422afa201b
https://simtk-confluence.stanford.edu:8 ... ith+Matlab

Best

User avatar
Alper Ayaz
Posts: 6
Joined: Tue Jan 16, 2018 1:27 am

Re: How to get Moment Arm of a Body on Matlab ?

Post by Alper Ayaz » Tue Mar 06, 2018 3:09 am

Hi,

Thank you for your reply Dimitar ! I'm a beginner using Opensim's method on matlab. But this code seems to compute moment arm of a muscle, in my case I need to obtain the moment arm of body ('r_ulna_radius_hand').
If there is not method to compute this moment arm, I think that I can have it by obtaining the position of the center of mass of the 'r_ulna_radius_hand' as a SimTK::Vec3. But still I didn't find methods, even using this way.
Do you have any suggestions ?

Thanks,

Alper

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

Re: How to get Moment Arm of a Body on Matlab ?

Post by Dimitar Stanev » Thu Mar 08, 2018 2:40 am

I can't think of an easy way to calculate this in OpenSim. If you use v3.3 you can get the body CoM in the body local frame and express it in ground frame as follows (this can be done for any point on any body):

Code: Select all

OpenSim::Body& ground = model.getGroundBody();
Vec3 com, comG;
femur.getMassCenter(com);
model.getSimbodyEngine().transformPosition(state, femur, com, ground, comG)
where the state is updated from the pose (as in the example provided in the previous post)

https://simtk.org/api_docs/opensim/api_ ... ngine.html

The API of v4.0 is different.

Best

User avatar
Alper Ayaz
Posts: 6
Joined: Tue Jan 16, 2018 1:27 am

Re: How to get Moment Arm of a Body on Matlab ?

Post by Alper Ayaz » Wed Mar 14, 2018 4:24 am

Hi,

thanks again Dimitar. I tried this code (equivalent of what you have posted) and it works !

import org.opensim.modeling.*
model = Model('arm26.osim');
state = model.initSystem();
ForeArm = model.getBodySet().get( 'r_ulna_radius_hand') ;
massCenter = Vec3(0.0,0.0,0.0);
position = Vec3(0.0,0.0,0.0);
ForeArm.getMassCenter(massCenter);
simbodyEngine = model.getSimbodyEngine();
simbodyEngine.getPosition(state, ForeArm, massCenter, position);
MomentArmForeArm = position.get(0)

best

Alper

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

Re: How to get Moment Arm of a Body on Matlab ?

Post by In Bae Chung » Wed Jun 12, 2019 1:47 am

Hi, I tried using the python code for calculating the moment arm of the BIClong muscle and it gave me this error

TypeError: in method 'PathActuator_computeMomentArm', argument 3 of type 'OpenSim::Coordinate &'

I'm a beginner in OpenSIM API and can't find what exactly is wrong with the code. I'll really appreciate your help.
Thanks in advance!

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

Re: How to get Moment Arm of a Body on Matlab ?

Post by Thomas Uchida » Wed Jun 12, 2019 6:43 am

The computeMomentArm() method (https://simtk.org/api_docs/opensim/api_ ... 6c06767289) takes two arguments: a State and the Coordinate with respect to which you wish to compute the moment arm. The second argument you are providing is not of type Coordinate. Here is a working example:

Code: Select all

import opensim as osim
model = osim.Model('leg6dof9musc.osim')
state = model.initSystem()
force = model.getForceSet().get('med_gas_r')
muscle = osim.Thelen2003Muscle.safeDownCast(force)
coord = model.getCoordinateSet().get('knee_angle_r')
print muscle.computeMomentArm(state, coord)

User avatar
Sepehr Ramezani
Posts: 35
Joined: Tue Nov 05, 2019 2:02 pm

Re: How to get Moment Arm of a Body on Matlab ?

Post by Sepehr Ramezani » Thu Apr 30, 2020 11:40 pm

tkuchida wrote:
Wed Jun 12, 2019 6:43 am
The computeMomentArm() method (https://simtk.org/api_docs/opensim/api_ ... 6c06767289) takes two arguments: a State and the Coordinate with respect to which you wish to compute the moment arm. The second argument you are providing is not of type Coordinate. Here is a working example:

Code: Select all

import opensim as osim
model = osim.Model('leg6dof9musc.osim')
state = model.initSystem()
force = model.getForceSet().get('med_gas_r')
muscle = osim.Thelen2003Muscle.safeDownCast(force)
coord = model.getCoordinateSet().get('knee_angle_r')
print muscle.computeMomentArm(state, coord)
Thank you @Thomas for sharing.
I am trying to observe the momentum arm of a group of muscle (knee flexors) during motion. So it's not just a certain point. For example, during walking, I want to observe the momentum arm at the same time with the motion (IK.mot). Do you have any suggestions?

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

Re: How to get Moment Arm of a Body on Matlab ?

Post by Thomas Uchida » Mon May 04, 2020 6:32 am

I am trying to observe the momentum arm of a group of muscle (knee flexors) during motion. So it's not just a certain point.
Perhaps look at the moment arm of each muscle separately? The best approach may depend on your research question.

User avatar
Sepehr Ramezani
Posts: 35
Joined: Tue Nov 05, 2019 2:02 pm

Re: How to get Moment Arm of a Body on Matlab ?

Post by Sepehr Ramezani » Mon May 04, 2020 10:18 am

tkuchida wrote:
Mon May 04, 2020 6:32 am
Perhaps look at the moment arm of each muscle separately? The best approach may depend on your research question.
Yes, I want to calculate the moment arm of each desired muscle during movement. I mean after this calculation I should have a time-table with the first column of time, plus columns that represent momentum arm of each muscle. Also, I am trying to use a time step similar to the motion (IK.mot) time step.
Thank you.

POST REPLY