examples/code_generation/mpc_mhe/getting_started.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 
33 
34 int main( )
35 {
37 
38  // Variables:
39  DifferentialState p ; // the trolley position
40  DifferentialState v ; // the trolley velocity
41  DifferentialState phi ; // the excitation angle
42  DifferentialState omega; // the angular velocity
43  Control a ; // the acc. of the trolley
44 
45  const double g = 9.81; // the gravitational constant
46  const double b = 0.20; // the friction coefficient
47 
48  // Model equations:
50 
51  f << dot( p ) == v;
52  f << dot( v ) == a;
53  f << dot( phi ) == omega;
54  f << dot( omega ) == -g * sin(phi) - a * cos(phi) - b * omega;
55 
56  // Reference functions and weighting matrices:
57  Function h, hN;
58  h << p << v << phi << omega << a;
59  hN << p << v << phi << omega;
60 
61  // Provide defined weighting matrices:
62  DMatrix W = eye<double>( h.getDim() );
63  DMatrix WN = eye<double>( hN.getDim() );
64  WN *= 5;
65 
66  // Or provide sparsity patterns for the weighting matrices
67 // BMatrix W = eye<bool>( h.getDim() );
68 // BMatrix WN = eye<bool>( hN.getDim() );
69 
70  //
71  // Optimal Control Problem
72  //
73  OCP ocp(0.0, 3.0, 10);
74 
75  ocp.subjectTo( f );
76 
77  ocp.minimizeLSQ(W, h);
78  ocp.minimizeLSQEndTerm(WN, hN);
79 
80  ocp.subjectTo( -1.0 <= a <= 1.0 );
81  ocp.subjectTo( -0.5 <= v <= 1.5 );
82 
83  // Export the code:
84  OCPexport mpc( ocp );
85 
88  mpc.set( INTEGRATOR_TYPE, INT_RK4 );
89  mpc.set( NUM_INTEGRATOR_STEPS, 30 );
90 
91  mpc.set( QP_SOLVER, QP_QPOASES );
92 // mpc.set( HOTSTART_QP, YES );
93 // mpc.set( LEVENBERG_MARQUARDT, 1.0e-4 );
94  mpc.set( GENERATE_TEST_FILE, YES );
95  mpc.set( GENERATE_MAKE_FILE, YES );
98 
99 // mpc.set( USE_SINGLE_PRECISION, YES );
100 
101  if (mpc.exportCode( "getting_started_export" ) != SUCCESSFUL_RETURN)
102  exit( EXIT_FAILURE );
103 
104  mpc.printDimensionsQP( );
105 
106  return EXIT_SUCCESS;
107 }
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
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
IntermediateState cos(const Expression &arg)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue minimizeLSQ(const DMatrix &S, const Function &h, const DVector &r)
Definition: ocp.cpp:244
#define YES
Definition: acado_types.hpp:51
returnValue minimizeLSQEndTerm(const DMatrix &S, const Function &m, const DVector &r)
Definition: ocp.cpp:297
int getDim() const
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
Expression dot(const Expression &arg)
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:39