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

Description

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

This can be used to track joint angles, activations, etc. 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. If columns for rotational coordinates are in degrees, those columns will be converted to radians. 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:
exampleTracking.cpp.
Inheritance diagram for OpenSim::MocoStateTrackingGoal:
OpenSim::MocoGoal

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

Public Member Functions

 MocoStateTrackingGoal (std::string name)
 
 MocoStateTrackingGoal (std::string name, double weight)
 
void setReference (TableProcessor ref)
 Provide a table containing reference values for the states you want to track. More...
 
const TableProcessorgetReference () const
 If no reference has been provided, this returns an empty processor.
 
void setWeightForState (const std::string &stateName, const double &weight)
 Set the weight for an individual state variable. More...
 
void setWeightSet (const MocoWeightSet &weightSet)
 Provide a MocoWeightSet to weight the state variables in the cost. More...
 
void setPattern (std::string pattern)
 Only state paths matching the regular expression are tracked. More...
 
void clearPattern ()
 Unset the pattern, which causes all states to be matched.
 
std::string getPattern () const
 
void setAllowUnusedReferences (bool tf)
 Specify whether or not extra columns in the reference are allowed. More...
 
void setScaleWeightsWithRange (bool tf)
 Use the range, or the distance between the maximum and minimum value, of each reference quantity to scale the weight for the associated tracking error in the cost. More...
 
- 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

◆ calcIntegrandImpl()

void OpenSim::MocoStateTrackingGoal::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::MocoStateTrackingGoal::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::MocoStateTrackingGoal::setAllowUnusedReferences ( bool  tf)
inline

Specify whether or not extra columns in the reference are allowed.

If set true, the extra references will be ignored by the cost. If false, extra reference will cause an Exception to be raised.

◆ setPattern()

void OpenSim::MocoStateTrackingGoal::setPattern ( std::string  pattern)
inline

Only state paths matching the regular expression are tracked.

The regular expression must match the entire state path for a state path to be tracked (that is, we use std::regex_match, not std::regex_search). To track only generalized coordinates, use .*value$. To track generalized coordinates and speeds, use .*(value|speed)$. To track only activations, use .*activation$. If the reference contains columns for states whose path does not match this pattern, you will get an error unless you use setAllowUnusedReferences(true).

◆ setReference()

void OpenSim::MocoStateTrackingGoal::setReference ( TableProcessor  ref)
inline

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

Each column label must be the path of a state variable, e.g., knee/flexion/value. The table is not loaded until the MocoProblem is initialized.

Examples:
exampleTracking.cpp.

◆ setScaleWeightsWithRange()

void OpenSim::MocoStateTrackingGoal::setScaleWeightsWithRange ( bool  tf)
inline

Use the range, or the distance between the maximum and minimum value, of each reference quantity to scale the weight for the associated tracking error in the cost.

The scale is computed by the inverse of the range, so a reference quantity that changes less across the trajectory has a larger weight. Each reference has a default weight of 1, so this flag works even if no user weights have be set. This may be useful when tracking quantities with different units, which may have tracking errors with different magnitudes.

◆ setWeightForState()

void OpenSim::MocoStateTrackingGoal::setWeightForState ( const std::string &  stateName,
const double &  weight 
)
inline

Set the weight for an individual state variable.

If a weight is already set for the requested state, then the provided weight replaces the previous weight. An exception is thrown if a weight for an unknown state is provided.

◆ setWeightSet()

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

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

Replaces the weight set if it already exists.


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