Net Joint Torque calculation using opensim API with MATLAB

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Jong In Han
Posts: 5
Joined: Thu May 17, 2018 6:26 am

Net Joint Torque calculation using opensim API with MATLAB

Post by Jong In Han » Mon Feb 11, 2019 5:03 am

Hello.

I'm working on a task to get the 'net joint torques' of the generalized coordinates by using opensim API with MATLAB.
Specifically, given the states(i.e. angles, angular velocities, muscle lengths and muscle actuations) and controls(muscle excitations) in my model, I want to calculate the net joint torques of each joint at that moment.
The method I'm trying to use is to multiply the muscle force by the moment arm to calculate the net joint torques of the generalized coordinate.
(please let me know if there is any other way to get the net joint torques more conveniently than this approach using opensim API.)
My model is a 3-DOF right leg model.

Now I've got the moment arms using the MATLAB method 'computeMomentArm'
here is my code :
=================================================
import org.opensim.modeling.*
myModel = Model('Lowerlimb.osim')
state = myModel.initSystem()

myMuscle = myModel.getMuscles().get(0); %bifemlh_r
aCoord1 = myModel.getCoordinateSet.get(0); % hip_flexion_r
aCoord2 = myModel.getCoordinateSet.get(1); % knee_angle_r
aCoord3 = myModel.getCoordinateSet.get(2); % ankle_angle_r

momentarm1 = myMuscle.computeMomentArm(state.aCoord1);
momentarm2 = myMuscle.computeMomentArm(state.aCoord2);
momentarm3 = myMuscle.computeMomentArm(state.aCoord3);
===================================================

Next, I tried to calculate Muscle Force, and I found 'getForce' and 'computeForce' in 'Muscle' class. Is it possible to get the muscle forces by using these classes? or should I use muscle actuation multiplied by the max isometric force as the value of the force exerted on the current muscle?
I am also wondering if the direction of the torque can be obtained using api.

Thank you!

Tags:

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

Re: Net Joint Torque calculation using opensim API with MATLAB

Post by Dimitar Stanev » Tue Feb 12, 2019 2:24 am

If you want to calculate the generalized forces (joint torques) then you do not need to use the muscles. For example, if you know the movement and the externally applied forces then you can solve the inverse dynamics problem directly. Typically, muscle forces are determined from the generalized forces by solving an optimization problem.

---

You are using OpenSim incorrectly.

After initializing the model you are asking for the generalized coordinates, which should be the input for your calculation.

Then you are calculating the muscle moment arm that corresponds to a particular coordinate. Please note that each muscle spans multiple degrees of freedom.

Then again, for a muscle to produce a force it must be activated. Furthermore, due to the activation dynamics the model must be advanced numerically in time and this is a forward dynamics calculation.

---

I know that these points may seem strange but you should try to familiarize with the different algorithms first (IK, ID, SO, CMC, FD). Furthermore, using the API is not very easy if you are not familiar with these concepts. You can find a lot of information in the user guide:

https://simtk-confluence.stanford.edu/d ... %27s+Guide

Most of the user problems are solved by utilizing some of the existing tools, provided the correct input, so it may be possible to solve your problem easier.

User avatar
Jong In Han
Posts: 5
Joined: Thu May 17, 2018 6:26 am

Re: Net Joint Torque calculation using opensim API with MATLAB

Post by Jong In Han » Tue Feb 12, 2019 4:14 am

Thank you for your answer Dimitar Stanev.

First of all, there was a typo in the post. (state, aCoord) instead of (state.aCoord).
My opensim model has only one degree of freedom in each joint, so it was the purpose of the code first to see how much moment arm the bifemlh_r muscle has for generalized coordinates. When the code is executed, the moment arm between the bifemlh_r muscle and the hip, knee, and ankle joints could be obtained as -0.0578, -0.0299, 0 (because it is the muscle attached to the upper thigh, it has a moment arm that is effective on the hip and knee joints , And does not seem to have moment arm with ankle joint.) As you said, each muscle spans multiple degrees of freedom. If my model allowed only one degree of freedom at each joints(generalized coordinates), would it be okay to use the result of the moment arm from the code?

In fact, the optimization problem you mentioned is part of my interest. As you mentioned above, given the generalized forces, the muscular force can be obtained by solving optimization problems. In solving the optimization problem, should muscle forces and moment arms be used to determine if the moments generated by the muscle forces are consistent with generalized forces? To do this I'm trying to get muscle strength and moment arms with the Opensim API. It would be really helpful if you let me know about this in detail and tell me something I'm misunderstanding.

POST REPLY