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

Description

Minimize the sum of squares of specified reaction moment and force measures for a given joint, integrated over the phase.

If the magnitude of the gravity acceleration vector (Model::get_gravity()) is non-zero, then the goal is normalized by the model's weight; otherwise, the goal is normalized by the model's mass. We assume the system's mass is constant (that is, MocoParameters do not affect mass).

In addition to specifying the joint and reaction measures, the user may also specify the frame the loads are computed from ("parent" or "child"), and the frame the loads are expressed in (any valid frame in the model).

Minimizing the y-direction reaction force on the child frame of the right knee joint expressed in the right tibia frame:

auto* cost = problem.addGoal<MocoJointReactionCost>();
cost->setName("tibiofemoral_compressive_force");
cost->setJointPath("/jointset/knee_r");
cost->setLoadsFrame("child");
cost->setExpressedInFramePath("/bodyset/tibia_r");
cost->setReactionMeasures({"force-y"});

This cost requires realizing to the Acceleration stage.

Inheritance diagram for OpenSim::MocoJointReactionGoal:
OpenSim::MocoGoal

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

Public Member Functions

 MocoJointReactionGoal (std::string name)
 
 MocoJointReactionGoal (std::string name, double weight)
 
void setJointPath (const std::string &jointPath)
 Set the model path to the joint whose reaction load(s) will be minimized. More...
 
void setLoadsFrame (const std::string &frame)
 Set the frame from which the reaction loads are computed. More...
 
void setExpressedInFramePath (const std::string &framePath)
 Set the frame in which the minimized reaction load is expressed. More...
 
void setReactionMeasures (const std::vector< std::string > &measures)
 Set a specific set of reaction measures to be minimized. More...
 
void setWeight (const std::string &stateName, const double &weight)
 Set the weight for an individual reaction measure. More...
 
void setWeightSet (const MocoWeightSet &weightSet)
 Provide a MocoWeightSet to weight the reaction measures 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::MocoJointReactionGoal::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::MocoJointReactionGoal::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.

◆ setExpressedInFramePath()

void OpenSim::MocoJointReactionGoal::setExpressedInFramePath ( const std::string &  framePath)
inline

Set the frame in which the minimized reaction load is expressed.

By default, it is set to the parent or child frame depending on the 'loads_frame' property value.

◆ setJointPath()

void OpenSim::MocoJointReactionGoal::setJointPath ( const std::string &  jointPath)
inline

Set the model path to the joint whose reaction load(s) will be minimized.

◆ setLoadsFrame()

void OpenSim::MocoJointReactionGoal::setLoadsFrame ( const std::string &  frame)
inline

Set the frame from which the reaction loads are computed.

Options: "parent" or "child" (default: "parent").

◆ setReactionMeasures()

void OpenSim::MocoJointReactionGoal::setReactionMeasures ( const std::vector< std::string > &  measures)
inline

Set a specific set of reaction measures to be minimized.

Options: "moment-x", "moment-y", "moment-z", "force-x", "force-y", and "force-z". All reaction measures are minimized by default. Replaces the reaction measure set if it already exists.

◆ setWeight()

void OpenSim::MocoJointReactionGoal::setWeight ( const std::string &  stateName,
const double &  weight 
)
inline

Set the weight for an individual reaction measure.

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

◆ setWeightSet()

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

Provide a MocoWeightSet to weight the reaction measures in the cost.

Replaces the weight set if it already exists.


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