plotting.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00027 
00035 #include <acado_toolkit.hpp>
00036 #include <acado_gnuplot.hpp>
00037 
00038 
00039 int main( ){
00040 
00041     USING_NAMESPACE_ACADO
00042 
00043 
00044         // DEFINE SAMPLE OCP
00045         // -----------------
00046         DifferentialState x, y;
00047         Control           u;
00048 
00049         DifferentialEquation f;
00050         
00051         f << dot(x) == y;
00052     f << dot(y) == u;
00053 
00054     OCP ocp( 0.0, 5.0 );
00055     ocp.minimizeLagrangeTerm( x*x + 0.01*u*u );
00056 
00057     ocp.subjectTo( f );
00058     ocp.subjectTo( AT_START, x ==  1.0 );
00059     ocp.subjectTo( AT_START, y ==  0.0 );
00060 
00061         ocp.subjectTo( -1.0 <= u <=  1.0 );
00062 
00063 
00064         // SETUP OPTIMIZATION ALGORITHM AND DEFINE VARIOUS PLOT WINDOWS
00065         // ------------------------------------------------------------
00066         OptimizationAlgorithm algorithm( ocp );
00067 
00068         GnuplotWindow window1;
00069         window1.addSubplot( x, "1st state" );
00070         window1.addSubplot( y, "2nd state","x label","y label",PM_POINTS );
00071         window1.addSubplot( u, "control input","x label","y label",PM_LINES,0,5,-2,2 );
00072         window1.addSubplot( 2.0*sin(x)+y*u, "Why not plotting fancy stuff!?" );
00073 //      window1.addSubplot( PLOT_KKT_TOLERANCE, "","iteration","KKT tolerance" );
00074         
00075         GnuplotWindow window2( PLOT_AT_EACH_ITERATION );
00076         window2.addSubplot( x, "1st state evolving..." );
00077         
00078         algorithm << window1;
00079         algorithm << window2;
00080         
00081         algorithm.solve( );
00082 
00083 
00084         // For illustration, an alternative way to plot differential states
00085         // in form of a VariablesGrid
00086         VariablesGrid states;
00087         algorithm.getDifferentialStates( states );
00088         
00089         GnuplotWindow window3;
00090         window3.addSubplot( states(0), "1st state obtained as VariablesGrid" );
00091         window3.addSubplot( states(1), "2nd state obtained as VariablesGrid" );
00092         window3.plot();
00093 
00094         VariablesGrid data( 1, 0.0,10.0,11 );
00095         data.setZero();
00096         data( 2,0 ) = 1.0;
00097         data( 5,0 ) = -1.0;
00098         data( 8,0 ) = 2.0;
00099         data( 9,0 ) = 2.0;
00100         
00101 //      data.setType( VT_CONTROL );
00102         
00103         GnuplotWindow window4;
00104         window4.addSubplot( data, "Any data can be plotted" );
00105         window4.plot();
00106 
00107 
00108     return 0;
00109 }


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:49