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

This goal minimizes the distance between the body's center of mass projection and the center of the base of support defined by the foot frames. More...

#include <MocoBOSGoal.h>

Inheritance diagram for MocoBOSGoal:

Public Member Functions

 MocoBOSGoal ()
 Default constructor.
 
 MocoBOSGoal (std::string name)
 Constructor with name.
 
 MocoBOSGoal (std::string name, double weight)
 Constructor with name and weight.
 
void setExponent (int ex)
 Set the exponent applied to the distance measure.
 
bool getExponent () const
 Get the current exponent value.
 
void setLeftFootFrame (std::string left_foot)
 Set the frame associated with the left foot.
 
std::string getLeftFootFrame () const
 Get the name of the left foot frame.
 
void setRightFootFrame (std::string right_foot)
 Set the frame associated with the right foot.
 
std::string getRightFootFrame () const
 Get the name of the right foot frame.
 
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.
 
void setLeftFootFrame (std::string left_foot)
 Set the body frame for the left foot.
 
std::string getLeftFootFrame () const
 Get the name of the left foot frame.
 
void setRightFootFrame (std::string right_foot)
 Set the body frame for the right foot.
 
std::string getRightFootFrame () const
 Get the name of the right foot frame.
 
Constructors
 MocoBOSGoal ()
 Default constructor.
 
 MocoBOSGoal (std::string name)
 Constructor with name.
 
 MocoBOSGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

SimTK::Vec3 avg (const SimTK::Vec3 &a, const SimTK::Vec3 &b) const
 Calculate the average of two 3D vectors.
 
SimTK::Matrix FlattenSpatialVec (const SimTK::SpatialVec &S) const
 Convert a spatial vector to a matrix representation.
 
Required implementations of virtual methods
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
 
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::Vec3 avg (const SimTK::Vec3 &a, const SimTK::Vec3 &b) const
 Calculate the average of two 3D vectors.
 
SimTK::Matrix FlattenSpatialVec (const SimTK::SpatialVec &S) const
 Convert a spatial vector to a matrix representation.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoBOSGoal, MocoGoal)
 
 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 (left_foot_frame, std::string, "The model frame associated with the left foot.")
 
 OpenSim_DECLARE_PROPERTY (right_foot_frame, std::string, "The model frame associated with the right foot.")
 
void constructProperties ()
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoBOSGoal, 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.")
 
 OpenSim_DECLARE_PROPERTY (left_foot_frame, std::string, "The model frame associated with the left foot.")
 
 OpenSim_DECLARE_PROPERTY (right_foot_frame, std::string, "The model frame associated with the right foot.")
 

Private Attributes

Internal working variables
std::vector< std::string > m_force_names
 
SimTK::ReferencePtr< const Body > m_left_foot_frame
 Reference to the left foot frame.
 
SimTK::ReferencePtr< const Body > m_right_foot_frame
 Reference to the right foot frame.
 
std::function< double(const double &)> m_power_function
 Function to compute power of values.
 

Detailed Description

This goal minimizes the distance between the body's center of mass projection and the center of the base of support defined by the foot frames.

Goal that minimizes the deviation of the base of support (BOS) from a target.

The goal helps maintain balance during movement optimization.

The base of support is calculated using the specified left and right foot frames. The goal can be weighted and the distance measure can be modified using an exponent parameter.

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

This goal can be useful for:

  • Improving balance and stability in walking simulations
  • Controlling foot placement and weight transfer
  • Minimizing risk of falls

The goal requires specification of frames for both feet to properly calculate the base of support. 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

◆ MocoBOSGoal() [1/6]

MocoBOSGoal ( )
inline

Default constructor.

◆ MocoBOSGoal() [2/6]

MocoBOSGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoBOSGoal() [3/6]

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

◆ MocoBOSGoal() [4/6]

MocoBOSGoal ( )
inline

Default constructor.

◆ MocoBOSGoal() [5/6]

MocoBOSGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoBOSGoal() [6/6]

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

◆ avg() [1/2]

SimTK::Vec3 avg ( const SimTK::Vec3 & a,
const SimTK::Vec3 & b ) const
protected

Calculate the average of two 3D vectors.

Parameters
aFirst vector
bSecond vector
Returns
Average vector
Here is the caller graph for this function:

◆ avg() [2/2]

SimTK::Vec3 avg ( const SimTK::Vec3 & a,
const SimTK::Vec3 & b ) const
protected

Calculate the average of two 3D vectors.

Parameters
aFirst vector
bSecond vector
Returns
Average vector

◆ calcGoalImpl() [1/2]

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

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

◆ 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

◆ constructProperties() [2/2]

void constructProperties ( )
private

Initialize the goal's properties.

◆ FlattenSpatialVec() [1/2]

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

◆ FlattenSpatialVec() [2/2]

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

◆ 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 distance measure

◆ getExponent() [2/2]

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent value

◆ getLeftFootFrame() [1/2]

std::string getLeftFootFrame ( ) const
inline

Get the name of the left foot frame.

Returns
Name of the left foot frame

◆ getLeftFootFrame() [2/2]

std::string getLeftFootFrame ( ) const
inline

Get the name of the left foot frame.

Returns
Name of the left foot frame

◆ getRightFootFrame() [1/2]

std::string getRightFootFrame ( ) const
inline

Get the name of the right foot frame.

Returns
Name of the right foot frame

◆ getRightFootFrame() [2/2]

std::string getRightFootFrame ( ) const
inline

Get the name of the right foot frame.

Returns
Name of the right foot frame

◆ getSupportsEndpointConstraintImpl() [1/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

◆ getSupportsEndpointConstraintImpl() [2/2]

bool getSupportsEndpointConstraintImpl ( ) const
inlineoverrideprotected

Whether this goal supports endpoint constraint mode.

◆ initializeOnModelImpl() [1/2]

void initializeOnModelImpl ( const Model & model) const
overrideprotected

◆ 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 ( MocoBOSGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoBOSGoal ,
MocoGoal  )
private

◆ OpenSim_DECLARE_PROPERTY() [1/7]

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

◆ OpenSim_DECLARE_PROPERTY() [2/7]

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/7]

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

OpenSim_DECLARE_PROPERTY ( left_foot_frame ,
std::string ,
"The model frame associated with the left foot."  )
private

◆ OpenSim_DECLARE_PROPERTY() [5/7]

OpenSim_DECLARE_PROPERTY ( left_foot_frame ,
std::string ,
"The model frame associated with the left foot."  )
private

◆ OpenSim_DECLARE_PROPERTY() [6/7]

OpenSim_DECLARE_PROPERTY ( right_foot_frame ,
std::string ,
"The model frame associated with the right foot."  )
private

◆ OpenSim_DECLARE_PROPERTY() [7/7]

OpenSim_DECLARE_PROPERTY ( right_foot_frame ,
std::string ,
"The model frame associated with the right foot."  )
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 applied to the distance measure.

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

◆ setLeftFootFrame() [1/2]

void setLeftFootFrame ( std::string left_foot)
inline

Set the frame associated with the left foot.

Parameters
left_footName of the left foot frame in the model

◆ setLeftFootFrame() [2/2]

void setLeftFootFrame ( std::string left_foot)
inline

Set the body frame for the left foot.

Parameters
left_footName of the left foot frame

◆ setRightFootFrame() [1/2]

void setRightFootFrame ( std::string right_foot)
inline

Set the frame associated with the right foot.

Parameters
right_footName of the right foot frame in the model

◆ setRightFootFrame() [2/2]

void setRightFootFrame ( std::string right_foot)
inline

Set the body frame for the right foot.

Parameters
right_footName of the right foot frame

Member Data Documentation

◆ m_force_names

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

Names of forces used in calculations

◆ m_left_foot_frame

SimTK::ReferencePtr< const Body > m_left_foot_frame
mutableprivate

Reference to the left foot frame.

◆ m_power_function

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

Function to compute power of values.

◆ m_right_foot_frame

SimTK::ReferencePtr< const Body > m_right_foot_frame
mutableprivate

Reference to the right foot frame.


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