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

This goal minimizes the acceleration of specified coordinates in the model. More...

#include <MocoCoordinateAccelerationGoal.h>

Inheritance diagram for MocoCoordinateAccelerationGoal:

Public Member Functions

 MocoCoordinateAccelerationGoal ()
 Default constructor.
 
 MocoCoordinateAccelerationGoal (std::string name)
 Constructor with name.
 
 MocoCoordinateAccelerationGoal (std::string name, double weight)
 Constructor with name and weight.
 
void setStateNames (const std::vector< std::string > refCoordNames)
 Set the names of coordinates whose accelerations should be minimized.
 
void setExponent (int ex)
 Set the exponent for the acceleration terms.
 
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 setStateNames (const std::vector< std::string > refCoordNames)
 Set the coordinates to track for acceleration minimization.
 
Constructors
 MocoCoordinateAccelerationGoal ()
 Default constructor.
 
 MocoCoordinateAccelerationGoal (std::string name)
 Constructor with name.
 
 MocoCoordinateAccelerationGoal (std::string name, double weight)
 Constructor with name and weight.
 

Protected Member Functions

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.
 

Private Member Functions

 OpenSim_DECLARE_CONCRETE_OBJECT (MocoCoordinateAccelerationGoal, 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.")
 
void constructProperties ()
 
 OpenSim_DECLARE_CONCRETE_OBJECT (MocoCoordinateAccelerationGoal, 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

Internal working variables
std::function< double(const double &)> m_power_function
 Function to compute power of acceleration values.
 
std::vector< int > m_sysYIndices
 System Y indices for all states.
 
std::vector< int > m_state_indices
 Indices of states we want to minimize acceleration for.
 
std::vector< std::string > m_state_names
 Names of states for which we want to minimize acceleration.
 

Detailed Description

This goal minimizes the acceleration of specified coordinates in the model.

Goal that minimizes the acceleration of specified coordinates.

The integrand is:

\[
\sum_i |\ddot{q}_i|^p
\]

where $ \ddot{q}_i $ are the coordinate accelerations and $ p $ is the exponent (default: 2).

This goal can be useful for:

  • Reducing rapid changes in movement
  • Smoothing motion trajectories
  • Minimizing jerk in the solution

This goal minimizes the acceleration of selected model coordinates, integrated over the phase. This can help produce smoother, more natural motions by penalizing rapid changes in coordinate velocities.

The goal can be applied to any subset of model coordinates by specifying their names. For each coordinate, the squared acceleration is computed and can be raised to a specified power.

This goal can be useful for:

  • Generating smoother motions
  • Reducing joint jerk
  • Minimizing rapid changes in movement
  • Improving numerical conditioning of the optimization

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

◆ MocoCoordinateAccelerationGoal() [1/6]

Default constructor.

◆ MocoCoordinateAccelerationGoal() [2/6]

MocoCoordinateAccelerationGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoCoordinateAccelerationGoal() [3/6]

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

◆ MocoCoordinateAccelerationGoal() [4/6]

Default constructor.

◆ MocoCoordinateAccelerationGoal() [5/6]

MocoCoordinateAccelerationGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoCoordinateAccelerationGoal() [6/6]

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

◆ 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

◆ 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.

◆ 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()

bool getExponent ( ) const
inline

Get the current exponent value.

Returns
The exponent value

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

◆ OpenSim_DECLARE_CONCRETE_OBJECT() [2/2]

OpenSim_DECLARE_CONCRETE_OBJECT ( MocoCoordinateAccelerationGoal ,
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()

void setExponent ( int ex)
inline

Set the exponent for the acceleration terms.

Parameters
exThe exponent value

◆ setStateNames() [1/2]

void setStateNames ( const std::vector< std::string > refCoordNames)
inline

Set the names of coordinates whose accelerations should be minimized.

Parameters
refCoordNamesVector of coordinate names. Each name should be a state variable path (e.g., '/jointset/knee_r/knee_angle_r')

◆ setStateNames() [2/2]

void setStateNames ( const std::vector< std::string > refCoordNames)
inline

Set the coordinates to track for acceleration minimization.

Parameters
refCoordNamesVector of coordinate names to track

The coordinate names should be state variable paths, e.g., '/jointset/knee_r/knee_angle_r'

Member Data Documentation

◆ m_power_function

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

Function to compute power of acceleration values.

Function to compute power of acceleration values

◆ m_state_indices

std::vector< int > m_state_indices
mutableprivate

Indices of states we want to minimize acceleration for.

Indices of states in the state vector.

◆ m_state_names

std::vector< std::string > m_state_names
mutableprivate

Names of states for which we want to minimize acceleration.

Names of coordinates to track.

◆ m_sysYIndices

std::vector< int > m_sysYIndices
mutableprivate

System Y indices for all states.

System Y indices for state derivatives


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