simple_ocp.cpp
Go to the documentation of this file.
00001 
00035 #include <acado_toolkit.hpp>                    // Include the ACADO toolkit
00036 #include <acado/utils/matlab_acado_utils.hpp>   // Include specific Matlab utils
00037 
00038 USING_NAMESPACE_ACADO                           // Open the namespace
00039 
00040 void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )  // Start the MEX function. Do NOT change the header of this function.
00041  { 
00042     clearAllStaticCounters( );                  // Clear software counters
00043  
00044     
00045     
00046     DifferentialState        s,v,m      ;     // the differential states
00047     Control                  u          ;     // the control input u
00048     Parameter                T          ;     // the time horizon T
00049     DifferentialEquation     f( 0.0, T );     // the differential equation
00050 
00051 //  -------------------------------------
00052     OCP ocp( 0.0, T );                        // time horizon of the OCP: [0,T]
00053     ocp.minimizeMayerTerm( T );               // the time T should be optimized
00054 
00055     f << dot(s) == v;                         // an implementation
00056     f << dot(v) == (u-0.2*v*v)/m;             // of the model equations
00057     f << dot(m) == -0.01*u*u;                 // for the rocket.
00058 
00059     ocp.subjectTo( f                   );     // minimize T s.t. the model,
00060     ocp.subjectTo( AT_START, s ==  0.0 );     // the initial values for s,
00061     ocp.subjectTo( AT_START, v ==  0.0 );     // v,
00062     ocp.subjectTo( AT_START, m ==  1.0 );     // and m,
00063 
00064     ocp.subjectTo( AT_END  , s == 10.0 );     // the terminal constraints for s
00065     ocp.subjectTo( AT_END  , v ==  0.0 );     // and v,
00066 
00067     ocp.subjectTo( -0.1 <= v <=  1.7   );     // as well as the bounds on v
00068     ocp.subjectTo( -1.1 <= u <=  1.1   );     // the control input u,
00069     ocp.subjectTo(  5.0 <= T <= 15.0   );     // and the time horizon T.
00070 //  -------------------------------------
00071     
00072     OptimizationAlgorithm algorithm(ocp);     // the optimization algorithm
00073     algorithm.solve();                        // solves the problem.
00074 
00075     
00076     // ...AND PLOT THE RESULTS
00077     // ----------------------------------------------------------
00078         VariablesGrid states_out;
00079         algorithm.getDifferentialStates ( states_out );
00080     acadoPlot(states_out);
00081     
00082         VariablesGrid controls_out;
00083         algorithm.getControls ( controls_out );
00084     acadoPlot(controls_out);
00085 
00086           
00087     clearAllStaticCounters( );                  // Clear software counters
00088 } 
00089 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:00