Page 1 of 1

How to use the BodyActuator?

Posted: Fri Dec 01, 2023 5:46 am
by luke31
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.

Re: How to use the BodyActuator?

Posted: Sat Dec 02, 2023 5:12 pm
by tkuchida
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.