getting_started.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 
00036 #include <acado_toolkit.hpp>
00037 #include <acado_gnuplot.hpp>
00038 
00039 
00040 int main( )
00041 {
00042         USING_NAMESPACE_ACADO
00043 
00044 
00045     // INTRODUCE THE VARIABLES:
00046     // -------------------------
00047         DifferentialState xB;
00048         DifferentialState xW;
00049         DifferentialState vB;
00050         DifferentialState vW;
00051 
00052         Disturbance R;
00053         Control F;
00054 
00055         Parameter mB;
00056         double mW = 50.0;
00057         double kS = 20000.0;
00058         double kT = 200000.0;
00059 
00060 
00061     // DEFINE THE DYNAMIC SYSTEM:
00062     // --------------------------
00063     DifferentialEquation f;
00064 
00065         f << dot(xB) == vB;
00066         f << dot(xW) == vW;
00067         f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
00068         f << dot(vW) == (  kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
00069 
00070         OutputFcn g;
00071         g << xB;
00072         g << 500.0*vB + F;
00073 
00074     DynamicSystem dynSys( f,g );
00075 
00076 
00077     // SETUP THE PROCESS:
00078     // ------------------
00079         Process myProcess;
00080         
00081         myProcess.setDynamicSystem( dynSys,INT_RK45 );
00082         myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
00083         
00084         DVector x0( 4 );
00085         x0.setZero( );
00086         x0( 0 ) = 0.01;
00087 
00088         myProcess.initializeStartValues( x0 );
00089         myProcess.setProcessDisturbance( "road.txt" );
00090 
00091         myProcess.set( PLOT_RESOLUTION,HIGH );
00092 
00093         GnuplotWindow window;
00094           window.addSubplot( xB, "Body Position [m]" );
00095           window.addSubplot( xW, "Wheel Position [m]" );
00096           window.addSubplot( vB, "Body Velocity [m/s]" );
00097           window.addSubplot( vW, "Wheel Velocity [m/s]" );
00098 
00099           window.addSubplot( F,"Damping Force [N]" );
00100           window.addSubplot( mB,"Body Mass [kg]" );
00101           window.addSubplot( R, "Road Disturbance" );
00102           window.addSubplot( g(0),"Output 1" );
00103           window.addSubplot( g(1),"Output 2" );
00104 
00105         myProcess << window;
00106 
00107 
00108     // SIMULATE AND GET THE RESULTS:
00109     // -----------------------------
00110         VariablesGrid u( 1,0.0,1.0,6 );
00111 
00112         u( 0,0 ) = 10.0;
00113         u( 1,0 ) = -200.0;
00114         u( 2,0 ) = 200.0;
00115         u( 3,0 ) = 0.0;
00116         u( 4,0 ) = 0.0;
00117         u( 5,0 ) = 0.0;
00118 
00119         DVector p( 1 );
00120         p(0) = 350.0;
00121 
00122         myProcess.init( 0.0 );
00123         myProcess.run( u,p );
00124 
00125 
00126         VariablesGrid xSim, ySim;
00127 
00128         myProcess.getLast( LOG_SIMULATED_DIFFERENTIAL_STATES,xSim );
00129         xSim.print( "Simulated Differential States" );
00130 
00131         myProcess.getLast( LOG_PROCESS_OUTPUT,ySim );
00132         ySim.print( "Process Output" );
00133 
00134 
00135         return 0;
00136 }
00137 
00138 
00139 


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