Page 1 of 1

inverseDynamicsSolver - appliedBodyForces

Posted: Tue Nov 07, 2017 9:48 am
by rogerpallares
Hi all,

I'm using OpenSim libraries in MATLAB to perform an inverse dynamic analysis. I'm using the inverseDynamicsSolver class. I realized I have an issue with appliedBodyForces when I'm performing the analysis. When I introduce the external forces to the appliedBodyForces spatial vector, I find out they are applied to the origin of the local reference of each body, instead of being applied to the COM of each body.

I would like to know if there is any way to introduce external forces to the COM and not to the origin of the local axes when performing the inverse dynamic analysis. I attach a little piece of code to illustrate what I'm doing:

Code: Select all

% Initializing variables
idSolver = InverseDynamicsSolver(osimModel);
appliedBodyForces = VectorOfSpatialVec(13,BodyForce_0);
appliedMobilityForces = Vector(10,0.0);
Force_5 = Vec3(0.0);
Moment_5 = Vec3(0.0);
bodies = osimModel.getBodySet();

for i=1:n % Loop for each time frame

	% Introducing external forces to body 5 (applied to the origin of local reference...)
	% FPL is a matrix of external forces and moments
	Force_5.set(0,FPL1(i,1));
	Force_5.set(1,FPL1(i,2));
	Force_5.set(2,FPL1(i,3));
	Moment_5.set(0,FPL1(i,4));
	Moment_5.set(1,FPL1(i,5));
	Moment_5.set(2,FPL1(i,6));
	BodyForce_5.set(0,Moment_5);
	BodyForce_5.set(1,Force_5);
	appliedBodyForces.set(5,BodyForce_5);
    	
	% Performing the inverse dynamics analysis
	jointTorques = idSolver.solve(osimState,xdot2,appliedMobilityForces,appliedBodyForces);		

end
I would appreciate any suggest or help, thank you very much.

Re: inverseDynamicsSolver - appliedBodyForces

Posted: Wed Nov 08, 2017 3:08 am
by tkuchida
Here is the method you are calling: https://github.com/opensim-org/opensim- ... er.cpp#L73. The appliedBodyForces argument is passed straight through to calcResidualForceIgnoringConstraints() (in Simbody); here's the doxygen for that method: https://simtk.org/api_docs/simbody/3.5/ ... d43db05df0.

You have at least two options: (1) modify your model so that the COM is at the origin of each body, or (2) transform the COM forces/torques into the equivalent forces/torques applied at the body origin. You might find some useful methods in the SimbodyEngine class (https://simtk.org/api_docs/opensim/api_ ... ngine.html).

Re: inverseDynamicsSolver - appliedBodyForces

Posted: Thu Nov 09, 2017 5:48 am
by rogerpallares
Thank you very much for your help. I didn't think about modifying the model and actually it's a good and fast way to solve the problem. Also, I will try to do it using this SimbodyEngine class you mentioned. Thank you so much again!