Open nickbianco opened 3 months ago
It seems like I might be able to leverage the existing CalcForcesTask
and ParallelExecutor
within GeneralForceSubsystemRep
by setting enabledNonParallelForces
and/or enabledParallelForces
to reflect the forces I'd like to include in the computation. Taking a closer look now.
I decided to open a PR for this, since I had relatively straight-forward implementation working for me. I decided to keep it simple and avoid CalcForcesTask
for now, since there's some caching steps in there that I don't fully understand yet.
I am working on a new feature for OpenSim Moco that would allow users to track a reference set of generalized coordinate forces in a trajectory optimization problem. The OpenSim
InverseDynamicsTool
usesSimbodyMatterSubsystem::calcResidualForce()
to compute generalized coordinate forces by internally making a copy of the model and disabling forces that should be excluded from the anaylsis (usually all forces except external loads, e.g., from ground reaction force data).In Moco, it would be preferable to not require a copy of the model since all classes that implement cost function terms already have a reference to the original model. Instead, we ideally should only need to retrieve the set of body and mobility forces needed to compute the generalized forces from inverse dynamics.
Force::calcForceContribution
has the desired functionality, but, as noted in the documentation, it requires resizing and zeroing out passed in body and mobility force arrays and is therefore not the best choice for use in optimization.Desired workflow
The desired workflow to compute generalized forces within Moco's trajectory optimization framework would look as follows:
Proposed method
One potential option is to add a method to
GeneralForceSubsystemRep
to calculate the subset of desired forces based on a list ofForceIndex
es:Even if we need to resize/zero the input arrays in this implementation, it would only need to be done once for all forces. If it's possible to skip the zeroing step (and rename to method to something like
addInForces
or something), that could be even better.If an addition like this make sense to add to the API, I'd be happy to submit pull request after agreeing upon an implementation.