OpenSim Moco  0.4.0
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
OpenSim::MocoGoal Class Referenceabstract

Description

A goal is term in the cost functional to be minimized, or a set of endpoint constraints that must lie within provided bounds.

Goals depend on the phase's initial and final states and controls, and optionally on the integral of a quantity over the phase. Not all goals support endpoint constraint mode; see getSupportsEndpointConstraint(). If a goal does support endpoint constraint mode, then the default mode is available via getMode(). Use endpoint constraint mode if you require the goal to be met strictly and do not want to allow a trade-off between this goal and other goals. The calculation of the goal may differ between cost and endpoint constraint modes; cost mode may require that outputs are squared, for example.

For developers
Every time the problem is solved, a copy of this goal is used. An individual instance of a goal is only ever used in a single problem. Therefore, there is no need to clear cache variables that you create in initializeImpl(). Also, information stored in this goal does not persist across multiple solves.
Examples:
exampleSlidingMassAdvanced.cpp.
Inheritance diagram for OpenSim::MocoGoal:
OpenSim::MocoAccelerationTrackingGoal OpenSim::MocoAngularVelocityTrackingGoal OpenSim::MocoAverageSpeedGoal OpenSim::MocoContactTrackingGoal OpenSim::MocoControlGoal OpenSim::MocoControlTrackingGoal OpenSim::MocoFinalTimeGoal OpenSim::MocoInitialActivationGoal OpenSim::MocoInitialForceEquilibriumGoal OpenSim::MocoInitialVelocityEquilibriumDGFGoal OpenSim::MocoJointReactionGoal OpenSim::MocoMarkerFinalGoal OpenSim::MocoMarkerTrackingGoal OpenSim::MocoOrientationTrackingGoal OpenSim::MocoOutputGoal OpenSim::MocoPeriodicityGoal OpenSim::MocoStateTrackingGoal OpenSim::MocoSumSquaredStateGoal OpenSim::MocoTranslationTrackingGoal

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

Classes

struct  GoalInput
 

Public Types

enum  Mode { Cost, EndpointConstraint }
 

Public Member Functions

 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

virtual void initializeOnModelImpl (const Model &) const =0
 Perform any caching before the problem is solved. More...
 
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
 
virtual void calcIntegrandImpl (const SimTK::State &state, double &integrand) const
 
virtual void calcGoalImpl (const GoalInput &input, SimTK::Vector &goal) const =0
 The Lagrange multipliers for kinematic constraints are not available.
 
virtual void printDescriptionImpl (std::ostream &stream=std::cout) const
 Print a more detailed description unique to each goal.
 
const Model & getModel () const
 For use within virtual function implementations.
 
double calcSystemDisplacement (const SimTK::State &initial, const SimTK::State &final) const
 

Member Function Documentation

◆ calcGoal()

void OpenSim::MocoGoal::calcGoal ( const GoalInput input,
SimTK::Vector &  goal 
) const
inline

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.

In endpoint constraint mode, each element of the vector is a different scalar equation to enforce as a constraint. The length of the returned vector is getNumOutputs().

◆ calcIntegrand()

SimTK::Real OpenSim::MocoGoal::calcIntegrand ( const SimTK::State &  state) const
inline

Calculate the integrand that should be integrated and passed to calcCost().

If getNumIntegrals() is not zero, this must be implemented.

◆ calcIntegrandImpl()

void OpenSim::MocoGoal::calcIntegrandImpl ( const SimTK::State &  state,
double &  integrand 
) const
inlineprotectedvirtual
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 in OpenSim::MocoContactTrackingGoal, OpenSim::MocoControlTrackingGoal, OpenSim::MocoOrientationTrackingGoal, OpenSim::MocoAngularVelocityTrackingGoal, OpenSim::MocoTranslationTrackingGoal, OpenSim::MocoStateTrackingGoal, OpenSim::MocoAccelerationTrackingGoal, OpenSim::MocoJointReactionGoal, OpenSim::MocoControlGoal, OpenSim::MocoSumSquaredStateGoal, OpenSim::MocoMarkerTrackingGoal, and OpenSim::MocoOutputGoal.

◆ getConstraintInfo()

const MocoConstraintInfo& OpenSim::MocoGoal::getConstraintInfo ( ) const
inline

Get bounds for the constraints when using this goal in endpoint constraint mode.

◆ getDefaultMode()

Mode OpenSim::MocoGoal::getDefaultMode ( ) const
inline

Types of goals have a class-level default for whether they are enforced as a cost or endpoint constraint.

◆ getModeAsString()

std::string OpenSim::MocoGoal::getModeAsString ( ) const
inline

This returns the default mode of the goal, unless the user overrode the default using setMode().

◆ getNumIntegrals()

int OpenSim::MocoGoal::getNumIntegrals ( ) const
inline

Get the number of integrals required by this cost.

This returns either 0 (for a strictly-endpoint cost) or 1.

Precondition(s):
This goal must be initialized.

◆ initializeOnModelImpl()

virtual void OpenSim::MocoGoal::initializeOnModelImpl ( const Model &  ) const
protectedpure virtual

◆ printDescription()

void OpenSim::MocoGoal::printDescription ( std::ostream &  stream = std::cout) const

Print the name type and mode of this goal.

In cost mode, this prints the weight.

◆ setMode()

void OpenSim::MocoGoal::setMode ( std::string  mode)
inline

Set the mode property to either 'cost' or 'endpoint_constraint'.

This should be set before initializing. Setting to 'endpoint_constraint' if getSupportsEndpointConstraint() is false causes an exception during initializing.

◆ setNumIntegralsAndOutputs()

void OpenSim::MocoGoal::setNumIntegralsAndOutputs ( int  numIntegrals,
int  numOutputs 
) const
inlineprotected

Set the number of integral terms required by this goal and the length of the vector passed into calcGoalImpl().

This must be set within initializeOnModelImpl(), otherwise an exception is thrown during initialization. The number of integrals must be either 0 or 1.

◆ setWeight()

void OpenSim::MocoGoal::setWeight ( double  weight)
inline

In cost mode, the goal is multiplied by this weight.

Use the weight to control the relative importance of terms in the cost functional.

Examples:
example2DWalking.cpp, and exampleMocoInverse.cpp.

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