]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGState.h
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGState.h
index 4e0fcf67fd3f80c6b729215174931c23fbb14b38..5d7b70dcdef868a70a7c26e946c0486862e7a9f1 100644 (file)
@@ -26,9 +26,6 @@
 FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
  
-Based on Flightgear code, which is based on LaRCSim. This class wraps all
-global state variables (such as velocity, position, orientation, etc.).
 HISTORY
 --------------------------------------------------------------------------------
 11/17/98   JSB   Created
@@ -52,93 +49,304 @@ INCLUDES
 #    include <fstream.h>
 #  endif
 #else
-#  include <fstream>
+#  if defined(sgi) && !defined(__GNUC__)
+#    include <fstream.h>
+#  else
+#    include <fstream>
+#  endif
 #endif
 
 #include <string>
 #include <map>
-#include "FGDefs.h"
+#include "FGJSBBase.h"
 #include "FGInitialCondition.h"
-#include "FGMatrix.h"
+#include "FGMatrix33.h"
+#include "FGColumnVector3.h"
+#include "FGColumnVector4.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-DEFINES
+DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_STATE "$Header$"
+#define ID_STATE "$Id$"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-CLASS DECLARATION
+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]
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DOCUMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/** Encapsulates the calculation of aircraft state.
+    @author Jon S. Berndt
+    @version $Id$
+    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
+         Header File </a>
+    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
+         Source File </a>
+*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DECLARATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGState {
+class FGState : public FGJSBBase
+{
 public:
+  /** Constructor
+      @param Executive a pointer to the parent executive object */
   FGState(FGFDMExec*);
-  ~FGState(void);
+  /// 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);
 
-  bool Reset(string, string, string);
-  void Initialize(float, float, float, float, float, float, float, float, float);
+  /** 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.
+      @param lat latitude measured in radians from the equator, negative values are south.
+      @param lon longitude, measured in radians from the Greenwich meridian, negative values are west.
+      @param phi the roll angle in radians.
+      @param tht the pitch angle in radians.
+      @param psi the heading angle in radians measured clockwise from north.
+      @param h altitude in feet.
+      @param wnorth north velocity in feet per second
+      @param weast eastward velocity in feet per second
+      @param wdown downward velocity in feet per second
+      */
+  void Initialize(double U,
+                  double V,
+                  double W,
+                  double lat,
+                  double lon,
+                  double phi,
+                  double tht,
+                  double psi,
+                  double h,
+                  double wnorth,
+                  double weast,
+                  double wdown);
+
+  /** Initializes the simulation state based on parameters from an Initial Conditions object.
+      @param FGIC pointer to an initial conditions object.
+      @see FGInitialConditions.
+      */
   void Initialize(FGInitialCondition *FGIC);
-  bool StoreData(string);
 
-  inline float Geta(void) { return a; }
+  /// returns the speed of sound in feet per second.
+  inline double Geta(void) { return a; }
 
-  inline float Getsim_time(void) { return sim_time; }
-  inline float Getdt(void) { return dt; }
+  /// Returns the simulation time in seconds.
+  inline double Getsim_time(void) const { return sim_time; }
+  /// Returns the simulation delta T.
+  inline double Getdt(void) { return dt; }
 
+  /// Suspends the simulation and sets the delta T to zero.
   inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
+  /// Resumes the simulation by resetting delta T to the correct value.
   inline void Resume(void)  {dt = saved_dt;}
 
-  float GetParameter(eParam val_idx);
-  float GetParameter(string val_string);
-  eParam GetParameterIndex(string val_string);
-
+  /** Sets the speed of sound.
+      @param speed the speed of sound in feet per second.
+      */
+  inline void Seta(double speed) { a = speed; }
 
-  inline void Seta(float tt) { a = tt; }
-
-  inline float Setsim_time(float tt) {
-    sim_time = tt;
+  /** Sets the current sim time.
+      @param cur_time the current time
+      @return the current time.
+      */
+  inline double Setsim_time(double cur_time) {
+    sim_time = cur_time;
     return sim_time;
   }
-  inline void  Setdt(float tt) { dt = tt; }
-
-  void SetParameter(eParam, float);
+  
+  /** Sets the integration time step for the simulation executive.
+      @param delta_t the time step in seconds.
+      */
+  inline void  Setdt(double delta_t) { dt = delta_t; }
 
-  inline float IncrTime(void) {
+  /** Increments the simulation time.
+      @return the new simulation time.
+      */
+  inline double IncrTime(void) {
     sim_time+=dt;
     return sim_time;
   }
-  void InitMatrices(float phi, float tht, float psi);
+
+  /** Initializes the transformation matrices.
+      @param phi the roll angle in radians.
+      @param tht the pitch angle in radians.
+      @param psi the heading angle in radians
+      */
+  void InitMatrices(double phi, double tht, double psi);
+
+  /** Calculates the local-to-body and body-to-local conversion matrices.
+      */
   void CalcMatrices(void);
-  void IntegrateQuat(FGColumnVector vPQR, int rate);
-  FGColumnVector CalcEuler(void);
-  FGMatrix GetTs2b(float alpha, float beta);
-  FGMatrix GetTl2b(void) { return mTl2b; }
-  FGMatrix GetTb2l(void) { return mTb2l; }
-  typedef map<eParam, string> ParamMap;
-  ParamMap paramdef;
 
-private:
+  /** Integrates the quaternion.
+      Given the supplied rotational rate vector and integration rate, the quaternion
+      is integrated. The quaternion is later used to update the transformation
+      matrices.
+      @param vPQR the body rotational rate column vector.
+      @param rate the integration rate in seconds.
+      */
+  void IntegrateQuat(FGColumnVector3 vPQR, int rate);
+
+  /** Calculates Euler angles from the local-to-body matrix.
+      @return a reference to the vEuler column vector.
+      */
+  FGColumnVector3& CalcEuler(void);
+
+  /** Calculates and returns the stability-to-body axis transformation matrix.
+      @return a reference to the stability-to-body transformation matrix.
+      */
+  FGMatrix33& GetTs2b(void);
+  
+  /** Calculates and returns the body-to-stability axis transformation matrix.
+      @return a reference to the stability-to-body transformation matrix.
+      */
+  FGMatrix33& GetTb2s(void);
+
+  /** Retrieves the local-to-body transformation matrix.
+      @return a reference to the local-to-body transformation matrix.
+      */
+  FGMatrix33& GetTl2b(void) { return mTl2b; }
+
+  /** Retrieves a specific local-to-body matrix element.
+      @param r matrix row index.
+      @param c matrix column index.
+      @return the matrix element described by the row and column supplied.
+      */
+  double GetTl2b(int r, int c) { return mTl2b(r,c);}
 
-  float a;                          // speed of sound
-  float sim_time, dt;
-  float saved_dt;
+  /** Retrieves the body-to-local transformation matrix.
+      @return a reference to the body-to-local matrix.
+      */
+  FGMatrix33& GetTb2l(void) { return mTb2l; }
+
+  /** Retrieves a specific body-to-local matrix element.
+      @param r matrix row index.
+      @param c matrix column index.
+      @return the matrix element described by the row and column supplied.
+      */
+  double GetTb2l(int i, int j) { return mTb2l(i,j);}
+  
+  /** Prints a summary of simulator state (speed, altitude, 
+      configuration, etc.)
+  */
+  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();
+
+private:
+  double a;                          // speed of sound
+  double sim_time, dt;
+  double saved_dt;
 
   FGFDMExec* FDMExec;
-  FGMatrix mTb2l;
-  FGMatrix mTl2b;
-  FGMatrix mTs2b;
-  FGColumnVector vQtrn;
+  FGMatrix33 mTb2l;
+  FGMatrix33 mTl2b;
+  FGMatrix33 mTs2b;
+  FGMatrix33 mTb2s;
+  FGColumnVector4 vQtrn;
+  FGColumnVector4 vlastQdot;
+  FGColumnVector4 vQdot;
+  FGColumnVector3 vUVW;
+  FGColumnVector3 vLocalVelNED;
+  FGColumnVector3 vLocalEuler;
+  
+  FGColumnVector4 vTmp;
+  FGColumnVector3 vEuler;
 
-  typedef map<string, eParam> CoeffMap;
+  FGAircraft* Aircraft;
+  FGPosition* Position;
+  FGTranslation* Translation;
+  FGRotation* Rotation;
+  FGOutput* Output;
+  FGAtmosphere* Atmosphere;
+  FGFCS* FCS;
+  FGAerodynamics* Aerodynamics;
+  FGGroundReactions* GroundReactions;
+  FGPropulsion* Propulsion;
+  FGPropertyManager* PropertyManager;
+
+ /*  typedef map<string, eParam> CoeffMap;
   CoeffMap coeffdef;
 
-protected:
-  enum {ePhi=1, eTht, ePsi};
-  enum {eP=1, eQ, eR};
+  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
+