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
00027
00035 #include <acado_optimal_control.hpp>
00036 #include <acado_gnuplot.hpp>
00037
00038
00039
00040
00041 void myAcadoDifferentialEquation1( double *xx, double *f, void *user_data ){
00042
00043
00044 double x = xx[1];
00045
00046 double z = xx[3];
00047 double u = xx[4];
00048
00049 f[0] = -x + 0.5*x*x + u + 0.5*z;
00050 f[1] = x*x + 3.0*u*u ;
00051 f[2] = z + exp(z) - 1.0 + x;
00052 }
00053
00054
00055
00056
00057 int main( ){
00058
00059 USING_NAMESPACE_ACADO
00060
00061 TIME autotime;
00062 DifferentialState x("", 2, 1);
00063 AlgebraicState z;
00064 Control u;
00065 DifferentialEquation f1;
00066 IntermediateState setc_is_1(5);
00067 setc_is_1(0) = autotime;
00068 setc_is_1(1) = x(0);
00069 setc_is_1(2) = x(1);
00070 setc_is_1(3) = z;
00071 setc_is_1(4) = u;
00072
00073
00074 CFunction cLinkModel_1( 3, myAcadoDifferentialEquation1 );
00075 f1 << cLinkModel_1(setc_is_1);
00076
00077
00078 double dconstant1 = 0.0;
00079 double dconstant2 = 5.0;
00080 int dconstant3 = 10;
00081 OCP ocp1(dconstant1, dconstant2, dconstant3);
00082 ocp1.minimizeMayerTerm(x(1));
00083 ocp1.subjectTo(f1);
00084 ocp1.subjectTo(AT_START, x(0) == 1.0 );
00085 ocp1.subjectTo(AT_START, x(1) == 0.0 );
00086
00087
00088 GnuplotWindow window;
00089 window.addSubplot(x(0),"DIFFERENTIAL STATE x");
00090 window.addSubplot(z,"ALGEBRAIC STATE z" );
00091 window.addSubplot(u,"CONTROL u" );
00092
00093
00094 OptimizationAlgorithm algo1(ocp1);
00095 algo1.set( KKT_TOLERANCE, 1.000000E-05 );
00096 algo1.set( RELAXATION_PARAMETER, 1.500000E+00 );
00097
00098
00099
00100 algo1 << window;
00101
00102 algo1.solve();
00103
00104 return 0;
00105 }
00106
00107
00108