Net Joint Torque calculation using opensim API with MATLAB
Posted: 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!
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!