pendulum_dae_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 
27 
29 
30 int main(int argc, char * const argv[ ])
31 {
32  //
33  // Variables
34  //
35 
36  DifferentialState x, y, w, dx, dy, dw;
37  AlgebraicState mu;
38  Control F;
39 
40  IntermediateState c, dc;
41 
42  const double m = 1.0;
43  const double mc = 1.0;
44  const double L = 1.0;
45  const double g = 9.81;
46  const double p = 5.0;
47 
48  c = 0.5 * ((x - w) * (x - w) + y * y - L * L);
49  dc = dy * y + (dw - dx) * (w - x);
50 
51  //
52  // Differential algebraic equation
53  //
54 
56 
57  f << 0 == dot( x ) - dx;
58  f << 0 == dot( y ) - dy;
59  f << 0 == dot( w ) - dw;
60 
61  f << 0 == m * dot( dx ) + (x - w) * mu;
62  f << 0 == m * dot( dy ) + y * mu + m * g;
63  f << 0 == mc * dot( dw ) + (w - x) * mu - F;
64 
65  f << 0 == (x - w) * dot( dx ) + y * dot( dy ) + (w - x) * dot( dw )
66  - (-p * p * c - 2 * p * dc - dy * dy - (dw - dx) * (dw - dx));
67 
68  //
69  // Weighting matrices and reference functions
70  //
71 
72  Function rf;
73  Function rfN;
74 
75  rf << x << y << w << dx << dy << dw << F;
76  rfN << x << y << w << dx << dy << dw;
77 
78  DMatrix W = eye<double>( rf.getDim() );
79  DMatrix WN = eye<double>( rfN.getDim() ) * 10;
80 
81  //
82  // Optimal Control Problem
83  //
84 
85  const int N = 10;
86  const int Ni = 4;
87  const double Ts = 0.1;
88 
89  OCP ocp(0, N * Ts, N);
90 
91  ocp.subjectTo( f );
92 
93  ocp.minimizeLSQ(W, rf);
94  ocp.minimizeLSQEndTerm(WN, rfN);
95 
96  ocp.subjectTo(-20 <= F <= 20);
97 // ocp.subjectTo( -5 <= x <= 5 );
98 
99  //
100  // Export the code:
101  //
102  OCPexport mpc( ocp );
103 
106 
108  mpc.set(NUM_INTEGRATOR_STEPS, N * Ni);
109 
111 // mpc.set(SPARSE_QP_SOLUTION, CONDENSING);
112  mpc.set(QP_SOLVER, QP_QPOASES);
113 // mpc.set(MAX_NUM_QP_ITERATIONS, 20);
114  mpc.set(HOTSTART_QP, YES);
115 
116 // mpc.set(SPARSE_QP_SOLUTION, SPARSE_SOLVER);
117 // mpc.set(QP_SOLVER, QP_FORCES);
118 
119 // mpc.set(LEVENBERG_MARQUARDT, 1.0e-10);
120 
121  mpc.set(GENERATE_TEST_FILE, NO);
122  mpc.set(GENERATE_MAKE_FILE, NO);
124 
125 // mpc.set(USE_SINGLE_PRECISION, YES);
126 // mpc.set(CG_USE_OPENMP, YES);
127 
128  if (mpc.exportCode( "pendulum_dae_nmpc_export" ) != SUCCESSFUL_RETURN)
129  exit( EXIT_FAILURE );
130 
131  mpc.printDimensionsQP( );
132 
133  return EXIT_SUCCESS;
134 }
#define N
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
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
#define NO
Definition: acado_types.hpp:53
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
#define L
A user class for auto-generation of OCP solvers.
Definition: ocp_export.hpp:57
returnValue printDimensionsQP()
Definition: ocp_export.cpp:464
USING_NAMESPACE_ACADO int main(int argc, char *const argv[])
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:58