wave_energy.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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   // Parameters
00043   double h_hw = 10;    // water level
00044   double A_hw = 1.0;   // amplitude of the waves
00045   double T_hw = 5.0;   // duration of a wave
00046   double h_b  = 3.0;   // height of the buoy
00047   double rho  = 1000;  // density of water
00048   double A    = 1.0;   // bottom area of the buoy
00049   double m    = 100;   // mass of the buoy
00050   double g    = 9.81;  // gravitational constant
00051 
00052   // Free parameter
00053   Control u;
00054 
00055   // Variables
00056   DifferentialState h; // Position of the buoy
00057   DifferentialState v; // Velocity of the buoy
00058   DifferentialState w; // Produced wave energy
00059   TIME t;
00060 
00061   // Differential equation
00062   DifferentialEquation f;
00063   
00064   // Height of the wave
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   // DEFINE AN OPTIMAL CONTROL PROBLEM:
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 //   double x_start[3];
00083 //   x_start[0] = h_hw - 0*A_hw;
00084 //   x_start[1] = 0;
00085 //   x_start[2] = 0;
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       // DEFINE A PLOT WINDOW:
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   //  window.addSubplot( PLOT_KKT_TOLERANCE,"KKT Tolerance" );
00105 
00106   // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
00107   // ---------------------------------------------------
00108   OptimizationAlgorithm algorithm(ocp);
00109   algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00110   algorithm.set( MAX_NUM_ITERATIONS, 100 );
00111   //  algorithm.set( KKT_TOLERANCE, 1e-10 );
00112   
00113   algorithm << window;
00114   algorithm.solve();
00115 
00116   return 0;
00117 }
00118 
00119 
00120 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:40:19