OpenSim Moco
0.4.0
|
This goal enforces equality between initial and final variable values in the optimal control problem.
The initial and final values can belong to separate continuous variables or the same continuous variable, as long as they are the same type of variable (e.g., state or control). Value pairs are specified via a MocoPeriodicityGoalPair, where the initial variable of the pair indicates the initial state/control variable and the final variable indicates the final state/control variable. Set the initial and final variables to the same variable to enforce periodicity on a single continuous variable. Only state and control continuous variable pairs are supported, and are specified via the 'state_pairs' and 'control_pairs' properties.
To handle initial and final variable values that are equal in absolute value but differ in sign (e.g. a pelvis rotation in walking), use addNegatedStatePair or addNegatedControlPair.
To impose bilateral symmetry in a walking simulation, we can simulate over half a gait cycle and impose periodic constraints. For bilateral variables (e.g., hip flexion speeds and hamstrings controls), the constraints should enforce that right and left values, and inversely, should be the same at the beginning and half of the gait cycle, respectively. For the other variables (e.g., pelvis tilt values), the constraints should enforce that the values should be the same at the beginning and half of the gait cycle. The example code below illustrates how to enforce the aforementioned constraints with different constructors.
Periodic contraint for the pelvis tilt values:
Periodic contraints for the hip flexion speeds:
Periodic contraints for the hamstrings controls:
This is an endpoint constraint goal by default.
#include <Moco/Moco/MocoGoal/MocoPeriodicityGoal.h>
Public Member Functions | |
MocoPeriodicityGoal (std::string name) | |
void | addStatePair (MocoPeriodicityGoalPair pair) |
void | addNegatedStatePair (MocoPeriodicityGoalPair pair) |
void | addControlPair (MocoPeriodicityGoalPair pair) |
void | addNegatedControlPair (MocoPeriodicityGoalPair pair) |
Public Member Functions inherited from OpenSim::MocoGoal | |
MocoGoal (std::string name) | |
MocoGoal (std::string name, double weight) | |
void | setEnabled (bool enabled) |
Set whether this goal is used in the problem. | |
bool | getEnabled () const |
void | setWeight (double weight) |
In cost mode, the goal is multiplied by this weight. More... | |
double | getWeight () const |
void | setMode (std::string mode) |
Set the mode property to either 'cost' or 'endpoint_constraint'. More... | |
std::string | getModeAsString () const |
This returns the default mode of the goal, unless the user overrode the default using setMode(). More... | |
Mode | getMode () const |
bool | getModeIsCost () const |
bool | getModeIsEndpointConstraint () const |
Mode | getDefaultMode () const |
Types of goals have a class-level default for whether they are enforced as a cost or endpoint constraint. More... | |
bool | getSupportsEndpointConstraint () const |
Can this constraint be used in endpoint constraint mode? | |
const MocoConstraintInfo & | getConstraintInfo () const |
Get bounds for the constraints when using this goal in endpoint constraint mode. More... | |
MocoConstraintInfo & | updConstraintInfo () |
int | getNumOutputs () const |
Get the length of the return value of calcGoal(). | |
int | getNumIntegrals () const |
Get the number of integrals required by this cost. More... | |
SimTK::Real | calcIntegrand (const SimTK::State &state) const |
Calculate the integrand that should be integrated and passed to calcCost(). More... | |
void | calcGoal (const GoalInput &input, SimTK::Vector &goal) const |
In cost mode, the returned cost includes the weight, and the elements of the returned vector should be summed by the caller to obtain the total cost. More... | |
void | initializeOnModel (const Model &model) const |
For use by solvers. This also performs error checks on the Problem. | |
void | printDescription (std::ostream &stream=std::cout) const |
Print the name type and mode of this goal. More... | |
Protected Member Functions | |
bool | getSupportsEndpointConstraintImpl () const override |
Mode | getDefaultModeImpl () const override |
void | initializeOnModelImpl (const Model &model) const override |
Perform any caching before the problem is solved. More... | |
void | calcGoalImpl (const GoalInput &input, SimTK::Vector &goal) const override |
The Lagrange multipliers for kinematic constraints are not available. | |
void | printDescriptionImpl (std::ostream &stream=std::cout) const override |
Print a more detailed description unique to each goal. | |
Protected Member Functions inherited from OpenSim::MocoGoal | |
void | setNumIntegralsAndOutputs (int numIntegrals, int numOutputs) const |
Set the number of integral terms required by this goal and the length of the vector passed into calcGoalImpl(). More... | |
virtual void | calcIntegrandImpl (const SimTK::State &state, double &integrand) const |
const Model & | getModel () const |
For use within virtual function implementations. | |
double | calcSystemDisplacement (const SimTK::State &initial, const SimTK::State &final) const |
Additional Inherited Members | |
Public Types inherited from OpenSim::MocoGoal | |
enum | Mode { Cost, EndpointConstraint } |
|
overrideprotectedvirtual |
Perform any caching before the problem is solved.
You must override this function and invoke setNumIntegralsAndOutputs().
Implements OpenSim::MocoGoal.