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
MocoCOPGoal Class Reference

Goal that minimizes the deviation of the center of pressure (COP) from a target. More...

#include <MocoCOPGoal.h>

Inheritance diagram for MocoCOPGoal:

Public Member Functions

void setExponent (int ex)
 Set the exponent for the deviation term.
 
bool getExponent () const
 Get the current exponent value.
 
void setDivideByDisplacement (bool tf)
 Set whether to divide by displacement.
 
bool getDivideByDisplacement () const
 Get whether the goal is divided by displacement.
 
Constructors
 MocoCOPGoal ()
 Default constructor.
 
 MocoCOPGoal (std::string name)
 Constructor with name.
 
 MocoCOPGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

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.
 
SimTK::Matrix FlattenSpatialVec (const SimTK::SpatialVec &S) const
 Convert a spatial vector to a matrix representation.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoCOPGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
Properties
 OpenSim_DECLARE_PROPERTY (divide_by_displacement, bool, "Divide by the model's displacement over the phase (default: " "false)")
 
 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

std::vector< std::string > m_force_names
 
std::function< double(const double &)> m_power_function
 

Detailed Description

Goal that minimizes the deviation of the center of pressure (COP) from a target.

This goal minimizes the deviation of the model's center of pressure from a desired target location, integrated over the phase. The center of pressure is calculated using the contact forces between the model and the ground.

This goal can be useful for:

  • Controlling weight transfer during stance
  • Improving balance and stability
  • Generating more natural gait patterns
  • Reducing excessive pressure points

The goal can optionally be divided by the total displacement of the model during the phase to make the cost invariant to the distance traveled.

Constructor & Destructor Documentation

◆ MocoCOPGoal() [1/3]

MocoCOPGoal ( )
inline

Default constructor.

◆ MocoCOPGoal() [2/3]

MocoCOPGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoCOPGoal() [3/3]

MocoCOPGoal ( 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

Member Function Documentation

◆ calcGoalImpl()

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

◆ calcIntegrandImpl()

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
Here is the call graph for this function:

◆ constructProperties()

void constructProperties ( )
private

Initialize the goal's properties.

◆ FlattenSpatialVec()

SimTK::Matrix FlattenSpatialVec ( const SimTK::SpatialVec & S) const
protected

Convert a spatial vector to a matrix representation.

Parameters
SSpatial vector to flatten
Returns
Matrix representation
Here is the caller graph for this function:

◆ getDefaultModeImpl()

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

Get the default mode for this goal.

◆ getDivideByDisplacement()

bool getDivideByDisplacement ( ) const
inline

Get whether the goal is divided by displacement.

Returns
True if divided by displacement, false otherwise

◆ getExponent()

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent value

◆ getSupportsEndpointConstraintImpl()

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ initializeOnModelImpl()

void initializeOnModelImpl ( const Model & model) const
overrideprotected

Initialize the goal with the model.

◆ OpenSim_DECLARE_CONCRETE_OBJECT()

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoCOPGoal ,
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

Set whether to divide by displacement.

Parameters
tfTrue to divide by displacement, false otherwise

◆ setExponent()

void setExponent ( int ex)
inline

Set the exponent for the deviation term.

Parameters
exThe exponent value

Member Data Documentation

◆ m_force_names

std::vector<std::string> m_force_names
mutableprivate

◆ m_power_function

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

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