Page 1 of 1

How to define Body Forces in Inverse Dynamics Solver in Matlab.

Posted: Mon May 24, 2021 6:27 am
by sambhav.ratna
Hi,

I have already done the Inverse Dynamics simulation without the external force using the following command.
tau = InverseDynamicsSolver.solve(ID_state, u_dot).
Here I set u_dot as desired joint accelerations and state consisting of desired current joint position and velocity. I iterated the above process for every time instance and got the results which I would got from OpenSim GUI.

But when external body force is applied, then what will be the process of doing inverse dynamics with the above method.
Using the command below, I wanted to do Inverse Dynamics simulation with an externally applied body force (force and torque at say 'forearm' of the arm26 model)

InverseDynamicsSolver::solve ( const SimTK::State & s,
const SimTK::Vector & udot,
const SimTK::Vector & appliedMobilityForces,
const SimTK::Vector_< SimTK::SpatialVec > & appliedBodyForces
)

How can I define this SpatialVec for a general spatial force acting on a particular point of forearm (where force magnitude and point location can be expressed in global frame)?

Thanks.

Re: How to define Body Forces in Inverse Dynamics Solver in Matlab.

Posted: Tue May 25, 2021 3:19 am
by nicos1993
Hello Ratna,

To create the vector of spatial vectors in Matlab I believe the command is:
appliedBodyForces = VectorOfSpatialVec();

I think you will have to define the size of this too; check the available methods of VectorOfSpatialVec() as there should be a 'resize' and it should reflect the number of bodies in the model (nbodies = yourModel.getBodySet().getSize();)

To do what you then ask (i.e. apply force at a point in the forearm) you will need to figure out which spatial vector in the vector of spatial vectors corresponds to the body of interest.

I think you can do this in Matlab by using something like this:
yourModel.getMatterSubsystem().addInStationForce(state,mobilizedBodyIndex,forceLocation,appliedForce,appliedBodyForces)

.addInStationForce() will update the appliedBodyForces vector of spatial vectors for the body you desire (mobilizedBodyIndex) with the force you wish (appliedForce) at the point (forceLocation) described in the body of interests frame. See here for further: https://simtk.org/api_docs/molmodel/api ... dfed3ffa54

I hope that helps!

Nicos