crane_cl_nmpc.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
32 
33 int main( )
34 {
36 
37  // Variables:
38  DifferentialState p ; // the trolley position
39  DifferentialState v ; // the trolley velocity
40  DifferentialState phi ; // the excitation angle
41  DifferentialState omega; // the angular velocity
42  Control a ; // the acc. of the trolley
43 
44  const double g = 9.81; // the gravitational constant
45  const double b = 0.20; // the friction coefficient
46 
47  // Model equations:
49 
50  f << dot( p ) == v;
51  f << dot( v ) == a;
52  f << dot( phi ) == omega;
53  f << dot( omega ) == -g * sin(phi) - a * cos(phi) - b * omega;
54 
55  // Reference functions and weighting matrices:
56  Function h, hN;
57  h << p << v << phi << omega << a;
58  hN << p << v << phi << omega;
59 
60  BMatrix W = eye<bool>( h.getDim() );
61  BMatrix WN = eye<bool>( hN.getDim() );
62 
63  //
64  // Optimal Control Problem
65  //
66  OCP ocp(0.0, 3.0, 10);
67 
68  ocp.subjectTo( f );
69 
70  ocp.minimizeLSQ(W, h);
71  ocp.minimizeLSQEndTerm(WN, hN);
72 
73  ocp.subjectTo( -1.0 <= a <= 1.0 );
74  ocp.subjectTo( -0.5 <= v <= 1.5 );
75 
76  // Export the code:
77  OCPexport mpc( ocp );
78 
81  mpc.set( INTEGRATOR_TYPE, INT_RK4 );
82  mpc.set( NUM_INTEGRATOR_STEPS, 30 );
83 
85  mpc.set( QP_SOLVER, QP_QPOASES );
86 
87 // mpc.set( SPARSE_QP_SOLUTION, SPARSE_SOLVER );
88 // mpc.set( QP_SOLVER, QP_QPDUNES );
89 
90  mpc.set( HOTSTART_QP, YES );
91  mpc.set( GENERATE_TEST_FILE, NO);
92  mpc.set( GENERATE_MAKE_FILE, NO );
95 
96  // Optionally set custom module name:
97  mpc.set( CG_MODULE_NAME, "nmpc" );
98 
99  if (mpc.exportCode( "crane_cl_nmpc_export" ) != SUCCESSFUL_RETURN)
100  exit( EXIT_FAILURE );
101 
102  mpc.printDimensionsQP( );
103 
104  return EXIT_SUCCESS;
105 }
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
#define USING_NAMESPACE_ACADO
virtual returnValue exportCode(const std::string &dirName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16)
Definition: ocp_export.cpp:68
IntermediateState cos(const Expression &arg)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define YES
Definition: acado_types.hpp:51
int getDim() const
#define NO
Definition: acado_types.hpp:53
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
int main()
A user class for auto-generation of OCP solvers.
Definition: ocp_export.hpp:57
returnValue printDimensionsQP()
Definition: ocp_export.cpp:464
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31