Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00046
00047 DifferentialState r;
00048 DifferentialState phi;
00049 DifferentialState theta;
00050
00051 DifferentialState dr;
00052 DifferentialState dphi;
00053 DifferentialState dtheta;
00054
00055 DifferentialState n;
00056
00057 DifferentialState Psi;
00058 DifferentialState CL;
00059
00060 DifferentialState W;
00061
00062
00063
00064
00065
00066 Control ddr0;
00067 Control dPsi;
00068 Control dCL;
00069
00070
00071
00072
00073
00074
00075 double mk = 850.00;
00076 double A = 500.00;
00077 double V = 720.00;
00078 double cd0 = 0.04;
00079
00080 double K = 0.04;
00081
00082
00083
00084
00085 double g = 9.81;
00086 double rho = 1.23;
00087
00088
00089
00090 double rhoc = 1450.00;
00091 double cc = 1.00;
00092 double dc = 0.05614;
00093
00094
00095
00096
00097 double w0 = 10.00;
00098 double h0 = 100.00;
00099 double hr = 0.10;
00100
00101
00102
00103
00104
00105
00106 double AQ ;
00107
00108 IntermediateState mc;
00109 IntermediateState m ;
00110 IntermediateState m_;
00111
00112 IntermediateState Cg;
00113
00114 IntermediateState dm;
00115
00116
00117
00118
00119
00120 double PI = 3.1415926535897932;
00121
00122
00123
00124
00125
00126 IntermediateState h ;
00127 IntermediateState w ;
00128 IntermediateState we [ 3];
00129 IntermediateState nwe ;
00130 IntermediateState nwep ;
00131 IntermediateState ewep [ 3];
00132 IntermediateState eta ;
00133 IntermediateState et [ 3];
00134 IntermediateState Caer ;
00135 IntermediateState Cf ;
00136 IntermediateState CD ;
00137 IntermediateState Fg [ 3];
00138 IntermediateState Faer [ 3];
00139 IntermediateState Ff [ 3];
00140 IntermediateState F [ 3];
00141
00142
00143
00144
00145
00146
00147
00148 IntermediateState a_pseudo [ 3];
00149 IntermediateState dn ;
00150 IntermediateState ddr ;
00151 IntermediateState ddphi ;
00152 IntermediateState ddtheta ;
00153 IntermediateState power ;
00154
00155 IntermediateState regularisation ;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 AQ = PI*dc*dc/4.0 ;
00168
00169
00170
00171
00172 mc = rhoc*AQ*r ;
00173 m = mk + mc / 3.0;
00174 m_ = mk + mc / 2.0;
00175
00176 dm = (rhoc*AQ/ 3.0)*dr;
00177
00178
00179
00180
00181
00182 h = r*cos(theta) ;
00183 w = log(h/hr) / log(h0/hr) *w0 ;
00184
00185
00186
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
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
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
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
00225
00226
00227 CD = cd0 + K*CL*CL ;
00228
00229
00230
00231
00232
00233
00234 Fg [0] = Cg * cos(theta) ;
00235
00236 Fg [2] = Cg * sin(theta) ;
00237
00238
00239
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
00248
00249
00250
00251 Ff [1] = Cf * cc* we[1] ;
00252 Ff [2] = Cf * cc* we[2] ;
00253
00254
00255
00256
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
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
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
00296
00297
00298 dn = ( dphi*ddtheta - dtheta*ddphi ) /
00299 (2.0*PI*(dphi*dphi + dtheta*dtheta) ) ;
00300
00301
00302
00303
00304
00305
00306 power = m*ddr*dr ;
00307
00308
00309
00310
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
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
00342
00343 OCP ocp( 0.0, 18.0, 18 );
00344 ocp.minimizeMayerTerm( W );
00345 ocp.subjectTo( f );
00346
00347
00348
00349
00350 ocp.subjectTo( AT_START, n == 0.0 );
00351 ocp.subjectTo( AT_START, W == 0.0 );
00352
00353
00354
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
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
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