powerkite.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00034 #include <acado_optimal_control.hpp>
00035 #include <acado_gnuplot.hpp>
00036 
00037 
00038 
00039 int main( ){
00040 
00041 
00042    USING_NAMESPACE_ACADO
00043 
00044 
00045 // DIFFERENTIAL STATES :
00046 // -------------------------
00047    DifferentialState      r;      //  the length r of the cable
00048    DifferentialState    phi;      //  the angle phi
00049    DifferentialState  theta;      //  the angle theta
00050 // -------------------------      //  -------------------------------------------
00051    DifferentialState     dr;      //  first  derivative of r0    with respect to t
00052    DifferentialState   dphi;      //  first  derivative of phi   with respect to t
00053    DifferentialState dtheta;      //  first  derivative of theta with respect to t
00054 // -------------------------      //  -------------------------------------------
00055    DifferentialState      n;      //  winding number
00056 // -------------------------      //  -------------------------------------------
00057    DifferentialState    Psi;      //  the roll angle Psi
00058    DifferentialState     CL;      //  the aerodynamic lift coefficient
00059 // -------------------------      //  -------------------------------------------
00060    DifferentialState      W;      //  integral over the power at the generator
00061                                   //  ( = ENERGY )
00062 
00063 
00064 // CONTROL :
00065 // -------------------------
00066    Control             ddr0;      //  second derivative of r0    with respect to t
00067    Control             dPsi;      //  first  derivative of Psi   with respect to t
00068    Control              dCL;      //  first  derivative of CL    with respect to t
00069 
00070 
00071 // PARAMETERS :
00072 // ------------------------
00073                                      //  PARAMETERS OF THE KITE :
00074                                      //  -----------------------------
00075    double         mk =  850.00;      //  mass of the kite               //  [ kg    ]
00076    double          A =  500.00;      //  effective area                 //  [ m^2   ]
00077    double          V =  720.00;      //  volume                         //  [ m^3   ]
00078    double        cd0 =    0.04;      //  aerodynamic drag coefficient   //  [       ]
00079                                      //  ( cd0: without downwash )
00080    double          K =    0.04;      //  induced drag constant          //  [       ]
00081 
00082 
00083                                      //   PHYSICAL CONSTANTS :
00084                                      //  -----------------------------
00085    double          g =    9.81;      //  gravitational constant         //  [ m /s^2]
00086    double        rho =    1.23;      //  density of the air             //  [ kg/m^3]
00087 
00088                                      //  PARAMETERS OF THE CABLE :
00089                                      //  -----------------------------
00090    double       rhoc = 1450.00;      //  density of the cable           //  [ kg/m^3]
00091    double         cc =    1.00;      //  frictional constant            //  [       ]
00092    double         dc = 0.05614;      //  diameter                       //  [ m     ]
00093 
00094 
00095                                      //  PARAMETERS OF THE WIND :
00096                                      //  -----------------------------
00097    double         w0 =   10.00;      //  wind velocity at altitude h0   //  [ m/s   ]
00098    double         h0 =  100.00;      //  the altitude h0                //  [ m     ]
00099    double         hr =    0.10;      //  roughness length               //  [ m     ]
00100 
00101 
00102 
00103 // OTHER VARIABLES :
00104 // ------------------------
00105 
00106    double AQ               ;      //  cross sectional area
00107 
00108    IntermediateState     mc;      //  mass of the cable
00109    IntermediateState     m ;      //  effective inertial mass
00110    IntermediateState     m_;      //  effective gravitational mass
00111 
00112    IntermediateState     Cg;
00113 
00114    IntermediateState     dm;      //  first  derivative of m     with respect to t
00115 
00116 
00117 // DEFINITION OF PI :
00118 // ------------------------
00119 
00120    double PI = 3.1415926535897932;
00121 
00122 
00123 // ORIENTATION AND FORCES :
00124 // ------------------------
00125 
00126    IntermediateState h               ;      //  altitude of the kite
00127    IntermediateState w               ;      //  the wind at altitude h
00128    IntermediateState we          [ 3];      //  effective wind vector
00129    IntermediateState nwe             ;      //  norm of the effective wind vector
00130    IntermediateState nwep            ;      //  -
00131    IntermediateState ewep        [ 3];      //  projection of ewe
00132    IntermediateState eta            ;      //  angle eta: cf. [2]
00133    IntermediateState et          [ 3];      //  unit vector from the left to the right wing tip
00134    IntermediateState Caer            ;
00135    IntermediateState Cf              ;      //  simple constants
00136    IntermediateState CD              ;      //  the aerodynamic drag coefficient
00137    IntermediateState Fg          [ 3];      //  the gravitational force
00138    IntermediateState Faer        [ 3];      //  the aerodynamic force
00139    IntermediateState Ff          [ 3];      //  the frictional force
00140    IntermediateState F           [ 3];      //  the total force
00141 
00142 
00143 // TERMS ON RIGHT-HAND-SIDE
00144 // OF THE DIFFERENTIAL
00145 // EQUATIONS              :
00146 // ------------------------
00147 
00148    IntermediateState a_pseudo    [ 3];      //  the pseudo accelaration
00149    IntermediateState dn              ;      //  the time derivate of the kite's winding number
00150    IntermediateState ddr             ;      //  second derivative of s     with respect to t
00151    IntermediateState ddphi           ;      //  second derivative of phi   with respect to t
00152    IntermediateState ddtheta         ;      //  second derivative of theta with respect to t
00153    IntermediateState power           ;      //  the power at the generator
00154 // ------------------------                 //  ----------------------------------------------
00155    IntermediateState regularisation  ;      //  regularisation of controls
00156 
00157 
00158 
00159 //                        MODEL EQUATIONS :
00160 // ===============================================================
00161 
00162 
00163 
00164 // CROSS AREA OF THE CABLE :
00165 // ---------------------------------------------------------------
00166 
00167    AQ      =  PI*dc*dc/4.0                                       ;
00168 
00169 // THE EFECTIVE MASS' :
00170 // ---------------------------------------------------------------
00171 
00172    mc      =  rhoc*AQ*r        ;   // mass of the cable
00173    m       =  mk + mc     / 3.0;   // effective inertial mass
00174    m_      =  mk + mc     / 2.0;   // effective gravitational mass
00175 // -----------------------------   // ----------------------------
00176    dm      =  (rhoc*AQ/ 3.0)*dr;   // time derivative of the mass
00177 
00178 
00179 // WIND SHEAR MODEL :
00180 // ---------------------------------------------------------------
00181 
00182    h       =  r*cos(theta)                                       ;
00183    w       =  log(h/hr) / log(h0/hr) *w0                         ;
00184 
00185 
00186 // EFFECTIVE WIND IN THE KITE`S SYSTEM :
00187 // ---------------------------------------------------------------
00188 
00189    we[0]   =  w*sin(theta)*cos(phi) -              dr    ;
00190    we[1]   = -w*sin(phi)            - r*sin(theta)*dphi  ;
00191    we[2]   = -w*cos(theta)*cos(phi) + r           *dtheta;
00192 
00193 
00194 // CALCULATION OF THE KITE`S TRANSVERSAL AXIS :
00195 // ---------------------------------------------------------------
00196 
00197    nwep    =  pow(                we[1]*we[1] + we[2]*we[2], 0.5 );
00198    nwe     =  pow(  we[0]*we[0] + we[1]*we[1] + we[2]*we[2], 0.5 );
00199    eta     =  asin( we[0]*tan(Psi)/ nwep )                       ;
00200 
00201 // ---------------------------------------------------------------
00202 
00203 // ewep[0] =  0.0                                                ;
00204    ewep[1] =  we[1] / nwep                                       ;
00205    ewep[2] =  we[2] / nwep                                       ;
00206 
00207 // ---------------------------------------------------------------
00208 
00209    et  [0] =  sin(Psi)                                                  ;
00210    et  [1] =  (-cos(Psi)*sin(eta))*ewep[1] - (cos(Psi)*cos(eta))*ewep[2];
00211    et  [2] =  (-cos(Psi)*sin(eta))*ewep[2] + (cos(Psi)*cos(eta))*ewep[1];
00212 
00213 
00214 
00215 
00216 // CONSTANTS FOR SEVERAL FORCES :
00217 // ---------------------------------------------------------------
00218 
00219    Cg      =  (V*rho-m_)*g                                       ;
00220    Caer    =  (rho*A/2.0 )*nwe                                   ;
00221    Cf      =  (rho*dc/8.0)*r*nwe                                 ;
00222 
00223 
00224 // THE DRAG-COEFFICIENT :
00225 // ---------------------------------------------------------------
00226 
00227    CD      =  cd0 + K*CL*CL                                      ;
00228 
00229 
00230 
00231 // SUM OF GRAVITATIONAL AND LIFTING FORCE :
00232 // ---------------------------------------------------------------
00233 
00234    Fg  [0] =  Cg  *  cos(theta)                                  ;
00235 // Fg  [1] =  Cg  *  0.0                                         ;
00236    Fg  [2] =  Cg  *  sin(theta)                                  ;
00237 
00238 
00239 // SUM OF THE AERODYNAMIC FORCES :
00240 // ---------------------------------------------------------------
00241 
00242    Faer[0] =  Caer*( CL*(we[1]*et[2]-we[2]*et[1]) + CD*we[0] )   ;
00243    Faer[1] =  Caer*( CL*(we[2]*et[0]-we[0]*et[2]) + CD*we[1] )   ;
00244    Faer[2] =  Caer*( CL*(we[0]*et[1]-we[1]*et[0]) + CD*we[2] )   ;
00245 
00246 
00247 // THE FRICTION OF THE CABLE :
00248 // ---------------------------------------------------------------
00249 
00250 // Ff  [0] =  Cf  *  cc* we[0]                                   ;
00251    Ff  [1] =  Cf  *  cc* we[1]                                   ;
00252    Ff  [2] =  Cf  *  cc* we[2]                                   ;
00253 
00254 
00255 
00256 // THE TOTAL FORCE :
00257 // ---------------------------------------------------------------
00258 
00259    F   [0] = Fg[0] + Faer[0]                                     ;
00260    F   [1] =         Faer[1] + Ff[1]                             ;
00261    F   [2] = Fg[2] + Faer[2] + Ff[2]                             ;
00262 
00263 
00264 
00265 // THE PSEUDO ACCELERATION:
00266 // ---------------------------------------------------------------
00267 
00268    a_pseudo [0] =  - ddr0
00269                    + r*(                         dtheta*dtheta
00270                          + sin(theta)*sin(theta)*dphi  *dphi   )
00271                    - dm/m*dr                                     ;
00272 
00273    a_pseudo [1] =  - 2.0*cos(theta)/sin(theta)*dphi*dtheta
00274                    - 2.0*dr/r*dphi
00275                    - dm/m*dphi                                   ;
00276 
00277    a_pseudo [2] =    cos(theta)*sin(theta)*dphi*dphi
00278                    - 2.0*dr/r*dtheta
00279                    - dm/m*dtheta                                 ;
00280 
00281 
00282 
00283 
00284 // THE EQUATIONS OF MOTION:
00285 // ---------------------------------------------------------------
00286 
00287    ddr          =  F[0]/m                + a_pseudo[0]           ;
00288    ddphi        =  F[1]/(m*r*sin(theta)) + a_pseudo[1]           ;
00289    ddtheta      = -F[2]/(m*r           ) + a_pseudo[2]           ;
00290 
00291 
00292 
00293 
00294 
00295 // THE DERIVATIVE OF THE WINDING NUMBER :
00296 // ---------------------------------------------------------------
00297 
00298    dn           =  (        dphi*ddtheta - dtheta*ddphi     ) /
00299                    (2.0*PI*(dphi*dphi    + dtheta*dtheta)   )      ;
00300 
00301 
00302 
00303 // THE POWER AT THE GENERATOR :
00304 // ---------------------------------------------------------------
00305 
00306    power        =   m*ddr*dr                                     ;
00307 
00308 
00309 
00310 // REGULARISATION TERMS :
00311 // ---------------------------------------------------------------
00312 
00313 
00314    regularisation =    5.0e2 * ddr0    * ddr0
00315                      + 1.0e8 * dPsi    * dPsi
00316                      + 1.0e5 * dCL     * dCL
00317                      + 2.5e5 * dn      * dn
00318                      + 2.5e7 * ddphi   * ddphi;
00319                      + 2.5e7 * ddtheta * ddtheta;
00320                      + 2.5e6 * dtheta  * dtheta;
00321 //                   ---------------------------
00322 
00323 
00324 
00325 // THE "RIGHT-HAND-SIDE" OF THE ODE:
00326 // ---------------------------------------------------------------
00327    DifferentialEquation f;
00328 
00329    f  << dot(r)      ==  dr                             ;
00330    f  << dot(phi)    ==  dphi                           ;
00331    f  << dot(theta)  ==  dtheta                         ;
00332    f  << dot(dr)     ==  ddr0                           ;
00333    f  << dot(dphi)   ==  ddphi                          ;
00334    f  << dot(dtheta) ==  ddtheta                        ;
00335    f  << dot(n)      ==  dn                             ;
00336    f  << dot(Psi)    ==  dPsi                           ;
00337    f  << dot(CL)     ==  dCL                            ;
00338    f  << dot(W)      == (-power + regularisation)*1.0e-6;
00339 
00340 
00341     // DEFINE AN OPTIMAL CONTROL PROBLEM:
00342     // ----------------------------------
00343     OCP ocp( 0.0, 18.0, 18 );
00344     ocp.minimizeMayerTerm( W );
00345     ocp.subjectTo( f );
00346 
00347 
00348     // INITIAL VALUE CONSTRAINTS:
00349     // ---------------------------------
00350     ocp.subjectTo( AT_START, n == 0.0 );
00351     ocp.subjectTo( AT_START, W == 0.0 );
00352 
00353 
00354     // PERIODIC BOUNDARY CONSTRAINTS:
00355     // ----------------------------------------
00356     ocp.subjectTo( 0.0, r     , -r     , 0.0 );
00357     ocp.subjectTo( 0.0, phi   , -phi   , 0.0 );
00358     ocp.subjectTo( 0.0, theta , -theta , 0.0 );
00359     ocp.subjectTo( 0.0, dr    , -dr    , 0.0 );
00360     ocp.subjectTo( 0.0, dphi  , -dphi  , 0.0 );
00361     ocp.subjectTo( 0.0, dtheta, -dtheta, 0.0 );
00362     ocp.subjectTo( 0.0, Psi   , -Psi   , 0.0 );
00363     ocp.subjectTo( 0.0, CL    , -CL    , 0.0 );
00364 
00365     ocp.subjectTo( -0.34   <= phi   <= 0.34   );
00366     ocp.subjectTo(  0.85   <= theta <= 1.45   );
00367     ocp.subjectTo( -40.0   <= dr    <= 10.0   );
00368     ocp.subjectTo( -0.29   <= Psi   <= 0.29   );
00369     ocp.subjectTo(  0.1    <= CL    <= 1.50   );
00370     ocp.subjectTo( -0.7    <= n     <= 0.90   );
00371     ocp.subjectTo( -25.0   <= ddr0  <= 25.0   );
00372     ocp.subjectTo( -0.065  <= dPsi  <= 0.065  );
00373     ocp.subjectTo( -3.5    <= dCL   <= 3.5    );
00374 
00375 
00376     // CREATE A PLOT WINDOW AND VISUALIZE THE RESULT:
00377     // ----------------------------------------------
00378 
00379     GnuplotWindow window;
00380     window.addSubplot( r,    "CABLE LENGTH  r [m]" );
00381     window.addSubplot( phi,  "POSITION ANGLE  phi [rad]" );
00382     window.addSubplot( theta,"POSITION ANGLE theta [rad]" );
00383     window.addSubplot( Psi,  "ROLL ANGLE  psi [rad]" );
00384     window.addSubplot( CL,   "LIFT COEFFICIENT  CL" );
00385     window.addSubplot( W,    "ENERGY  W [MJ]" );
00386         window.addSubplot( F[0], "FORCE IN CABLE [N]" );
00387         window.addSubplot( phi,theta, "Kite Orbit","theta [rad]","phi [rad]" );
00388 
00389     // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
00390     // ---------------------------------------------------
00391 
00392     OptimizationAlgorithm algorithm(ocp);
00393 
00394     algorithm.initializeDifferentialStates("powerkite_states.txt"    );
00395     algorithm.initializeControls          ("powerkite_controls.txt"  );
00396     algorithm.set                         ( MAX_NUM_ITERATIONS, 100  );
00397     algorithm.set                         ( KKT_TOLERANCE    , 1e-2 );
00398 
00399     algorithm << window;
00400 
00401     algorithm.set( PRINT_SCP_METHOD_PROFILE, YES );
00402 
00403     algorithm.solve();
00404     return 0;
00405 }
00406 
00407 
00408 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:49