interfaces/matlab/examples/mexfiles/simple_ocp.cpp
Go to the documentation of this file.
1 
35 #include <acado_toolkit.hpp> // Include the ACADO toolkit
36 #include <acado/utils/matlab_acado_utils.hpp> // Include specific Matlab utils
37 
38 USING_NAMESPACE_ACADO // Open the namespace
39 
40 void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) // Start the MEX function. Do NOT change the header of this function.
41  {
42  clearAllStaticCounters( ); // Clear software counters
43 
44 
45 
46  DifferentialState s,v,m ; // the differential states
47  Control u ; // the control input u
48  Parameter T ; // the time horizon T
49  DifferentialEquation f( 0.0, T ); // the differential equation
50 
51 // -------------------------------------
52  OCP ocp( 0.0, T ); // time horizon of the OCP: [0,T]
53  ocp.minimizeMayerTerm( T ); // the time T should be optimized
54 
55  f << dot(s) == v; // an implementation
56  f << dot(v) == (u-0.2*v*v)/m; // of the model equations
57  f << dot(m) == -0.01*u*u; // for the rocket.
58 
59  ocp.subjectTo( f ); // minimize T s.t. the model,
60  ocp.subjectTo( AT_START, s == 0.0 ); // the initial values for s,
61  ocp.subjectTo( AT_START, v == 0.0 ); // v,
62  ocp.subjectTo( AT_START, m == 1.0 ); // and m,
63 
64  ocp.subjectTo( AT_END , s == 10.0 ); // the terminal constraints for s
65  ocp.subjectTo( AT_END , v == 0.0 ); // and v,
66 
67  ocp.subjectTo( -0.1 <= v <= 1.7 ); // as well as the bounds on v
68  ocp.subjectTo( -1.1 <= u <= 1.1 ); // the control input u,
69  ocp.subjectTo( 5.0 <= T <= 15.0 ); // and the time horizon T.
70 // -------------------------------------
71 
72  OptimizationAlgorithm algorithm(ocp); // the optimization algorithm
73  algorithm.solve(); // solves the problem.
74 
75 
76  // ...AND PLOT THE RESULTS
77  // ----------------------------------------------------------
78  VariablesGrid states_out;
79  algorithm.getDifferentialStates ( states_out );
80  acadoPlot(states_out);
81 
82  VariablesGrid controls_out;
83  algorithm.getControls ( controls_out );
84  acadoPlot(controls_out);
85 
86 
87  clearAllStaticCounters( ); // Clear software counters
88 }
89 
void acadoPlot(VariablesGrid grid)
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
returnValue getControls(VariablesGrid &p_) const
returnValue clearAllStaticCounters()
USING_NAMESPACE_ACADO void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
virtual returnValue solve()
returnValue getDifferentialStates(VariablesGrid &xd_) const
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:04