Page 1 of 2
Obtaining reaction forces
Posted: Tue May 22, 2018 3:47 pm
by adrianlai88
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
Re: Obtaining reaction forces
Posted: Fri Jun 01, 2018 4:55 am
by chrisdembia
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).
Re: Obtaining reaction forces
Posted: Fri Jun 01, 2018 6:06 am
by adrianlai88
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).
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
Re: Obtaining reaction forces
Posted: Sun Jun 03, 2018 6:23 pm
by chrisdembia
In 3.3 you may be able to use SimbodyEngine::computeReactions():
https://github.com/opensim-org/opensim- ... ine.h#L118
Re: Obtaining reaction forces
Posted: Sun Jun 03, 2018 8:54 pm
by adrianlai88
How do you run simbody functions using the MATLAB API if I can't find it in the documentation?
Re: Obtaining reaction forces
Posted: Sun Jun 03, 2018 11:10 pm
by tkuchida
Re: Obtaining reaction forces
Posted: Mon Jun 04, 2018 1:11 pm
by adrianlai88
Thanks Tom! I'll let you know how it goes.
Re: Obtaining reaction forces
Posted: Tue Jun 05, 2018 4:03 pm
by adrianlai88
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!
Re: Obtaining reaction forces
Posted: Tue Jun 05, 2018 6:30 pm
by tkuchida
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);
Re: Obtaining reaction forces
Posted: Wed Jun 06, 2018 10:58 am
by adrianlai88
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