| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGInitialCondition.h |
| 4 | Author: Tony Peden |
| 5 | Date started: 7/1/99 |
| 6 | |
| 7 | --------- Copyright (C) 1999 Anthony K. Peden ([email protected]) --------- |
| 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 FGAircraft; |
| 64 | class FGAuxiliary; |
| 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 JSBSIM_API 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 */ |
| 242 | void SetVtrueKtsIC(double vtrue) { SetVtrueFpsIC(vtrue*ktstofps); } |
| 243 | |
| 244 | /** Set ground speed initial condition in knots. |
| 245 | @param vg Ground speed in knots */ |
| 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 */ |
| 254 | void SetAlphaDegIC(double a) { SetAlphaRadIC(a*degtorad); } |
| 255 | |
| 256 | /** Sets angle of sideslip initial condition in degrees. |
| 257 | @param B Beta in degrees */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 308 | void SetGeodLatitudeDegIC(double glat) |
| 309 | { SetGeodLatitudeRadIC(glat*degtorad); } |
| 310 | |
| 311 | /** Sets the initial longitude. |
| 312 | @param lon Initial longitude in degrees */ |
| 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 */ |
| 325 | double GetVgroundKtsIC(void) const { return GetVgroundFpsIC() * fpstokts; } |
| 326 | |
| 327 | /** Gets the initial true velocity. |
| 328 | @return Initial true airspeed in knots. */ |
| 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 */ |
| 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 */ |
| 342 | double GetFlightPathAngleDegIC(void) const |
| 343 | { return GetFlightPathAngleRadIC()*radtodeg; } |
| 344 | |
| 345 | /** Gets the initial angle of attack. |
| 346 | @return Initial alpha in degrees */ |
| 347 | double GetAlphaDegIC(void) const { return alpha*radtodeg; } |
| 348 | |
| 349 | /** Gets the initial sideslip angle. |
| 350 | @return Initial beta in degrees */ |
| 351 | double GetBetaDegIC(void) const { return beta*radtodeg; } |
| 352 | |
| 353 | /** Gets the initial pitch angle. |
| 354 | @return Initial pitch angle in degrees */ |
| 355 | double GetThetaDegIC(void) const { return orientation.GetEulerDeg(eTht); } |
| 356 | |
| 357 | /** Gets the initial roll angle. |
| 358 | @return Initial phi in degrees */ |
| 359 | double GetPhiDegIC(void) const { return orientation.GetEulerDeg(ePhi); } |
| 360 | |
| 361 | /** Gets the initial heading angle. |
| 362 | @return Initial psi in degrees */ |
| 363 | double GetPsiDegIC(void) const { return orientation.GetEulerDeg(ePsi); } |
| 364 | |
| 365 | /** Gets the initial latitude. |
| 366 | @return Initial geocentric latitude in degrees */ |
| 367 | double GetLatitudeDegIC(void) const { return position.GetLatitudeDeg(); } |
| 368 | |
| 369 | /** Gets the initial geodetic latitude. |
| 370 | @return Initial geodetic latitude in degrees */ |
| 371 | double GetGeodLatitudeDegIC(void) const |
| 372 | { return position.GetGeodLatitudeDeg(); } |
| 373 | |
| 374 | /** Gets the initial longitude. |
| 375 | @return Initial longitude in degrees */ |
| 376 | double GetLongitudeDegIC(void) const { return position.GetLongitudeDeg(); } |
| 377 | |
| 378 | /** Gets the initial altitude above sea level. |
| 379 | @return Initial altitude in feet. */ |
| 380 | double GetAltitudeASLFtIC(void) const; |
| 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. */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 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 */ |
| 490 | FGColumnVector3 GetWindNEDFpsIC(void) const; |
| 491 | |
| 492 | /** Gets the initial wind velocity in local frame. |
| 493 | @return Initial wind velocity toward north in feet/second */ |
| 494 | double GetWindNFpsIC(void) const { return GetWindNEDFpsIC()(eX); } |
| 495 | |
| 496 | /** Gets the initial wind velocity in local frame. |
| 497 | @return Initial wind velocity eastwards in feet/second */ |
| 498 | double GetWindEFpsIC(void) const { return GetWindNEDFpsIC()(eY); } |
| 499 | |
| 500 | /** Gets the initial wind velocity in local frame. |
| 501 | @return Initial wind velocity downwards in feet/second */ |
| 502 | double GetWindDFpsIC(void) const { return GetWindNEDFpsIC()(eZ); } |
| 503 | |
| 504 | /** Gets the initial total wind velocity in feet/sec. |
| 505 | @return Initial wind velocity in feet/second */ |
| 506 | double GetWindFpsIC(void) const; |
| 507 | |
| 508 | /** Gets the initial wind direction. |
| 509 | @return Initial wind direction in feet/second */ |
| 510 | double GetWindDirDegIC(void) const; |
| 511 | |
| 512 | /** Gets the initial climb rate. |
| 513 | @return Initial rate of climb in feet/second */ |
| 514 | double GetClimbRateFpsIC(void) const |
| 515 | { |
| 516 | const FGMatrix33& Tb2l = orientation.GetTInv(); |
| 517 | FGColumnVector3 _vt_NED = Tb2l * Tw2b * FGColumnVector3(vt, 0., 0.); |
| 518 | return -_vt_NED(eW); |
| 519 | } |
| 520 | |
| 521 | /** Gets the initial body velocity |
| 522 | @return Initial body velocity in feet/second. */ |
| 523 | const FGColumnVector3 GetUVWFpsIC(void) const { |
| 524 | const FGMatrix33& Tl2b = orientation.GetT(); |
| 525 | return Tl2b * vUVW_NED; |
| 526 | } |
| 527 | |
| 528 | /** Gets the initial body axis X velocity. |
| 529 | @return Initial body axis X velocity in feet/second. */ |
| 530 | double GetUBodyFpsIC(void) const { return GetBodyVelFpsIC(eU); } |
| 531 | |
| 532 | /** Gets the initial body axis Y velocity. |
| 533 | @return Initial body axis Y velocity in feet/second. */ |
| 534 | double GetVBodyFpsIC(void) const { return GetBodyVelFpsIC(eV); } |
| 535 | |
| 536 | /** Gets the initial body axis Z velocity. |
| 537 | @return Initial body axis Z velocity in feet/second. */ |
| 538 | double GetWBodyFpsIC(void) const { return GetBodyVelFpsIC(eW); } |
| 539 | |
| 540 | /** Gets the initial local frame X (North) velocity. |
| 541 | @return Initial local frame X (North) axis velocity in feet/second. */ |
| 542 | double GetVNorthFpsIC(void) const { return vUVW_NED(eU); } |
| 543 | |
| 544 | /** Gets the initial local frame Y (East) velocity. |
| 545 | @return Initial local frame Y (East) axis velocity in feet/second. */ |
| 546 | double GetVEastFpsIC(void) const { return vUVW_NED(eV); } |
| 547 | |
| 548 | /** Gets the initial local frame Z (Down) velocity. |
| 549 | @return Initial local frame Z (Down) axis velocity in feet/second. */ |
| 550 | double GetVDownFpsIC(void) const { return vUVW_NED(eW); } |
| 551 | |
| 552 | /** Gets the initial body rotation rate |
| 553 | @return Initial body rotation rate in radians/second */ |
| 554 | const FGColumnVector3 GetPQRRadpsIC(void) const { return vPQR_body; } |
| 555 | |
| 556 | /** Gets the initial body axis roll rate. |
| 557 | @return Initial body axis roll rate in radians/second */ |
| 558 | double GetPRadpsIC() const { return vPQR_body(eP); } |
| 559 | |
| 560 | /** Gets the initial body axis pitch rate. |
| 561 | @return Initial body axis pitch rate in radians/second */ |
| 562 | double GetQRadpsIC() const { return vPQR_body(eQ); } |
| 563 | |
| 564 | /** Gets the initial body axis yaw rate. |
| 565 | @return Initial body axis yaw rate in radians/second */ |
| 566 | double GetRRadpsIC() const { return vPQR_body(eR); } |
| 567 | |
| 568 | /** Sets the initial flight path angle. |
| 569 | @param gamma Initial flight path angle in radians */ |
| 570 | void SetFlightPathAngleRadIC(double gamma) |
| 571 | { SetClimbRateFpsIC(vt*sin(gamma)); } |
| 572 | |
| 573 | /** Sets the initial angle of attack. |
| 574 | @param alpha Initial angle of attack in radians */ |
| 575 | void SetAlphaRadIC(double alpha); |
| 576 | |
| 577 | /** Sets the initial sideslip angle. |
| 578 | @param beta Initial angle of sideslip in radians. */ |
| 579 | void SetBetaRadIC(double beta); |
| 580 | |
| 581 | /** Sets the initial roll angle. |
| 582 | @param phi Initial roll angle in radians */ |
| 583 | void SetPhiRadIC(double phi) { SetEulerAngleRadIC(ePhi, phi); } |
| 584 | |
| 585 | /** Sets the initial pitch angle. |
| 586 | @param theta Initial pitch angle in radians */ |
| 587 | void SetThetaRadIC(double theta) { SetEulerAngleRadIC(eTht, theta); } |
| 588 | |
| 589 | /** Sets the initial heading angle. |
| 590 | @param psi Initial heading angle in radians */ |
| 591 | void SetPsiRadIC(double psi) { SetEulerAngleRadIC(ePsi, psi); } |
| 592 | |
| 593 | /** Sets the initial latitude. |
| 594 | @param lat Initial latitude in radians */ |
| 595 | void SetLatitudeRadIC(double lat); |
| 596 | |
| 597 | /** Sets the initial geodetic latitude. |
| 598 | This method modifies the geodetic altitude in order to keep the altitude |
| 599 | above sea level unchanged. |
| 600 | @param glat Initial geodetic latitude in radians */ |
| 601 | void SetGeodLatitudeRadIC(double glat); |
| 602 | |
| 603 | /** Sets the initial longitude. |
| 604 | @param lon Initial longitude in radians */ |
| 605 | void SetLongitudeRadIC(double lon); |
| 606 | |
| 607 | /** Sets the target normal load factor. |
| 608 | @param nlf Normal load factor*/ |
| 609 | void SetTargetNlfIC(double nlf) { targetNlfIC=nlf; } |
| 610 | |
| 611 | /** Gets the initial flight path angle. |
| 612 | If total velocity is zero, this function returns zero. |
| 613 | @return Initial flight path angle in radians */ |
| 614 | double GetFlightPathAngleRadIC(void) const |
| 615 | { return (vt == 0.0)?0.0:asin(GetClimbRateFpsIC() / vt); } |
| 616 | |
| 617 | /** Gets the initial angle of attack. |
| 618 | @return Initial alpha in radians */ |
| 619 | double GetAlphaRadIC(void) const { return alpha; } |
| 620 | |
| 621 | /** Gets the initial angle of sideslip. |
| 622 | @return Initial sideslip angle in radians */ |
| 623 | double GetBetaRadIC(void) const { return beta; } |
| 624 | |
| 625 | /** Gets the initial position |
| 626 | @return Initial location */ |
| 627 | const FGLocation& GetPosition(void) const { return position; } |
| 628 | |
| 629 | /** Gets the initial latitude. |
| 630 | @return Initial latitude in radians */ |
| 631 | double GetLatitudeRadIC(void) const { return position.GetLatitude(); } |
| 632 | |
| 633 | /** Gets the initial geodetic latitude. |
| 634 | @return Initial geodetic latitude in radians */ |
| 635 | double GetGeodLatitudeRadIC(void) const |
| 636 | { return position.GetGeodLatitudeRad(); } |
| 637 | |
| 638 | /** Gets the initial longitude. |
| 639 | @return Initial longitude in radians */ |
| 640 | double GetLongitudeRadIC(void) const { return position.GetLongitude(); } |
| 641 | |
| 642 | /** Gets the initial orientation |
| 643 | @return Initial orientation */ |
| 644 | const FGQuaternion& GetOrientation(void) const { return orientation; } |
| 645 | |
| 646 | /** Gets the initial roll angle. |
| 647 | @return Initial roll angle in radians */ |
| 648 | double GetPhiRadIC(void) const { return orientation.GetEuler(ePhi); } |
| 649 | |
| 650 | /** Gets the initial pitch angle. |
| 651 | @return Initial pitch angle in radians */ |
| 652 | double GetThetaRadIC(void) const { return orientation.GetEuler(eTht); } |
| 653 | |
| 654 | /** Gets the initial heading angle. |
| 655 | @return Initial heading angle in radians */ |
| 656 | double GetPsiRadIC(void) const { return orientation.GetEuler(ePsi); } |
| 657 | |
| 658 | /** Gets the initial speedset. |
| 659 | @return Initial speedset */ |
| 660 | speedset GetSpeedSet(void) const { return lastSpeedSet; } |
| 661 | |
| 662 | /** Gets the target normal load factor set from IC. |
| 663 | @return target normal load factor set from IC*/ |
| 664 | double GetTargetNlfIC(void) const { return targetNlfIC; } |
| 665 | |
| 666 | /** Loads the initial conditions. |
| 667 | @param rstname The name of an initial conditions file |
| 668 | @param useAircraftPath true if path is given relative to the aircraft path. |
| 669 | @return true if successful */ |
| 670 | bool Load(const SGPath& rstname, bool useAircraftPath = true ); |
| 671 | |
| 672 | /** Is an engine running ? |
| 673 | @param index of the engine to be checked |
| 674 | @return true if the engine is running. */ |
| 675 | bool IsEngineRunning(unsigned int n) const { return (enginesRunning & (1 << n)) != 0; } |
| 676 | |
| 677 | /** Does initialization file call for trim ? |
| 678 | @return Trim type, if any requested (version 1). */ |
| 679 | int TrimRequested(void) const { return trimRequested; } |
| 680 | |
| 681 | /** Initialize the initial conditions to default values */ |
| 682 | void InitializeIC(void); |
| 683 | |
| 684 | void bind(FGPropertyManager* pm); |
| 685 | |
| 686 | private: |
| 687 | FGColumnVector3 vUVW_NED; |
| 688 | FGColumnVector3 vPQR_body; |
| 689 | FGLocation position; |
| 690 | FGQuaternion orientation; |
| 691 | double vt; |
| 692 | |
| 693 | double targetNlfIC; |
| 694 | |
| 695 | FGMatrix33 Tw2b, Tb2w; |
| 696 | double alpha, beta; |
| 697 | double epa; |
| 698 | |
| 699 | speedset lastSpeedSet; |
| 700 | altitudeset lastAltitudeSet; |
| 701 | latitudeset lastLatitudeSet; |
| 702 | unsigned int enginesRunning; |
| 703 | int trimRequested; |
| 704 | |
| 705 | FGFDMExec *fdmex; |
| 706 | FGAircraft* Aircraft; |
| 707 | FGAuxiliary* Auxiliary; |
| 708 | |
| 709 | bool Load_v1(Element* document); |
| 710 | bool Load_v2(Element* document); |
| 711 | |
| 712 | void SetEulerAngleRadIC(int idx, double angle); |
| 713 | void SetBodyVelFpsIC(int idx, double vel); |
| 714 | void SetNEDVelFpsIC(int idx, double vel); |
| 715 | double GetBodyWindFpsIC(int idx) const; |
| 716 | double GetBodyVelFpsIC(int idx) const; |
| 717 | void calcAeroAngles(const FGColumnVector3& _vt_BODY); |
| 718 | void calcThetaBeta(double alfa, const FGColumnVector3& _vt_NED); |
| 719 | double ComputeGeodAltitude(double geodLatitude); |
| 720 | bool LoadLatitude(Element* position_el); |
| 721 | void SetTrimRequest(std::string trim); |
| 722 | void Debug(int from); |
| 723 | }; |
| 724 | } |
| 725 | #endif |