kite_carousel.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:
40  DifferentialState theta;
41  DifferentialState dphi;
42  DifferentialState dtheta;
43 
44  Control u1;
45  Control u2;
46 
47  IntermediateState c;// c := rho * |we|^2 / (2*m)
48  DifferentialEquation f;// the right-hand side of the model
49 
50  // Parameters:
51  const double R = 1.00;// radius of the carousel arm
52  const double Omega = 1.00;// constant rotational velocity of the carousel arm
53  const double m = 0.80;// the mass of the plane
54  const double r = 1.00;// length of the cable between arm and plane
55  const double A = 0.15;// wing area of the plane
56 
57  const double rho = 1.20;// density of the air
58  const double CL = 1.00;// nominal lift coefficient
59  const double CD = 0.15;// nominal drag coefficient
60  const double b = 15.00;// roll stabilization coefficient
61  const double g = 9.81;// gravitational constant
62 
63  // COMPUTE THE CONSTANT c:
64  // -------------------------
65  c = ( (R*R*Omega*Omega)
66  + (r*r)*( (Omega+dphi)*(Omega+dphi) + dtheta*dtheta )
67  + (2.0*r*R*Omega)*( (Omega+dphi)*sin(theta)*cos(phi)
68  + dtheta*cos(theta)*sin(phi) ) ) * ( A*rho/( 2.0*m ) );
69 
70  f << dot( phi ) == dphi;
71  f << dot( theta ) == dtheta;
72 
73  f << dot( dphi ) == ( 2.0*r*(Omega+dphi)*dtheta*cos(theta)
74  + (R*Omega*Omega)*sin(phi)
75  + c*(CD*(1.0+u2)+CL*(1.0+0.5*u2)*phi) ) / (-r*sin(theta));
76 
77  f << dot( dtheta ) == ( (R*Omega*Omega)*cos(theta)*cos(phi)
78  + r*(Omega+dphi)*sin(theta)*cos(theta)
79  + g*sin(theta) - c*( CL*u1 + b*dtheta ) ) / r;
80 
81  // Reference functions and weighting matrices:
82  Function h, hN;
83  h << phi << theta << dphi << dtheta << u1 << u2;
84  hN << phi << theta << dphi << dtheta;
85 
86  DMatrix W = eye<double>( h.getDim() );
87  DMatrix WN = eye<double>( hN.getDim() );
88 
89  W(0,0) = 5.000;
90  W(1,1) = 1.000;
91  W(2,2) = 10.000;
92  W(3,3) = 10.000;
93  W(4,4) = 0.1;
94  W(5,5) = 0.1;
95 
96  WN(0,0) = 1.0584373059248833e+01;
97  WN(0,1) = 1.2682415889087276e-01;
98  WN(0,2) = 1.2922232012424681e+00;
99  WN(0,3) = 3.7982078044271374e-02;
100  WN(1,0) = 1.2682415889087265e-01;
101  WN(1,1) = 3.2598407653299275e+00;
102  WN(1,2) = -1.1779732282636639e-01;
103  WN(1,3) = 9.8830655348904548e-02;
104  WN(2,0) = 1.2922232012424684e+00;
105  WN(2,1) = -1.1779732282636640e-01;
106  WN(2,2) = 4.3662024133354898e+00;
107  WN(2,3) = -5.9269992411260908e-02;
108  WN(3,0) = 3.7982078044271367e-02;
109  WN(3,1) = 9.8830655348904534e-02;
110  WN(3,2) = -5.9269992411260901e-02;
111  WN(3,3) = 3.6495564367004318e-01;
112 
113  //
114  // Optimal Control Problem
115  //
116 
117 // OCP ocp( 0.0, 12.0, 15 );
118  OCP ocp( 0.0, 2.0 * M_PI, 10 );
119 
120  ocp.subjectTo( f );
121 
122  ocp.minimizeLSQ(W, h);
123  ocp.minimizeLSQEndTerm(WN, hN);
124 
125  ocp.subjectTo( 18.0 <= u1 <= 22.0 );
126  ocp.subjectTo( -0.2 <= u2 <= 0.2 );
127 
128  // Export the code:
129  OCPexport mpc(ocp);
130 
131  mpc.set( INTEGRATOR_TYPE , INT_RK4 );
132  mpc.set( NUM_INTEGRATOR_STEPS , 30 );
134  mpc.set( HOTSTART_QP, YES );
135  mpc.set( GENERATE_TEST_FILE, NO );
136 
137  if (mpc.exportCode("kite_carousel_export") != SUCCESSFUL_RETURN)
138  exit( EXIT_FAILURE );
139 
140  mpc.printDimensionsQP( );
141 
142 // DifferentialState Gx(4,4), Gu(4,2);
143 //
144 // Expression rhs;
145 // f.getExpression( rhs );
146 //
147 // Function Df;
148 // Df << rhs;
149 // Df << forwardDerivative( rhs, x ) * Gx;
150 // Df << forwardDerivative( rhs, x ) * Gu + forwardDerivative( rhs, u );
151 //
152 //
153 // EvaluationPoint z(Df);
154 //
155 // DVector xx(28);
156 // xx.setZero();
157 //
158 // xx(0) = -4.2155955213988627e-02;
159 // xx(1) = 1.8015724412870739e+00;
160 // xx(2) = 0.0;
161 // xx(3) = 0.0;
162 //
163 // DVector uu(2);
164 // uu(0) = 20.5;
165 // uu(1) = -0.1;
166 //
167 // z.setX( xx );
168 // z.setU( uu );
169 //
170 // DVector result = Df.evaluate( z );
171 // result.print( "x" );
172 
173  return EXIT_SUCCESS;
174 }
175 
176 
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 M_PI
Definition: acado_utils.hpp:54
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)
A user class for auto-generation of OCP solvers.
Definition: ocp_export.hpp:57
returnValue printDimensionsQP()
Definition: ocp_export.cpp:464
#define R
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:46