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

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

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

Post by Ratna Sambhav » Mon May 24, 2021 6:27 am

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.

Tags:

User avatar
Nicos Haralabidis
Posts: 197
Joined: Tue Aug 16, 2016 1:46 am

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

Post by Nicos Haralabidis » Tue May 25, 2021 3:19 am

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

POST REPLY