crane_cl_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 
00031 #include <acado_code_generation.hpp>
00032 
00033 int main()
00034 {
00035         USING_NAMESPACE_ACADO
00036 
00037         // Variables:
00038         DifferentialState       p;              // the trolley position
00039         DifferentialState v;            // the trolley velocity
00040         DifferentialState phi;          // the excitation angle
00041         DifferentialState omega;        // the angular velocity
00042         Control a;                                      // the acc. of the trolley
00043 
00044         const double g = 9.81;          // the gravitational constant
00045         const double b = 0.20;          // the friction coefficient
00046 
00047         // Model equations:
00048         DifferentialEquation f;
00049 
00050         f << dot( p ) == v;
00051         f << dot( v ) == a;
00052         f << dot( phi ) == omega;
00053         f << dot( omega ) == -g * sin(phi) - a * cos(phi) - b * omega;
00054 
00055         // Measurement functions and weighting matrices:
00056         Function h, hN;
00057         h << p << phi << a;
00058         hN << p << phi;
00059 
00060         BMatrix W = eye<bool>( h.getDim() );
00061         BMatrix WN = eye<bool>( hN.getDim() );
00062 
00063         //
00064         // Optimal Control Problem
00065         //
00066         OCP ocp(0.0, 3.0, 10);
00067 
00068         ocp.subjectTo( f );
00069 
00070         ocp.minimizeLSQ(W, h);
00071         ocp.minimizeLSQEndTerm(WN, hN);
00072 
00073         // Export the code:
00074         OCPexport mhe( ocp );
00075 
00076         mhe.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
00077         mhe.set( DISCRETIZATION_TYPE, MULTIPLE_SHOOTING );
00078         mhe.set( INTEGRATOR_TYPE, INT_RK4 );
00079         mhe.set( NUM_INTEGRATOR_STEPS, 30 );
00080 
00081         // NOTE: Those three options define MHE configuration!
00082         mhe.set( FIX_INITIAL_STATE, NO );
00083         mhe.set( SPARSE_QP_SOLUTION, CONDENSING );
00084         mhe.set( QP_SOLVER, QP_QPOASES );
00085 
00086 //      mpc.set( LEVENBERG_MARQUARDT, 1.0e-4 );
00087 
00088         mhe.set( GENERATE_TEST_FILE, NO );
00089         mhe.set( GENERATE_MAKE_FILE, NO );
00090         mhe.set( GENERATE_MATLAB_INTERFACE, NO );
00091         mhe.set( GENERATE_SIMULINK_INTERFACE, YES );
00092 
00093 //      mpc.set( USE_SINGLE_PRECISION, YES );
00094 
00095         // Optionally set custom module name:
00096         mhe.set( CG_MODULE_NAME, "mhe" );
00097 
00098         if (mhe.exportCode( "crane_cl_mhe_export" ) != SUCCESSFUL_RETURN)
00099                 exit( EXIT_FAILURE );
00100 
00101         mhe.printDimensionsQP( );
00102 
00103         return EXIT_SUCCESS;
00104 }


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