Calculation of joint moment in matlab using joint angle and speed from external file using InverseDynamicsSolver.

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

Calculation of joint moment in matlab using joint angle and speed from external file using InverseDynamicsSolver.

Post by Ratna Sambhav » Wed May 13, 2020 11:10 am

Hello,
I have an excel file containing the elbow angle and elbow speed.
I want to use this and calculate what will be the value of elbow moment at every instance.

For that I've used the "InverseDynamicSolver" in the following way:

ID = InverseDynamicsSolver(model);
for i = 1:410
%% Assigned the value of elbow and shoulder angle and speed in the state of current model
model.getJointSet().get(1).getCoordinate().setValue(state, shoulder_angle(i));
model.getJointSet().get(1).getCoordinate().setSpeedValue(state, shoulder_speed(i));
model.getJointSet().get(2).getCoordinate().setValue(state, elbow_angle(i));
model.getJointSet().get(2).getCoordinate().setSpeedValue(state, elbow_speed(i));

%% Calculaated the value of shoulder and elbow accelerations from the external file and made a u_dot
%% vector from that.
elbow_alpha = (elbow_speed(i+1)-elbow_speed(i))/(time(i+1)-time(i));
shoulder_alpha = (shoulder_speed(i+1)-shoulder_speed(i))/(time(i+1)-time(i));
u_dot = Vector(2, 0);
u_dot.set(0,shoulder_alpha);
u_dot.set(1, elbow_alpha);

%% Finally I've used the InverseDynamicsSolver.solve to calculate the shoulder and elbow moment
tau = ID.solve(state, u_dot);
shoulder_tau = tau.get(0);
elbow_tau = tau.get(1);
end

Unfortunately, I am not getting able to obtain the exact result. The value of torque coming as output is more than what I expected.
Can you point out what I did wrong and suggest any code which can be used in this regard.

Regards,
Ratna Sambhav

Tags:

User avatar
Carmichael Ong
Posts: 393
Joined: Fri Feb 24, 2012 11:50 am

Re: Calculation of joint moment in matlab using joint angle and speed from external file using InverseDynamicsSolver.

Post by Carmichael Ong » Mon May 18, 2020 4:50 pm

Seems like that should be okay. What are you comparing to that you're considering "the answer"? How different are the values?

User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

Re: Calculation of joint moment in matlab using joint angle and speed from external file using InverseDynamicsSolver.

Post by Ratna Sambhav » Tue May 19, 2020 3:47 am

Thanks Ong for the response.

I have taken the arm26 model and performing inverse dynamics for elbow flexion, calculating the elbow moment.
The output I am getting from the matlab code as described above, I am comparing with the OpenSim inverseDynamics result for the same input trajectory file.
Here is the plot which has to be the answer (output from OpenSim):
opensim_tau.JPG
opensim_tau.JPG (22.97 KiB) Viewed 613 times
And output I am getting using InverseDynamicsSolver code shown above is:
matlab_tau.JPG
matlab_tau.JPG (14.28 KiB) Viewed 613 times
So, you see its almost one unit higher and more scattered. I am not understanding what's the mistake.

User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

Re: Calculation of joint moment in matlab using joint angle and speed from external file using InverseDynamicsSolver.

Post by Ratna Sambhav » Sat May 30, 2020 11:12 am

Hi,
Apologies for not giving the full information but the problem is solved now. The Arm26 model which I was using has muscles attached to it, which was creating the anomaly in joint torque calculation (probably because of the passive force which it was exerting).
When I removed the muscles from the model, the plot of elbow torque is coming exactly as compared to the plot from OpenSim GUI.

Thankfully,
Ratna

POST REPLY