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 double h = ((double*) user_data)[0];
00061
00062 double v = x[0];
00063 double m = x[1];
00064 double u = x[2];
00065 double L = x[3];
00066 double s = x[4];
00067
00068 f[0] = s + h*v;
00069 f[1] = v + h*(u-0.02*v*v)/(1.0+m);
00070 f[2] = m - h*0.01*u*u;
00071 f[3] = L + h*u*u;
00072 }
00073
00074
00075 void myObjectiveFunction( double *x, double *f, void *user_data ){
00076
00077 f[0] = x[3];
00078 }
00079
00080
00081 void myInitialValueConstraint( double *x, double *f, void *user_data ){
00082
00083 f[0] = x[4];
00084 f[1] = x[0];
00085 f[2] = x[1];
00086 f[3] = x[3];
00087 }
00088
00089
00090 void myEndPointConstraint( double *x, double *f, void *user_data ){
00091
00092 f[0] = x[4] - 10.0;
00093 f[1] = x[0];
00094 }
00095
00096
00097 void myInequalityPathConstraint( double *x, double *f, void *user_data ){
00098
00099 f[0] = x[0];
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 USING_NAMESPACE_ACADO
00109
00110
00111 int main( ){
00112
00113
00114
00115
00116 DifferentialState s,v,m,L;
00117 Control u ;
00118
00119 const double h = 0.01;
00120 DiscretizedDifferentialEquation f(h);
00121
00122
00123
00124
00125 CFunction F( NX, myDifferentialEquation );
00126 CFunction M( NJ, myObjectiveFunction );
00127 CFunction I( NI, myInitialValueConstraint );
00128 CFunction E( NE, myEndPointConstraint );
00129 CFunction H( NH, myInequalityPathConstraint );
00130
00131 F.setUserData( (void*) &h );
00132
00133
00134
00135
00136
00137 IntermediateState x(5);
00138
00139 x(0) = v; x(1) = m; x(2) = u; x(3) = L; x(4) = s;
00140
00141
00142
00143
00144 OCP ocp( 0.0, 10.0, 20 );
00145
00146 ocp.minimizeMayerTerm( M(x) );
00147
00148 ocp.subjectTo( f << F(x) );
00149
00150 ocp.subjectTo( AT_START, I(x) == 0.0 );
00151 ocp.subjectTo( AT_END , E(x) == 0.0 );
00152 ocp.subjectTo( H(x) <= 1.3 );
00153
00154
00155
00156
00157 GnuplotWindow window1;
00158 window1.addSubplot( s,"DifferentialState s" );
00159 window1.addSubplot( v,"DifferentialState v" );
00160 window1.addSubplot( m,"DifferentialState m" );
00161 window1.addSubplot( u,"Control u" );
00162
00163
00164
00165
00166 OptimizationAlgorithm algorithm(ocp);
00167 algorithm.set( INTEGRATOR_TOLERANCE, 1e-6 );
00168 algorithm.set( KKT_TOLERANCE, 1e-3 );
00169 algorithm << window1;
00170 algorithm.solve();
00171
00172
00173 return 0;
00174 }
00175