discrete_time_rocket.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 /* >>> start tutorial code >>> */
39 int main( ){
40 
42 
43  // INTRODUCE THE VARIABLES:
44  // ------------------------------------
45  DifferentialState v,s,m;
46  Control u ;
47 
48  const double t_start = 0.0;
49  const double t_end = 10.0;
50  const double h = 0.01;
51 
53 
54 
55  // DEFINE A DISCRETE-TIME SYTSEM:
56  // -------------------------------
57  f << next(s) == s + h*v;
58  f << next(v) == v + h*(u-0.02*v*v)/m;
59  f << next(m) == m - h*0.01*u*u;
60 
61 
62  Function eta;
63  eta << u;
64 
65  // DEFINE AN OPTIMAL CONTROL PROBLEM:
66  // ----------------------------------
67  OCP ocp( t_start, t_end, 50 );
68 
69  //ocp.minimizeLagrangeTerm( u*u );
70  ocp.minimizeLSQ( eta );
71  ocp.subjectTo( f );
72 
73  ocp.subjectTo( AT_START, s == 0.0 );
74  ocp.subjectTo( AT_START, v == 0.0 );
75  ocp.subjectTo( AT_START, m == 1.0 );
76 
77  ocp.subjectTo( AT_END , s == 10.0 );
78  ocp.subjectTo( AT_END , v == 0.0 );
79 
80  ocp.subjectTo( -0.01 <= v <= 1.3 );
81 
82 
83  // DEFINE A PLOT WINDOW:
84  // ---------------------
85  GnuplotWindow window;
86  window.addSubplot( s,"DifferentialState s" );
87  window.addSubplot( v,"DifferentialState v" );
88  window.addSubplot( m,"DifferentialState m" );
89  window.addSubplot( u,"Control u" );
90  window.addSubplot( PLOT_KKT_TOLERANCE,"KKT Tolerance" );
91  window.addSubplot( 0.5 * m * v*v,"Kinetic Energy" );
92 
93 
94  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
95  // ---------------------------------------------------
96  OptimizationAlgorithm algorithm(ocp);
97  algorithm.set( INTEGRATOR_TYPE, INT_DISCRETE );
99  algorithm.set( KKT_TOLERANCE, 1e-10 );
100 
101  algorithm << window;
102  algorithm.solve();
103 
104  return 0;
105 }
106 /* <<< end tutorial code <<< */
107 
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
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)
int main()
Allows to setup and evaluate discretized differential equations based on SymbolicExpressions.
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue minimizeLSQ(const DMatrix &S, const Function &h, const DVector &r)
Definition: ocp.cpp:244
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
const double t_end
const double t_start
Expression next(const Expression &arg)
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()


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