1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 3 Header: FGInitialCondition.h 4 Author: Tony Peden 5 Date started: 7/1/99 6 7 --------- Copyright (C) 1999 Anthony K. Peden (apeden@earthlink.net) --------- 8 9 This program is free software; you can redistribute it and/or modify it under 10 the terms of the GNU Lesser General Public License as published by the Free 11 Software Foundation; either version 2 of the License, or (at your option) any 12 later version. 13 14 This program is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 details. 18 19 You should have received a copy of the GNU Lesser General Public License along 20 with this program; if not, write to the Free Software Foundation, Inc., 59 21 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 23 Further information about the GNU Lesser General Public License can also be 24 found on the world wide web at http://www.gnu.org. 25 26 HISTORY 27 -------------------------------------------------------------------------------- 28 7/1/99 TP Created 29 30 FUNCTIONAL DESCRIPTION 31 -------------------------------------------------------------------------------- 32 33 The purpose of this class is to take a set of initial conditions and provide a 34 kinematically consistent set of body axis velocity components, euler angles, and 35 altitude. This class does not attempt to trim the model i.e. the sim will most 36 likely start in a very dynamic state (unless, of course, you have chosen your 37 IC's wisely) even after setting it up with this class. 38 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 SENTRY 41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 42 43 #ifndef FGINITIALCONDITION_H 44 #define FGINITIALCONDITION_H 45 46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 47 INCLUDES 48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 49 50 #include "math/FGLocation.h" 51 #include "math/FGQuaternion.h" 52 #include "simgear/misc/sg_path.hxx" 53 54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 55 FORWARD DECLARATIONS 56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 57 58 namespace JSBSim { 59 60 class FGFDMExec; 61 class FGMatrix33; 62 class FGColumnVector3; 63 class FGAtmosphere; 64 class FGAircraft; 65 class FGPropertyManager; 66 class Element; 67 68 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset; 69 typedef enum { setasl, setagl } altitudeset; 70 typedef enum { setgeoc, setgeod } latitudeset; 71 72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 73 CLASS DOCUMENTATION 74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 75 76 /** Initializes the simulation run. 77 Takes a set of initial conditions (IC) and provide a kinematically 78 consistent set of body axis velocity components, euler angles, and altitude. 79 This class does not attempt to trim the model i.e. the sim will most likely 80 start in a very dynamic state (unless, of course, you have chosen your IC's 81 wisely, or started on the ground) even after setting it up with this class. 82 83 <h3>Usage Notes</h3> 84 85 With a valid object of FGFDMExec and an aircraft model loaded: 86 87 @code 88 FGInitialCondition* fgic = FDMExec->GetIC(); 89 90 // Reset the initial conditions and set VCAS and altitude 91 fgic->InitializeIC(); 92 fgic->SetVcalibratedKtsIC(vcas); 93 fgic->SetAltitudeAGLFtIC(altitude); 94 95 // directly into Run 96 FDMExec->GetPropagate()->SetInitialState(fgic); 97 delete fgic; 98 FDMExec->Run(); 99 100 //or to loop the sim w/o integrating 101 FDMExec->RunIC(); 102 @endcode 103 104 Alternatively, you can load initial conditions from an XML file: 105 106 @code 107 FGInitialCondition* fgic = FDMExec->GetIC(); 108 fgic->Load(IC_file); 109 @endcode 110 111 <h3>Speed</h3> 112 113 Since vc, ve, vt, and mach all represent speed, the remaining 114 three are recalculated each time one of them is set (using the 115 current altitude). The most recent speed set is remembered so 116 that if and when altitude is reset, the last set speed is used 117 to recalculate the remaining three. Setting any of the body 118 components forces a recalculation of vt and vt then becomes the 119 most recent speed set. 120 121 <h3>Alpha,Gamma, and Theta</h3> 122 123 This class assumes that it will be used to set up the sim for a 124 steady, zero pitch rate condition. Since any two of those angles 125 specifies the third gamma (flight path angle) is favored when setting 126 alpha and theta and alpha is favored when setting gamma. i.e. 127 128 - set alpha : recalculate theta using gamma as currently set 129 - set theta : recalculate alpha using gamma as currently set 130 - set gamma : recalculate theta using alpha as currently set 131 132 The idea being that gamma is most interesting to pilots (since it 133 is indicative of climb rate). 134 135 Setting climb rate is, for the purpose of this discussion, 136 considered equivalent to setting gamma. 137 138 These are the items that can be set in an initialization file: 139 140 - ubody (velocity, ft/sec) 141 - vbody (velocity, ft/sec) 142 - wbody (velocity, ft/sec) 143 - vnorth (velocity, ft/sec) 144 - veast (velocity, ft/sec) 145 - vdown (velocity, ft/sec) 146 - latitude (position, degrees) 147 - longitude (position, degrees) 148 - phi (orientation, degrees) 149 - theta (orientation, degrees) 150 - psi (orientation, degrees) 151 - alpha (angle, degrees) 152 - beta (angle, degrees) 153 - gamma (angle, degrees) 154 - roc (vertical velocity, ft/sec) 155 - elevation (local terrain elevation, ft) 156 - altitude (altitude AGL, ft) 157 - altitudeAGL (altitude AGL, ft) 158 - altitudeMSL (altitude MSL, ft) 159 - winddir (wind from-angle, degrees) 160 - vwind (magnitude wind speed, ft/sec) 161 - hwind (headwind speed, knots) 162 - xwind (crosswind speed, knots) 163 - vc (calibrated airspeed, ft/sec) 164 - mach (mach) 165 - vground (ground speed, ft/sec) 166 - trim (0 for no trim, 1 for ground trim, 'Longitudinal', 'Full', 'Ground', 'Pullup', 'Custom', 'Turn') 167 - running (-1 for all engines, 0 ... n-1 for specific engines) 168 169 <h3>Properties</h3> 170 @property ic/vc-kts (read/write) Calibrated airspeed initial condition in knots 171 @property ic/ve-kts (read/write) Knots equivalent airspeed initial condition 172 @property ic/vg-kts (read/write) Ground speed initial condition in knots 173 @property ic/vt-kts (read/write) True airspeed initial condition in knots 174 @property ic/mach (read/write) Mach initial condition 175 @property ic/roc-fpm (read/write) Rate of climb initial condition in feet/minute 176 @property ic/gamma-deg (read/write) Flightpath angle initial condition in degrees 177 @property ic/alpha-deg (read/write) Angle of attack initial condition in degrees 178 @property ic/beta-deg (read/write) Angle of sideslip initial condition in degrees 179 @property ic/theta-deg (read/write) Pitch angle initial condition in degrees 180 @property ic/phi-deg (read/write) Roll angle initial condition in degrees 181 @property ic/psi-true-deg (read/write) Heading angle initial condition in degrees 182 @property ic/lat-gc-deg (read/write) Latitude initial condition in degrees 183 @property ic/long-gc-deg (read/write) Longitude initial condition in degrees 184 @property ic/h-sl-ft (read/write) Height above sea level initial condition in feet 185 @property ic/h-agl-ft (read/write) Height above ground level initial condition in feet 186 @property ic/sea-level-radius-ft (read/write) Radius of planet at sea level in feet 187 @property ic/terrain-elevation-ft (read/write) Terrain elevation above sea level in feet 188 @property ic/vg-fps (read/write) Ground speed initial condition in feet/second 189 @property ic/vt-fps (read/write) True airspeed initial condition in feet/second 190 @property ic/vw-bx-fps (read/write) Wind velocity initial condition in Body X frame in feet/second 191 @property ic/vw-by-fps (read/write) Wind velocity initial condition in Body Y frame in feet/second 192 @property ic/vw-bz-fps (read/write) Wind velocity initial condition in Body Z frame in feet/second 193 @property ic/vw-north-fps (read/write) Wind northward velocity initial condition in feet/second 194 @property ic/vw-east-fps (read/write) Wind eastward velocity initial condition in feet/second 195 @property ic/vw-down-fps (read/write) Wind downward velocity initial condition in feet/second 196 @property ic/vw-mag-fps (read/write) Wind velocity magnitude initial condition in feet/sec. 197 @property ic/vw-dir-deg (read/write) Wind direction initial condition, in degrees from north 198 @property ic/roc-fps (read/write) Rate of climb initial condition, in feet/second 199 @property ic/u-fps (read/write) Body frame x-axis velocity initial condition in feet/second 200 @property ic/v-fps (read/write) Body frame y-axis velocity initial condition in feet/second 201 @property ic/w-fps (read/write) Body frame z-axis velocity initial condition in feet/second 202 @property ic/vn-fps (read/write) Local frame x-axis (north) velocity initial condition in feet/second 203 @property ic/ve-fps (read/write) Local frame y-axis (east) velocity initial condition in feet/second 204 @property ic/vd-fps (read/write) Local frame z-axis (down) velocity initial condition in feet/second 205 @property ic/gamma-rad (read/write) Flight path angle initial condition in radians 206 @property ic/alpha-rad (read/write) Angle of attack initial condition in radians 207 @property ic/theta-rad (read/write) Pitch angle initial condition in radians 208 @property ic/beta-rad (read/write) Angle of sideslip initial condition in radians 209 @property ic/phi-rad (read/write) Roll angle initial condition in radians 210 @property ic/psi-true-rad (read/write) Heading angle initial condition in radians 211 @property ic/lat-gc-rad (read/write) Geocentric latitude initial condition in radians 212 @property ic/long-gc-rad (read/write) Longitude initial condition in radians 213 @property ic/p-rad_sec (read/write) Roll rate initial condition in radians/second 214 @property ic/q-rad_sec (read/write) Pitch rate initial condition in radians/second 215 @property ic/r-rad_sec (read/write) Yaw rate initial condition in radians/second 216 217 @author Tony Peden 218 */ 219 220 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 221 CLASS DECLARATION 222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 223 224 class FGInitialCondition : public FGJSBBase 225 { 226 public: 227 /// Constructor 228 explicit FGInitialCondition(FGFDMExec *fdmex); 229 /// Destructor 230 ~FGInitialCondition(); 231 232 /** Set calibrated airspeed initial condition in knots. 233 @param vc Calibrated airspeed in knots */ 234 void SetVcalibratedKtsIC(double vc); 235 236 /** Set equivalent airspeed initial condition in knots. 237 @param ve Equivalent airspeed in knots */ 238 void SetVequivalentKtsIC(double ve); 239 240 /** Set true airspeed initial condition in knots. 241 @param vtrue True airspeed in knots */ SetVtrueKtsIC(double vtrue)242 void SetVtrueKtsIC(double vtrue) { SetVtrueFpsIC(vtrue*ktstofps); } 243 244 /** Set ground speed initial condition in knots. 245 @param vg Ground speed in knots */ SetVgroundKtsIC(double vg)246 void SetVgroundKtsIC(double vg) { SetVgroundFpsIC(vg*ktstofps); } 247 248 /** Set mach initial condition. 249 @param mach Mach number */ 250 void SetMachIC(double mach); 251 252 /** Sets angle of attack initial condition in degrees. 253 @param a Alpha in degrees */ SetAlphaDegIC(double a)254 void SetAlphaDegIC(double a) { SetAlphaRadIC(a*degtorad); } 255 256 /** Sets angle of sideslip initial condition in degrees. 257 @param B Beta in degrees */ SetBetaDegIC(double b)258 void SetBetaDegIC(double b) { SetBetaRadIC(b*degtorad);} 259 260 /** Sets pitch angle initial condition in degrees. 261 @param theta Theta (pitch) angle in degrees */ SetThetaDegIC(double theta)262 void SetThetaDegIC(double theta) { SetThetaRadIC(theta*degtorad); } 263 264 /** Resets the IC data structure to new values 265 @param u, v, w, ... **/ 266 void ResetIC(double u0, double v0, double w0, double p0, double q0, double r0, 267 double alpha0, double beta0, double phi0, double theta0, double psi0, 268 double latitudeRad0, double longitudeRad0, double altitudeAGL0, 269 double gamma0); 270 271 /** Sets the roll angle initial condition in degrees. 272 @param phi roll angle in degrees */ SetPhiDegIC(double phi)273 void SetPhiDegIC(double phi) { SetPhiRadIC(phi*degtorad);} 274 275 /** Sets the heading angle initial condition in degrees. 276 @param psi Heading angle in degrees */ SetPsiDegIC(double psi)277 void SetPsiDegIC(double psi){ SetPsiRadIC(psi*degtorad); } 278 279 /** Sets the climb rate initial condition in feet/minute. 280 @param roc Rate of Climb in feet/minute */ SetClimbRateFpmIC(double roc)281 void SetClimbRateFpmIC(double roc) { SetClimbRateFpsIC(roc/60.0); } 282 283 /** Sets the flight path angle initial condition in degrees. 284 @param gamma Flight path angle in degrees */ SetFlightPathAngleDegIC(double gamma)285 void SetFlightPathAngleDegIC(double gamma) 286 { SetClimbRateFpsIC(vt*sin(gamma*degtorad)); } 287 288 /** Sets the altitude above sea level initial condition in feet. 289 @param altitudeASL Altitude above sea level in feet */ 290 void SetAltitudeASLFtIC(double altitudeASL); 291 292 /** Sets the initial Altitude above ground level. 293 @param agl Altitude above ground level in feet */ 294 void SetAltitudeAGLFtIC(double agl); 295 296 /** Sets the initial terrain elevation. 297 @param elev Initial terrain elevation in feet */ 298 void SetTerrainElevationFtIC(double elev); 299 300 /** Sets the initial latitude. 301 @param lat Initial latitude in degrees */ SetLatitudeDegIC(double lat)302 void SetLatitudeDegIC(double lat) { SetLatitudeRadIC(lat*degtorad); } 303 304 /** Sets the initial geodetic latitude. 305 This method modifies the geodetic altitude in order to keep the altitude 306 above sea level unchanged. 307 @param glat Initial geodetic latitude in degrees */ SetGeodLatitudeDegIC(double glat)308 void SetGeodLatitudeDegIC(double glat) 309 { SetGeodLatitudeRadIC(glat*degtorad); } 310 311 /** Sets the initial longitude. 312 @param lon Initial longitude in degrees */ SetLongitudeDegIC(double lon)313 void SetLongitudeDegIC(double lon) { SetLongitudeRadIC(lon*degtorad); } 314 315 /** Gets the initial calibrated airspeed. 316 @return Initial calibrated airspeed in knots */ 317 double GetVcalibratedKtsIC(void) const; 318 319 /** Gets the initial equivalent airspeed. 320 @return Initial equivalent airspeed in knots */ 321 double GetVequivalentKtsIC(void) const; 322 323 /** Gets the initial ground speed. 324 @return Initial ground speed in knots */ GetVgroundKtsIC(void)325 double GetVgroundKtsIC(void) const { return GetVgroundFpsIC() * fpstokts; } 326 327 /** Gets the initial true velocity. 328 @return Initial true airspeed in knots. */ GetVtrueKtsIC(void)329 double GetVtrueKtsIC(void) const { return vt*fpstokts; } 330 331 /** Gets the initial mach. 332 @return Initial mach number */ 333 double GetMachIC(void) const; 334 335 /** Gets the initial climb rate. 336 @return Initial climb rate in feet/minute */ GetClimbRateFpmIC(void)337 double GetClimbRateFpmIC(void) const 338 { return GetClimbRateFpsIC()*60; } 339 340 /** Gets the initial flight path angle. 341 @return Initial flight path angle in degrees */ GetFlightPathAngleDegIC(void)342 double GetFlightPathAngleDegIC(void) const 343 { return GetFlightPathAngleRadIC()*radtodeg; } 344 345 /** Gets the initial angle of attack. 346 @return Initial alpha in degrees */ GetAlphaDegIC(void)347 double GetAlphaDegIC(void) const { return alpha*radtodeg; } 348 349 /** Gets the initial sideslip angle. 350 @return Initial beta in degrees */ GetBetaDegIC(void)351 double GetBetaDegIC(void) const { return beta*radtodeg; } 352 353 /** Gets the initial pitch angle. 354 @return Initial pitch angle in degrees */ GetThetaDegIC(void)355 double GetThetaDegIC(void) const { return orientation.GetEulerDeg(eTht); } 356 357 /** Gets the initial roll angle. 358 @return Initial phi in degrees */ GetPhiDegIC(void)359 double GetPhiDegIC(void) const { return orientation.GetEulerDeg(ePhi); } 360 361 /** Gets the initial heading angle. 362 @return Initial psi in degrees */ GetPsiDegIC(void)363 double GetPsiDegIC(void) const { return orientation.GetEulerDeg(ePsi); } 364 365 /** Gets the initial latitude. 366 @return Initial geocentric latitude in degrees */ GetLatitudeDegIC(void)367 double GetLatitudeDegIC(void) const { return position.GetLatitudeDeg(); } 368 369 /** Gets the initial geodetic latitude. 370 @return Initial geodetic latitude in degrees */ GetGeodLatitudeDegIC(void)371 double GetGeodLatitudeDegIC(void) const 372 { return position.GetGeodLatitudeDeg(); } 373 374 /** Gets the initial longitude. 375 @return Initial longitude in degrees */ GetLongitudeDegIC(void)376 double GetLongitudeDegIC(void) const { return position.GetLongitudeDeg(); } 377 378 /** Gets the initial altitude above sea level. 379 @return Initial altitude in feet. */ GetAltitudeASLFtIC(void)380 double GetAltitudeASLFtIC(void) const { return position.GetAltitudeASL(); } 381 382 /** Gets the initial altitude above ground level. 383 @return Initial altitude AGL in feet */ 384 double GetAltitudeAGLFtIC(void) const; 385 386 /** Gets the initial terrain elevation. 387 @return Initial terrain elevation in feet */ 388 double GetTerrainElevationFtIC(void) const; 389 390 /** Gets the initial Earth position angle. 391 @return Initial Earth position angle in radians. */ GetEarthPositionAngleIC(void)392 double GetEarthPositionAngleIC(void) const { return epa; } 393 394 /** Sets the initial ground speed. 395 @param vg Initial ground speed in feet/second */ 396 void SetVgroundFpsIC(double vg); 397 398 /** Sets the initial true airspeed. 399 @param vt Initial true airspeed in feet/second */ 400 void SetVtrueFpsIC(double vt); 401 402 /** Sets the initial body axis X velocity. 403 @param ubody Initial X velocity in feet/second */ SetUBodyFpsIC(double ubody)404 void SetUBodyFpsIC(double ubody) { SetBodyVelFpsIC(eU, ubody); } 405 406 /** Sets the initial body axis Y velocity. 407 @param vbody Initial Y velocity in feet/second */ SetVBodyFpsIC(double vbody)408 void SetVBodyFpsIC(double vbody) { SetBodyVelFpsIC(eV, vbody); } 409 410 /** Sets the initial body axis Z velocity. 411 @param wbody Initial Z velocity in feet/second */ SetWBodyFpsIC(double wbody)412 void SetWBodyFpsIC(double wbody) { SetBodyVelFpsIC(eW, wbody); } 413 414 /** Sets the initial local axis north velocity. 415 @param vn Initial north velocity in feet/second */ SetVNorthFpsIC(double vn)416 void SetVNorthFpsIC(double vn) { SetNEDVelFpsIC(eU, vn); } 417 418 /** Sets the initial local axis east velocity. 419 @param ve Initial east velocity in feet/second */ SetVEastFpsIC(double ve)420 void SetVEastFpsIC(double ve) { SetNEDVelFpsIC(eV, ve); } 421 422 /** Sets the initial local axis down velocity. 423 @param vd Initial down velocity in feet/second */ SetVDownFpsIC(double vd)424 void SetVDownFpsIC(double vd) { SetNEDVelFpsIC(eW, vd); } 425 426 /** Sets the initial body axis roll rate. 427 @param P Initial roll rate in radians/second */ SetPRadpsIC(double P)428 void SetPRadpsIC(double P) { vPQR_body(eP) = P; } 429 430 /** Sets the initial body axis pitch rate. 431 @param Q Initial pitch rate in radians/second */ SetQRadpsIC(double Q)432 void SetQRadpsIC(double Q) { vPQR_body(eQ) = Q; } 433 434 /** Sets the initial body axis yaw rate. 435 @param R initial yaw rate in radians/second */ SetRRadpsIC(double R)436 void SetRRadpsIC(double R) { vPQR_body(eR) = R; } 437 438 /** Sets the initial wind velocity. 439 @param wN Initial wind velocity in local north direction, feet/second 440 @param wE Initial wind velocity in local east direction, feet/second 441 @param wD Initial wind velocity in local down direction, feet/second */ 442 void SetWindNEDFpsIC(double wN, double wE, double wD); 443 444 /** Sets the initial total wind speed. 445 @param mag Initial wind velocity magnitude in knots */ 446 void SetWindMagKtsIC(double mag); 447 448 /** Sets the initial wind direction. 449 @param dir Initial direction wind is coming from in degrees */ 450 void SetWindDirDegIC(double dir); 451 452 /** Sets the initial headwind velocity. 453 @param head Initial headwind speed in knots */ 454 void SetHeadWindKtsIC(double head); 455 456 /** Sets the initial crosswind speed. 457 @param cross Initial crosswind speed, positive from left to right */ 458 void SetCrossWindKtsIC(double cross); 459 460 /** Sets the initial wind downward speed. 461 @param wD Initial downward wind speed in knots*/ 462 void SetWindDownKtsIC(double wD); 463 464 /** Sets the initial climb rate. 465 @param roc Initial Rate of climb in feet/second */ 466 void SetClimbRateFpsIC(double roc); 467 468 /** Gets the initial ground velocity. 469 @return Initial ground velocity in feet/second */ GetVgroundFpsIC(void)470 double GetVgroundFpsIC(void) const { return vUVW_NED.Magnitude(eU, eV); } 471 472 /** Gets the initial true velocity. 473 @return Initial true velocity in feet/second */ GetVtrueFpsIC(void)474 double GetVtrueFpsIC(void) const { return vt; } 475 476 /** Gets the initial body axis X wind velocity. 477 @return Initial body axis X wind velocity in feet/second */ GetWindUFpsIC(void)478 double GetWindUFpsIC(void) const { return GetBodyWindFpsIC(eU); } 479 480 /** Gets the initial body axis Y wind velocity. 481 @return Initial body axis Y wind velocity in feet/second */ GetWindVFpsIC(void)482 double GetWindVFpsIC(void) const { return GetBodyWindFpsIC(eV); } 483 484 /** Gets the initial body axis Z wind velocity. 485 @return Initial body axis Z wind velocity in feet/second */ GetWindWFpsIC(void)486 double GetWindWFpsIC(void) const { return GetBodyWindFpsIC(eW); } 487 488 /** Gets the initial wind velocity in the NED local frame 489 @return Initial wind velocity in NED frame in feet/second */ GetWindNEDFpsIC(void)490 const FGColumnVector3 GetWindNEDFpsIC(void) const { 491 const FGMatrix33& Tb2l = orientation.GetTInv(); 492 FGColumnVector3 _vt_NED = Tb2l * Tw2b * FGColumnVector3(vt, 0., 0.); 493 return _vt_NED - vUVW_NED; 494 } 495 496 /** Gets the initial wind velocity in local frame. 497 @return Initial wind velocity toward north in feet/second */ GetWindNFpsIC(void)498 double GetWindNFpsIC(void) const { return GetNEDWindFpsIC(eX); } 499 500 /** Gets the initial wind velocity in local frame. 501 @return Initial wind velocity eastwards in feet/second */ GetWindEFpsIC(void)502 double GetWindEFpsIC(void) const { return GetNEDWindFpsIC(eY); } 503 504 /** Gets the initial wind velocity in local frame. 505 @return Initial wind velocity downwards in feet/second */ GetWindDFpsIC(void)506 double GetWindDFpsIC(void) const { return GetNEDWindFpsIC(eZ); } 507 508 /** Gets the initial total wind velocity in feet/sec. 509 @return Initial wind velocity in feet/second */ 510 double GetWindFpsIC(void) const; 511 512 /** Gets the initial wind direction. 513 @return Initial wind direction in feet/second */ 514 double GetWindDirDegIC(void) const; 515 516 /** Gets the initial climb rate. 517 @return Initial rate of climb in feet/second */ GetClimbRateFpsIC(void)518 double GetClimbRateFpsIC(void) const 519 { 520 const FGMatrix33& Tb2l = orientation.GetTInv(); 521 FGColumnVector3 _vt_NED = Tb2l * Tw2b * FGColumnVector3(vt, 0., 0.); 522 return _vt_NED(eW); 523 } 524 525 /** Gets the initial body velocity 526 @return Initial body velocity in feet/second. */ GetUVWFpsIC(void)527 const FGColumnVector3 GetUVWFpsIC(void) const { 528 const FGMatrix33& Tl2b = orientation.GetT(); 529 return Tl2b * vUVW_NED; 530 } 531 532 /** Gets the initial body axis X velocity. 533 @return Initial body axis X velocity in feet/second. */ GetUBodyFpsIC(void)534 double GetUBodyFpsIC(void) const { return GetBodyVelFpsIC(eU); } 535 536 /** Gets the initial body axis Y velocity. 537 @return Initial body axis Y velocity in feet/second. */ GetVBodyFpsIC(void)538 double GetVBodyFpsIC(void) const { return GetBodyVelFpsIC(eV); } 539 540 /** Gets the initial body axis Z velocity. 541 @return Initial body axis Z velocity in feet/second. */ GetWBodyFpsIC(void)542 double GetWBodyFpsIC(void) const { return GetBodyVelFpsIC(eW); } 543 544 /** Gets the initial local frame X (North) velocity. 545 @return Initial local frame X (North) axis velocity in feet/second. */ GetVNorthFpsIC(void)546 double GetVNorthFpsIC(void) const { return vUVW_NED(eU); } 547 548 /** Gets the initial local frame Y (East) velocity. 549 @return Initial local frame Y (East) axis velocity in feet/second. */ GetVEastFpsIC(void)550 double GetVEastFpsIC(void) const { return vUVW_NED(eV); } 551 552 /** Gets the initial local frame Z (Down) velocity. 553 @return Initial local frame Z (Down) axis velocity in feet/second. */ GetVDownFpsIC(void)554 double GetVDownFpsIC(void) const { return vUVW_NED(eW); } 555 556 /** Gets the initial body rotation rate 557 @return Initial body rotation rate in radians/second */ GetPQRRadpsIC(void)558 const FGColumnVector3 GetPQRRadpsIC(void) const { return vPQR_body; } 559 560 /** Gets the initial body axis roll rate. 561 @return Initial body axis roll rate in radians/second */ GetPRadpsIC()562 double GetPRadpsIC() const { return vPQR_body(eP); } 563 564 /** Gets the initial body axis pitch rate. 565 @return Initial body axis pitch rate in radians/second */ GetQRadpsIC()566 double GetQRadpsIC() const { return vPQR_body(eQ); } 567 568 /** Gets the initial body axis yaw rate. 569 @return Initial body axis yaw rate in radians/second */ GetRRadpsIC()570 double GetRRadpsIC() const { return vPQR_body(eR); } 571 572 /** Sets the initial flight path angle. 573 @param gamma Initial flight path angle in radians */ SetFlightPathAngleRadIC(double gamma)574 void SetFlightPathAngleRadIC(double gamma) 575 { SetClimbRateFpsIC(vt*sin(gamma)); } 576 577 /** Sets the initial angle of attack. 578 @param alpha Initial angle of attack in radians */ 579 void SetAlphaRadIC(double alpha); 580 581 /** Sets the initial sideslip angle. 582 @param beta Initial angle of sideslip in radians. */ 583 void SetBetaRadIC(double beta); 584 585 /** Sets the initial roll angle. 586 @param phi Initial roll angle in radians */ SetPhiRadIC(double phi)587 void SetPhiRadIC(double phi) { SetEulerAngleRadIC(ePhi, phi); } 588 589 /** Sets the initial pitch angle. 590 @param theta Initial pitch angle in radians */ SetThetaRadIC(double theta)591 void SetThetaRadIC(double theta) { SetEulerAngleRadIC(eTht, theta); } 592 593 /** Sets the initial heading angle. 594 @param psi Initial heading angle in radians */ SetPsiRadIC(double psi)595 void SetPsiRadIC(double psi) { SetEulerAngleRadIC(ePsi, psi); } 596 597 /** Sets the initial latitude. 598 @param lat Initial latitude in radians */ 599 void SetLatitudeRadIC(double lat); 600 601 /** Sets the initial geodetic latitude. 602 This method modifies the geodetic altitude in order to keep the altitude 603 above sea level unchanged. 604 @param glat Initial geodetic latitude in radians */ 605 void SetGeodLatitudeRadIC(double glat); 606 607 /** Sets the initial longitude. 608 @param lon Initial longitude in radians */ 609 void SetLongitudeRadIC(double lon); 610 611 /** Sets the target normal load factor. 612 @param nlf Normal load factor*/ SetTargetNlfIC(double nlf)613 void SetTargetNlfIC(double nlf) { targetNlfIC=nlf; } 614 615 /** Gets the initial flight path angle. 616 If total velocity is zero, this function returns zero. 617 @return Initial flight path angle in radians */ GetFlightPathAngleRadIC(void)618 double GetFlightPathAngleRadIC(void) const 619 { return (vt == 0.0)?0.0:asin(GetClimbRateFpsIC() / vt); } 620 621 /** Gets the initial angle of attack. 622 @return Initial alpha in radians */ GetAlphaRadIC(void)623 double GetAlphaRadIC(void) const { return alpha; } 624 625 /** Gets the initial angle of sideslip. 626 @return Initial sideslip angle in radians */ GetBetaRadIC(void)627 double GetBetaRadIC(void) const { return beta; } 628 629 /** Gets the initial position 630 @return Initial location */ GetPosition(void)631 const FGLocation& GetPosition(void) const { return position; } 632 633 /** Gets the initial latitude. 634 @return Initial latitude in radians */ GetLatitudeRadIC(void)635 double GetLatitudeRadIC(void) const { return position.GetLatitude(); } 636 637 /** Gets the initial geodetic latitude. 638 @return Initial geodetic latitude in radians */ GetGeodLatitudeRadIC(void)639 double GetGeodLatitudeRadIC(void) const 640 { return position.GetGeodLatitudeRad(); } 641 642 /** Gets the initial longitude. 643 @return Initial longitude in radians */ GetLongitudeRadIC(void)644 double GetLongitudeRadIC(void) const { return position.GetLongitude(); } 645 646 /** Gets the initial orientation 647 @return Initial orientation */ GetOrientation(void)648 const FGQuaternion& GetOrientation(void) const { return orientation; } 649 650 /** Gets the initial roll angle. 651 @return Initial roll angle in radians */ GetPhiRadIC(void)652 double GetPhiRadIC(void) const { return orientation.GetEuler(ePhi); } 653 654 /** Gets the initial pitch angle. 655 @return Initial pitch angle in radians */ GetThetaRadIC(void)656 double GetThetaRadIC(void) const { return orientation.GetEuler(eTht); } 657 658 /** Gets the initial heading angle. 659 @return Initial heading angle in radians */ GetPsiRadIC(void)660 double GetPsiRadIC(void) const { return orientation.GetEuler(ePsi); } 661 662 /** Gets the initial speedset. 663 @return Initial speedset */ GetSpeedSet(void)664 speedset GetSpeedSet(void) const { return lastSpeedSet; } 665 666 /** Gets the target normal load factor set from IC. 667 @return target normal load factor set from IC*/ GetTargetNlfIC(void)668 double GetTargetNlfIC(void) const { return targetNlfIC; } 669 670 /** Loads the initial conditions. 671 @param rstname The name of an initial conditions file 672 @param useStoredPath true if the stored path to the IC file should be used 673 @return true if successful */ 674 bool Load(const SGPath& rstname, bool useStoredPath = true ); 675 676 /** Is an engine running ? 677 @param index of the engine to be checked 678 @return true if the engine is running. */ IsEngineRunning(unsigned int n)679 bool IsEngineRunning(unsigned int n) const { return (enginesRunning & (1 << n)) != 0; } 680 681 /** Does initialization file call for trim ? 682 @return Trim type, if any requested (version 1). */ TrimRequested(void)683 int TrimRequested(void) const { return trimRequested; } 684 685 void bind(FGPropertyManager* pm); 686 687 private: 688 FGColumnVector3 vUVW_NED; 689 FGColumnVector3 vPQR_body; 690 FGLocation position; 691 FGQuaternion orientation; 692 double vt; 693 694 double targetNlfIC; 695 696 FGMatrix33 Tw2b, Tb2w; 697 double alpha, beta; 698 double a, e2; 699 double epa; 700 701 speedset lastSpeedSet; 702 altitudeset lastAltitudeSet; 703 latitudeset lastLatitudeSet; 704 unsigned int enginesRunning; 705 int trimRequested; 706 707 FGFDMExec *fdmex; 708 FGAtmosphere* Atmosphere; 709 FGAircraft* Aircraft; 710 711 bool Load_v1(Element* document); 712 bool Load_v2(Element* document); 713 714 void InitializeIC(void); 715 void SetEulerAngleRadIC(int idx, double angle); 716 void SetBodyVelFpsIC(int idx, double vel); 717 void SetNEDVelFpsIC(int idx, double vel); 718 double GetBodyWindFpsIC(int idx) const; 719 double GetNEDWindFpsIC(int idx) const; 720 double GetBodyVelFpsIC(int idx) const; 721 void calcAeroAngles(const FGColumnVector3& _vt_BODY); 722 void calcThetaBeta(double alfa, const FGColumnVector3& _vt_NED); 723 double ComputeGeodAltitude(double geodLatitude); 724 bool LoadLatitude(Element* position_el); 725 void SetTrimRequest(std::string trim); 726 void Debug(int from); 727 }; 728 } 729 #endif 730