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_toolkit.hpp>
00036 #include <acado_gnuplot.hpp>
00037
00038
00039 int main( ){
00040
00041 USING_NAMESPACE_ACADO
00042
00043
00044
00045
00046 DifferentialState x, y;
00047 Control u;
00048
00049 DifferentialEquation f;
00050
00051 f << dot(x) == y;
00052 f << dot(y) == u;
00053
00054 OCP ocp( 0.0, 5.0 );
00055 ocp.minimizeLagrangeTerm( x*x + 0.01*u*u );
00056
00057 ocp.subjectTo( f );
00058 ocp.subjectTo( AT_START, x == 1.0 );
00059 ocp.subjectTo( AT_START, y == 0.0 );
00060
00061 ocp.subjectTo( -1.0 <= u <= 1.0 );
00062
00063
00064
00065
00066 OptimizationAlgorithm algorithm( ocp );
00067
00068 GnuplotWindow window1;
00069 window1.addSubplot( x, "1st state" );
00070 window1.addSubplot( y, "2nd state","x label","y label",PM_POINTS );
00071 window1.addSubplot( u, "control input","x label","y label",PM_LINES,0,5,-2,2 );
00072 window1.addSubplot( 2.0*sin(x)+y*u, "Why not plotting fancy stuff!?" );
00073
00074
00075 GnuplotWindow window2( PLOT_AT_EACH_ITERATION );
00076 window2.addSubplot( x, "1st state evolving..." );
00077
00078 algorithm << window1;
00079 algorithm << window2;
00080
00081 algorithm.solve( );
00082
00083
00084
00085
00086 VariablesGrid states;
00087 algorithm.getDifferentialStates( states );
00088
00089 GnuplotWindow window3;
00090 window3.addSubplot( states(0), "1st state obtained as VariablesGrid" );
00091 window3.addSubplot( states(1), "2nd state obtained as VariablesGrid" );
00092 window3.plot();
00093
00094 VariablesGrid data( 1, 0.0,10.0,11 );
00095 data.setZero();
00096 data( 2,0 ) = 1.0;
00097 data( 5,0 ) = -1.0;
00098 data( 8,0 ) = 2.0;
00099 data( 9,0 ) = 2.0;
00100
00101
00102
00103 GnuplotWindow window4;
00104 window4.addSubplot( data, "Any data can be plotted" );
00105 window4.plot();
00106
00107
00108 return 0;
00109 }