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.
How to define Body Forces in Inverse Dynamics Solver in Matlab.
- Ratna Sambhav
- Posts: 42
- Joined: Sat Jan 12, 2019 10:16 am
- Nicos Haralabidis
- Posts: 196
- Joined: Tue Aug 16, 2016 1:46 am
Re: How to define Body Forces in Inverse Dynamics Solver in Matlab.
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
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