van_der_pol.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 
27 
36 #include <acado_gnuplot.hpp>
37 
38 
39 /* >>> start tutorial code >>> */
40 int main( ){
41 
43 
44 
45  // INTRODUCE THE VARIABLES:
46  // -------------------------
47 
48  DifferentialState x1,x2;
49  Control u;
50  Parameter p;
51  Parameter T;
52  DifferentialEquation f(0.0,T);
53 
54  const double t_start = 0.0;
55 
56 
57  // DEFINE A DIFFERENTIAL EQUATION:
58  // -------------------------------
59 
60  f << dot(x1) == (1.0-x2*x2)*x1 - x2 + p*u;
61  f << dot(x2) == x1;
62 
63 
64  // DEFINE AN OPTIMAL CONTROL PROBLEM:
65  // ----------------------------------
66  OCP ocp( t_start, T, 27 );
67 
68 
69  // ocp.minimizeMayerTerm( T );
70  ocp.minimizeLagrangeTerm(10*x1*x1 + 10*x2*x2 + u*u);
71 
72  ocp.subjectTo( f );
73  ocp.subjectTo( AT_START, x1 == 0.0 );
74  ocp.subjectTo( AT_START, x2 == 1.0 );
75 
76  ocp.subjectTo( AT_END , x1 == 0.0 );
77  ocp.subjectTo( AT_END , x2 == 0.0 );
78 
79  ocp.subjectTo( -0.5 <= u <= 1.0 );
80 
81  ocp.subjectTo( p == 1.0 );
82  ocp.subjectTo( 0.0 <= T <= 20.0 );
83 
84 
85  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
86  // ------------------------------------------
87  GnuplotWindow window;
88  window << x1;
89  window << x2;
90  window << u;
91  window << T;
92 
93  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
94  // ---------------------------------------------------
95  OptimizationAlgorithm algorithm(ocp);
96 
97  algorithm.initializeControls("van_der_pol_controls.txt");
98 
99  algorithm << window;
100  algorithm.solve();
101 
102  algorithm.getControls("van_der_pol_controls2.txt");
103 
104  return 0;
105 }
106 /* <<< end tutorial code <<< */
107 
108 
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
returnValue minimizeLagrangeTerm(const Expression &arg)
Definition: ocp.cpp:240
returnValue initializeControls(const char *fileName)
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
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
returnValue getControls(VariablesGrid &p_) const
const double t_start
int main()
Definition: van_der_pol.cpp:40
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