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

Goal that minimizes deviation of the Zero Moment Point (ZMP) from a desired location. More...

#include <MocoZMPGoal.h>

Inheritance diagram for MocoZMPGoal:

Public Member Functions

void setExponent (int ex)
 Set the exponent for the goal.
 
bool getExponent () const
 Get the current exponent value.
 
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
 MocoZMPGoal ()
 Default constructor.
 
 MocoZMPGoal (std::string name)
 Constructor with name.
 
 MocoZMPGoal (std::string name, double weight)
 Constructor with name and weight.
 
 MocoZMPGoal ()
 Default constructor.
 
 MocoZMPGoal (std::string name)
 Constructor with name.
 
 MocoZMPGoal (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.
 
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 (MocoZMPGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoZMPGoal, MocoGoal)
 
void constructProperties ()
 Initialize the goal's properties.
 
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.")
 
 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

Internal working variables
std::vector< std::string > m_force_names
 
std::function< double(const double &)> m_power_function
 Function to compute power of ZMP deviation.
 
OpenSim::Model m_model
 Reference to the model.
 

Detailed Description

Goal that minimizes deviation of the Zero Moment Point (ZMP) from a desired location.

Goal that minimizes the deviation of the Zero Moment Point (ZMP) from a target.

This goal minimizes the distance between the actual Zero Moment Point (ZMP) and a target location. The ZMP is the point where the horizontal component of the moment of ground reaction forces equals zero. The integrand is:

\[
|p_{zmp} - p_{target}|^p
\]

where $ p_{zmp} $ is the current ZMP location, $ p_{target} $ is the target location, and $ p $ is the exponent (default: 2).

This goal is useful for:

  • Maintaining dynamic balance during motion
  • Controlling the center of pressure location
  • Generating stable walking motions

The ZMP is computed using ground reaction forces and moments from contact forces in the model.

This goal minimizes the deviation of the model's Zero Moment Point (ZMP) from a desired target location, integrated over the phase. The ZMP is calculated using the ground reaction forces and moments acting on the model.

The ZMP is a point on the ground where the net moment of the inertial forces and gravity forces has no component along the horizontal axes. It is commonly used in balance control and gait analysis.

This goal can be useful for:

  • Improving dynamic balance during motion
  • Generating more stable walking patterns
  • Controlling weight transfer during stance
  • Reducing risk of falls

The deviation 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

◆ MocoZMPGoal() [1/6]

MocoZMPGoal ( )
inline

Default constructor.

◆ MocoZMPGoal() [2/6]

MocoZMPGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoZMPGoal() [3/6]

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

◆ MocoZMPGoal() [4/6]

MocoZMPGoal ( )
inline

Default constructor.

◆ MocoZMPGoal() [5/6]

MocoZMPGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoZMPGoal() [6/6]

MocoZMPGoal ( 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() [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

Calculate the goal value.

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

◆ 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

Calculate the integrand value for the cost function.

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

◆ constructProperties() [1/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ constructProperties() [2/2]

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

◆ getDefaultModeImpl() [1/2]

Mode getDefaultModeImpl ( ) const
inlineoverrideprotected

Get the default mode for this goal.

◆ getDefaultModeImpl() [2/2]

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() [1/2]

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent applied to the ZMP deviation

◆ getExponent() [2/2]

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent value

◆ getSupportsEndpointConstraintImpl() [1/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ getSupportsEndpointConstraintImpl() [2/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ 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

Initialize the goal with the model.

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [1/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoZMPGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoZMPGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_PROPERTY() [1/3]

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

◆ OpenSim_DECLARE_PROPERTY() [2/3]

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

◆ OpenSim_DECLARE_PROPERTY() [3/3]

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

◆ setExponent() [1/2]

void setExponent ( int ex)
inline

Set the exponent for the goal.

Parameters
exThe exponent value. For ex > 1, absolute value is applied first

◆ setExponent() [2/2]

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

Names of forces to consider for ZMP calculation

Names of forces used in calculations

◆ m_model

OpenSim::Model m_model
mutableprivate

Reference to the model.

Reference to the model being used.

◆ m_power_function

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

Function to compute power of ZMP deviation.

Function to compute power of values.


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