examples/getting_started/plotting.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 
35 #include <acado_toolkit.hpp>
36 #include <acado_gnuplot.hpp>
37 
38 
39 int main( ){
40 
42 
43 
44  // DEFINE SAMPLE OCP
45  // -----------------
47  Control u;
48 
50 
51  f << dot(x) == y;
52  f << dot(y) == u;
53 
54  OCP ocp( 0.0, 5.0 );
55  ocp.minimizeLagrangeTerm( x*x + 0.01*u*u );
56 
57  ocp.subjectTo( f );
58  ocp.subjectTo( AT_START, x == 1.0 );
59  ocp.subjectTo( AT_START, y == 0.0 );
60 
61  ocp.subjectTo( -1.0 <= u <= 1.0 );
62 
63 
64  // SETUP OPTIMIZATION ALGORITHM AND DEFINE VARIOUS PLOT WINDOWS
65  // ------------------------------------------------------------
66  OptimizationAlgorithm algorithm( ocp );
67 
68  GnuplotWindow window1;
69  window1.addSubplot( x, "1st state" );
70  window1.addSubplot( y, "2nd state","x label","y label",PM_POINTS );
71  window1.addSubplot( u, "control input","x label","y label",PM_LINES,0,5,-2,2 );
72  window1.addSubplot( 2.0*sin(x)+y*u, "Why not plotting fancy stuff!?" );
73 // window1.addSubplot( PLOT_KKT_TOLERANCE, "","iteration","KKT tolerance" );
74 
76  window2.addSubplot( x, "1st state evolving..." );
77 
78  algorithm << window1;
79  algorithm << window2;
80 
81  algorithm.solve( );
82 
83 
84  // For illustration, an alternative way to plot differential states
85  // in form of a VariablesGrid
86  VariablesGrid states;
87  algorithm.getDifferentialStates( states );
88 
89  GnuplotWindow window3;
90  window3.addSubplot( states(0), "1st state obtained as VariablesGrid" );
91  window3.addSubplot( states(1), "2nd state obtained as VariablesGrid" );
92  window3.plot();
93 
94  VariablesGrid data( 1, 0.0,10.0,11 );
95  data.setZero();
96  data( 2,0 ) = 1.0;
97  data( 5,0 ) = -1.0;
98  data( 8,0 ) = 2.0;
99  data( 9,0 ) = 2.0;
100 
101 // data.setType( VT_CONTROL );
102 
103  GnuplotWindow window4;
104  window4.addSubplot( data, "Any data can be plotted" );
105  window4.plot();
106 
107 
108  return 0;
109 }
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
returnValue minimizeLagrangeTerm(const Expression &arg)
Definition: ocp.cpp:240
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue addSubplot(PlotWindowSubplot &_subplot)
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
returnValue getDifferentialStates(VariablesGrid &xd_) const
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:34:59