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
00034 #include <acado_optimal_control.hpp>
00035 #include <acado_gnuplot.hpp>
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #define NJ 1 // number of objective functions
00047 #define NX 4 // number of differential states
00048 #define NI 4 // number of initial value constraints
00049 #define NE 2 // number of end-point / terminal constraints
00050 #define NH 1 // number of inequality path constraints
00051
00052
00053
00054
00055
00056
00057
00058 void myDifferentialEquation( double *x, double *f, void *user_data ){
00059
00060 f[0] = x[0];
00061 f[1] = (x[2]-0.02*x[0]*x[0])/(1.0+x[1]);
00062 f[2] = -0.01*x[2]*x[2];
00063 f[3] = x[2]*x[2];
00064 }
00065
00066 void myObjectiveFunction( double *x, double *f, void *user_data ){
00067
00068 f[0] = x[3];
00069 }
00070
00071
00072 void myInitialValueConstraint( double *x, double *f, void *user_data ){
00073
00074 f[0] = x[4];
00075 f[1] = x[0];
00076 f[2] = x[1];
00077 f[3] = x[3];
00078 }
00079
00080
00081 void myEndPointConstraint( double *x, double *f, void *user_data ){
00082
00083 f[0] = x[4] - 10.0;
00084 f[1] = x[0];
00085 }
00086
00087
00088 void myInequalityPathConstraint( double *x, double *f, void *user_data ){
00089
00090 f[0] = x[0];
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 USING_NAMESPACE_ACADO
00100
00101
00102 int main( ){
00103
00104
00105
00106
00107 DifferentialState s,v,m,L;
00108 Control u ;
00109 DifferentialEquation f ;
00110
00111
00112
00113
00114 CFunction F( NX, myDifferentialEquation );
00115 CFunction M( NJ, myObjectiveFunction );
00116 CFunction I( NI, myInitialValueConstraint );
00117 CFunction E( NE, myEndPointConstraint );
00118 CFunction H( NH, myInequalityPathConstraint );
00119
00120
00121
00122
00123
00124 IntermediateState x(5);
00125
00126 x(0) = v; x(1) = m; x(2) = u; x(3) = L; x(4) = s;
00127
00128
00129
00130
00131 OCP ocp( 0.0, 10.0 );
00132
00133 ocp.minimizeMayerTerm( M(x) );
00134
00135 ocp.subjectTo( f << F(x) );
00136
00137 ocp.subjectTo( AT_START, I(x) == 0.0 );
00138 ocp.subjectTo( AT_END , E(x) == 0.0 );
00139 ocp.subjectTo( H(x) <= 1.3 );
00140
00141
00142
00143
00144 GnuplotWindow window1;
00145 window1.addSubplot( s,"DifferentialState s" );
00146 window1.addSubplot( v,"DifferentialState v" );
00147 window1.addSubplot( m,"DifferentialState m" );
00148 window1.addSubplot( u,"Control u" );
00149
00150
00151
00152
00153 OptimizationAlgorithm algorithm(ocp);
00154 algorithm.set( INTEGRATOR_TOLERANCE, 1e-6 );
00155 algorithm.set( KKT_TOLERANCE, 1e-3 );
00156 algorithm << window1;
00157 algorithm.solve();
00158
00159
00160 return 0;
00161 }
00162