crane_kul_mhe.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 #include <acado_code_generation.hpp>
00027 
00028 USING_NAMESPACE_ACADO
00029 
00030 int main( void )
00031 {
00032         //
00033         // OCP parameters
00034         //
00035         // Sampling time
00036         double Ts = 0.01;
00037         // Number of shootin' intervals
00038         int N = 20;
00039         // Number of integrator steps per shootin' interval
00040         int Ni = 1;
00041 
00042         //
00043         // DEFINE THE VARIABLES
00044         //
00045         DifferentialState       xT;     // the trolley position
00046         DifferentialState       vT;     // the trolley velocity
00047         IntermediateState       aT;     // the trolley acceleration
00048 
00049         DifferentialState       xL;     // the cable length
00050         DifferentialState       vL;     // the cable velocity
00051         IntermediateState       aL;     // the cable acceleration
00052 
00053         DifferentialState       phi;    // the angle
00054         DifferentialState       omega;  // the angular velocity
00055 
00056         DifferentialState       uT;             // trolley velocity control
00057         DifferentialState       uL;             // cable velocity control
00058 
00059         Control                         duT;    // trolley accel control
00060         Control                         duL;    // cable accel control
00061 
00062         //
00063         // DEFINE THE MODEL PARAMETERS
00064         //
00065         const double            tau1    = 0.012790605943772;
00066         const double            a1              = 0.047418203070092;
00067         const double            tau2    = 0.024695192379264;
00068         const double            a2              = 0.034087337273386;
00069         const double            g               = 9.81;
00070 //      const double            c               = 0.0;
00071 //      const double            m               = 1.3180;
00072 
00073         //
00074         // DEFINE THE MODEL EQUATIONS
00075         //
00076         DifferentialEquation    f;
00077         aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
00078         aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
00079 
00080         f << dot(xT) == vT;
00081         f << dot(vT) == aT;
00082         f << dot(xL) == vL;
00083         f << dot(vL) == aL;
00084         f << dot(phi) == omega;
00085         f << dot(omega)
00086                         == -(g * sin(phi) + a1 * duT * cos(phi) + 2 * vL * omega) / xL;
00087         f << dot(uT) == duT;
00088         f << dot(uL) == duL;
00089 
00090         //
00091         // MHE PROBLEM FORMULATION
00092         //
00093         OCP ocp(0.0, N * Ts, N);
00094 
00095         ocp.subjectTo( f );
00096 
00097         // Measurement function h(x, u) on first N nodes
00098         Function h;
00099 
00100         h << xT << xL << phi << uT << uL << duT << duL;
00101 
00102         // Weighting matrices and measurement functions
00103         DMatrix W = eye<double>( 7 );
00104 //      W(0,0) = 16.5;
00105 //      W(1,1) = 23.9;
00106 //      W(2,2) = 25.1;
00107 //      W(3,3) = 12.1;
00108 //      W(4,4) = 119.4;
00109 //      W(5,5) = 45.0;
00110 //      W(6,6) = 1.2;
00111 //      W(7,7) = 0.4;
00112 
00113         Function hN;
00114         hN << xT << xL << phi << uT << uL;
00115 
00116         DMatrix WN = eye<double>( 5 );
00117         WN(0, 0) = W(0, 0);
00118         WN(1, 1) = W(1, 1);
00119         WN(2, 2) = W(2, 2);
00120         WN(3, 3) = W(3, 3);
00121         WN(4, 4) = W(4, 4);
00122 
00123         ocp.minimizeLSQ(W, h);
00124         ocp.minimizeLSQEndTerm(WN, hN);
00125 
00126         OCPexport mhe( ocp );
00127 
00128         mhe.set(INTEGRATOR_TYPE, INT_RK4);
00129         mhe.set(NUM_INTEGRATOR_STEPS, N * Ni);
00130 
00131         mhe.set(HESSIAN_APPROXIMATION, GAUSS_NEWTON);
00132         mhe.set(DISCRETIZATION_TYPE, MULTIPLE_SHOOTING);
00133 
00134         mhe.set(HOTSTART_QP, YES);
00135 
00136         // NOTE: This is crucial for export of MHE!
00137         mhe.set(SPARSE_QP_SOLUTION, CONDENSING);
00138         mhe.set(FIX_INITIAL_STATE, NO);
00139 
00140 //      mhe.set( LEVENBERG_MARQUARDT, 1e-10 );
00141 
00142         if (mhe.exportCode("crane_kul_mhe_export") != SUCCESSFUL_RETURN)
00143                 exit( EXIT_FAILURE );
00144 
00145         mhe.printDimensionsQP( );
00146 
00147         return EXIT_SUCCESS;
00148 }


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