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

Goal that minimizes muscle strain during motion. More...

#include <MocoMuscleStrainGoal.h>

Inheritance diagram for MocoMuscleStrainGoal:

Public Member Functions

void setExponent (int ex)
 Set the exponent for the strain 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.
 
Constructors
 MocoMuscleStrainGoal ()
 Default constructor.
 
 MocoMuscleStrainGoal (std::string name)
 Constructor with name.
 
 MocoMuscleStrainGoal (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 (MocoMuscleStrainGoal, 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::vector< std::string > m_force_names
 
std::function< double(const double &)> m_power_function
 Function to compute power of values.
 
std::vector< int > m_act_indices
 Indices of muscle activation states.
 
std::vector< double > m_Fiso
 Maximum isometric forces for each muscle.
 
std::vector< double > m_Lopt
 Optimal fiber lengths for each muscle.
 
std::vector< double > m_Vol
 Muscle volumes.
 

Detailed Description

Goal that minimizes muscle strain during motion.

This goal minimizes the strain experienced by muscles during the motion, integrated over the phase. The strain is computed based on the muscle's current length relative to its optimal fiber length.

The goal accounts for:

  • Muscle fiber lengths
  • Optimal fiber lengths
  • Muscle volumes
  • Maximum isometric forces

This goal can be useful for:

  • Preventing excessive muscle stretching
  • Reducing risk of muscle injury
  • Generating more physiologically realistic motions
  • Maintaining muscle lengths within normal operating ranges

The strain values can be raised to a specified power using the exponent property, and 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

◆ MocoMuscleStrainGoal() [1/3]

Default constructor.

◆ MocoMuscleStrainGoal() [2/3]

MocoMuscleStrainGoal ( std::string name)
inline

Constructor with name.

Parameters
nameThe name of the goal

◆ MocoMuscleStrainGoal() [3/3]

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

◆ 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

◆ 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 ( MocoMuscleStrainGoal ,
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 strain terms.

Parameters
exThe exponent value

Member Data Documentation

◆ m_act_indices

std::vector<int> m_act_indices
mutableprivate

Indices of muscle activation states.

◆ m_Fiso

std::vector<double> m_Fiso
mutableprivate

Maximum isometric forces for each muscle.

◆ m_force_names

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

Names of forces used in calculations

◆ m_Lopt

std::vector<double> m_Lopt
mutableprivate

Optimal fiber lengths for each muscle.

◆ m_power_function

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

Function to compute power of values.

◆ m_Vol

std::vector<double> m_Vol
mutableprivate

Muscle volumes.


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