]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGEngine.h
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGEngine.h
index a515983cf7f0fb697577506ad5ac1720404163a5..ac5ea64208461a8339c719240bdfa75214a4a82b 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  Header:       FGEngine.h
  Author:       Jon S. Berndt
@@ -33,34 +33,44 @@ HISTORY
 --------------------------------------------------------------------------------
 01/21/99   JSB   Created
 
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 SENTRY
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#ifndef FGEngine_H
-#define FGEngine_H
+#ifndef FGENGINE_H
+#define FGENGINE_H
 
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #ifdef FGFS
-#  include <Include/compiler.h>
+#  include <simgear/compiler.h>
 #  include STL_STRING
-FG_USING_STD(string);
+   SG_USING_STD(string);
+#  ifdef SG_HAVE_STD_INCLUDES
+#    include <vector>
+#  else
+#    include <vector.h>
+#  endif
 #else
+#  include <vector>
 #  include <string>
 #endif
 
-/*******************************************************************************
-DEFINES
-*******************************************************************************/
+#include "FGJSBBase.h"
 
-using namespace std;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-/*******************************************************************************
-CLASS DECLARATION
-*******************************************************************************/
+#define ID_ENGINE "$Id$"
+
+using std::string;
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+FORWARD DECLARATIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 class FGFDMExec;
 class FGState;
@@ -69,60 +79,158 @@ class FGFCS;
 class FGAircraft;
 class FGTranslation;
 class FGRotation;
+class FGPropulsion;
 class FGPosition;
 class FGAuxiliary;
 class FGOutput;
 
-class FGEngine
+using std::vector;
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DOCUMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/** Base class for all engines.
+    This base class contains methods and members common to all engines, such as
+    logic to drain fuel from the appropriate tank, etc.
+    @author Jon S. Berndt
+    @version $Id$ 
+*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DECLARATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+class FGEngine : public FGJSBBase
 {
 public:
-  FGEngine(FGFDMExec*, string, string, int);
-  ~FGEngine(void);
+  FGEngine(FGFDMExec* exec);
+  virtual ~FGEngine();
+
+  enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet, etTurboShaft};
+
+  virtual double  GetThrottleMin(void) { return MinThrottle; }
+  virtual double  GetThrottleMax(void) { return MaxThrottle; }
+  virtual double  GetThrottle(void) { return Throttle; }
+  virtual double  GetMixture(void) { return Mixture; }
+  virtual int     GetMagnetos(void) { return Magnetos; }
+  virtual bool    GetStarter(void) { return Starter; }
+  virtual double  GetThrust(void) { return Thrust; }
+  virtual bool    GetStarved(void) { return Starved; }
+  virtual bool    GetFlameout(void) { return Flameout; }
+  virtual bool    GetRunning(void) { return Running; }
+  virtual bool    GetCranking(void) { return Cranking; }
+  virtual int     GetType(void) { return Type; }
+  virtual string  GetName(void) { return Name; }
+
+  virtual double getFuelFlow_gph () const {
+    return FuelFlow_gph;
+  }
+
+  virtual double getManifoldPressure_inHg () const {
+    return ManifoldPressure_inHg;
+  }
+  virtual double getExhaustGasTemp_degF () const {
+    return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
+  }
+  virtual double getCylinderHeadTemp_degF () const {
+    return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
+  }
+  virtual double getOilPressure_psi () const {
+    return OilPressure_psi;
+  }
+  virtual double getOilTemp_degF () const {
+    return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
+  }
+
+  virtual void SetStarved(bool tt) {Starved = tt;}
+  virtual void SetStarved(void)    {Starved = true;}
 
-  enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet};
+  virtual void SetRunning(bool bb) { Running=bb; }
+  virtual void SetName(string name) {Name = name;}
+  virtual void AddFeedTank(int tkID);
 
-  float  GetThrottle(void) {return Throttle;}
-  float  GetThrust(void) {return Thrust;}
-  bool   GetStarved(void) {return Starved;}
-  bool   GetFlameout(void) {return Flameout;}
-  int    GetType(void) {return Type;}
-  string GetName() {return Name;}
+  virtual void SetMagnetos(int m) { Magnetos = m; }
+  virtual void SetStarter(bool s) { Starter = s;}
 
-  void SetStarved(bool tt) {Starved = tt;}
-  void SetStarved(void) {Starved = true;}
+  /** Calculates the thrust of the engine, and other engine functions.
+      @param PowerRequired this is the power required to run the thrusting device
+             such as a propeller. This resisting effect must be provided to the 
+             engine model.
+      @return Thrust in pounds */
+  virtual double Calculate(double PowerRequired) {return 0.0;};
 
-  float CalcThrust(void);
-  float CalcFuelNeed(void);
-  float CalcOxidizerNeed(void);
+  /** Reduces the fuel in the active tanks by the amount required.
+      This function should be called from within the
+      derived class' Calculate() function before any other calculations are
+      done. This base class method removes fuel from the fuel tanks as
+      appropriate, and sets the starved flag if necessary. */
+  virtual void ConsumeFuel(void);
 
-private:
+  /** The fuel need is calculated based on power levels and flow rate for that
+      power level. It is also turned from a rate into an actual amount (pounds)
+      by multiplying it by the delta T and the rate.
+      @return Total fuel requirement for this engine in pounds. */
+  virtual double CalcFuelNeed(void);
+
+  /** The oxidizer need is calculated based on power levels and flow rate for that
+      power level. It is also turned from a rate into an actual amount (pounds)
+      by multiplying it by the delta T and the rate.
+      @return Total oxidizer requirement for this engine in pounds. */
+  virtual double CalcOxidizerNeed(void);
+
+  /// Sets engine placement information
+  virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
+
+  /// Sets the engine number
+  virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
+
+  virtual double GetPowerAvailable(void) {return 0.0;};
+
+  virtual bool GetTrimMode(void) {return TrimMode;}
+  virtual void SetTrimMode(bool state) {TrimMode = state;}
+
+protected:
   string Name;
   EngineType Type;
-  float X, Y, Z;
-  float SLThrustMax;
-  float VacThrustMax;
-  float SLFuelFlowMax;
-  float SLOxiFlowMax;
-  float MaxThrottle;
-  float MinThrottle;
-
-  float BrakeHorsePower;
-  float SpeedSlope;
-  float SpeedIntercept;
-  float AltitudeSlope;
-
-  float Thrust;
-  float Throttle;
-  float FuelNeed, OxidizerNeed;
+  double X, Y, Z;
+  double EnginePitch;
+  double EngineYaw;
+  double SLFuelFlowMax;
+  double SLOxiFlowMax;
+  double MaxThrottle;
+  double MinThrottle;
+
+  double Thrust;
+  double Throttle;
+  double Mixture;
+  int   Magnetos;
+  bool  Starter;
+  double FuelNeed, OxidizerNeed;
   bool  Starved;
   bool  Flameout;
-  float PctPower;
+  bool  Running;
+  bool  Cranking;
+  double PctPower;
   int   EngineNumber;
+  bool  TrimMode;
+
+  double FuelFlow_gph;
+  double ManifoldPressure_inHg;
+  double ExhaustGasTemp_degK;
+  double CylinderHeadTemp_degK;
+  double OilPressure_psi;
+  double OilTemp_degK;
 
   FGFDMExec*      FDMExec;
   FGState*        State;
   FGAtmosphere*   Atmosphere;
   FGFCS*          FCS;
+  FGPropulsion*   Propulsion;
   FGAircraft*     Aircraft;
   FGTranslation*  Translation;
   FGRotation*     Rotation;
@@ -130,11 +238,22 @@ private:
   FGAuxiliary*    Auxiliary;
   FGOutput*       Output;
 
-protected:
-  float CalcRocketThrust(void);
-  float CalcPistonThrust(void);
-
+  vector <int> SourceTanks;
+  virtual void Debug(int from);
 };
 
-/******************************************************************************/
+#include "FGState.h"
+#include "FGFDMExec.h"
+#include "FGAtmosphere.h"
+#include "FGFCS.h"
+#include "FGAircraft.h"
+#include "FGTranslation.h"
+#include "FGRotation.h"
+#include "FGPropulsion.h"
+#include "FGPosition.h"
+#include "FGAuxiliary.h"
+#include "FGOutput.h"
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 #endif
+