Obtaining reaction forces

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Obtaining reaction forces

Post by Thomas Uchida » Wed Jun 06, 2018 5:20 pm

What version of OpenSim are you using? In 3.3, rForces and rTorques are filled for i = 0, 1, ..., _model->getNumBodies()-1; in 4.0, these Vectors are filled for i = 0, 1, ..., _model->getNumJoints()-1. You might want to read through the code and do some testing to understand the differences. In MATLAB, you might just be able to allocate max(#bodies, #joints) but I would need to investigate in detail.

User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Re: Obtaining reaction forces

Post by Adrian Lai » Wed Jun 06, 2018 5:52 pm

Hi Tom,

Thanks for the information. From the test code I sent earlier, using your function, I can obtain rForces and rTorques that equal to the number of joints in my model (I'm running OpenSim 3.3). It works fine when I run the code the first time around.

However, when I re-run the code or re-open a new instance of MATLAB after it crashes, I get a MATLAB System Error where in the details, it contains either

Code: Select all

Fault Code: 1 Abnormal termination: Access violation
or

Code: Select all

Fault Code: 1 Assertion in void __cdecl `anonymous-namespace'::mwJavaAbort(void) at b:\matlab\src\jmi\javainit.cpp line 1346:Fatal Java Exception.  See Java Crash Report for details.
I also tried running other SimbodyEngine functions like getAngularVelocity and getAcceleration and they work without problem. I also get the error if I use updSimbodyEngine().computeReactions(osimState,rForce,rTorque). I tried another generic model and it also gives the error.

It only occurs when I run the function that computes the reaction forces not with any other part of the code. Do I need to clear the variables or provide a close function in order to run the function multiple times?

Thanks for your help troubleshooting!

Adrian

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Obtaining reaction forces

Post by Thomas Uchida » Wed Jun 06, 2018 10:56 pm

I'm running OpenSim 3.3
As I said in my previous post, the computeReactions() method fills rForce and rTorque from 0 to model.getBodySet().getSize()-1 in OpenSim 3.3, so there will be a memory address violation if (1) you size rForce and rTorque based on the number of joints in the model and (2) the model contains more bodies than joints. The following code does not produce any errors; hopefully the numbers make sense (I recommend verifying):

Code: Select all

% OpenSim 3.3
import org.opensim.modeling.*;
model = Model('arm26.osim');
state = model.initSystem();
nb = model.getBodySet().getSize();
for i = 1:5
    rForce  = VectorOfVec3(nb, Vec3(1));
    rTorque = VectorOfVec3(nb, Vec3(1));
    model.getSimbodyEngine().computeReactions(state, rForce, rTorque);
    rForce
    rTorque
end

User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Re: Obtaining reaction forces

Post by Adrian Lai » Thu Jun 07, 2018 9:27 am

Ahh sorry for the misunderstanding Tom.

I missed the part where the count started at 0 so I was only initialising the size of my rForce and rTorque to either model.getBodySet().getSize()-1 or model.getJointSet().getSize(), which both caused the error.

Perfect! Thanks for working me through to a solution.

Adrian

POST REPLY