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 int main( ){
00039
00040 USING_NAMESPACE_ACADO;
00041
00042
00043 double h_hw = 10;
00044 double A_hw = 1.0;
00045 double T_hw = 5.0;
00046 double h_b = 3.0;
00047 double rho = 1000;
00048 double A = 1.0;
00049 double m = 100;
00050 double g = 9.81;
00051
00052
00053 Control u;
00054
00055
00056 DifferentialState h;
00057 DifferentialState v;
00058 DifferentialState w;
00059 TIME t;
00060
00061
00062 DifferentialEquation f;
00063
00064
00065 IntermediateState hw;
00066 hw = h_hw + A_hw*sin(2*M_PI*t/T_hw);
00067
00068 f << dot(h) == v;
00069 f << dot(v) == rho*A*(hw-h)/m - g - u;
00070 f << dot(w) == u*v;
00071
00072
00073
00074
00075 const double t_start = 0.0 ;
00076 const double t_end = 15;
00077
00078 OCP ocp( t_start, t_end, 100 );
00079 ocp.maximizeMayerTerm( w );
00080 ocp.subjectTo( f );
00081
00082
00083
00084
00085
00086
00087 ocp.subjectTo( AT_START, h - (h_hw-A_hw) == 0.0 );
00088 ocp.subjectTo( AT_START, v == 0.0 );
00089 ocp.subjectTo( AT_START, w == 0.0 );
00090
00091 ocp.subjectTo( -h_b <= h-hw <= 0.0 );
00092 ocp.subjectTo( 0.0 <= u <= 100.0 );
00093
00094
00095
00096
00097
00098 GnuplotWindow window;
00099 window.addSubplot( h,"Height of buoy" );
00100 window.addSubplot( v,"Velocity of buoy" );
00101 window.addSubplot( w,"Objective function " );
00102 window.addSubplot( u,"Resistance" );
00103 window.addSubplot( hw,"Wave height" );
00104
00105
00106
00107
00108 OptimizationAlgorithm algorithm(ocp);
00109 algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00110 algorithm.set( MAX_NUM_ITERATIONS, 100 );
00111
00112
00113 algorithm << window;
00114 algorithm.solve();
00115
00116 return 0;
00117 }
00118
00119
00120