Obtaining reaction forces

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Adrian Lai
Posts: 46
Joined: Tue Mar 13, 2012 11:33 am

Obtaining reaction forces

Post by Adrian Lai » Tue May 22, 2018 3:47 pm

Hi all,

I would like to get the reaction forces between two bodies at a weld joint using only the state values alone. The goal is to match the reaction forces with an external force through muscle force/activation alone.

I know I need to use the function calcEquivalentSpatialForce(states,mobility forces) but I'm unsure how to obtain the mobility forces without running an inverse dynamic analysis.

Can anyone point me in the right direction or an alternative methods to obtain a reaction force. I also tried using contact geometries but it didn't work because the joint of interest is a weld joint.

Thanks in advance!

Adrian

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Obtaining reaction forces

Post by Christopher Dembia » Fri Jun 01, 2018 4:55 am

Hey Adrian:

Could you clarify what you mean by "only the state values alone" and "through muscle force/activation alone"? I'm not sure I understand the distinction you're making.

If you're using 4.0, you can use Joint::calcReactionOnParentExpressedInGround(), etc.: https://github.com/opensim-org/opensim- ... #L250-L270

I don't think you want to use Joint::calcEquivalentSpatialForce(). This will not give you the correct joint reaction forces, even if you provided the mobility forces generated by muscles (because you would not account for the path of the muscle).

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

Re: Obtaining reaction forces

Post by Adrian Lai » Fri Jun 01, 2018 6:06 am

Could you clarify what you mean by "only the state values alone" and "through muscle force/activation alone"? I'm not sure I understand the distinction you're making.
I'm currently running my own direct collocation code and harnessing the OpenSim API to do all my dynamics by giving it the states and controls I need to solve for and asking it for outputs such as computing state derivatives and calculating metabolic cost.

I'm currently prescribing an experimentally-measured external force at a fixed point directly into the model osim. I would like to instead, call the model and obtain a reaction force as a result of the states and controls I provide it and then match the reaction force to the experimental data via my optimisation. Hence, when I say through "muscle force/activation alone", I would imagine these states/controls are what drive the model to match a prescribed force in the equations of motion especially in the case, for example, when the kinematics (angles, angular velocities) are identical but an external force is and is not applied. A similar approach was recently done for foot ground contact models to track ground reaction forces during walking (see https://goo.gl/Bhq2QS).
If you're using 4.0, you can use Joint::calcReactionOnParentExpressedInGround(), etc.: https://github.com/opensim-org/opensim- ... #L250-L270
I found this function in the documentation as well but I'm currently working in my OpenSim 3.3 environment because everything seems a bit more computationally efficient for my code. I have it written for 4.0 so I'll be migrating to it in the near future (maybe if it's the only way to solve my problem)

Thanks!

Adrian

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Obtaining reaction forces

Post by Christopher Dembia » Sun Jun 03, 2018 6:23 pm

In 3.3 you may be able to use SimbodyEngine::computeReactions(): https://github.com/opensim-org/opensim- ... ine.h#L118

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

Re: Obtaining reaction forces

Post by Adrian Lai » Sun Jun 03, 2018 8:54 pm

How do you run simbody functions using the MATLAB API if I can't find it in the documentation?


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

Re: Obtaining reaction forces

Post by Adrian Lai » Mon Jun 04, 2018 1:11 pm

Thanks Tom! I'll let you know how it goes.

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

Re: Obtaining reaction forces

Post by Adrian Lai » Tue Jun 05, 2018 4:03 pm

Hi Chris and Tom,

I've tried the following code but my MATLAB crashes. Can you point me in the right direction?

Code: Select all

import org.opensim.modeling.*
model_name = 'test_model.osim';
osimModel = Model(model_name);
osimState = osimModel.initSystem();
no_joints = osimModel.getJointSet.getSize();
temp_vector = Vec3(1);
rForce = VectorOfVec3(no_joints,temp_vector);
rTorque = VectorOfVec3(no_joints,temp_vector);

tool = SimbodyEngine();
tool.computeReactions(osimState,rForce,rTorque);
Thanks!

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

Re: Obtaining reaction forces

Post by Thomas Uchida » Tue Jun 05, 2018 6:30 pm

You're creating a new SimbodyEngine that isn't connected to the Model. This should work:

Code: Select all

osimModel.getSimbodyEngine().computeReactions(osimState,rForce,rTorque);

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 10:58 am

Thanks for the function Tom. It works and I can get reaction forces at all the joints.

However, I'm not sure if it's due to my computers (I've tried it on two computer so far), but after running the function once, the second time I run

Code: Select all

osimModel.getSimbodyEngine().computeReactions(osimState,rForce,rTorque);
, it crashes my MATLAB. Sometimes when I reopen a new instance of MATLAB, MATLAB crashes again when running the function the first time.

Is it related to some type of memory leak? Any ideas on a solution?

Thanks! So close to a working solution.

Adrian

POST REPLY