crane.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 
00036 using namespace std;
00037 USING_NAMESPACE_ACADO
00038 
00039 int main()
00040 {
00041         //
00042         // DEFINE THE VARIABLES:
00043     //
00044     DifferentialState   xT;     // the trolley position
00045     DifferentialState   vT;     // the trolley velocity
00046     IntermediateState   aT;     // the trolley acceleration
00047     DifferentialState   xL;     // the cable length
00048     DifferentialState   vL;     // the cable velocity
00049     IntermediateState   aL;     // the cable acceleration
00050     DifferentialState   phi;    // the excitation angle
00051     DifferentialState   omega;  // the angular velocity
00052         
00053     DifferentialState   uT;     // trolley velocity control
00054     DifferentialState   uL;     // cable velocity control
00055 
00056     Control             duT;
00057     Control             duL;
00058 
00059         //
00060     // DEFINE THE PARAMETERS:
00061     //
00062     const double      tau1 = 0.012790605943772;
00063     const double      a1   = 0.047418203070092;
00064     const double      tau2 = 0.024695192379264;
00065     const double      a2   = 0.034087337273386;
00066     const double      g = 9.81;                 
00067     const double      c = 0.0;                  
00068     const double      m = 1318.0;               
00069 
00070     //
00071     // DEFINE THE MODEL EQUATIONS:
00072     //
00073     DifferentialEquation   f;
00074     aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
00075     aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
00076 
00077     f << 0 == dot( xT ) - vT;
00078     f << 0 == dot( vT ) - aT;
00079     f << 0 == dot( xL ) - vL;
00080     f << 0 == dot( vL ) - aL;
00081     f << 0 == dot( phi ) - omega;
00082     f << 0 == dot( omega ) - 1.0/xL*(-g*sin(phi)-aT*cos(phi) 
00083                                                 -2*vL*omega-c*omega/(m*xL));
00084     f << 0 == dot( uT ) - duT;
00085     f << 0 == dot( uL ) - duL;
00086 
00087     //
00088     // DEFINE THE OUTPUT MODEL:
00089     //
00090         OutputFcn       h;
00091 
00092         h << aT;
00093         h << aL;
00094 
00095         //
00096         // SET UP THE SIMULATION EXPORT MODULE:
00097         //
00098         
00099         cout << "-----------------------------------------\n  Using an equidistant grid:\n-----------------------------------------\n";
00100         
00101         SIMexport sim( 1, 0.1 );
00102         
00103         sim.setModel( f );
00104         sim.addOutput( h, 5 );
00105         
00106         sim.set( INTEGRATOR_TYPE, INT_IRK_RIIA5 );
00107         sim.set( NUM_INTEGRATOR_STEPS, 5 );
00108         sim.setTimingSteps( 10000 );
00109         
00110         sim.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
00111         
00112         
00113         cout << "-----------------------------------------\n  Using a provided grid:\n-----------------------------------------\n";
00114         
00115         DVector Meas(5);
00116         Meas(0) = 0.0;
00117         Meas(1) = 0.2;
00118         Meas(2) = 0.4;
00119         Meas(3) = 0.6;
00120         Meas(4) = 0.8;
00121         
00122         SIMexport sim2( 1, 0.1 );
00123         
00124         sim2.setModel( f );
00125         sim2.addOutput( h, Meas );
00126         
00127         sim2.set( INTEGRATOR_TYPE, INT_IRK_RIIA5 );
00128         sim2.set( NUM_INTEGRATOR_STEPS, 5 );
00129         sim2.setTimingSteps( 10000 );
00130         
00131         sim2.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
00132 
00133         return 0;
00134 }
00135 


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