OpenSim Moco
0.4.0
|
Minimize the error between compliant contact force elements in the model and experimentally measured contact forces.
This class handles multiple groups of contact forces and a single experimental external loads file. Tracking ground reaction forces for the left and right feet in gait requires only one instance of this goal.
This goal is computed as follows:
\[ \frac{1}{mg} \int_{t_i}^{t_f} \sum_{j \in G} \|\mathrm{proj}_{\hat{n}}(\vec{F}_{m,j} - \vec{F}_{e,j})\|^2 ~dt \]
We use the following notation:
The projection is useful for selecting which components of the force to track. The force can be projected to be onto a vector or onto a plane. For example, with gait, projecting onto the vector (0, 1, 0) allows tracking only the vertical component of a ground reaction force; projecting onto the plane perpendicular to the vector (0, 0, 1) allows ignoring the transverse force. See the projection and projection_vector properties.
To use this goal, specify the following:
The ExternalLoads class is the standard way to provide experimental contact forces in OpenSim. This class is a set of ExternalForce objects. For gait, typically the ExternalLoads contains 2 ExternalForces, one for each foot. This goal uses the following information from ExternalLoads:
This goal uses the following information from each ExternalForce:
<force_identifier>x
, <force_identifier>y
, <force_identifier>z
.All other properties of ExternalLoads and ExternalForce are ignored by this goal. This means that experimental forces are processed differently by this goal than by other OpenSim tools such as Inverse Dynamics, Computed Muscle Control, and Forward.
#include <Moco/Moco/MocoGoal/MocoContactTrackingGoal.h>
Public Member Functions | |
MocoContactTrackingGoal (std::string name) | |
MocoContactTrackingGoal (std::string name, double weight) | |
void | setExternalLoadsFile (const std::string &extLoadsFile) |
Set the ExternalLoads as an XML file. More... | |
void | setExternalLoads (const ExternalLoads &extLoads) |
Set the ExternalLoads as an object. More... | |
void | addContactGroup (const std::vector< std::string > &contactForcePaths, const std::string &externalForceName) |
Add a group of contact forces whose sum should track the force data from a single ExternalForce. More... | |
void | addContactGroup (MocoContactTrackingGoalGroup group) |
Add a group of contact forces whose sum should track the force data from a single ExternalForce. More... | |
void | setProjection (std::string projection) |
Set if the force error should be projected onto either a vector or plane. More... | |
std::string | getProjection () const |
void | setProjectionVector (SimTK::Vec3 normal) |
Set the vector to use for projecting the force error. More... | |
void | clearProjectionVector () |
Unset the projection vector. | |
SimTK::Vec3 | getProjectionVector () const |
Public Member Functions inherited from OpenSim::MocoGoal | |
MocoGoal (std::string name) | |
MocoGoal (std::string name, double weight) | |
void | setEnabled (bool enabled) |
Set whether this goal is used in the problem. | |
bool | getEnabled () const |
void | setWeight (double weight) |
In cost mode, the goal is multiplied by this weight. More... | |
double | getWeight () const |
void | setMode (std::string mode) |
Set the mode property to either 'cost' or 'endpoint_constraint'. More... | |
std::string | getModeAsString () const |
This returns the default mode of the goal, unless the user overrode the default using setMode(). More... | |
Mode | getMode () const |
bool | getModeIsCost () const |
bool | getModeIsEndpointConstraint () const |
Mode | getDefaultMode () const |
Types of goals have a class-level default for whether they are enforced as a cost or endpoint constraint. More... | |
bool | getSupportsEndpointConstraint () const |
Can this constraint be used in endpoint constraint mode? | |
const MocoConstraintInfo & | getConstraintInfo () const |
Get bounds for the constraints when using this goal in endpoint constraint mode. More... | |
MocoConstraintInfo & | updConstraintInfo () |
int | getNumOutputs () const |
Get the length of the return value of calcGoal(). | |
int | getNumIntegrals () const |
Get the number of integrals required by this cost. More... | |
SimTK::Real | calcIntegrand (const SimTK::State &state) const |
Calculate the integrand that should be integrated and passed to calcCost(). More... | |
void | calcGoal (const GoalInput &input, SimTK::Vector &goal) const |
In cost mode, the returned cost includes the weight, and the elements of the returned vector should be summed by the caller to obtain the total cost. More... | |
void | initializeOnModel (const Model &model) const |
For use by solvers. This also performs error checks on the Problem. | |
void | printDescription (std::ostream &stream=std::cout) const |
Print the name type and mode of this goal. More... | |
Protected Member Functions | |
void | initializeOnModelImpl (const Model &) const override |
Perform any caching before the problem is solved. More... | |
void | calcIntegrandImpl (const SimTK::State &state, double &integrand) const override |
void | calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override |
The Lagrange multipliers for kinematic constraints are not available. | |
void | printDescriptionImpl (std::ostream &stream=std::cout) const override |
Print a more detailed description unique to each goal. | |
Protected Member Functions inherited from OpenSim::MocoGoal | |
void | setNumIntegralsAndOutputs (int numIntegrals, int numOutputs) const |
Set the number of integral terms required by this goal and the length of the vector passed into calcGoalImpl(). More... | |
virtual Mode | getDefaultModeImpl () const |
virtual bool | getSupportsEndpointConstraintImpl () const |
const Model & | getModel () const |
For use within virtual function implementations. | |
double | calcSystemDisplacement (const SimTK::State &initial, const SimTK::State &final) const |
Additional Inherited Members | |
Public Types inherited from OpenSim::MocoGoal | |
enum | Mode { Cost, EndpointConstraint } |
|
inline |
Add a group of contact forces whose sum should track the force data from a single ExternalForce.
The externalForceName should be the name of an ExternalForce object in the ExternalLoads.
|
inline |
Add a group of contact forces whose sum should track the force data from a single ExternalForce.
If the contact force elements associated with a single ExternalForce are distributed across multiple bodies use this function instead of the easier-to-use addContactGroup(), and set the group's alternative_frame_paths property accordingly. See MocoContactTrackingGoalGroup for more information.
|
overrideprotectedvirtual |
Reimplemented from OpenSim::MocoGoal.
|
overrideprotectedvirtual |
Perform any caching before the problem is solved.
You must override this function and invoke setNumIntegralsAndOutputs().
Implements OpenSim::MocoGoal.
void OpenSim::MocoContactTrackingGoal::setExternalLoads | ( | const ExternalLoads & | extLoads | ) |
Set the ExternalLoads as an object.
This clears the ExternalLoads XML file, if provided.
void OpenSim::MocoContactTrackingGoal::setExternalLoadsFile | ( | const std::string & | extLoadsFile | ) |
Set the ExternalLoads as an XML file.
This clears the ExternalLoads provided as an object, if one exists.
|
inline |
Set if the force error should be projected onto either a vector or plane.
Possible values: "none" (default), "vector", and "plane".
|
inline |
Set the vector to use for projecting the force error.
If the projection type is "vector", the force error is projected onto the vector provided here. If the projection type is "plane", the force error is projected onto the plane perpendicular to this vector.