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

FGEngine.h

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002 
00003  Header:       FGEngine.h
00004  Author:       Jon S. Berndt
00005  Date started: 01/21/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 details.
00017 
00018  You should have received a copy of the GNU Lesser General Public License along with
00019  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00020  Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022  Further information about the GNU Lesser General Public License can also be found on
00023  the world wide web at http://www.gnu.org.
00024 
00025 FUNCTIONAL DESCRIPTION
00026 --------------------------------------------------------------------------------
00027 
00028 Based on Flightgear code, which is based on LaRCSim. This class simulates
00029 a generic engine.
00030 
00031 HISTORY
00032 --------------------------------------------------------------------------------
00033 01/21/99   JSB   Created
00034 
00035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00036 SENTRY
00037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00038 
00039 #ifndef FGENGINE_H
00040 #define FGENGINE_H
00041 
00042 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00043 INCLUDES
00044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00045 
00046 #include <vector>
00047 #include <string>
00048 
00049 #include "math/FGModelFunctions.h"
00050 #include "input_output/FGXMLFileRead.h"
00051 #include "input_output/FGXMLElement.h"
00052 #include "math/FGColumnVector3.h"
00053 
00054 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00055 DEFINITIONS
00056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00057 
00058 #define ID_ENGINE "$Id: FGEngine.h,v 1.36 2012/07/29 12:04:09 bcoconni Exp $"
00059 
00060 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00061 FORWARD DECLARATIONS
00062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00063 
00064 namespace JSBSim {
00065 
00066 class FGFDMExec;
00067 class FGThruster;
00068 class Element;
00069 class FGPropertyManager;
00070 
00071 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00072 CLASS DOCUMENTATION
00073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00074 
00119 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00120 CLASS DECLARATION
00121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00122 
00123 class FGEngine : public FGModelFunctions, public FGXMLFileRead
00124 {
00125 public:
00126   struct Inputs {
00127     double SLPressure;
00128     double Pressure;
00129     double PressureRatio;
00130     double Temperature;
00131     double Density;
00132     double DensityRatio;
00133     double Soundspeed;
00134     double TotalPressure;
00135     double TotalTempearture;
00136     double TAT_c;
00137     double Vt;
00138     double Vc;
00139     double qbar;
00140     double alpha;
00141     double beta;
00142     double H_agl;
00143     FGColumnVector3 AeroUVW;
00144     FGColumnVector3 AeroPQR;
00145     FGColumnVector3 PQR;
00146     vector <double> ThrottleCmd;
00147     vector <double> MixtureCmd;
00148     vector <double> ThrottlePos;
00149     vector <double> MixturePos;
00150     vector <double> PropAdvance;
00151     vector <bool> PropFeather;
00152     double TotalDeltaT;
00153   };
00154 
00155   FGEngine(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input);
00156   virtual ~FGEngine();
00157 
00158   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
00159 
00160   EngineType             GetType(void) const { return Type; }
00161   virtual const string&  GetName(void) const { return Name; }
00162 
00163   // Engine controls
00164   virtual double  GetThrottleMin(void) const { return MinThrottle; }
00165   virtual double  GetThrottleMax(void) const { return MaxThrottle; }
00166   virtual bool    GetStarter(void) const     { return Starter; }
00167 
00168   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
00169   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
00170   virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
00171   virtual double GetFuelFlowRateGPH(void) const {return FuelFlowRate*3600/6.02;}
00172   virtual double GetFuelUsedLbs(void) const {return FuelUsedLbs;}
00173   virtual bool   GetStarved(void) const { return Starved; }
00174   virtual bool   GetRunning(void) const { return Running; }
00175   virtual bool   GetCranking(void) const { return Cranking; }
00176 
00177   virtual void SetStarved(bool tt) { Starved = tt; }
00178   virtual void SetStarved(void)    { Starved = true; }
00179 
00180   virtual void SetRunning(bool bb) { Running=bb; }
00181   virtual void SetName(const string& name) { Name = name; }
00182   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
00183 
00184   virtual void SetStarter(bool s) { Starter = s; }
00185 
00186   virtual int InitRunning(void){ return 1; }
00187 
00189   void ResetToIC(void);
00190 
00192   virtual void Calculate(void) = 0;
00193 
00194   virtual double GetThrust(void) const;
00195     
00197   virtual void SetPlacement(const FGColumnVector3& location, const FGColumnVector3& orientation);
00198 
00203   virtual double CalcFuelNeed(void);
00204 
00205   virtual double CalcOxidizerNeed(void) {return 0.0;}
00206 
00207   virtual double GetPowerAvailable(void) {return 0.0;};
00208 
00209   virtual const FGColumnVector3& GetBodyForces(void);
00210   virtual const FGColumnVector3& GetMoments(void);
00211 
00212   bool LoadThruster(Element *el);
00213   FGThruster* GetThruster(void) const {return Thruster;}
00214 
00215   unsigned int GetSourceTank(unsigned int i) const;
00216   unsigned int GetNumSourceTanks() const {return SourceTanks.size();}
00217 
00218   virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
00219   virtual std::string GetEngineValues(const std::string& delimiter) = 0;
00220 
00221   struct Inputs& in;
00222   void LoadThrusterInputs();
00223 
00224 protected:
00232   FGPropertyManager* PropertyManager;
00233   std::string Name;
00234   const int   EngineNumber;
00235   EngineType Type;
00236   double X, Y, Z;
00237   double EnginePitch;
00238   double EngineYaw;
00239   double SLFuelFlowMax;
00240   double MaxThrottle;
00241   double MinThrottle;
00242 
00243   double FuelExpended;
00244   double FuelFlowRate;
00245   double PctPower;
00246   bool  Starter;
00247   bool  Starved;
00248   bool  Running;
00249   bool  Cranking;
00250   bool  FuelFreeze;
00251 
00252   double FuelFlow_gph;
00253   double FuelFlow_pph;
00254   double FuelUsedLbs;
00255 
00256   FGFDMExec*      FDMExec;
00257   FGThruster*     Thruster;
00258 
00259   std::vector <int> SourceTanks;
00260 
00261   void Debug(int from);
00262 };
00263 }
00264 
00265 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00266 #endif
00267