ocp/wave_energy.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 #include <acado_gnuplot.hpp>
36 
37 
38 int main( ){
39 
41 
42  // Parameters
43  double h_hw = 10; // water level
44  double A_hw = 1.0; // amplitude of the waves
45  double T_hw = 5.0; // duration of a wave
46  double h_b = 3.0; // height of the buoy
47  double rho = 1000; // density of water
48  double A = 1.0; // bottom area of the buoy
49  double m = 100; // mass of the buoy
50  double g = 9.81; // gravitational constant
51 
52  // Free parameter
53  Control u;
54 
55  // Variables
56  DifferentialState h; // Position of the buoy
57  DifferentialState v; // Velocity of the buoy
58  DifferentialState w; // Produced wave energy
59  TIME t;
60 
61  // Differential equation
63 
64  // Height of the wave
66  hw = h_hw + A_hw*sin(2*M_PI*t/T_hw);
67 
68  f << dot(h) == v;
69  f << dot(v) == rho*A*(hw-h)/m - g - u;
70  f << dot(w) == u*v;
71 
72  // DEFINE AN OPTIMAL CONTROL PROBLEM:
73  // ----------------------------------
74 
75  const double t_start = 0.0 ;
76  const double t_end = 15;
77 
78  OCP ocp( t_start, t_end, 100 );
79  ocp.maximizeMayerTerm( w );
80  ocp.subjectTo( f );
81 
82 // double x_start[3];
83 // x_start[0] = h_hw - 0*A_hw;
84 // x_start[1] = 0;
85 // x_start[2] = 0;
86 
87  ocp.subjectTo( AT_START, h - (h_hw-A_hw) == 0.0 );
88  ocp.subjectTo( AT_START, v == 0.0 );
89  ocp.subjectTo( AT_START, w == 0.0 );
90 
91  ocp.subjectTo( -h_b <= h-hw <= 0.0 );
92  ocp.subjectTo( 0.0 <= u <= 100.0 );
93 
94 
95 
96  // DEFINE A PLOT WINDOW:
97  // ---------------------
98  GnuplotWindow window;
99  window.addSubplot( h,"Height of buoy" );
100  window.addSubplot( v,"Velocity of buoy" );
101  window.addSubplot( w,"Objective function " );
102  window.addSubplot( u,"Resistance" );
103  window.addSubplot( hw,"Wave height" );
104  // window.addSubplot( PLOT_KKT_TOLERANCE,"KKT Tolerance" );
105 
106  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
107  // ---------------------------------------------------
108  OptimizationAlgorithm algorithm(ocp);
110  algorithm.set( MAX_NUM_ITERATIONS, 100 );
111  // algorithm.set( KKT_TOLERANCE, 1e-10 );
112 
113  algorithm << window;
114  algorithm.solve();
115 
116  return 0;
117 }
118 
119 
120 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define M_PI
Definition: acado_utils.hpp:54
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
const double t_end
const double t_start
int main()
returnValue maximizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:239
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:16