JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGInitialCondition.h

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002 
00003  Header:       FGInitialCondition.h
00004  Author:       Tony Peden
00005  Date started: 7/1/99
00006 
00007  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
00008 
00009  This program is free software; you can redistribute it and/or modify it under
00010  the terms of the GNU Lesser General Public License as published by the Free Software
00011  Foundation; either version 2 of the License, or (at your option) any later
00012  version.
00013 
00014  This program is distributed in the hope that it will be useful, but WITHOUT
00015  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00017  details.
00018 
00019  You should have received a copy of the GNU Lesser General Public License along with
00020  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021  Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023  Further information about the GNU Lesser General Public License can also be found on
00024  the world wide web at http://www.gnu.org.
00025 
00026  HISTORY
00027 --------------------------------------------------------------------------------
00028 7/1/99   TP   Created
00029 
00030 FUNCTIONAL DESCRIPTION
00031 --------------------------------------------------------------------------------
00032 
00033 The purpose of this class is to take a set of initial conditions and provide
00034 a kinematically consistent set of body axis velocity components, euler
00035 angles, and altitude.  This class does not attempt to trim the model i.e.
00036 the sim will most likely start in a very dynamic state (unless, of course,
00037 you have chosen your IC's wisely) even after setting it up with this class.
00038 
00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00040 SENTRY
00041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00042 
00043 #ifndef FGINITIALCONDITION_H
00044 #define FGINITIALCONDITION_H
00045 
00046 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00047 INCLUDES
00048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00049 
00050 #include "input_output/FGXMLFileRead.h"
00051 #include "math/FGLocation.h"
00052 #include "math/FGQuaternion.h"
00053 
00054 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00055 DEFINITIONS
00056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00057 
00058 #define ID_INITIALCONDITION "$Id: FGInitialCondition.h,v 1.36 2013/01/19 14:19:43 bcoconni Exp $"
00059 
00060 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00061 FORWARD DECLARATIONS
00062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00063 
00064 namespace JSBSim {
00065 
00066 class FGFDMExec;
00067 class FGMatrix33;
00068 class FGColumnVector3;
00069 class FGAtmosphere;
00070 
00071 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset;
00072 typedef enum { setasl, setagl} altitudeset;
00073 
00074 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00075 CLASS DOCUMENTATION
00076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00077 
00222 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00223 CLASS DECLARATION
00224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00225 
00226 class FGInitialCondition : public FGJSBBase, public FGXMLFileRead
00227 {
00228 public:
00230   FGInitialCondition(FGFDMExec *fdmex);
00232   ~FGInitialCondition();
00233 
00236   void SetVcalibratedKtsIC(double vc);
00237 
00240   void SetVequivalentKtsIC(double ve);
00241 
00244   void SetVtrueKtsIC(double vtrue) { SetVtrueFpsIC(vtrue*ktstofps); }
00245 
00248   void SetVgroundKtsIC(double vg) { SetVgroundFpsIC(vg*ktstofps); }
00249 
00252   void SetMachIC(double mach);
00253 
00256   void SetAlphaDegIC(double a) { SetAlphaRadIC(a*degtorad); }
00257 
00260   void SetBetaDegIC(double b) { SetBetaRadIC(b*degtorad);}
00261 
00264   void SetThetaDegIC(double theta) { SetThetaRadIC(theta*degtorad); }
00265 
00268   void ResetIC(double u0, double v0, double w0, double p0, double q0, double r0,
00269                double alpha0, double beta0, double phi0, double theta0, double psi0,
00270                double latitudeRad0, double longitudeRad0, double altitudeAGL0,
00271                double gamma0);
00272 
00275   void SetPhiDegIC(double phi)  { SetPhiRadIC(phi*degtorad);}
00276 
00279   void SetPsiDegIC(double psi){ SetPsiRadIC(psi*degtorad); }
00280 
00283   void SetClimbRateFpmIC(double roc) { SetClimbRateFpsIC(roc/60.0); }
00284 
00287   void SetFlightPathAngleDegIC(double gamma)
00288   { SetClimbRateFpsIC(vt*sin(gamma*degtorad)); }
00289 
00292   void SetAltitudeASLFtIC(double altitudeASL);
00293 
00296   void SetAltitudeAGLFtIC(double agl);
00297 
00300   void SetSeaLevelRadiusFtIC(double slr);
00301 
00304   void SetTerrainElevationFtIC(double elev);
00305 
00308   void SetLatitudeDegIC(double lat) { SetLatitudeRadIC(lat*degtorad); }
00309 
00312   void SetLongitudeDegIC(double lon) { SetLongitudeRadIC(lon*degtorad); }
00313 
00316   double GetVcalibratedKtsIC(void) const;
00317 
00320   double GetVequivalentKtsIC(void) const;
00321 
00324   double GetVgroundKtsIC(void) const { return GetVgroundFpsIC() * fpstokts; }
00325 
00328   double GetVtrueKtsIC(void) const { return vt*fpstokts; }
00329 
00332   double GetMachIC(void) const;
00333 
00336   double GetClimbRateFpmIC(void) const
00337   { return GetClimbRateFpsIC()*60; }
00338 
00341   double GetFlightPathAngleDegIC(void) const
00342   { return GetFlightPathAngleRadIC()*radtodeg; }
00343 
00346   double GetAlphaDegIC(void) const { return alpha*radtodeg; }
00347 
00350   double GetBetaDegIC(void) const  { return beta*radtodeg; }
00351 
00354   double GetThetaDegIC(void) const { return orientation.GetEulerDeg(eTht); }
00355 
00358   double GetPhiDegIC(void) const { return orientation.GetEulerDeg(ePhi); }
00359 
00362   double GetPsiDegIC(void) const { return orientation.GetEulerDeg(ePsi); }
00363 
00366   double GetLatitudeDegIC(void) const { return position.GetLatitudeDeg(); }
00367 
00370   double GetLongitudeDegIC(void) const { return position.GetLongitudeDeg(); }
00371 
00374   double GetAltitudeASLFtIC(void) const { return position.GetAltitudeASL(); }
00375 
00378   double GetAltitudeAGLFtIC(void) const;
00379 
00382   double GetTerrainElevationFtIC(void) const;
00383 
00386   void SetVgroundFpsIC(double vg);
00387 
00390   void SetVtrueFpsIC(double vt);
00391 
00394   void SetUBodyFpsIC(double ubody) { SetBodyVelFpsIC(eU, ubody); }
00395 
00398   void SetVBodyFpsIC(double vbody) { SetBodyVelFpsIC(eV, vbody); }
00399 
00402   void SetWBodyFpsIC(double wbody) { SetBodyVelFpsIC(eW, wbody); }
00403 
00406   void SetVNorthFpsIC(double vn) { SetNEDVelFpsIC(eU, vn); }
00407 
00410   void SetVEastFpsIC(double ve) { SetNEDVelFpsIC(eV, ve); }
00411 
00414   void SetVDownFpsIC(double vd) { SetNEDVelFpsIC(eW, vd); }
00415 
00418   void SetPRadpsIC(double P)  { vPQR_body(eP) = P; }
00419 
00422   void SetQRadpsIC(double Q) { vPQR_body(eQ) = Q; }
00423 
00426   void SetRRadpsIC(double R) { vPQR_body(eR) = R; }
00427 
00432   void SetWindNEDFpsIC(double wN, double wE, double wD);
00433 
00436   void SetWindMagKtsIC(double mag);
00437 
00440   void SetWindDirDegIC(double dir);
00441 
00444   void SetHeadWindKtsIC(double head);
00445 
00448   void SetCrossWindKtsIC(double cross);
00449 
00452   void SetWindDownKtsIC(double wD);
00453 
00456   void SetClimbRateFpsIC(double roc);
00457 
00460   double GetVgroundFpsIC(void) const  { return vUVW_NED.Magnitude(eU, eV); }
00461 
00464   double GetVtrueFpsIC(void) const { return vt; }
00465 
00468   double GetWindUFpsIC(void) const { return GetBodyWindFpsIC(eU); }
00469 
00472   double GetWindVFpsIC(void) const { return GetBodyWindFpsIC(eV); }
00473 
00476   double GetWindWFpsIC(void) const { return GetBodyWindFpsIC(eW); }
00477 
00480   const FGColumnVector3 GetWindNEDFpsIC(void) const {
00481     const FGMatrix33& Tb2l = orientation.GetTInv();
00482     FGColumnVector3 _vt_NED = Tb2l * Tw2b * FGColumnVector3(vt, 0., 0.);
00483     return _vt_NED - vUVW_NED;
00484   }
00485 
00488   double GetWindNFpsIC(void) const { return GetNEDWindFpsIC(eX); }
00489 
00492   double GetWindEFpsIC(void) const { return GetNEDWindFpsIC(eY); }
00493 
00496   double GetWindDFpsIC(void) const { return GetNEDWindFpsIC(eZ); }
00497 
00500   double GetWindFpsIC(void)  const;
00501 
00504   double GetWindDirDegIC(void) const;
00505 
00508   double GetClimbRateFpsIC(void) const
00509   {
00510     const FGMatrix33& Tb2l = orientation.GetTInv();
00511     FGColumnVector3 _vt_NED = Tb2l * Tw2b * FGColumnVector3(vt, 0., 0.);
00512     return _vt_NED(eW);
00513   }
00514 
00517   const FGColumnVector3 GetUVWFpsIC(void) const {
00518     const FGMatrix33& Tl2b = orientation.GetT();
00519     return Tl2b * vUVW_NED;
00520   }
00521 
00524   double GetUBodyFpsIC(void) const { return GetBodyVelFpsIC(eU); }
00525 
00528   double GetVBodyFpsIC(void) const { return GetBodyVelFpsIC(eV); }
00529 
00532   double GetWBodyFpsIC(void) const { return GetBodyVelFpsIC(eW); }
00533 
00536   double GetVNorthFpsIC(void) const { return vUVW_NED(eU); }
00537 
00540   double GetVEastFpsIC(void) const { return vUVW_NED(eV); }
00541 
00544   double GetVDownFpsIC(void) const { return vUVW_NED(eW); }
00545 
00548   const FGColumnVector3 GetPQRRadpsIC(void) const { return vPQR_body; }
00549 
00552   double GetPRadpsIC() const { return vPQR_body(eP); }
00553 
00556   double GetQRadpsIC() const { return vPQR_body(eQ); }
00557 
00560   double GetRRadpsIC() const { return vPQR_body(eR); }
00561 
00564   void SetFlightPathAngleRadIC(double gamma)
00565   { SetClimbRateFpsIC(vt*sin(gamma)); }
00566 
00569   void SetAlphaRadIC(double alpha);
00570 
00573   void SetBetaRadIC(double beta);
00574 
00577   void SetPhiRadIC(double phi) { SetEulerAngleRadIC(ePhi, phi); }
00578 
00581   void SetThetaRadIC(double theta) { SetEulerAngleRadIC(eTht, theta); }
00582 
00585   void SetPsiRadIC(double psi) { SetEulerAngleRadIC(ePsi, psi); }
00586 
00589   void SetLatitudeRadIC(double lat);
00590 
00593   void SetLongitudeRadIC(double lon);
00594 
00597   void SetTargetNlfIC(double nlf) { targetNlfIC=nlf; }
00598 
00602   double GetFlightPathAngleRadIC(void) const
00603   { return (vt == 0.0)?0.0:asin(GetClimbRateFpsIC() / vt); }
00604 
00607   double GetAlphaRadIC(void) const { return alpha; }
00608 
00611   double GetBetaRadIC(void) const { return beta; }
00612 
00615   const FGLocation& GetPosition(void) const { return position; }
00616 
00619   double GetLatitudeRadIC(void) const { return position.GetLatitude(); }
00620 
00623   double GetLongitudeRadIC(void) const { return position.GetLongitude(); }
00624 
00627   const FGQuaternion& GetOrientation(void) const { return orientation; }
00628 
00631   double GetPhiRadIC(void) const { return orientation.GetEuler(ePhi); }
00632 
00635   double GetThetaRadIC(void) const { return orientation.GetEuler(eTht); }
00636 
00639   double GetPsiRadIC(void) const   { return orientation.GetEuler(ePsi); }
00640 
00643   speedset GetSpeedSet(void) const { return lastSpeedSet; }
00644 
00647   double GetTargetNlfIC(void) const { return targetNlfIC; }
00648 
00653   bool Load(string rstname, bool useStoredPath = true );
00654 
00657   unsigned int GetNumEnginesRunning(void) const
00658   { return (unsigned int)enginesRunning.size(); }
00659 
00663   int GetEngineRunning(unsigned int engine) const { return enginesRunning[engine]; }
00664 
00665 private:
00666   FGColumnVector3 vUVW_NED;
00667   FGColumnVector3 vPQR_body;
00668   FGLocation position;
00669   FGQuaternion orientation;
00670   double vt;
00671 
00672   double targetNlfIC;
00673 
00674   FGMatrix33 Tw2b, Tb2w;
00675   double  alpha, beta;
00676 
00677   speedset lastSpeedSet;
00678   altitudeset lastAltitudeSet;
00679   vector<int> enginesRunning;
00680 
00681   FGFDMExec *fdmex;
00682   FGPropertyManager *PropertyManager;
00683   FGAtmosphere* Atmosphere;
00684 
00685   bool Load_v1(void);
00686   bool Load_v2(void);
00687 
00688   void InitializeIC(void);
00689   void SetEulerAngleRadIC(int idx, double angle);
00690   void SetBodyVelFpsIC(int idx, double vel);
00691   void SetNEDVelFpsIC(int idx, double vel);
00692   double GetBodyWindFpsIC(int idx) const;
00693   double GetNEDWindFpsIC(int idx) const;
00694   double GetBodyVelFpsIC(int idx) const;
00695   void calcAeroAngles(const FGColumnVector3& _vt_BODY);
00696   void calcThetaBeta(double alfa, const FGColumnVector3& _vt_NED);
00697   void bind(void);
00698   void Debug(int from);
00699 };
00700 }
00701 #endif
00702