How to use the BodyActuator?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Lukas Schmitz
Posts: 3
Joined: Thu Aug 10, 2023 2:01 am

How to use the BodyActuator?

Post by Lukas Schmitz » Fri Dec 01, 2023 5:46 am

I want to apply 6d forces/torques on a body using the BodyActuator in C++.

Usually, when applying forces through i.e. the PointActuator or the CoordinateActuator, I would use the PrescribedController and the function prescribeControlForActuator() to generate a force to be applied. However, the documentation clearly states, that the BodyActuator can apply a spatial force (6D vector), while the PrescribedController uses the Function class, which generates 1D values, as far as I am aware.

Can I use the PrescribedController to set control values for the BodyActuator? If so, how? If not, how else can I apple values?

I have already tried applying the forces manually to the model like this:

Code: Select all

void applyBodyActuatorToModel(OpenSim::Model *model, const SimTK::State &state,
                              OpenSim::BodyActuator &body_actuator,
                              SimTK::Vector force) {

  auto modelControls = model->getDefaultControls();
  body_actuator.addInControls(force, modelControls);
  model->setDefaultControls(modelControls);
  model->computeStateVariableDerivatives(state);

}
However when looking at the output of the ForceReporter, the desired forces don't exist.

Tags:

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: How to use the BodyActuator?

Post by Thomas Uchida » Sat Dec 02, 2023 5:12 pm

An example can be found in testActuators.cpp (see the testBodyActuator() method here: https://github.com/opensim-org/opensim- ... s.cpp#L546). The BodyActuator is created and configured starting at line 648.

POST REPLY