getting_started_discretized.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         Control F;
00053 
00054 
00055     // DEFINE A DIFFERENTIAL EQUATION:
00056     // -------------------------------
00057 
00058         double h = 0.05;
00059         DiscretizedDifferentialEquation f( h );
00060 
00061 //      f << next(xB) == (  9.523918456856767e-01*xB - 3.093442425036754e-03*xW          + 4.450257887258270e-04*vW - 2.380407715716160e-07*F );
00062 //      f << next(xW) == ( -1.780103154903307e+00*xB - 1.005721624707961e+00*xW          - 3.093442425036752e-03*vW - 8.900515774516536e-06*F );
00063 //      f << next(vB) == ( -5.536210379145256e+00*xB - 2.021981836435758e-01*xW + 1.0*vB + 2.474992857984263e-02*vW + 1.294618052471308e-04*F );
00064 //      f << next(vW) == (  1.237376970014700e+01*xB + 1.183104351525840e+01*xW          - 1.005721624707961e+00*vW + 6.186884850073496e-05*F );
00065 
00066    f << next(xB) == (  0.9335*xB + 0.0252*xW + 0.048860*vB + 0.000677*vW  + 3.324e-06*F );
00067    f << next(xW) == (  0.1764*xB - 0.9821*xW + 0.004739*vB - 0.002591*vW  - 8.822e-06*F );
00068    f << next(vB) == ( -2.5210*xB - 0.1867*xW + 0.933500*vB + 0.025200*vW  + 0.0001261*F );
00069    f << next(vW) == ( -1.3070*xB + 11.670*xW + 0.176400*vB - 0.982100*vW  + 6.536e-05*F );
00070    
00071         OutputFcn g;
00072         g << xB;
00073         g << 500.0*vB + F;
00074 
00075     DynamicSystem dynSys( f,g );
00076 
00077 
00078     // SETUP THE PROCESS:
00079     // ------------------
00080         DVector mean( 1 ), amplitude( 1 );
00081         mean.setZero( );
00082         amplitude.setAll( 50.0 );
00083 
00084         GaussianNoise myNoise( mean,amplitude );
00085 
00086         Actuator myActuator( 1 );
00087 
00088         myActuator.setControlNoise( myNoise,0.1 );
00089         myActuator.setControlDeadTimes( 0.1 );
00090         
00091 
00092         mean.setZero( );
00093         amplitude.setAll( 0.001 );
00094         UniformNoise myOutputNoise1( mean,amplitude );
00095         
00096         mean.setAll( 20.0 );
00097         amplitude.setAll( 10.0 );
00098         GaussianNoise myOutputNoise2( mean,amplitude );
00099         
00100         Sensor mySensor( 2 );
00101         mySensor.setOutputNoise( 0,myOutputNoise1,0.1 );
00102         mySensor.setOutputNoise( 1,myOutputNoise2,0.1 );
00103         mySensor.setOutputDeadTimes( 0.15 );
00104 
00105 
00106         Process myProcess;
00107         
00108         myProcess.setDynamicSystem( dynSys );
00109         myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
00110         
00111         myProcess.setActuator( myActuator );
00112         myProcess.setSensor( mySensor );
00113 
00114         DVector x0( 4 );
00115         x0.setZero( );
00116         x0( 0 ) = 0.01;
00117 
00118         myProcess.initializeStartValues( x0 );
00119 
00120         myProcess.set( PLOT_RESOLUTION,HIGH );
00121 //      myProcess.set( CONTROL_PLOTTING,PLOT_NOMINAL );
00122 //      myProcess.set( PARAMETER_PLOTTING,PLOT_NOMINAL );
00123         myProcess.set( OUTPUT_PLOTTING,PLOT_REAL );
00124 
00125         GnuplotWindow window;
00126           window.addSubplot( xB, "Body Position [m]" );
00127           window.addSubplot( xW, "Wheel Position [m]" );
00128           window.addSubplot( vB, "Body Velocity [m/s]" );
00129           window.addSubplot( vW, "Wheel Velocity [m/s]" );
00130 
00131           window.addSubplot( F,"Damping Force [N]" );
00132           window.addSubplot( g(0),"Output 1" );
00133           window.addSubplot( g(1),"Output 2" );
00134 
00135         myProcess << window;
00136 
00137 
00138     // SIMULATE AND GET THE RESULTS:
00139     // -----------------------------
00140         VariablesGrid u( 1,0.0,1.0,6 );
00141 
00142         u( 0,0 ) = 10.0;
00143         u( 1,0 ) = -200.0;
00144         u( 2,0 ) = 200.0;
00145         u( 3,0 ) = 200.0;
00146         u( 4,0 ) = 0.0;
00147         u( 5,0 ) = 0.0;
00148 
00149         myProcess.init( 0.0,x0,u.getFirstVector() );
00150         myProcess.run( u );
00151 
00152 
00153         VariablesGrid uNom, uSim, ySim, ySens, xSim;
00154 
00155 //      myProcess.getLast( LOG_NOMINAL_CONTROLS,uNom ); uNom.print( "uNom" );
00156 //      myProcess.getLast( LOG_SIMULATED_CONTROLS,uSim ); uSim.print( "uSim" );
00157 //      myProcess.getLast( LOG_SIMULATED_OUTPUT,ySim ); ySim.print( "ySim" );
00158 //      myProcess.getLast( LOG_PROCESS_OUTPUT,ySens ); ySens.print( "ySens" );
00159 // 
00160 //      myProcess.getLast( LOG_DIFFERENTIAL_STATES,xSim );
00161         
00162 
00163 
00164         return 0;
00165 }
00166 
00167 
00168 


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