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

FGPropagate2.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.60 2011/07/10 20:18:14 jberndt 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, eAdamsBashforth3, eAdamsBashforth4};
00162 
00166   bool InitModel(void);
00167 
00175   bool Run(bool Holding);
00176 
00188   const FGColumnVector3& GetVel(void) const { return vVel; }
00189   
00200   const FGColumnVector3& GetUVW(void) const { return VState.vUVW; }
00201   
00214   const FGColumnVector3& GetPQR(void) const {return VState.vPQR;}
00215   
00228   const FGColumnVector3& GetPQRi(void) const {return VState.vPQRi;}
00229 
00245   const FGColumnVector3& GetEuler(void) const { return VState.qAttitudeLocal.GetEuler(); }
00246 
00258   double GetUVW   (int idx) const { return VState.vUVW(idx); }
00259 
00271   double GetVel(int idx) const { return vVel(idx); }
00272 
00275   double GetInertialVelocityMagnitude(void) const { return VState.vInertialVelocity.Magnitude(); }
00276 
00279   const FGColumnVector3& GetInertialVelocity(void) const { return VState.vInertialVelocity; }
00280 
00283   const FGColumnVector3& GetInertialPosition(void) const { return VState.vInertialPosition; }
00284 
00287   const FGColumnVector3 GetECEFVelocity(void) const {return Tb2ec * VState.vUVW; }
00288 
00294   double GetAltitudeASL(void)   const { return VState.vLocation.GetRadius() - SeaLevelRadius; }
00295 
00301   double GetAltitudeASLmeters(void) const { return GetAltitudeASL()*fttom;}
00302 
00314   double GetPQR(int axis) const {return VState.vPQR(axis);}
00315 
00327   double GetPQRi(int axis) const {return VState.vPQRi(axis);}
00328 
00339   double GetEuler(int axis) const { return VState.qAttitudeLocal.GetEuler(axis); }
00340 
00351   double GetCosEuler(int idx) const { return VState.qAttitudeLocal.GetCosEuler(idx); }
00352 
00363   double GetSinEuler(int idx) const { return VState.qAttitudeLocal.GetSinEuler(idx); }
00364 
00370   double Gethdot(void) const { return -vVel(eDown); }
00371 
00378   double GetLocalTerrainRadius(void) const { return LocalTerrainRadius; }
00379 
00380   double GetTerrainElevation(void) const;
00381   double GetDistanceAGL(void)  const;
00382   double GetRadius(void) const {
00383       if (VState.vLocation.GetRadius() == 0) return 1.0;
00384       else return VState.vLocation.GetRadius();
00385   }
00386   double GetLongitude(void) const { return VState.vLocation.GetLongitude(); }
00387   double GetLatitude(void) const { return VState.vLocation.GetLatitude(); }
00388 
00389   double GetGeodLatitudeRad(void) const { return VState.vLocation.GetGeodLatitudeRad(); }
00390   double GetGeodLatitudeDeg(void) const { return VState.vLocation.GetGeodLatitudeDeg(); }
00391 
00392   double GetGeodeticAltitude(void) const { return VState.vLocation.GetGeodAltitude(); }
00393 
00394   double GetLongitudeDeg(void) const { return VState.vLocation.GetLongitudeDeg(); }
00395   double GetLatitudeDeg(void) const { return VState.vLocation.GetLatitudeDeg(); }
00396   const FGLocation& GetLocation(void) const { return VState.vLocation; }
00397 
00402   const FGMatrix33& GetTl2b(void) const { return Tl2b; }
00403 
00408   const FGMatrix33& GetTb2l(void) const { return Tb2l; }
00409 
00412   const FGMatrix33& GetTec2b(void) const { return Tec2b; }
00413 
00416   const FGMatrix33& GetTb2ec(void) const { return Tb2ec; }
00417 
00420   const FGMatrix33& GetTi2b(void) const { return Ti2b; }
00421 
00424   const FGMatrix33& GetTb2i(void) const { return Tb2i; }
00425 
00428   const FGMatrix33& GetTec2i(void) const { return Tec2i; }
00429 
00432   const FGMatrix33& GetTi2ec(void) const { return Ti2ec; }
00433 
00438   const FGMatrix33& GetTec2l(void) const { return Tec2l; }
00439 
00444   const FGMatrix33& GetTl2ec(void) const { return Tl2ec; }
00445 
00448   const FGMatrix33& GetTl2i(void) const { return Tl2i; }
00449 
00452   const FGMatrix33& GetTi2l(void) const { return Ti2l; }
00453 
00454   const VehicleState& GetVState(void) const { return VState; }
00455 
00456   void SetVState(const VehicleState& vstate);
00457 
00458   void SetInertialOrientation(FGQuaternion Qi);
00459   void SetInertialVelocity(FGColumnVector3 Vi);
00460   void SetInertialRates(FGColumnVector3 vRates);
00461 
00462   const FGQuaternion GetQuaternion(void) const { return VState.qAttitudeLocal; }
00463 
00464   void SetPQR(unsigned int i, double val) {
00465       if ((i>=1) && (i<=3) )
00466           VState.vPQR(i) = val;
00467   }
00468 
00469   void SetUVW(unsigned int i, double val) {
00470       if ((i>=1) && (i<=3) )
00471           VState.vUVW(i) = val;
00472   }
00473 
00474 // SET functions
00475 
00476   void SetLongitude(double lon)
00477   {
00478     VState.vLocation.SetLongitude(lon);
00479     UpdateVehicleState();
00480   }
00481   void SetLongitudeDeg(double lon) { SetLongitude(lon*degtorad); }
00482   void SetLatitude(double lat)
00483   {
00484     VState.vLocation.SetLatitude(lat);
00485     UpdateVehicleState();
00486   }
00487   void SetLatitudeDeg(double lat) { SetLatitude(lat*degtorad); }
00488   void SetRadius(double r)
00489   {
00490     VState.vLocation.SetRadius(r);
00491     VehicleRadius = r;
00492     VState.vInertialPosition = Tec2i * VState.vLocation;
00493   }
00494   void SetAltitudeASL(double altASL) { SetRadius(altASL + SeaLevelRadius); }
00495   void SetAltitudeASLmeters(double altASL) { SetRadius(altASL/fttom + SeaLevelRadius); }
00496   void SetSeaLevelRadius(double tt) { SeaLevelRadius = tt; }
00497   void SetTerrainElevation(double tt);
00498   void SetDistanceAGL(double tt) { SetRadius(tt + LocalTerrainRadius); }
00499   void SetInitialState(const FGInitialCondition *);
00500   void SetLocation(const FGLocation& l);
00501   void SetLocation(const FGColumnVector3& lv)
00502   {
00503       FGLocation l = FGLocation(lv);
00504       SetLocation(l);
00505   }
00506   void SetPosition(const double Lon, const double Lat, const double Radius)
00507   {
00508       FGLocation l = FGLocation(Lon, Lat, Radius);
00509       SetLocation(l);
00510   }
00511 
00512   void RecomputeLocalTerrainRadius(void);
00513 
00514   void NudgeBodyLocation(FGColumnVector3 deltaLoc) {
00515     VState.vInertialPosition -= Tb2i*deltaLoc;
00516     VState.vLocation -= Tb2ec*deltaLoc;
00517   }
00518 
00519   void DumpState(void);
00520 
00521   struct Inputs {
00522     FGColumnVector3 vPQRidot;
00523     FGColumnVector3 vQtrndot;
00524     FGColumnVector3 vUVWidot;
00525     FGColumnVector3 vOmegaPlanet;
00526     double RefRadius;
00527     double SemiMajor;
00528     double SemiMinor;
00529     double EPA;
00530     double DeltaT;
00531   } in;
00532 
00533 private:
00534 
00535 // state vector
00536 
00537   struct VehicleState VState;
00538 
00539   FGColumnVector3 vVel;
00540   FGColumnVector3 vInertialVelocity;
00541   FGColumnVector3 vLocation;
00542   FGColumnVector3 vDeltaXYZEC;
00543   FGMatrix33 Tec2b;
00544   FGMatrix33 Tb2ec;
00545   FGMatrix33 Tl2b;   // local to body frame matrix copy for immediate local use
00546   FGMatrix33 Tb2l;   // body to local frame matrix copy for immediate local use
00547   FGMatrix33 Tl2ec;  // local to ECEF matrix copy for immediate local use
00548   FGMatrix33 Tec2l;  // ECEF to local frame matrix copy for immediate local use
00549   FGMatrix33 Tec2i;  // ECEF to ECI frame matrix copy for immediate local use
00550   FGMatrix33 Ti2ec;  // ECI to ECEF frame matrix copy for immediate local use
00551   FGMatrix33 Ti2b;   // ECI to body frame rotation matrix
00552   FGMatrix33 Tb2i;   // body to ECI frame rotation matrix
00553   FGMatrix33 Ti2l;
00554   FGMatrix33 Tl2i;
00555   
00556   double LocalTerrainRadius, SeaLevelRadius, VehicleRadius;
00557   FGColumnVector3 LocalTerrainVelocity, LocalTerrainAngularVelocity;
00558   eIntegrateType integrator_rotational_rate;
00559   eIntegrateType integrator_translational_rate;
00560   eIntegrateType integrator_rotational_position;
00561   eIntegrateType integrator_translational_position;
00562 
00563   void CalculateInertialVelocity(void);
00564   void CalculateUVW(void);
00565 
00566   void Integrate( FGColumnVector3& Integrand,
00567                   FGColumnVector3& Val,
00568                   deque <FGColumnVector3>& ValDot,
00569                   double dt,
00570                   eIntegrateType integration_type);
00571 
00572   void Integrate( FGQuaternion& Integrand,
00573                   FGQuaternion& Val,
00574                   deque <FGQuaternion>& ValDot,
00575                   double dt,
00576                   eIntegrateType integration_type);
00577 
00578   void UpdateLocationMatrices(void);
00579   void UpdateBodyMatrices(void);
00580   void UpdateVehicleState(void);
00581 
00582   void bind(void);
00583   void Debug(int from);
00584 };
00585 }
00586 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00587 #endif