pendulum_dae_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 
00026 #include <acado_code_generation.hpp>
00027 
00028 USING_NAMESPACE_ACADO
00029 
00030 int main(int argc, char * const argv[ ])
00031 {
00032         //
00033         // Variables
00034         //
00035 
00036         DifferentialState       x, y, w, dx, dy, dw;
00037         AlgebraicState          mu;
00038         Control                         F;
00039 
00040         IntermediateState       c, dc;
00041 
00042         const double            m = 1.0;
00043         const double            mc = 1.0;
00044         const double            L = 1.0;
00045         const double            g = 9.81;
00046         const double            p = 5.0;
00047 
00048         c       = 0.5 * ((x - w) * (x - w) + y * y - L * L);
00049         dc      = dy * y + (dw - dx) * (w - x);
00050 
00051         //
00052         // Differential algebraic equation
00053         //
00054 
00055         DifferentialEquation f;
00056 
00057         f << 0 == dot( x ) - dx;
00058         f << 0 == dot( y ) - dy;
00059         f << 0 == dot( w ) - dw;
00060 
00061         f << 0 == m * dot( dx ) + (x - w) * mu;
00062         f << 0 == m * dot( dy ) + y * mu + m * g;
00063         f << 0 == mc * dot( dw ) + (w - x) * mu  - F;
00064 
00065         f << 0 == (x - w) * dot( dx ) + y * dot( dy ) + (w - x) * dot( dw )
00066                                         - (-p * p * c - 2 * p * dc - dy * dy - (dw - dx) * (dw - dx));
00067 
00068         //
00069         // Weighting matrices and reference functions
00070         //
00071 
00072         Function rf;
00073         Function rfN;
00074 
00075         rf << x << y << w << dx << dy << dw << F;
00076         rfN << x << y << w << dx << dy << dw;
00077 
00078         DMatrix W = eye<double>( rf.getDim() );
00079         DMatrix WN = eye<double>( rfN.getDim() ) * 10;
00080 
00081         //
00082         // Optimal Control Problem
00083         //
00084 
00085         const int N  = 10;
00086         const int Ni = 4;
00087         const double Ts = 0.1;
00088 
00089         OCP ocp(0, N * Ts, N);
00090 
00091         ocp.subjectTo( f );
00092 
00093         ocp.minimizeLSQ(W, rf);
00094         ocp.minimizeLSQEndTerm(WN, rfN);
00095 
00096         ocp.subjectTo(-20 <= F <= 20);
00097 //      ocp.subjectTo( -5 <= x <= 5 );
00098 
00099         //
00100         // Export the code:
00101         //
00102         OCPexport mpc( ocp );
00103 
00104         mpc.set(HESSIAN_APPROXIMATION, GAUSS_NEWTON);
00105         mpc.set(DISCRETIZATION_TYPE, MULTIPLE_SHOOTING);
00106 
00107         mpc.set(INTEGRATOR_TYPE, INT_IRK_RIIA3);
00108         mpc.set(NUM_INTEGRATOR_STEPS, N * Ni);
00109 
00110         mpc.set(SPARSE_QP_SOLUTION, FULL_CONDENSING);
00111 //      mpc.set(SPARSE_QP_SOLUTION, CONDENSING);
00112         mpc.set(QP_SOLVER, QP_QPOASES);
00113 //      mpc.set(MAX_NUM_QP_ITERATIONS, 20);
00114         mpc.set(HOTSTART_QP, YES);
00115 
00116 //      mpc.set(SPARSE_QP_SOLUTION, SPARSE_SOLVER);
00117 //      mpc.set(QP_SOLVER, QP_FORCES);
00118 
00119 //      mpc.set(LEVENBERG_MARQUARDT, 1.0e-10);
00120 
00121         mpc.set(GENERATE_TEST_FILE, NO);
00122         mpc.set(GENERATE_MAKE_FILE, NO);
00123         mpc.set(GENERATE_MATLAB_INTERFACE, YES);
00124 
00125 //      mpc.set(USE_SINGLE_PRECISION, YES);
00126 //      mpc.set(CG_USE_OPENMP, YES);
00127 
00128         if (mpc.exportCode( "pendulum_dae_nmpc_export" ) != SUCCESSFUL_RETURN)
00129                 exit( EXIT_FAILURE );
00130 
00131         mpc.printDimensionsQP( );
00132 
00133         return EXIT_SUCCESS;
00134 }


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