Page 1 of 2

How to get Moment Arm of a Body on Matlab ?

Posted: Fri Mar 02, 2018 3:19 am
by alper75
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

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

Posted: Sat Mar 03, 2018 3:50 am
by mitkof6
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

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

Posted: Tue Mar 06, 2018 3:09 am
by alper75
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

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

Posted: Thu Mar 08, 2018 2:40 am
by mitkof6
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

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

Posted: Wed Mar 14, 2018 4:24 am
by alper75
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

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

Posted: Wed Jun 12, 2019 1:47 am
by inbae908
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!

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

Posted: Wed Jun 12, 2019 6:43 am
by tkuchida
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)

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

Posted: Thu Apr 30, 2020 11:40 pm
by s.ramezani
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?

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

Posted: Mon May 04, 2020 6:32 am
by tkuchida
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.

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

Posted: Mon May 04, 2020 10:18 am
by s.ramezani
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.