time_optimal_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 
27 
36 #include <acado_gnuplot.hpp>
37 
38 
39 int main( ){
40 
42 
43 
44  // INTRODUCE THE VARIABLES:
45  // -------------------------
46 
47  DifferentialState s,v,m;
48  Control u ;
49  Parameter T ;
50 
51  DifferentialEquation f( 0.0, T );
52 
53 
54  // DEFINE A DIFFERENTIAL EQUATION:
55  // -------------------------------
56 
57  f << dot(s) == v;
58  f << dot(v) == (u-0.2*v*v)/m;
59  f << dot(m) == -0.01*u*u;
60 
61 
62  // DEFINE AN OPTIMAL CONTROL PROBLEM:
63  // ----------------------------------
64  OCP ocp( 0, T, 20 );
65 
66  ocp.minimizeMayerTerm( T );
67  ocp.subjectTo( f );
68 
69  ocp.subjectTo( AT_START, s == 0.0 );
70  ocp.subjectTo( AT_START, v == 0.0 );
71  ocp.subjectTo( AT_START, m == 1.0 );
72 
73  ocp.subjectTo( AT_END , s == 10.0 );
74  ocp.subjectTo( AT_END , v == 0.0 );
75 
76  ocp.subjectTo( -0.1 <= v <= 1.7 );
77  ocp.subjectTo( -1.1 <= u <= 1.1 );
78  ocp.subjectTo( 5.0 <= T <= 15.0 );
79 
80 
81  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
82  // ------------------------------------------
83  GnuplotWindow window;
84  window.addSubplot( s, "THE DISTANCE s" );
85  window.addSubplot( v, "THE VELOCITY v" );
86  window.addSubplot( m, "THE MASS m" );
87  window.addSubplot( u, "THE CONTROL INPUT u" );
88 
89 
90  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
91  // ---------------------------------------------------
92  OptimizationAlgorithm algorithm(ocp);
93 
94  algorithm.set( MAX_NUM_ITERATIONS, 20 );
95 // algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
96 // algorithm.set( HESSIAN_PROJECTION_FACTOR, 1.0 );
97 
98  algorithm << window;
99 
100 
101 // algorithm.initializeDifferentialStates("tor_states.txt");
102 // algorithm.initializeParameters("tor_pars.txt");
103 // algorithm.initializeControls("tor_controls.txt");
104 
105  algorithm.solve();
106 
107 // algorithm.getDifferentialStates("tor_states.txt");
108 // algorithm.getParameters("tor_pars.txt");
109 // algorithm.getControls("tor_controls.txt");
110 
111  return 0;
112 }
113 
114 
115 
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
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 minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
int main()
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
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:12