OpenSim Moco
0.4.0
|
The top-level class for solving a custom optimal control problem.
This class consists of a MocoProblem, which describes the optimal control problem, and a MocoSolver, which describes the numerical method for solving the problem.
When building a MocoStudy programmatically (e.g., in C++), the workflow is as follows:
After calling solve(), you can edit the MocoProblem and/or the MocoSolver. You can then call solve() again, if you wish.
You can save the MocoStudy to a file by calling MocoStudy::print(), and you can load the setup using MocoStudy(const std::string& omocoFile). MocoStudy setup files have a .omoco
extension.
The default solver uses the tropter direct collocation library. We also provide the CasADi solver, which depends on the CasADi automatic differentiation and optimization library. If you want to use CasADi programmatically, call initCasADiSolver() before solve(). We would like to support users plugging in their own solvers, but there is no timeline for this. If you require additional features or enhancements to the solver, please consider contributing to tropter.
#include <Moco/Moco/MocoStudy.h>
Public Member Functions | |
OpenSim_DECLARE_PROPERTY (write_solution, std::string, "Provide the folder path (relative to working directory) to which " "the " "solution files should be written. Set to 'false' to not write the " "solution to disk.") | |
MocoStudy (const std::string &omocoFile) | |
Load a MocoStudy setup file. | |
const MocoProblem & | getProblem () const |
MocoProblem & | updProblem () |
If using this method in C++, make sure to include the "&" in the return type; otherwise, you'll make a copy of the problem, and the copy will have no effect on this MocoStudy. More... | |
MocoCasADiSolver & | initCasADiSolver () |
Call this method once you have finished setting up your MocoProblem. More... | |
MocoTropterSolver & | initTropterSolver () |
Call this method once you have finished setting up your MocoProblem. More... | |
MocoSolver & | updSolver () |
Access the solver. More... | |
MocoSolution | solve () const |
Solve the provided MocoProblem using the provided MocoSolver, and obtain the solution to the problem. More... | |
void | visualize (const MocoTrajectory &it) const |
Interactively visualize a trajectory using the simbody-visualizer. More... | |
TimeSeriesTable | analyze (const MocoTrajectory &it, std::vector< std::string > outputPaths) const |
Calculate the requested outputs using the model in the problem and the states and controls in the MocoTrajectory. More... | |
template<> | |
OSIMMOCO_API MocoTropterSolver & | initSolver () |
template<> | |
OSIMMOCO_API MocoCasADiSolver & | initSolver () |
Using other solvers | |
template<typename SolverType > | |
void | setCustomSolver () |
template<typename SolverType > | |
SolverType & | initSolver () |
template<typename SolverType > | |
SolverType & | updSolver () |
Protected Member Functions | |
OpenSim_DECLARE_PROPERTY (problem, MocoProblem, "The optimal control problem to solve.") | |
OpenSim_DECLARE_PROPERTY (solver, MocoSolver, "The optimal control algorithm for solving the problem.") | |
TimeSeriesTable OpenSim::MocoStudy::analyze | ( | const MocoTrajectory & | it, |
std::vector< std::string > | outputPaths | ||
) | const |
Calculate the requested outputs using the model in the problem and the states and controls in the MocoTrajectory.
The output paths can be regular expressions. For example, ".*activation" gives the activation of all muscles. Constraints are not enforced but prescribed motion (e.g., PositionMotion) is.
MocoCasADiSolver& OpenSim::MocoStudy::initCasADiSolver | ( | ) |
Call this method once you have finished setting up your MocoProblem.
This returns a reference to the MocoSolver, which you can then edit. If using this method in C++, make sure to include the "&" in the return type; otherwise, you'll make a copy of the solver, and the copy will have no effect on this MocoStudy. This deletes the previous solver if one exists.
|
inline |
MocoTropterSolver& OpenSim::MocoStudy::initTropterSolver | ( | ) |
Call this method once you have finished setting up your MocoProblem.
This returns a reference to the MocoSolver, which you can then edit. If using this method in C++, make sure to include the "&" in the return type; otherwise, you'll make a copy of the solver, and the copy will have no effect on this MocoStudy. This deletes the previous solver if one exists.
MocoSolution OpenSim::MocoStudy::solve | ( | ) | const |
Solve the provided MocoProblem using the provided MocoSolver, and obtain the solution to the problem.
If the write_solution property contains a file path (that is, it's not "false"), then the solution is also written to disk.
You must have finished setting up both the problem and solver.This reinitializes the solver so that any changes you have made will hold.
MocoProblem& OpenSim::MocoStudy::updProblem | ( | ) |
If using this method in C++, make sure to include the "&" in the return type; otherwise, you'll make a copy of the problem, and the copy will have no effect on this MocoStudy.
MocoSolver& OpenSim::MocoStudy::updSolver | ( | ) |
Access the solver.
Make sure to call initSolver()
beforehand. If using this method in C++, make sure to include the "&" in the return type; otherwise, you'll make a copy of the solver, and the copy will have no effect on this MocoStudy.
void OpenSim::MocoStudy::visualize | ( | const MocoTrajectory & | it | ) | const |
Interactively visualize a trajectory using the simbody-visualizer.
The trajectory could be an initial guess, a solution, etc.
The MocoProblem must contain the model corresponding to the provided trajectory.