Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #include <acado_optimal_control.hpp>
00034 #include <acado_gnuplot.hpp>
00035
00036
00037 #define NX 2
00038
00039
00040 USING_NAMESPACE_ACADO
00041
00042
00043 Expression model( const Expression &x, const Expression &u, const Expression &w ){
00044
00045 IntermediateState rhs(3);
00046
00047 rhs(0) = x(1);
00048 rhs(1) = -x(0) - (1.0-u*u)*x(1) + w;
00049 rhs(2) = x(0)*x(0) + u*u;
00050
00051
00052 return rhs;
00053 }
00054
00055 int main( ){
00056
00057
00058
00059 DifferentialState x1(3);
00060 Control u(1) ;
00061 Parameter ww ;
00062 DifferentialEquation f ;
00063
00064 IntermediateState rhs1(3);
00065 rhs1 = model( x1, u, ww );
00066
00067 f << dot(x1(0)) == rhs1(0);
00068 f << dot(x1(1)) == rhs1(1);
00069 f << dot(x1(2)) == rhs1(2);
00070
00071 DifferentialState P(3,3);
00072 IntermediateState A = forwardDerivative( rhs1, x1 );
00073 IntermediateState B = forwardDerivative( rhs1, ww );
00074
00075
00076
00077 f << dot(P) == Lyapunov(rhs1,A,B,P,x1,u,ww);
00078
00079
00080
00081
00082
00083 OCP ocp( 0.0, 2.0*M_PI, 20 );
00084 ocp.minimizeMayerTerm( x1(2) );
00085
00086
00087
00088 ocp.subjectTo( f );
00089
00090 ocp.subjectTo( AT_START, x1(0) == 0.0 );
00091 ocp.subjectTo( AT_START, x1(1) == 1.0 );
00092 ocp.subjectTo( AT_START, x1(2) == 0.0 );
00093 ocp.subjectTo( AT_START, ww == 0.0 );
00094 ocp.subjectTo( AT_START, P == 0.0 );
00095
00096 ocp.subjectTo( x1(0) <= 0.6 );
00097
00098 OptimizationAlgorithm algorithm(ocp);
00099 algorithm.set ( INTEGRATOR_TYPE , INT_LYAPUNOV45 );
00100 algorithm.set (DYNAMIC_SENSITIVITY, FORWARD_SENSITIVITY);
00101
00102
00103
00104 GnuplotWindow window;
00105 window.addSubplot( x1(0),"state x(0)" );
00106 window.addSubplot( x1(1),"state x(1)" );
00107 window.addSubplot( P(0),"Lyapunov matrix P(0)" );
00108 window.addSubplot( P(1),"Lyapunov matrix P(1)" );
00109 window.addSubplot( P(2),"Lyapunov matrix P(2)" );
00110 window.addSubplot( P(3),"Lyapunov matrix P(3)" );
00111
00112 window.addSubplot( u ,"Control u" );
00113
00114 algorithm << window;
00115
00116 algorithm.initializeControls("controls1.txt");
00117 algorithm.initializeDifferentialStates("states1.txt");
00118 algorithm.set( KKT_TOLERANCE, 1e-10 );
00119 algorithm.solve();
00120
00121 algorithm.getDifferentialStates("states2.txt" );
00122 algorithm.getControls ("controls2.txt" );
00123
00124 return 0;
00125 }
00126
00127
00128