API
4.2
For MATLAB, Python, Java, and C++ users
|
The primary intent of this class is for use by MocoSolvers, but users can also use this class to apply parameter values to the model and evaluate cost terms. More...
Public Member Functions | |
MocoProblemRep ()=default | |
MocoProblemRep (const MocoProblemRep &)=delete | |
MocoProblemRep & | operator= (const MocoProblemRep &)=delete |
MocoProblemRep (MocoProblemRep &&source) | |
MocoProblemRep & | operator= (MocoProblemRep &&source) |
const std::string & | getName () const |
const Model & | getModelBase () const |
Get a reference to the copy of the model being used by this MocoProblemRep. More... | |
SimTK::State & | updStateBase () const |
This is a state object that solvers can use along with ModelBase. More... | |
const DiscreteController & | getDiscreteControllerBase () const |
This is a component inside ModelBase that you can use to set the value of control signals. More... | |
const Model & | getModelDisabledConstraints () const |
Get a reference to a copy of the model being used by this MocoProblemRep, but with all constraints disabled and an additional DiscreteForces component. More... | |
SimTK::State & | updStateDisabledConstraints (int index=0) const |
This is a state object that solvers can use with ModelDisabledConstraints. More... | |
const DiscreteController & | getDiscreteControllerDisabledConstraints () const |
This is a component inside ModelDisabledConstraints that you can use to set the value of control signals. More... | |
const DiscreteForces & | getConstraintForces () const |
This is a component inside ModelDisabledConstraints that you can use to set the value of discrete forces, intended to hold the constraint forces obtained from ModelBase. More... | |
const AccelerationMotion & | getAccelerationMotion () const |
This is a component inside ModelDisabledConstraints that you can use to set the value of generalized accelerations UDot, for use in implicit dynamics formulations. More... | |
int | getNumStates () const |
int | getNumControls () const |
int | getNumParameters () const |
int | getNumCosts () const |
Get the number of goals in cost mode. More... | |
int | getNumEndpointConstraints () const |
Get the number of goals in endpoint constraint mode. More... | |
int | getNumKinematicConstraints () const |
bool | isPrescribedKinematics () const |
Does the model contain a PositionMotion to prescribe all generalized coordinates, speeds, and accelerations? More... | |
int | getNumImplicitAuxiliaryResiduals () const |
std::vector< std::string > | createStateVariableNamesInSystemOrder (std::unordered_map< int, int > &yIndexMap) const |
This excludes generalized coordinate and speed states if isPrescribedKinematics() is true. More... | |
std::vector< std::string > | createStateInfoNames () const |
Get the state names of all the state infos. More... | |
std::vector< std::string > | createControlInfoNames () const |
Get the control names of all the control infos. More... | |
std::vector< std::string > | createParameterNames () const |
Get the names of all the parameters. More... | |
std::vector< std::string > | createCostNames () const |
Get the names of all the goals in cost mode. More... | |
std::vector< std::string > | createEndpointConstraintNames () const |
Get the names of all the goals in endpoint constraint mode. More... | |
std::vector< std::string > | createPathConstraintNames () const |
Get the names of all the MocoPathConstraints. More... | |
std::vector< std::string > | createMultiplierInfoNames () const |
Get the names of all the Lagrange multiplier infos. More... | |
std::vector< std::string > | createKinematicConstraintNames () const |
Get the constraint names of all the kinematic constraints. More... | |
std::vector< std::string > | getKinematicConstraintEquationNames (bool includeDerivatives) const |
Get a vector of names for all kinematic constraint equations. More... | |
MocoInitialBounds | getTimeInitialBounds () const |
MocoFinalBounds | getTimeFinalBounds () const |
const MocoVariableInfo & | getStateInfo (const std::string &name) const |
Get information for state variables. See MocoPhase::setStateInfo(). More... | |
const MocoVariableInfo & | getControlInfo (const std::string &name) const |
Get information for actuator controls. More... | |
const MocoParameter & | getParameter (const std::string &name) const |
const MocoGoal & | getCost (const std::string &name) const |
Get a cost by name. This returns a MocoGoal in cost mode. More... | |
const MocoGoal & | getCostByIndex (int index) const |
Get a cost by index. More... | |
const MocoGoal & | getEndpointConstraint (const std::string &name) const |
Get an endpoint constraint by name. More... | |
const MocoGoal & | getEndpointConstraintByIndex (int index) const |
Get an endpoint constraint by index. More... | |
const MocoPathConstraint & | getPathConstraint (const std::string &name) const |
Get a MocoPathConstraint. More... | |
const MocoPathConstraint & | getPathConstraintByIndex (int index) const |
Get a path constraint by index. More... | |
int | getNumPathConstraintEquations () const |
Get the number of scalar path constraints in the MocoProblem. More... | |
const std::vector< MocoVariableInfo > & | getMultiplierInfos (const std::string &kinematicConstraintInfoName) const |
Given a kinematic constraint name, get a vector of MocoVariableInfos corresponding to the Lagrange multipliers for that kinematic constraint. More... | |
const MocoKinematicConstraint & | getKinematicConstraint (const std::string &name) const |
Get a MocoKinematicConstraint from this MocoPhase. More... | |
int | getNumKinematicConstraintEquations () const |
Get the number of scalar kinematic constraints in the MocoProblem. More... | |
void | printDescription () const |
Print a description of this problem, including costs and variable bounds. More... | |
Interface for solvers | |
These functions are for use by MocoSolvers, but can also be called by users for debugging. Calculate the errors in all the scalar path constraint equations in this phase. | |
void | calcPathConstraintErrors (const SimTK::State &state, SimTK::Vector &errors) const |
SimTK::Vector | calcKinematicConstraintErrors (const SimTK::State &state) const |
Calculate the errors in all the scalar kinematic constraint equations in this phase. More... | |
void | applyParametersToModelProperties (const SimTK::Vector ¶meterValues, bool initSystemAndDisableConstraints=false) const |
Apply paramater values to the models created from the model passed to initialize() within the current MocoProblem. More... | |
const std::vector< SimTK::ReferencePtr< const Output< double > > > & | getImplicitResidualReferencePtrs () const |
Get a vector of reference pointers to model outputs that return residual values for any components with dynamics in implicit forms. More... | |
const std::vector< std::pair< std::string, SimTK::ReferencePtr< const Component > > > & | getImplicitComponentReferencePtrs () const |
Get reference pointers to components that enforce dynamics in implicit form. More... | |
The primary intent of this class is for use by MocoSolvers, but users can also use this class to apply parameter values to the model and evaluate cost terms.
This class also checks the MocoProblem for various errors. To get an instance of this class, use MocoProblem::createRep(). This interface currently supports only single-phase problems. This class stores a reference (not a copy) to the original MocoProblem from which it was created.
|
default |
|
delete |
|
inline |
void OpenSim::MocoProblemRep::applyParametersToModelProperties | ( | const SimTK::Vector & | parameterValues, |
bool | initSystemAndDisableConstraints = false |
||
) | const |
Apply paramater values to the models created from the model passed to initialize() within the current MocoProblem.
Values must be consistent with the order of parameters returned from createParameterNames().
Note: initSystem() must be called on each model after calls to this method in order for provided parameter values to be applied to the model. You can pass true
to have initSystem() called for you, and to also re-disable any constraints re-enabled by the initSystem() call (see getModelDisabledConstraints()).
|
inline |
Calculate the errors in all the scalar kinematic constraint equations in this phase.
This may not be the most efficient solution for solvers, but is rather intended as a convenience method for a quick implementation or for debugging model constraints causing issues in an optimal control problem.
|
inline |
std::vector<std::string> OpenSim::MocoProblemRep::createControlInfoNames | ( | ) | const |
Get the control names of all the control infos.
std::vector<std::string> OpenSim::MocoProblemRep::createCostNames | ( | ) | const |
Get the names of all the goals in cost mode.
std::vector<std::string> OpenSim::MocoProblemRep::createEndpointConstraintNames | ( | ) | const |
Get the names of all the goals in endpoint constraint mode.
std::vector<std::string> OpenSim::MocoProblemRep::createKinematicConstraintNames | ( | ) | const |
Get the constraint names of all the kinematic constraints.
Note: this should only be called after initialize().
std::vector<std::string> OpenSim::MocoProblemRep::createMultiplierInfoNames | ( | ) | const |
Get the names of all the Lagrange multiplier infos.
std::vector<std::string> OpenSim::MocoProblemRep::createParameterNames | ( | ) | const |
Get the names of all the parameters.
std::vector<std::string> OpenSim::MocoProblemRep::createPathConstraintNames | ( | ) | const |
Get the names of all the MocoPathConstraints.
std::vector<std::string> OpenSim::MocoProblemRep::createStateInfoNames | ( | ) | const |
Get the state names of all the state infos.
std::vector<std::string> OpenSim::MocoProblemRep::createStateVariableNamesInSystemOrder | ( | std::unordered_map< int, int > & | yIndexMap | ) | const |
This excludes generalized coordinate and speed states if isPrescribedKinematics() is true.
|
inline |
This is a component inside ModelDisabledConstraints that you can use to set the value of generalized accelerations UDot, for use in implicit dynamics formulations.
The motion is not necessarily enabled.
|
inline |
This is a component inside ModelDisabledConstraints that you can use to set the value of discrete forces, intended to hold the constraint forces obtained from ModelBase.
const MocoVariableInfo& OpenSim::MocoProblemRep::getControlInfo | ( | const std::string & | name | ) | const |
Get information for actuator controls.
If the control is associated with a non-scalar actuator (i.e. uses multiple control variables), then the control name will be the actuator path appended by the control index (e.g. "/actuator_0"); See MocoPhase::setControlInfo().
const MocoGoal& OpenSim::MocoProblemRep::getCost | ( | const std::string & | name | ) | const |
Get a cost by name. This returns a MocoGoal in cost mode.
const MocoGoal& OpenSim::MocoProblemRep::getCostByIndex | ( | int | index | ) | const |
Get a cost by index.
The order is the same as in getCostNames(). Note: this does not perform a bounds check.
|
inline |
This is a component inside ModelBase that you can use to set the value of control signals.
|
inline |
This is a component inside ModelDisabledConstraints that you can use to set the value of control signals.
const MocoGoal& OpenSim::MocoProblemRep::getEndpointConstraint | ( | const std::string & | name | ) | const |
Get an endpoint constraint by name.
This returns a MocoGoal in endpoint constraint mode.
const MocoGoal& OpenSim::MocoProblemRep::getEndpointConstraintByIndex | ( | int | index | ) | const |
Get an endpoint constraint by index.
The order is the same as in getEndpointConstraintNames(). Note: this does not perform a bounds check.
|
inline |
Get reference pointers to components that enforce dynamics in implicit form.
This returns a vector of pairs including the name of the discrete derivative variable and the component reference pointer.
|
inline |
Get a vector of reference pointers to model outputs that return residual values for any components with dynamics in implicit forms.
The references returned are from the model returned by getModelDisabledConstraints().
const MocoKinematicConstraint& OpenSim::MocoProblemRep::getKinematicConstraint | ( | const std::string & | name | ) | const |
Get a MocoKinematicConstraint from this MocoPhase.
Note: this does not include MocoPathConstraints, use getPathConstraint() instead.
std::vector<std::string> OpenSim::MocoProblemRep::getKinematicConstraintEquationNames | ( | bool | includeDerivatives | ) | const |
Get a vector of names for all kinematic constraint equations.
Kinematic constraint equations are ordered as so:
|
inline |
Get a reference to the copy of the model being used by this MocoProblemRep.
This model is obtained by processing the ModelProcessor the user gives to MocoProblem. This model is not the model given to MocoGoal or MocoPathConstraint, but can be used within solvers to compute constraint forces and constraint errors (see getModelDisabledConstraints() for more details). Any parameter updates via a MocoParameter added to the problem will be applied to this model.
|
inline |
Get a reference to a copy of the model being used by this MocoProblemRep, but with all constraints disabled and an additional DiscreteForces component.
This new component can be used to apply constraint forces computed from the base model to this model, which updates the discrete variables in the state associated with these forces. You should use this model to compute accelerations via getModelDisabledConstraints().realizeAccleration(state), making sure to add any constraint forces to the model preceding the realization. This model is the same instance as that given to MocoGoal and MocoPathConstraint, ensuring that realizing to Stage::Acceleration in these classes produces the same accelerations computed by the solver. Any parameter updates via a MocoParameter added to the problem will be applied to this model.
const std::vector<MocoVariableInfo>& OpenSim::MocoProblemRep::getMultiplierInfos | ( | const std::string & | kinematicConstraintInfoName | ) | const |
Given a kinematic constraint name, get a vector of MocoVariableInfos corresponding to the Lagrange multipliers for that kinematic constraint.
const std::string& OpenSim::MocoProblemRep::getName | ( | ) | const |
|
inline |
|
inline |
Get the number of goals in cost mode.
|
inline |
Get the number of goals in endpoint constraint mode.
|
inline |
|
inline |
Get the number of scalar kinematic constraints in the MocoProblem.
This does not include path constraints equations.
|
inline |
|
inline |
|
inline |
Get the number of scalar path constraints in the MocoProblem.
This does not include kinematic constraints equations.
|
inline |
const MocoParameter& OpenSim::MocoProblemRep::getParameter | ( | const std::string & | name | ) | const |
const MocoPathConstraint& OpenSim::MocoProblemRep::getPathConstraint | ( | const std::string & | name | ) | const |
Get a MocoPathConstraint.
Note: this does not include MocoKinematicConstraints, use getKinematicConstraint() instead.
const MocoPathConstraint& OpenSim::MocoProblemRep::getPathConstraintByIndex | ( | int | index | ) | const |
Get a path constraint by index.
The order is the same as in getPathConstraintNames(). Note: this does not perform a bounds check.
const MocoVariableInfo& OpenSim::MocoProblemRep::getStateInfo | ( | const std::string & | name | ) | const |
Get information for state variables. See MocoPhase::setStateInfo().
MocoFinalBounds OpenSim::MocoProblemRep::getTimeFinalBounds | ( | ) | const |
Note: the return value is constructed fresh on every call from the internal property. Avoid repeated calls to this function.
MocoInitialBounds OpenSim::MocoProblemRep::getTimeInitialBounds | ( | ) | const |
Note: the return value is constructed fresh on every call from the internal property. Avoid repeated calls to this function.
|
inline |
Does the model contain a PositionMotion to prescribe all generalized coordinates, speeds, and accelerations?
|
delete |
|
inline |
void OpenSim::MocoProblemRep::printDescription | ( | ) | const |
Print a description of this problem, including costs and variable bounds.
Printing is done using OpenSim::log_cout().
|
inline |
This is a state object that solvers can use along with ModelBase.
|
inline |
This is a state object that solvers can use with ModelDisabledConstraints.
Some solvers may need to use 2 state objects at once; you can supply an index of 1 to get a second state object.