]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGState.h
Updates from JSBSim, including new turbine engine model from David Culp
[flightgear.git] / src / FDM / JSBSim / FGState.h
index 5d7b70dcdef868a70a7c26e946c0486862e7a9f1..ffab08c731ff994b0e94de31a8997bcbfe3a040d 100644 (file)
@@ -64,6 +64,19 @@ INCLUDES
 #include "FGColumnVector3.h"
 #include "FGColumnVector4.h"
 
+#include "FGFDMExec.h"
+#include "FGAtmosphere.h"
+#include "FGFCS.h"
+#include "FGTranslation.h"
+#include "FGRotation.h"
+#include "FGPosition.h"
+#include "FGAerodynamics.h"
+#include "FGOutput.h"
+#include "FGAircraft.h"
+#include "FGGroundReactions.h"
+#include "FGPropulsion.h"
+
+
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -74,16 +87,6 @@ DEFINITIONS
 FORWARD DECLARATIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGAircraft;
-class FGTranslation;
-class FGRotation;
-class FGAtmosphere;
-class FGOutput;
-class FGPosition;
-class FGFDMExec;
-class FGGroundReactions;
-class FGPropulsion;
-
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -105,6 +108,8 @@ CLASS DOCUMENTATION
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+namespace JSBSim {
+
 class FGState : public FGJSBBase
 {
 public:
@@ -114,30 +119,7 @@ public:
   /// Destructor
   ~FGState();
 
-  /** Specifies the Reset file to use.
-      The reset file normally resides in the same directory as an aircraft config file.
-      it includes the following information:
-      <ul>
-      <li>U, the body X-Axis velocity</li>
-      <li>V, the body Y-Axis velocity</li>
-      <li>W, the body Z-Axis velocity</li>
-      <li>Latitude measured in radians from the equator, negative values are south.</li>
-      <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
-      <li>Phi, the roll angle in radians.</li>
-      <li>Theta, the pitch attitude in radians.</li>
-      <li>Psi, the heading angle in radians.</li>
-      <li>H, the altitude in feet</li>
-      <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
-      <li>Wind magnitude, the wind speed in fps.</li>
-      </ul>
-      @param path the path string leading to the specific aircraft file, i.e. "aircraft".
-      @param aircraft the name of the aircraft, i.e. "c172".
-      @param filename the name of the reset file without an extension, i.e. "reset00".
-      @return true if successful, false if the file could not be opened.
-      */
-  bool Reset(string path, string aircraft, string filename);
-
-  /** Initializes the simulation state based on the passed-in parameters.
+ /** Initializes the simulation state based on the passed-in parameters.
       @param U the body X-Axis velocity in fps.
       @param V the body Y-Axis velocity in fps.
       @param W the body Z-Axis velocity in fps.
@@ -229,6 +211,77 @@ public:
       @param rate the integration rate in seconds.
       */
   void IntegrateQuat(FGColumnVector3 vPQR, int rate);
+  
+  // ======================================= General Purpose INTEGRATOR
+
+  enum iType {AB4, AB3, AB2, AM3, EULER, TRAPZ};
+  
+  /** Multi-method integrator.
+      @param type Type of intergation scheme to use. Can be one of:
+             <ul>
+             <li>AB4 - Adams-Bashforth, fourth order</li>
+             <li>AB3 - Adams-Bashforth, third order</li>
+             <li>AB2 - Adams-Bashforth, second order</li>
+             <li>AM3 - Adams Moulton, third order</li>
+             <li>EULER - Euler</li>
+             <li>TRAPZ - Trapezoidal</li>
+             </ul>
+      @param delta_t the integration time step in seconds
+      @param vTDeriv a reference to the current value of the time derivative of
+             the quantity being integrated (i.e. if vUVW is being integrated
+             vTDeriv is the current value of vUVWdot)
+      @param vLastArray an array of previously calculated and saved values of 
+             the quantity being integrated (i.e. if vUVW is being integrated
+             vLastArray[0] is the past value of vUVWdot, vLastArray[1] is the value of
+             vUVWdot prior to that, etc.)
+      @return the current, incremental value of the item integrated to add to the
+              previous value. */
+  
+  template <class T> T Integrate(iType type, double delta_t, T& vTDeriv, T *vLastArray)
+  {
+    T vResult;
+
+    switch (type) {
+    case AB4:
+      vResult = (delta_t/24.0)*(  55.0 * vTDeriv
+                                - 59.0 * vLastArray[0]
+                                + 37.0 * vLastArray[1]
+                                -  9.0 * vLastArray[2] );
+      vLastArray[2] = vLastArray[1];
+      vLastArray[1] = vLastArray[0];
+      vLastArray[0] = vTDeriv;
+      break;
+    case AB3:
+      vResult = (delta_t/12.0)*(  23.0 * vTDeriv
+                                - 16.0 * vLastArray[0]
+                                +  5.0 * vLastArray[1] );
+      vLastArray[1] = vLastArray[0];
+      vLastArray[0] = vTDeriv;
+      break;
+    case AB2:
+      vResult = (delta_t/2.0)*( 3.0 * vTDeriv - vLastArray[0] );
+      vLastArray[0] = vTDeriv;
+      break;
+    case AM3:
+      vResult = (delta_t/12.0)*(  5.0 * vTDeriv
+                                + 8.0 * vLastArray[0]
+                                - 1.0 * vLastArray[1] );
+      vLastArray[1] = vLastArray[0];
+      vLastArray[0] = vTDeriv;
+      break;
+    case EULER:
+      vResult = delta_t * vTDeriv;
+      break;
+    case TRAPZ:
+      vResult = (delta_t*0.5) * (vTDeriv + vLastArray[0]);
+      vLastArray[0] = vTDeriv;
+      break;
+    }
+
+    return vResult;
+  }
+
+  // =======================================
 
   /** Calculates Euler angles from the local-to-body matrix.
       @return a reference to the vEuler column vector.
@@ -274,10 +327,6 @@ public:
   */
   void ReportState(void);
   
-  inline string GetPropertyName(string prm) { return ParamNameToProp[prm]; }
-  //inline string GetPropertyName(eParam prm) { return ParamIdxToProp[prm]; }
-  //inline eParam GetParam(string property) { return PropToParam[property]; }
-  
   void bind();
   void unbind();
 
@@ -292,7 +341,7 @@ private:
   FGMatrix33 mTs2b;
   FGMatrix33 mTb2s;
   FGColumnVector4 vQtrn;
-  FGColumnVector4 vlastQdot;
+  FGColumnVector4 vQdot_prev[3];
   FGColumnVector4 vQdot;
   FGColumnVector3 vUVW;
   FGColumnVector3 vLocalVelNED;
@@ -313,40 +362,11 @@ private:
   FGPropulsion* Propulsion;
   FGPropertyManager* PropertyManager;
 
- /*  typedef map<string, eParam> CoeffMap;
-  CoeffMap coeffdef;
-
-  typedef map<eParam, string> ParamMap;
-  //ParamMap paramdef; */
-
-  
-  typedef map<string,string> ParamNameMap;
-  ParamNameMap ParamNameToProp;
-  
-  typedef map<eParam,string> ParamIdxMap;
-  ParamIdxMap ParamIdxToProp;
-  //CoeffMap PropToParam;
-
-  int ActiveEngine;
-  
-  void InitPropertyMaps(void);
-  
   void Debug(int from);
 };
-
+}
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-#include "FGFDMExec.h"
-#include "FGAtmosphere.h"
-#include "FGFCS.h"
-#include "FGTranslation.h"
-#include "FGRotation.h"
-#include "FGPosition.h"
-#include "FGAerodynamics.h"
-#include "FGOutput.h"
-#include "FGAircraft.h"
-#include "FGGroundReactions.h"
-#include "FGPropulsion.h"
 
 #endif