OpenSim Moco  0.4.0
Public Member Functions | Protected Member Functions | List of all members
OpenSim::MocoFrameDistanceConstraint Class Reference

Description

This path constraint enforces that the distance between the origins of pairs of model frames is kept between minimum and maximum bounds.

Frame pairs and their bounds are specified via a MocoFrameDistancConstraintPair. Any model component derived from Frame is valid to be included in a frame pair, and any number of frame pairs may be append to this constraint via addFramePair().

This constraint can be used as a simple method for preventing bodies in your model from intersecting during an optimization. For example, the following prevents feet from intersecting during a walking optimization:

distance = problem.addPathConstraint<MocoFrameDistanceConstraint>();
distance.setName("minimum_distance");
SimTK::Real inf = SimTK::Infinity;
distance.addFramePair('/bodyset/calcn_l', '/bodyset/calcn_r', 0.1, inf);
distance.addFramePair('/bodyset/toes_l', '/bodyset/toes_r', 0.1, inf);
distance.addFramePair('/bodyset/calcn_l', '/bodyset/toes_r', 0.1, inf);
distance.addFramePair('/bodyset/toes_l', '/bodyset/calcn_r', 0.1, inf);

To project the frame distance onto a vector or plane before ensuring its within the provided bounds, use setProjection() and setProjectionVector().

Note
This class represents a path constraint, not a model kinematic constraint. Therefore, there are no Lagrange multipliers or constraint forces associated with this constraint. The model's force elements (including actuators) must generate the forces necessary for satisfying this constraint.
Inheritance diagram for OpenSim::MocoFrameDistanceConstraint:
OpenSim::MocoPathConstraint

#include <Moco/Moco/MocoFrameDistanceConstraint.h>

Public Member Functions

void addFramePair (MocoFrameDistanceConstraintPair pair)
 
void addFramePair (const std::string &frame1_path, const std::string &frame2_path, double minimum_distance, double maximum_distance)
 
void setProjection (std::string projection)
 Set if each distance should be projected onto either a vector or plane. More...
 
std::string getProjection () const
 
void setProjectionVector (SimTK::Vec3 normal)
 Set the vector to use for projecting each distance. More...
 
void clearProjectionVector ()
 Unset the projection vector.
 
SimTK::Vec3 getProjectionVector () const
 
- Public Member Functions inherited from OpenSim::MocoPathConstraint
const MocoConstraintInfogetConstraintInfo () const
 
MocoConstraintInfoupdConstraintInfo ()
 
void setConstraintInfo (const MocoConstraintInfo &cInfo)
 
int getPathConstraintIndex () const
 For use by solvers. More...
 
void calcPathConstraintErrors (const SimTK::State &state, SimTK::Vector &errors) const
 Calculate errors in the path constraint equations. More...
 
void initializeOnModel (const Model &model, const MocoProblemInfo &, const int &pathConstraintIndex) const
 For use by solvers. This also performs error checks on the Problem.
 

Protected Member Functions

void initializeOnModelImpl (const Model &model, const MocoProblemInfo &) const override
 Perform any caching. More...
 
void calcPathConstraintErrorsImpl (const SimTK::State &state, SimTK::Vector &errors) const override
 
- Protected Member Functions inherited from OpenSim::MocoPathConstraint
 OpenSim_DECLARE_UNNAMED_PROPERTY (MocoConstraintInfo, "The bounds and " "labels for this MocoPathConstraint.")
 
void setNumEquations (int numEqs) const
 Set the number of scalar equations for this MocoPathConstraint. More...
 
const Model & getModel () const
 For use within virtual function implementations.
 

Member Function Documentation

◆ calcPathConstraintErrorsImpl()

void OpenSim::MocoFrameDistanceConstraint::calcPathConstraintErrorsImpl ( const SimTK::State &  state,
SimTK::Vector &  errors 
) const
overrideprotectedvirtual
Precondition(s):
The state is realized to SimTK::Stage::Position. If you need access to the controls, you must realize to Velocity:
getModel().realizeVelocity(state);

Implements OpenSim::MocoPathConstraint.

◆ initializeOnModelImpl()

void OpenSim::MocoFrameDistanceConstraint::initializeOnModelImpl ( const Model &  ,
const MocoProblemInfo  
) const
overrideprotectedvirtual

Perform any caching.

The number of scalar constraint equations this MocoPathConstraint implements must be defined here (see setNumEquations() below).

Precondition(s):
The model is initialized (initSystem()) and getModel() is available. The passed-in model is equivalent to getModel(). Use this opportunity to check for errors in user input, in addition to the checks provided in initialize().

Implements OpenSim::MocoPathConstraint.

◆ setProjection()

void OpenSim::MocoFrameDistanceConstraint::setProjection ( std::string  projection)
inline

Set if each distance should be projected onto either a vector or plane.

Possible values: "none" (default), "vector", and "plane".

◆ setProjectionVector()

void OpenSim::MocoFrameDistanceConstraint::setProjectionVector ( SimTK::Vec3  normal)
inline

Set the vector to use for projecting each distance.

If the projection type is "vector", the distance is projected onto the vector provided here. If the projection type is "plane", the distance is projected onto the plane perpendicular to this vector.


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