extern_model.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 
00033 #include <acado_code_generation.hpp>
00034 
00035 using namespace std;
00036 USING_NAMESPACE_ACADO
00037 
00038 int main()
00039 {
00040         // Define variables, functions and constants:
00041         // ----------------------------------------------------------
00042     DifferentialState   x;      
00043     DifferentialState   y;      
00044     DifferentialState   alpha;  
00045     DifferentialState   dx;
00046     DifferentialState   dy;
00047     DifferentialState   dalpha;
00048     
00049     AlgebraicState              ddx;
00050     AlgebraicState              ddy;
00051         AlgebraicState          ddalpha;
00052         AlgebraicState          Fx;
00053         AlgebraicState          Fy;
00054         
00055         Control                         u;
00056 
00057     DifferentialEquation   f1, f2;  
00058     
00059     OutputFcn h;
00060     
00061     h << Fx;
00062     h << Fy;
00063     
00064     const double      m = 2;
00065     const double      M = 3.5;
00066     const double      I = 0.1;
00067     const double          g = 9.81;
00068 
00069         // Pendulum DAE model in ACADO syntax (semi-explicit):
00070         // ----------------------------------------------------------
00071     f1 << dot( x )              ==  dx;
00072     f1 << dot( y )              ==  dy;
00073     f1 << dot( alpha )  ==  dalpha;
00074     f1 << dot( dx )             ==  ddx ;
00075     f1 << dot( dy )             ==  ddy;
00076     f1 << dot( dalpha ) ==  ddalpha;
00077     
00078     f1 << 0                     == m*ddx - (Fx+u);
00079     f1 << 0                             == m*ddy + m*g - (Fy+u);
00080     f1 << 0                             == I*ddalpha - M - (Fx+u)*y + (Fy+u)*x;
00081     f1 << 0                             == ddx + dy*dalpha + y*ddalpha;
00082     f1 << 0                     == ddy - dx*dalpha - x*ddalpha;
00083 
00084 
00085         // Pendulum DAE model in ACADO syntax (implicit):
00086         // ----------------------------------------------------------
00087     f2 << 0                     == dot( x ) - dx;
00088     f2 << 0                     == dot( y ) - dy;
00089     f2 << 0                     == dot( alpha ) - dalpha;
00090     f2 << 0                     == dot( dx ) - ddx ;
00091     f2 << 0                     == dot( dy ) - ddy;
00092     f2 << 0                     == dot( dalpha ) - ddalpha;
00093     
00094     f2 << 0                 == m*ddx - (Fx+u);
00095     f2 << 0                     == m*ddy + m*g - (Fy+u);
00096     f2 << 0                     == I*ddalpha - M - (Fx+u)*y + (Fy+u)*x;
00097     f2 << 0                     == ddx + dy*dalpha + y*ddalpha;
00098     f2 << 0             == ddy - dx*dalpha - x*ddalpha;
00099  
00100         // ----------------------------------------------------------
00101         // ----------------------------------------------------------
00102     SIMexport sim1( 1, 0.1 );
00103     
00104     sim1.set( INTEGRATOR_TYPE, INT_IRK_RIIA3 );
00105     sim1.set( NUM_INTEGRATOR_STEPS, 4 );
00106     sim1.set( MEASUREMENT_GRID, OFFLINE_GRID );
00107     
00108     sim1.setModel( f1 );
00109     sim1.addOutput( h, 5 );
00110         sim1.setTimingSteps( 10000 );
00111     
00112     cout << "-----------------------------------------------------------\n  Using a Pendulum DAE model in ACADO syntax (semi-explicit):\n-----------------------------------------------------------\n";
00113     sim1.exportAndRun( "pendulum_export", "init_externModel.txt", "controls_externModel.txt" );
00114  
00115  
00116         // ----------------------------------------------------------
00117         // ----------------------------------------------------------
00118     SIMexport sim2( 1, 0.1 );
00119     
00120     sim2.set( INTEGRATOR_TYPE, INT_IRK_RIIA3 );
00121     sim2.set( NUM_INTEGRATOR_STEPS, 4 );
00122     sim2.set( MEASUREMENT_GRID, OFFLINE_GRID );
00123     
00124     sim2.setModel( f2 );
00125     sim2.addOutput( h, 5 );
00126         sim2.setTimingSteps( 10000 );
00127     
00128     cout << "-----------------------------------------------------------\n  Using a Pendulum DAE model in ACADO syntax (implicit):\n-----------------------------------------------------------\n";
00129     sim2.exportAndRun( "pendulum_export", "init_externModel.txt", "controls_externModel.txt" );
00130     
00131     
00132         // ----------------------------------------------------------
00133         // ----------------------------------------------------------
00134     SIMexport sim3( 1, 0.1 );
00135 
00136     sim3.set( INTEGRATOR_TYPE, INT_IRK_RIIA3 );
00137     sim3.set( NUM_INTEGRATOR_STEPS, 4 );
00138     sim3.set( MEASUREMENT_GRID, OFFLINE_GRID );
00139     sim3.set( GENERATE_MAKE_FILE, NO );
00140 
00141     sim3.setModel( "model", "rhs", "rhs_jac" );
00142         sim3.setDimensions(6, 6, 5, 1, 0, 0);
00143 
00144     sim3.addOutput( "out", "out_jac", 2, 5 );
00145         sim3.setTimingSteps( 10000 );
00146 
00147     cout << "-----------------------------------------------------------\n  Using an externally defined Pendulum DAE model:\n-----------------------------------------------------------\n";
00148     sim3.exportAndRun( "externModel_export", "init_externModel.txt", "controls_externModel.txt" );
00149     
00150     
00151         return 0;
00152 } 
00153 


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