getting_started_advanced.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 A 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         DVector mean( 1 ), amplitude( 1 );
00080         mean.setZero( );
00081         amplitude.setAll( 50.0 );
00082 
00083         GaussianNoise myNoise( mean,amplitude );
00084 
00085         Actuator myActuator( 1,1 );
00086 
00087         myActuator.setControlNoise( myNoise,0.1 );
00088         myActuator.setControlDeadTimes( 0.1 );
00089         
00090         myActuator.setParameterDeadTimes( 0.2 );
00091 //      myActuator.setParameterNoise( myNoise,0.1 );
00092 
00093 
00094         mean.setZero( );
00095         amplitude.setAll( 0.005 );
00096         UniformNoise myOutputNoise1( mean,amplitude );
00097         
00098         mean.setAll( 10.0 );
00099         amplitude.setAll( 50.0 );
00100         GaussianNoise myOutputNoise2( mean,amplitude );
00101         
00102         Sensor mySensor( 2 );
00103         mySensor.setOutputNoise( 0,myOutputNoise1,0.1 );
00104         mySensor.setOutputNoise( 1,myOutputNoise2,0.1 );
00105         mySensor.setOutputDeadTimes( 0.2 );
00106 
00107 
00108         Process myProcess;
00109         
00110         myProcess.setDynamicSystem( dynSys,INT_RK45 );
00111         myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
00112         
00113         myProcess.setActuator( myActuator );
00114         myProcess.setSensor( mySensor );
00115 
00116         DVector x0( 4 );
00117         x0.setZero( );
00118         x0( 0 ) = 0.01;
00119 
00120         myProcess.initializeStartValues( x0 );
00121         myProcess.setProcessDisturbance( "road.txt" );
00122 
00123         myProcess.set( PLOT_RESOLUTION,HIGH );
00124 //      myProcess.set( CONTROL_PLOTTING,PLOT_NOMINAL );
00125 //      myProcess.set( PARAMETER_PLOTTING,PLOT_NOMINAL );
00126         myProcess.set( OUTPUT_PLOTTING,PLOT_REAL );
00127 
00128         GnuplotWindow window;
00129           window.addSubplot( xB, "Body Position [m]" );
00130           window.addSubplot( xW, "Wheel Position [m]" );
00131           window.addSubplot( vB, "Body Velocity [m/s]" );
00132           window.addSubplot( vW, "Wheel Velocity [m/s]" );
00133 
00134           window.addSubplot( F,"Damping Force [N]" );
00135           window.addSubplot( mB,"Body Mass [kg]" );
00136           window.addSubplot( R, "Road Disturbance" );
00137           window.addSubplot( g(0),"Output 1" );
00138           window.addSubplot( g(1),"Output 2" );
00139 
00140         myProcess << window;
00141 
00142 
00143     // SIMULATE AND GET THE RESULTS:
00144     // -----------------------------
00145         VariablesGrid u( 1,0.0,1.0,6 );
00146 
00147         u( 0,0 ) = 10.0;
00148         u( 1,0 ) = -200.0;
00149         u( 2,0 ) = 200.0;
00150         u( 3,0 ) = 0.0;
00151         u( 4,0 ) = 0.0;
00152         u( 5,0 ) = 0.0;
00153 
00154         DVector p( 1 );
00155         p(0) = 350.0;
00156 
00157         DVector pInit( 1 );
00158         pInit(0) = 300.0;
00159 
00160         myProcess.init( 0.0,x0,u.getFirstVector(),pInit );
00161         myProcess.run( u,p );
00162 
00163 
00164         VariablesGrid xSim, ySim;
00165 
00166 //      myProcess.getLast( LOG_SIMULATED_DIFFERENTIAL_STATES,xSim );
00167 //      xSim.print( "Simulated Differential States" );
00168 // 
00169 //      myProcess.getLast( LOG_PROCESS_OUTPUT,ySim );
00170 //      ySim.print( "Process Output" );
00171 
00172         return 0;
00173 }
00174 
00175 
00176 


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