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

Description

Minimize the sum of the absolute value of the controls raised to a given exponent, integrated over the phase.

The default weight for each control is 1.0; this can be changed by calling setWeight() or editing the control_weights property in XML. The exponent must be an integer greater than or equal to 2, and is 2 by default. If conducting a predictive simulation, you likely want to set divide_by_displacement to true; otherwise, this cost is minimized by not moving. Dividing by displacement leads to a quantity similar to cost of transport.

This goal is computed as follows:

\[ \frac{1}{d} \int_{t_i}^{t_f} \sum_{c \in C} w_c |x_c(t)|^p ~dt \]

We use the following notation:

If p > 2, we first the absolute value of the control; this is to properly handle odd exponents.

Examples:
example2DWalking.cpp, and exampleMocoTrack.cpp.
Inheritance diagram for OpenSim::MocoControlGoal:
OpenSim::MocoGoal

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

Public Member Functions

 MocoControlGoal (std::string name)
 
 MocoControlGoal (std::string name, double weight)
 
void setWeightForControl (const std::string &controlName, const double &weight)
 Set the weight to use for the term in the cost associated with controlName (the name or path of the corresponding actuator). More...
 
void setWeightForControlPattern (const std::string &pattern, const double &weight)
 Set weights for all controls whose entire path matches the provided regular expression pattern. More...
 
void setExponent (int exponent)
 Set the exponent on the control signals.
 
double getExponent () const
 
void setDivideByDisplacement (bool tf)
 Set if the goal should be divided by the displacement of the system's center of mass over the phase. More...
 
bool getDivideByDisplacement () 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

◆ calcIntegrandImpl()

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

◆ setDivideByDisplacement()

void OpenSim::MocoControlGoal::setDivideByDisplacement ( bool  tf)
inline

Set if the goal should be divided by the displacement of the system's center of mass over the phase.

◆ setWeightForControl()

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

Set the weight to use for the term in the cost associated with controlName (the name or path of the corresponding actuator).

To remove a control from the cost function, set its weight to 0. If a weight is already set for the requested state, then the provided weight replaces the previous weight. Only controls with non-zero weights that are associated with actuators for which appliesForce is True are included in the cost function. Weights set here take precedence over weights specified with a regular expression.

Examples:
exampleMocoTrack.cpp.

◆ setWeightForControlPattern()

void OpenSim::MocoControlGoal::setWeightForControlPattern ( const std::string &  pattern,
const double &  weight 
)

Set weights for all controls whose entire path matches the provided regular expression pattern.

Multiple pairs of patterns and weights can be provided by calling this function multiple times. If a control matches multiple patterns, the weight associated with the last pattern is used.


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