crane_cl_nmpc.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         // Reference functions and weighting matrices:
00056         Function h, hN;
00057         h << p << v << phi << omega << a;
00058         hN << p << v << phi << omega;
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         ocp.subjectTo( -1.0 <= a <= 1.0 );
00074         ocp.subjectTo( -0.5 <= v <= 1.5 );
00075 
00076         // Export the code:
00077         OCPexport mpc( ocp );
00078 
00079         mpc.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
00080         mpc.set( DISCRETIZATION_TYPE, MULTIPLE_SHOOTING );
00081         mpc.set( INTEGRATOR_TYPE, INT_RK4 );
00082         mpc.set( NUM_INTEGRATOR_STEPS, 30 );
00083 
00084         mpc.set( SPARSE_QP_SOLUTION, CONDENSING );
00085         mpc.set( QP_SOLVER, QP_QPOASES );
00086         
00087 //      mpc.set( SPARSE_QP_SOLUTION, SPARSE_SOLVER );
00088 //      mpc.set( QP_SOLVER, QP_QPDUNES );
00089         
00090         mpc.set( HOTSTART_QP, YES );
00091         mpc.set( GENERATE_TEST_FILE, NO);
00092         mpc.set( GENERATE_MAKE_FILE, NO );
00093         mpc.set( GENERATE_MATLAB_INTERFACE, NO );
00094         mpc.set( GENERATE_SIMULINK_INTERFACE, YES );
00095 
00096         // Optionally set custom module name:
00097         mpc.set( CG_MODULE_NAME, "nmpc" );
00098 
00099         if (mpc.exportCode( "crane_cl_nmpc_export" ) != SUCCESSFUL_RETURN)
00100                 exit( EXIT_FAILURE );
00101 
00102         mpc.printDimensionsQP( );
00103 
00104         return EXIT_SUCCESS;
00105 }


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