crane_kul_mhe.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( void )
31 {
32  //
33  // OCP parameters
34  //
35  // Sampling time
36  double Ts = 0.01;
37  // Number of shootin' intervals
38  int N = 20;
39  // Number of integrator steps per shootin' interval
40  int Ni = 1;
41 
42  //
43  // DEFINE THE VARIABLES
44  //
45  DifferentialState xT; // the trolley position
46  DifferentialState vT; // the trolley velocity
47  IntermediateState aT; // the trolley acceleration
48 
49  DifferentialState xL; // the cable length
50  DifferentialState vL; // the cable velocity
51  IntermediateState aL; // the cable acceleration
52 
53  DifferentialState phi; // the angle
54  DifferentialState omega; // the angular velocity
55 
56  DifferentialState uT; // trolley velocity control
57  DifferentialState uL; // cable velocity control
58 
59  Control duT; // trolley accel control
60  Control duL; // cable accel control
61 
62  //
63  // DEFINE THE MODEL PARAMETERS
64  //
65  const double tau1 = 0.012790605943772;
66  const double a1 = 0.047418203070092;
67  const double tau2 = 0.024695192379264;
68  const double a2 = 0.034087337273386;
69  const double g = 9.81;
70 // const double c = 0.0;
71 // const double m = 1.3180;
72 
73  //
74  // DEFINE THE MODEL EQUATIONS
75  //
77  aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
78  aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
79 
80  f << dot(xT) == vT;
81  f << dot(vT) == aT;
82  f << dot(xL) == vL;
83  f << dot(vL) == aL;
84  f << dot(phi) == omega;
85  f << dot(omega)
86  == -(g * sin(phi) + a1 * duT * cos(phi) + 2 * vL * omega) / xL;
87  f << dot(uT) == duT;
88  f << dot(uL) == duL;
89 
90  //
91  // MHE PROBLEM FORMULATION
92  //
93  OCP ocp(0.0, N * Ts, N);
94 
95  ocp.subjectTo( f );
96 
97  // Measurement function h(x, u) on first N nodes
98  Function h;
99 
100  h << xT << xL << phi << uT << uL << duT << duL;
101 
102  // Weighting matrices and measurement functions
103  DMatrix W = eye<double>( 7 );
104 // W(0,0) = 16.5;
105 // W(1,1) = 23.9;
106 // W(2,2) = 25.1;
107 // W(3,3) = 12.1;
108 // W(4,4) = 119.4;
109 // W(5,5) = 45.0;
110 // W(6,6) = 1.2;
111 // W(7,7) = 0.4;
112 
113  Function hN;
114  hN << xT << xL << phi << uT << uL;
115 
116  DMatrix WN = eye<double>( 5 );
117  WN(0, 0) = W(0, 0);
118  WN(1, 1) = W(1, 1);
119  WN(2, 2) = W(2, 2);
120  WN(3, 3) = W(3, 3);
121  WN(4, 4) = W(4, 4);
122 
123  ocp.minimizeLSQ(W, h);
124  ocp.minimizeLSQEndTerm(WN, hN);
125 
126  OCPexport mhe( ocp );
127 
129  mhe.set(NUM_INTEGRATOR_STEPS, N * Ni);
130 
133 
134  mhe.set(HOTSTART_QP, YES);
135 
136  // NOTE: This is crucial for export of MHE!
138  mhe.set(FIX_INITIAL_STATE, NO);
139 
140 // mhe.set( LEVENBERG_MARQUARDT, 1e-10 );
141 
142  if (mhe.exportCode("crane_kul_mhe_export") != SUCCESSFUL_RETURN)
143  exit( EXIT_FAILURE );
144 
145  mhe.printDimensionsQP( );
146 
147  return EXIT_SUCCESS;
148 }
#define N
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
#define NO
Definition: acado_types.hpp:53
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
USING_NAMESPACE_ACADO int main(void)
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