MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
MocoMaxCoordinateGoal Class Reference

Goal that finds the maximum value of a coordinate over the motion. More...

#include <MocoMaxCoordinateGoal.h>

Inheritance diagram for MocoMaxCoordinateGoal:

Public Member Functions

void setStateName (const std::string refCoordName)
 Set the name of the coordinate whose maximum value should be found.
 
 MocoMaxCoordinateGoal ()
 
 MocoMaxCoordinateGoal (std::string name)
 
 MocoMaxCoordinateGoal (std::string name, double weight)
 
void setDivideByDisplacement (bool tf)
 
bool getDivideByDisplacement () const
 
void setStateName (const std::string refCoordName)
 
Constructors
 MocoMaxCoordinateGoal ()
 Default constructor.
 
 MocoMaxCoordinateGoal (std::string name)
 Constructor with name.
 
 MocoMaxCoordinateGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

Mode getDefaultModeImpl () const override
 
bool getSupportsEndpointConstraintImpl () const override
 
void initializeOnModelImpl (const Model &) const override
 
void calcIntegrandImpl (const IntegrandInput &input, double &integrand) const override
 
void calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override
 
Required implementations of virtual methods
Mode getDefaultModeImpl () const override
 Get the default mode for this goal.
 
bool getSupportsEndpointConstraintImpl () const override
 Whether this goal supports endpoint constraint mode.
 
void initializeOnModelImpl (const Model &) const override
 Initialize the goal with the model.
 
void calcIntegrandImpl (const IntegrandInput &input, double &integrand) const override
 Calculate the integrand value for the cost function.
 
void calcGoalImpl (const GoalInput &input, SimTK::Vector &cost) const override
 Calculate the goal value.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoMaxCoordinateGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoMaxCoordinateGoal, MocoGoal)
 
 OpenSim_DECLARE_PROPERTY (divide_by_displacement, bool, "Divide by the model's displacement over the phase (default: " "false)")
 
void constructProperties ()
 
Properties
 OpenSim_DECLARE_PROPERTY (exponent, int, "The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1, the absolute value function is " "applied to the output (before the exponent is applied), meaning " "that odd numbered exponents (greater than 1) do not take on " "negative values.")
 

Private Attributes

Internal working variables
StatesTrajectory st
 
std::vector< double > inte
 Vector for storing intermediate values.
 
double coord_max
 Maximum coordinate value found.
 
double v
 Current coordinate value.
 
int m_state_index
 Index of the coordinate state.
 
std::string m_state_name
 Name of the coordinate state.
 
std::function< double(const double &)> m_power_function
 Function to compute power of coordinate values.
 

Detailed Description

Goal that finds the maximum value of a coordinate over the motion.

This goal computes the maximum value that a specified coordinate achieves during the motion. The goal value is:

\[
\max_{t \in [t_i, t_f]} |q(t)|^p
\]

where $ q(t) $ is the coordinate value at time t, $ t_i $ and $ t_f $ are the initial and final times, and $ p $ is the exponent (default: 2).

This goal can be useful for:

  • Finding peak values of joint angles
  • Identifying maximum deviations from a neutral position
  • Constraining the range of motion
Note
The coordinate must exist in the model and its name must be specified using setStateName() before the goal can be used.

Constructor & Destructor Documentation

◆ MocoMaxCoordinateGoal() [1/6]

Default constructor.

◆ MocoMaxCoordinateGoal() [2/6]

MocoMaxCoordinateGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoMaxCoordinateGoal() [3/6]

MocoMaxCoordinateGoal ( std::string name,
double weight )
inline

Constructor with name and weight.

Parameters
nameThe name of the goal
weightWeight for this goal term in the optimization

◆ MocoMaxCoordinateGoal() [4/6]

◆ MocoMaxCoordinateGoal() [5/6]

MocoMaxCoordinateGoal ( std::string name)
inline

◆ MocoMaxCoordinateGoal() [6/6]

MocoMaxCoordinateGoal ( std::string name,
double weight )
inline

Member Function Documentation

◆ calcGoalImpl() [1/2]

void calcGoalImpl ( const GoalInput & input,
SimTK::Vector & cost ) const
overrideprotected

Calculate the goal value.

Parameters
inputInput data containing the integral
costVector to store the calculated cost

◆ calcGoalImpl() [2/2]

void calcGoalImpl ( const GoalInput & input,
SimTK::Vector & cost ) const
overrideprotected

◆ calcIntegrandImpl() [1/2]

void calcIntegrandImpl ( const IntegrandInput & input,
double & integrand ) const
overrideprotected

Calculate the integrand value for the cost function.

Parameters
inputInput data for the current state
integrandReference to store the calculated integrand value

◆ calcIntegrandImpl() [2/2]

void calcIntegrandImpl ( const IntegrandInput & input,
double & integrand ) const
overrideprotected

◆ constructProperties() [1/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ constructProperties() [2/2]

void constructProperties ( )
private

◆ getDefaultModeImpl() [1/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

Get the default mode for this goal.

◆ getDefaultModeImpl() [2/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

◆ getDivideByDisplacement()

bool getDivideByDisplacement ( ) const
inline

◆ getSupportsEndpointConstraintImpl() [1/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ getSupportsEndpointConstraintImpl() [2/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

◆ initializeOnModelImpl() [1/2]

void initializeOnModelImpl ( const Model & model) const
overrideprotected

Initialize the goal with the model.

◆ initializeOnModelImpl() [2/2]

void initializeOnModelImpl ( const Model & ) const
overrideprotected

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [1/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoMaxCoordinateGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoMaxCoordinateGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_PROPERTY() [1/2]

OpenSim_DECLARE_PROPERTY ( divide_by_displacement ,
bool ,
"Divide by the model's displacement over the phase (default: " "false)"  )
private

◆ OpenSim_DECLARE_PROPERTY() [2/2]

OpenSim_DECLARE_PROPERTY ( exponent ,
int ,
"The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1,
the absolute value function is " "applied to the outputbefore the exponent is applied,
meaning " "that odd numbered exponents(greater than 1) do not take on " "negative values."  )
private

◆ setDivideByDisplacement()

void setDivideByDisplacement ( bool tf)
inline
Here is the caller graph for this function:

◆ setStateName() [1/2]

void setStateName ( const std::string refCoordName)
inline

Set the name of the coordinate whose maximum value should be found.

Parameters
refCoordNameName of the coordinate in the model. Should be a state variable path (e.g., '/jointset/knee_r/knee_angle_r')

◆ setStateName() [2/2]

void setStateName ( const std::string refCoordName)
inline

Member Data Documentation

◆ coord_max

double coord_max
mutableprivate

Maximum coordinate value found.

◆ inte

std::vector< double > inte
mutableprivate

Vector for storing intermediate values.

◆ m_power_function

std::function<double(const double&)> m_power_function
mutableprivate

Function to compute power of coordinate values.

◆ m_state_index

int m_state_index
mutableprivate

Index of the coordinate state.

◆ m_state_name

std::string m_state_name
mutableprivate

Name of the coordinate state.

◆ st

StatesTrajectory st
mutableprivate

States trajectory for computing maximum

◆ v

double v
mutableprivate

Current coordinate value.


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