rocket_with_logging.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 
44 
45  // INTRODUCE THE VARIABLES:
46  // -------------------------
47  DifferentialState s,v,m;
48  Control u ;
50 
51  const double t_start = 0.0;
52  const double t_end = 10.0;
53 
54  // DEFINE A DIFFERENTIAL EQUATION:
55  // -------------------------------
56  f << dot(s) == v;
57  f << dot(v) == (u-0.02*v*v)/m;
58  f << dot(m) == -0.01*u*u;
59 
60 
61  // DEFINE AN OPTIMAL CONTROL PROBLEM:
62  // ----------------------------------
63  OCP ocp( t_start, t_end, 20 );
64  ocp.minimizeLagrangeTerm( u*u );
65  ocp.subjectTo( f );
66 
67  ocp.subjectTo( AT_START, s == 0.0 );
68  ocp.subjectTo( AT_START, v == 0.0 );
69  ocp.subjectTo( AT_START, m == 1.0 );
70  ocp.subjectTo( AT_END , s == 10.0 );
71  ocp.subjectTo( AT_END , v == 0.0 );
72 
73  ocp.subjectTo( -0.01 <= v <= 1.3 );
74 
75 
76  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
77  // ---------------------------------------------------
78  OptimizationAlgorithm algorithm(ocp);
79 
80  // Additionally, flush a plotting object
81  GnuplotWindow window( PLOT_AT_END );
82  window.addSubplot( s,"DifferentialState s" );
83  window.addSubplot( v,"DifferentialState v" );
84  window.addSubplot( m,"DifferentialState m" );
85  window.addSubplot( u,"Control u" );
86 
87  // Additionally, flush a logging object
88  LogRecord logRecord( LOG_AT_EACH_ITERATION );
89  logRecord << LOG_KKT_TOLERANCE;
90 
91  algorithm << logRecord;
92  algorithm << window;
93 
95  algorithm.set( MAX_NUM_ITERATIONS, 20 );
96  algorithm.set( KKT_TOLERANCE, 1e-10 );
97 
98  algorithm.solve();
99 
100  // Get the logging object back and print it
101  algorithm.getLogRecord( logRecord );
102  logRecord.print( );
103 
104 
105  return 0;
106 }
107 /* <<< end tutorial code <<< */
108 
109 // algorithm.set( DISCRETIZATION_TYPE, MULTIPLE_SHOOTING );
110 // algorithm.set( DISCRETIZATION_TYPE, SINGLE_SHOOTING );
111 //
112 // algorithm.set( DYNAMIC_SENSITIVITY, FORWARD_SENSITIVITY );
113 // algorithm.set( DYNAMIC_SENSITIVITY, BACKWARD_SENSITIVITY );
114 
115 // algorithm.set( INTEGRATOR_TYPE, INT_RK45 );
116 // algorithm.set( INTEGRATOR_TYPE, INT_RK78 );
117 // algorithm.set( INTEGRATOR_TYPE, INT_BDF );
118 //
119 // algorithm.set( KKT_TOLERANCE, 1e-4 );
120 // algorithm.set( MAX_NUM_ITERATIONS, 20 );
Lowest level, the debug level.
returnValue minimizeLagrangeTerm(const Expression &arg)
Definition: ocp.cpp:240
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
int main()
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
static Logger & instance()
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
returnValue getLogRecord(LogRecord &_record) const
Definition: logging.cpp:77
Allows to setup and store user-specified log records of algorithmic information.
Definition: log_record.hpp:72
Logger & setLogLevel(returnValueLevel level)
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:03