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


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