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

FGPropagate.h

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002 
00003  Header:       FGPropagate.h
00004  Author:       Jon S. Berndt
00005  Date started: 1/5/99
00006 
00007  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
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 01/05/99   JSB   Created
00029 
00030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00031 SENTRY
00032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00033 
00034 #ifndef FGPROPAGATE_H
00035 #define FGPROPAGATE_H
00036 
00037 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00038 INCLUDES
00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00040 
00041 #include "models/FGModel.h"
00042 #include "math/FGColumnVector3.h"
00043 #include "math/FGLocation.h"
00044 #include "math/FGQuaternion.h"
00045 #include "math/FGMatrix33.h"
00046 #include <deque>
00047 
00048 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00049 DEFINITIONS
00050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00051 
00052 #define ID_PROPAGATE "$Id: FGPropagate.h,v 1.74 2013/01/19 13:49:37 bcoconni Exp $"
00053 
00054 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00055 FORWARD DECLARATIONS
00056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00057 
00058 namespace JSBSim {
00059 
00060 using std::deque;
00061 class FGInitialCondition;
00062 
00063 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00064 CLASS DOCUMENTATION
00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00066 
00099 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00100 CLASS DECLARATION
00101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00102 
00103 class FGPropagate : public FGModel {
00104 public:
00105 
00108   struct VehicleState {
00112     FGLocation vLocation;
00113 
00117     FGColumnVector3 vUVW;
00118 
00122     FGColumnVector3 vPQR;
00123 
00127     FGColumnVector3 vPQRi;
00128 
00131     FGQuaternion qAttitudeLocal;
00132 
00135     FGQuaternion qAttitudeECI;
00136 
00137     FGColumnVector3 vInertialVelocity;
00138 
00139     FGColumnVector3 vInertialPosition;
00140 
00141     deque <FGColumnVector3> dqPQRidot;
00142     deque <FGColumnVector3> dqUVWidot;
00143     deque <FGColumnVector3> dqInertialVelocity;
00144     deque <FGQuaternion>    dqQtrndot;
00145   };
00146 
00155   FGPropagate(FGFDMExec* Executive);
00156 
00158   ~FGPropagate();
00159 
00161   enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2,
00162                        eAdamsBashforth3, eAdamsBashforth4, eBuss1, eBuss2, eLocalLinearization};
00163 
00167   bool InitModel(void);
00168 
00169   void InitializeDerivatives();
00170 
00178   bool Run(bool Holding);
00179 
00191   const FGColumnVector3& GetVel(void) const { return vVel; }
00192 
00203   const FGColumnVector3& GetUVW(void) const { return VState.vUVW; }
00204 
00217   const FGColumnVector3& GetPQR(void) const {return VState.vPQR;}
00218 
00231   const FGColumnVector3& GetPQRi(void) const {return VState.vPQRi;}
00232 
00248   const FGColumnVector3& GetEuler(void) const { return VState.qAttitudeLocal.GetEuler(); }
00249 
00261   double GetUVW(int idx) const { return VState.vUVW(idx); }
00262 
00274   double GetVel(int idx) const { return vVel(idx); }
00275 
00278   double GetInertialVelocityMagnitude(void) const { return VState.vInertialVelocity.Magnitude(); }
00279 
00282   const FGColumnVector3& GetInertialVelocity(void) const { return VState.vInertialVelocity; }
00283 
00286   const FGColumnVector3& GetInertialPosition(void) const { return VState.vInertialPosition; }
00287 
00290   FGColumnVector3 GetECEFVelocity(void) const {return Tb2ec * VState.vUVW; }
00291 
00297   double GetAltitudeASL(void) const { return VState.vLocation.GetAltitudeASL(); }
00298 
00304   double GetAltitudeASLmeters(void) const { return GetAltitudeASL()*fttom;}
00305 
00317   double GetPQR(int axis) const {return VState.vPQR(axis);}
00318 
00330   double GetPQRi(int axis) const {return VState.vPQRi(axis);}
00331 
00342   double GetEuler(int axis) const { return VState.qAttitudeLocal.GetEuler(axis); }
00343 
00354   double GetCosEuler(int idx) const { return VState.qAttitudeLocal.GetCosEuler(idx); }
00355 
00366   double GetSinEuler(int idx) const { return VState.qAttitudeLocal.GetSinEuler(idx); }
00367 
00373   double Gethdot(void) const { return -vVel(eDown); }
00374 
00381   double GetLocalTerrainRadius(void) const;
00382 
00383   double GetEarthPositionAngle(void) const { return VState.vLocation.GetEPA(); }
00384 
00385   double GetEarthPositionAngleDeg(void) const { return GetEarthPositionAngle()*radtodeg;}
00386 
00387   const FGColumnVector3& GetTerrainVelocity(void) const { return LocalTerrainVelocity; }
00388   const FGColumnVector3& GetTerrainAngularVelocity(void) const { return LocalTerrainAngularVelocity; }
00389   void RecomputeLocalTerrainVelocity();
00390 
00391   double GetTerrainElevation(void) const { return GetLocalTerrainRadius() - VState.vLocation.GetSeaLevelRadius(); }
00392   double GetDistanceAGL(void)  const;
00393   double GetRadius(void) const {
00394       if (VState.vLocation.GetRadius() == 0) return 1.0;
00395       else return VState.vLocation.GetRadius();
00396   }
00397   double GetLongitude(void) const { return VState.vLocation.GetLongitude(); }
00398   double GetLatitude(void) const { return VState.vLocation.GetLatitude(); }
00399 
00400   double GetGeodLatitudeRad(void) const { return VState.vLocation.GetGeodLatitudeRad(); }
00401   double GetGeodLatitudeDeg(void) const { return VState.vLocation.GetGeodLatitudeDeg(); }
00402 
00403   double GetGeodeticAltitude(void) const { return VState.vLocation.GetGeodAltitude(); }
00404 
00405   double GetLongitudeDeg(void) const { return VState.vLocation.GetLongitudeDeg(); }
00406   double GetLatitudeDeg(void) const { return VState.vLocation.GetLatitudeDeg(); }
00407   const FGLocation& GetLocation(void) const { return VState.vLocation; }
00408 
00413   const FGMatrix33& GetTl2b(void) const { return Tl2b; }
00414 
00419   const FGMatrix33& GetTb2l(void) const { return Tb2l; }
00420 
00423   const FGMatrix33& GetTec2b(void) const { return Tec2b; }
00424 
00427   const FGMatrix33& GetTb2ec(void) const { return Tb2ec; }
00428 
00431   const FGMatrix33& GetTi2b(void) const { return Ti2b; }
00432 
00435   const FGMatrix33& GetTb2i(void) const { return Tb2i; }
00436 
00439   const FGMatrix33& GetTec2i(void) const { return Tec2i; }
00440 
00443   const FGMatrix33& GetTi2ec(void) const { return Ti2ec; }
00444 
00449   const FGMatrix33& GetTec2l(void) const { return Tec2l; }
00450 
00455   const FGMatrix33& GetTl2ec(void) const { return Tl2ec; }
00456 
00459   const FGMatrix33& GetTl2i(void) const { return Tl2i; }
00460 
00463   const FGMatrix33& GetTi2l(void) const { return Ti2l; }
00464 
00465   const VehicleState& GetVState(void) const { return VState; }
00466 
00467   void SetVState(const VehicleState& vstate);
00468 
00469   void SetEarthPositionAngle(double epa) {VState.vLocation.SetEarthPositionAngle(epa);}
00470 
00471   void SetInertialOrientation(const FGQuaternion& Qi);
00472   void SetInertialVelocity(const FGColumnVector3& Vi);
00473   void SetInertialRates(const FGColumnVector3& vRates);
00474 
00476   const FGQuaternion GetQuaternion(void) const { return VState.qAttitudeLocal; }
00477 
00479   const FGQuaternion GetQuaternionECI(void) const { return VState.qAttitudeECI; }
00480 
00482   const FGQuaternion GetQuaternionECEF(void) const { return Qec2b; }
00483 
00484   void SetPQR(unsigned int i, double val) {
00485     VState.vPQR(i) = val;
00486     VState.vPQRi = VState.vPQR + Ti2b * in.vOmegaPlanet;
00487   }
00488 
00489   void SetUVW(unsigned int i, double val) {
00490     VState.vUVW(i) = val;
00491     CalculateInertialVelocity();
00492   }
00493 
00494 // SET functions
00495 
00496   void SetLongitude(double lon)
00497   {
00498     VState.vLocation.SetLongitude(lon);
00499     UpdateVehicleState();
00500   }
00501   void SetLongitudeDeg(double lon) { SetLongitude(lon*degtorad); }
00502   void SetLatitude(double lat)
00503   {
00504     VState.vLocation.SetLatitude(lat);
00505     UpdateVehicleState();
00506   }
00507   void SetLatitudeDeg(double lat) { SetLatitude(lat*degtorad); }
00508   void SetRadius(double r)
00509   {
00510     VState.vLocation.SetRadius(r);
00511     VehicleRadius = r;
00512     VState.vInertialPosition = Tec2i * VState.vLocation;
00513   }
00514 
00515   void SetAltitudeASL(double altASL)
00516   {
00517     VState.vLocation.SetAltitudeASL(altASL);
00518     UpdateVehicleState();
00519   }
00520   void SetAltitudeASLmeters(double altASL) { SetAltitudeASL(altASL/fttom); }
00521 
00522   void SetSeaLevelRadius(double tt);
00523   void SetTerrainElevation(double tt);
00524   void SetDistanceAGL(double tt);
00525 
00526   void SetInitialState(const FGInitialCondition *);
00527   void SetLocation(const FGLocation& l);
00528   void SetLocation(const FGColumnVector3& lv)
00529   {
00530       FGLocation l = FGLocation(lv);
00531       SetLocation(l);
00532   }
00533   void SetPosition(const double Lon, const double Lat, const double Radius)
00534   {
00535       FGLocation l = FGLocation(Lon, Lat, Radius);
00536       SetLocation(l);
00537   }
00538 
00539   void NudgeBodyLocation(const FGColumnVector3& deltaLoc) {
00540     VState.vInertialPosition -= Tb2i*deltaLoc;
00541     VState.vLocation -= Tb2ec*deltaLoc;
00542   }
00543 
00544   void DumpState(void);
00545 
00546   struct Inputs {
00547     FGColumnVector3 vPQRidot;
00548     FGQuaternion vQtrndot;
00549     FGColumnVector3 vUVWidot;
00550     FGColumnVector3 vOmegaPlanet;
00551     double SemiMajor;
00552     double SemiMinor;
00553     double DeltaT;
00554   } in;
00555 
00556 private:
00557 
00558 // state vector
00559 
00560   struct VehicleState VState;
00561 
00562   FGColumnVector3 vVel;
00563   FGColumnVector3 vLocation;
00564   FGMatrix33 Tec2b;
00565   FGMatrix33 Tb2ec;
00566   FGMatrix33 Tl2b;   // local to body frame matrix copy for immediate local use
00567   FGMatrix33 Tb2l;   // body to local frame matrix copy for immediate local use
00568   FGMatrix33 Tl2ec;  // local to ECEF matrix copy for immediate local use
00569   FGMatrix33 Tec2l;  // ECEF to local frame matrix copy for immediate local use
00570   FGMatrix33 Tec2i;  // ECEF to ECI frame matrix copy for immediate local use
00571   FGMatrix33 Ti2ec;  // ECI to ECEF frame matrix copy for immediate local use
00572   FGMatrix33 Ti2b;   // ECI to body frame rotation matrix
00573   FGMatrix33 Tb2i;   // body to ECI frame rotation matrix
00574   FGMatrix33 Ti2l;
00575   FGMatrix33 Tl2i;
00576 
00577   FGQuaternion Qec2b;
00578 
00579   double VehicleRadius;
00580   FGColumnVector3 LocalTerrainVelocity, LocalTerrainAngularVelocity;
00581 
00582   eIntegrateType integrator_rotational_rate;
00583   eIntegrateType integrator_translational_rate;
00584   eIntegrateType integrator_rotational_position;
00585   eIntegrateType integrator_translational_position;
00586 
00587   void CalculateInertialVelocity(void);
00588   void CalculateUVW(void);
00589 
00590   void Integrate( FGColumnVector3& Integrand,
00591                   FGColumnVector3& Val,
00592                   deque <FGColumnVector3>& ValDot,
00593                   double dt,
00594                   eIntegrateType integration_type);
00595 
00596   void Integrate( FGQuaternion& Integrand,
00597                   FGQuaternion& Val,
00598                   deque <FGQuaternion>& ValDot,
00599                   double dt,
00600                   eIntegrateType integration_type);
00601 
00602   void UpdateLocationMatrices(void);
00603   void UpdateBodyMatrices(void);
00604   void UpdateVehicleState(void);
00605 
00606   void WriteStateFile(int num);
00607   void bind(void);
00608   void Debug(int from);
00609 };
00610 }
00611 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00612 #endif