OpenSim Moco  0.4.0
Classes | Public Member Functions | Protected Member Functions | List of all members
OpenSim::MocoContactTrackingGoal Class Reference

Description

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.

Note
The only contact element supported is SmoothSphereHalfSpaceForce.
This goal does not include torques or centers of pressure.

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:

Tracking a subset of force components

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.

Usage

To use this goal, specify the following:

Configuring the ExternalLoads

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:

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.

Note
The ExternalLoads used by this goal is separate from the model. Using this goal implies that the model contains compliant contact forces, so adding ExternalLoads to the model would be redundant. This class uses the ExternalLoads only for computing the force error, not for applying forces to the model.
Examples:
example2DWalking.cpp.
Inheritance diagram for OpenSim::MocoContactTrackingGoal:
OpenSim::MocoGoal

#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 MocoConstraintInfogetConstraintInfo () const
 Get bounds for the constraints when using this goal in endpoint constraint mode. More...
 
MocoConstraintInfoupdConstraintInfo ()
 
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 }
 

Member Function Documentation

◆ addContactGroup() [1/2]

void OpenSim::MocoContactTrackingGoal::addContactGroup ( const std::vector< std::string > &  contactForcePaths,
const std::string &  externalForceName 
)
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.

◆ addContactGroup() [2/2]

void OpenSim::MocoContactTrackingGoal::addContactGroup ( MocoContactTrackingGoalGroup  group)
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.

◆ calcIntegrandImpl()

void OpenSim::MocoContactTrackingGoal::calcIntegrandImpl ( const SimTK::State &  state,
double &  integrand 
) const
overrideprotectedvirtual
Precondition(s):
The state is realized to SimTK::Stage::Position. If you need access to the controls, you must realize to Velocity:
getModel().realizeVelocity(state);
The Lagrange multipliers for kinematic constraints are not available.

Reimplemented from OpenSim::MocoGoal.

◆ initializeOnModelImpl()

void OpenSim::MocoContactTrackingGoal::initializeOnModelImpl ( const Model &  ) const
overrideprotectedvirtual

Perform any caching before the problem is solved.

You must override this function and invoke setNumIntegralsAndOutputs().

Precondition(s):
The model is initialized (initSystem()) and getModel() is available. The passed-in model is equivalent to getModel(). Use this opportunity to check for errors in user input.

Implements OpenSim::MocoGoal.

◆ setExternalLoads()

void OpenSim::MocoContactTrackingGoal::setExternalLoads ( const ExternalLoads &  extLoads)

Set the ExternalLoads as an object.

This clears the ExternalLoads XML file, if provided.

◆ setExternalLoadsFile()

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.

Examples:
example2DWalking.cpp.

◆ setProjection()

void OpenSim::MocoContactTrackingGoal::setProjection ( std::string  projection)
inline

Set if the force error should be projected onto either a vector or plane.

Possible values: "none" (default), "vector", and "plane".

◆ setProjectionVector()

void OpenSim::MocoContactTrackingGoal::setProjectionVector ( SimTK::Vec3  normal)
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.


The documentation for this class was generated from the following file: