How to get Moment Arm of a Body on Matlab ?
- Alper Ayaz
- Posts: 6
- Joined: Tue Jan 16, 2018 1:27 am
How to get Moment Arm of a Body on Matlab ?
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
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
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: How to get Moment Arm of a Body on Matlab ?
This is a python code for calculating the moment arm of the BIClong muscle as a function of the elbow flexion:
https://simtk.org/api_docs/opensim/api_ ... 422afa201b
https://simtk-confluence.stanford.edu:8 ... ith+Matlab
Best
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-confluence.stanford.edu:8 ... ith+Matlab
Best
- Alper Ayaz
- Posts: 6
- Joined: Tue Jan 16, 2018 1:27 am
Re: How to get Moment Arm of a Body on Matlab ?
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
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
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: How to get Moment Arm of a Body on Matlab ?
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):
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
Code: Select all
OpenSim::Body& ground = model.getGroundBody();
Vec3 com, comG;
femur.getMassCenter(com);
model.getSimbodyEngine().transformPosition(state, femur, com, ground, comG)
https://simtk.org/api_docs/opensim/api_ ... ngine.html
The API of v4.0 is different.
Best
- Alper Ayaz
- Posts: 6
- Joined: Tue Jan 16, 2018 1:27 am
Re: How to get Moment Arm of a Body on Matlab ?
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
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
- In Bae Chung
- Posts: 19
- Joined: Mon Jan 14, 2019 11:46 pm
Re: How to get Moment Arm of a Body on Matlab ?
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!
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!
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: How to get Moment Arm of a Body on Matlab ?
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)
- Sepehr Ramezani
- Posts: 35
- Joined: Tue Nov 05, 2019 2:02 pm
Re: How to get Moment Arm of a Body on Matlab ?
Thank you @Thomas for sharing.tkuchida wrote: ↑Wed Jun 12, 2019 6:43 amThe 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)
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?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: How to get Moment Arm of a Body on Matlab ?
Perhaps look at the moment arm of each muscle separately? The best approach may depend on your research question.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.
- Sepehr Ramezani
- Posts: 35
- Joined: Tue Nov 05, 2019 2:02 pm
Re: How to get Moment Arm of a Body on Matlab ?
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.