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

Description

The squared difference between a control variable value and a reference control variable value, summed over the control variables for which a reference is provided, and integrated over the phase.

This can be used to track actuator controls, muscle excitations, etc.

This goal is computed as follows:

\[ \int_{t_i}^{t_f} \sum_{c \in C} w_c \|x_{m,c}(t) - x_{e,c})\|^2 ~dt \]

We use the following notation:

This goal has two labeling modes: 'auto' and 'manual':

Control variable names

Control variable names are based on paths to actuators, e.g., /forceset/soleus_r. For non-scalar actuators, the control variable name includes the index for the actuator control; e.g., /forceset/body_actuator_0, where 'body_actuator' is the name of the actuator and _0 specifies the control index.

Reference data

The reference can be provided as a file name to a STO or CSV file (or other file types for which there is a FileAdapter), or programmatically as a TimeSeriesTable.

Helpful tips

Tracking problems in direct collocation perform best when tracking smooth data, so it is recommended to filter the data in the reference you provide to the cost.

Examples:
exampleMocoInverse.cpp.
Inheritance diagram for OpenSim::MocoControlTrackingGoal:
OpenSim::MocoGoal

#include <Moco/Moco/MocoGoal/MocoControlTrackingGoal.h>

Public Member Functions

 MocoControlTrackingGoal (std::string name)
 
 MocoControlTrackingGoal (std::string name, double weight)
 
void setReference (const TableProcessor &ref)
 Provide a table containing reference values for the controls you want to track. More...
 
void setWeightForControl (const std::string &controlName, const double &weight)
 Set the weight for an individual control variable. More...
 
void setWeightSet (const MocoWeightSet &weightSet)
 Provide a MocoWeightSet to weight the control variables in the cost. More...
 
void setReferenceLabel (const std::string &control, const std::string &label)
 Set the column of the reference data that a given control should track. More...
 
void clearReferenceLabels ()
 Clear the 'reference_labels' property, which ensures this goal is used in 'auto' labeling mode. More...
 
void setAllowUnusedReferences (bool tf)
 Specify whether the reference can have columns not associated with controls. More...
 
const TableProcessorgetReference () const
 If no reference has been provided, this returns an empty processor.
 
bool hasReferenceLabel (const std::string &control) const
 
std::string getReferenceLabel (const std::string &control) const
 
bool getAllowUnusedReferences () 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 &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

◆ calcIntegrandImpl()

void OpenSim::MocoControlTrackingGoal::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.

◆ clearReferenceLabels()

void OpenSim::MocoControlTrackingGoal::clearReferenceLabels ( )
inline

Clear the 'reference_labels' property, which ensures this goal is used in 'auto' labeling mode.

◆ initializeOnModelImpl()

void OpenSim::MocoControlTrackingGoal::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.

◆ setAllowUnusedReferences()

void OpenSim::MocoControlTrackingGoal::setAllowUnusedReferences ( bool  tf)
inline

Specify whether the reference can have columns not associated with controls.

If set true, then such columns will be ignored by the cost. If false, such columns will cause an Exception to be raised. Only takes effect in 'auto' labeling mode.

◆ setReference()

void OpenSim::MocoControlTrackingGoal::setReference ( const TableProcessor ref)
inline

Provide a table containing reference values for the controls you want to track.

In 'auto' labeling mode, each column label must be a control variable name. In 'manual' labeling mode, the column labels need not be control variable names; use setReferenceLabel() to associate controls with columns. The table is not loaded until the MocoProblem is initialized.

◆ setReferenceLabel()

void OpenSim::MocoControlTrackingGoal::setReferenceLabel ( const std::string &  control,
const std::string &  label 
)
inline

Set the column of the reference data that a given control should track.

Multiple controls can track the same column of the reference data. This replaces the reference label for the given control, if one had already been provided. If controls are not manually associated with a reference label, then it is assumed that the column labels for the reference data exactly match the names of controls.

◆ setWeightForControl()

void OpenSim::MocoControlTrackingGoal::setWeightForControl ( const std::string &  controlName,
const double &  weight 
)
inline

Set the weight for an individual control variable.

If a weight is already set for the requested control, then the provided weight replaces the previous weight. If no weight is specified for a control, a weight of 1.0 is used internally. Set the weight to 0 to avoid tracking a given control. An exception is thrown if a weight for an unknown control is provided.

◆ setWeightSet()

void OpenSim::MocoControlTrackingGoal::setWeightSet ( const MocoWeightSet weightSet)
inline

Provide a MocoWeightSet to weight the control variables in the cost.

Replaces the weight set if it already exists.


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