]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.h
Merge branch 'next' of http://git.gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
index 6ae678cfd9a66811f0ef0f3d96b581cca7857cfa..b982654e7aa613158ec47548c21fbb0b5ac18d76 100644 (file)
@@ -4,7 +4,7 @@
  Date started: 11/17/98
  file The header file for the JSBSim executive.
 
- ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -41,24 +41,26 @@ SENTRY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#include <models/FGModel.h>
-#include <models/FGOutput.h>
-#include <models/FGInput.h>
-#include <initialization/FGTrim.h>
-#include <initialization/FGInitialCondition.h>
-#include <FGJSBBase.h>
-#include <input_output/FGPropertyManager.h>
-#include <input_output/FGXMLParse.h>
-#include <input_output/FGGroundCallback.h>
-#include <models/FGPropagate.h>
-
 #include <vector>
+#include <string>
+
+//#include "models/FGModel.h"
+#include "models/FGOutput.h"
+#include "models/FGInput.h"
+#include "initialization/FGTrim.h"
+#include "initialization/FGInitialCondition.h"
+#include "FGJSBBase.h"
+#include "input_output/FGPropertyManager.h"
+#include "input_output/FGGroundCallback.h"
+#include "input_output/FGXMLFileRead.h"
+#include "models/FGPropagate.h"
+#include "math/FGColumnVector3.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_FDMEXEC "$Id$"
+#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.56 2010/11/18 20:37:10 jberndt Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -67,6 +69,21 @@ FORWARD DECLARATIONS
 namespace JSBSim {
 
 class FGScript;
+class FGTrim;
+class FGAerodynamics;
+class FGAircraft;
+class FGAtmosphere;
+class FGAuxiliary;
+class FGBuoyantForces;
+class FGExternalReactions;
+class FGGroundReactions;
+class FGFCS;
+class FGInertial;
+class FGInput;
+class FGOutput;
+class FGPropagate;
+class FGPropulsion;
+class FGMassBalance;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DOCUMENTATION
@@ -84,8 +101,8 @@ CLASS DOCUMENTATION
     file:
 
     @code
-    fdmex = new FGFDMExec( \85 );
-    result = fdmex->LoadModel( \85 );
+    fdmex = new FGFDMExec( ... );
+    result = fdmex->LoadModel( ... );
     @endcode
 
     When an aircraft model is loaded, the config file is parsed and for each of the
@@ -166,23 +183,52 @@ CLASS DOCUMENTATION
                                 property actually maps toa function call of DoTrim().
 
     @author Jon S. Berndt
-    @version $Revision$
+    @version $Revision: 1.56 $
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGFDMExec : public FGJSBBase
+class FGFDMExec : public FGJSBBase, public FGXMLFileRead
 {
+  struct childData {
+    FGFDMExec* exec;
+    string info;
+    FGColumnVector3 Loc;
+    FGColumnVector3 Orient;
+    bool mated;
+    bool internal;
+
+    childData(void) {
+      info = "";
+      Loc = FGColumnVector3(0,0,0);
+      Orient = FGColumnVector3(0,0,0);
+      mated = true;
+      internal = false;
+    }
+    
+    void Run(void) {exec->Run();}
+    void AssignState(FGPropagate* source_prop) {
+      exec->GetPropagate()->SetVState(source_prop->GetVState());
+    }
+
+    ~childData(void) {
+      delete exec;
+    }
+  };
+
 public:
 
   /// Default constructor
-  FGFDMExec(FGPropertyManager* root = 0);
+  FGFDMExec(FGPropertyManager* root = 0, unsigned int* fdmctr = 0);
 
   /// Default destructor
   ~FGFDMExec();
 
+  /** Unbind all tied JSBSim properties. */
+  void Unbind(void) {instance->Unbind();}
+
   /** This routine places a model into the runlist at the specified rate. The
       "rate" is not really a clock rate. It represents how many calls to the
       FGFDMExec::Run() method must be made before the model is executed. A
@@ -193,7 +239,7 @@ public:
       @param model A pointer to the model being scheduled.
       @param rate The rate at which to execute the model as described above.
       @return Currently returns 0 always. */
-  int  Schedule(FGModel* model, int rate);
+  void Schedule(FGModel* model, int rate);
 
   /** This function executes each scheduled model in succession.
       @return true if successful, false if sim should be ended  */
@@ -214,6 +260,8 @@ public:
       modeled aircraft such as C172/, x15/, etc.
       @param EnginePath path to the directory under which engine config
       files are kept, for instance "engine"
+      @param SystemsPath path to the directory under which systems config
+      files are kept, for instance "systems"
       @param model the name of the aircraft model itself. This file will
       be looked for in the directory specified in the AircraftPath variable,
       and in turn under the directory with the same name as the model. For
@@ -221,8 +269,8 @@ public:
       @param addModelToPath set to true to add the model name to the
       AircraftPath, defaults to true
       @return true if successful */
-  bool LoadModel(string AircraftPath, string EnginePath, string model,
-                 bool addModelToPath = true);
+  bool LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
+                 const string& model, bool addModelToPath = true);
 
   /** Loads an aircraft model.  The paths to the aircraft and engine
       config file directories must be set prior to calling this.  See
@@ -234,92 +282,107 @@ public:
       @param addModelToPath set to true to add the model name to the
       AircraftPath, defaults to true
       @return true if successful*/
-  bool LoadModel(string model, bool addModelToPath = true);
+  bool LoadModel(const string& model, bool addModelToPath = true);
 
   /** Loads a script
       @param Script the full path name and file name for the script to be loaded.
       @return true if successfully loadsd; false otherwise. */
-  bool LoadScript(string Script);
+  bool LoadScript(const string& Script, double deltaT);
 
   /** Sets the path to the engine config file directories.
       @param path path to the directory under which engine config
       files are kept, for instance "engine"  */
-  bool SetEnginePath(string path)   { EnginePath = path; return true; }
+  bool SetEnginePath(const string& path)   { EnginePath = RootDir + path; return true; }
 
   /** Sets the path to the aircraft config file directories.
       @param path path to the aircraft directory. For instance:
       "aircraft". Under aircraft, then, would be directories for various
       modeled aircraft such as C172/, x15/, etc.  */
-  bool SetAircraftPath(string path) { AircraftPath = path; return true; }
-
+  bool SetAircraftPath(const string& path) { AircraftPath = RootDir + path; return true; }
+  
+  /** Sets the path to the systems config file directories.
+      @param path path to the directory under which systems config
+      files are kept, for instance "systems"  */
+  bool SetSystemsPath(const string& path)   { SystemsPath = RootDir + path; return true; }
+  
   /// @name Top-level executive State and Model retrieval mechanism
   //@{
   /// Returns the FGAtmosphere pointer.
-  inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
+  FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
   /// Returns the FGFCS pointer.
-  inline FGFCS* GetFCS(void)                  {return FCS;}
+  FGFCS* GetFCS(void)                  {return FCS;}
   /// Returns the FGPropulsion pointer.
-  inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
+  FGPropulsion* GetPropulsion(void)    {return Propulsion;}
   /// Returns the FGAircraft pointer.
-  inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
+  FGMassBalance* GetMassBalance(void)  {return MassBalance;}
   /// Returns the FGAerodynamics pointer
-  inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
+  FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
   /// Returns the FGInertial pointer.
-  inline FGInertial* GetInertial(void)        {return Inertial;}
+  FGInertial* GetInertial(void)        {return Inertial;}
   /// Returns the FGGroundReactions pointer.
-  inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+  FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+  /// Returns the FGExternalReactions pointer.
+  FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
+  /// Returns the FGBuoyantForces pointer.
+  FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
   /// Returns the FGAircraft pointer.
-  inline FGAircraft* GetAircraft(void)        {return Aircraft;}
+  FGAircraft* GetAircraft(void)        {return Aircraft;}
   /// Returns the FGPropagate pointer.
-  inline FGPropagate* GetPropagate(void)      {return Propagate;}
+  FGPropagate* GetPropagate(void)      {return Propagate;}
   /// Returns the FGAuxiliary pointer.
-  inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
+  FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
   /// Returns the FGInput pointer.
-  inline FGInput* GetInput(void)              {return Input;}
+  FGInput* GetInput(void)              {return Input;}
   /// Returns the FGGroundCallback pointer.
-  inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
-  /// Returns the FGState pointer.
-  inline FGState* GetState(void)              {return State;}
+  FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
+  /// Retrieves the script object
+  FGScript* GetScript(void) {return Script;}
   // Returns a pointer to the FGInitialCondition object
-  inline FGInitialCondition* GetIC(void)      {return IC;}
+  FGInitialCondition* GetIC(void)      {return IC;}
   // Returns a pointer to the FGTrim object
-  inline FGTrim* GetTrim(void);
+  FGTrim* GetTrim(void);
   //@}
 
   /// Retrieves the engine path.
-  inline string GetEnginePath(void)          {return EnginePath;}
+  const string& GetEnginePath(void)    {return EnginePath;}
   /// Retrieves the aircraft path.
-  inline string GetAircraftPath(void)        {return AircraftPath;}
+  const string& GetAircraftPath(void)  {return AircraftPath;}
+  /// Retrieves the systems path.
+  const string& GetSystemsPath(void)   {return SystemsPath;}
   /// Retrieves the full aircraft path name.
-  inline string GetFullAircraftPath(void)    {return FullAircraftPath;}
+  const string& GetFullAircraftPath(void) {return FullAircraftPath;}
 
   /** Retrieves the value of a property.
       @param property the name of the property
       @result the value of the specified property */
-  inline double GetPropertyValue(string property) {return instance->GetDouble(property);}
+  inline double GetPropertyValue(const string& property) {return instance->GetDouble(property);}
 
   /** Sets a property value.
       @param property the property to be set
       @param value the value to set the property to */
-  inline void SetPropertyValue(string property, double value) {
+  inline void SetPropertyValue(const string& property, double value) {
     instance->SetDouble(property, value);
   }
 
   /// Returns the model name.
-  string GetModelName(void) { return modelName; }
-
+  const string& GetModelName(void) { return modelName; }
+/*
   /// Returns the current time.
   double GetSimTime(void);
 
   /// Returns the current frame time (delta T).
   double GetDeltaT(void);
-
+*/  
   /// Returns a pointer to the property manager object.
   FGPropertyManager* GetPropertyManager(void);
   /// Returns a vector of strings representing the names of all loaded models (future)
   vector <string> EnumerateFDMs(void);
-  /// Marks this instance of the Exec object as a "slave" object.
-  void SetSlave(bool s) {IsSlave = s;}
+  /// Gets the number of child FDMs.
+  int GetFDMCount(void) {return (int)ChildFDMList.size();}
+  /// Gets a particular child FDM.
+  childData* GetChildFDM(int i) {return ChildFDMList[i];}
+  /// Marks this instance of the Exec object as a "child" object.
+  void SetChild(bool ch) {IsChild = ch;}
 
   /** Sets the output (logging) mechanism for this run.
       Calling this function passes the name of an output directives file to
@@ -336,12 +399,12 @@ public:
       be logged.
       @param fname the filename of an output directives file.
     */
-  bool SetOutputDirectives(string fname);
+  bool SetOutputDirectives(const string& fname);
 
   /** Sets (or overrides) the output filename
       @param fname the name of the file to output data to
       @return true if successful, false if there is no output specified for the flight model */
-  bool SetOutputFileName(string fname) {
+  bool SetOutputFileName(const string& fname) {
     if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
     else return false;
     return true;
@@ -365,6 +428,7 @@ public:
   * - tTurn
   * - tNone  */
   void DoTrim(int mode);
+//  void DoTrimAnalysis(int mode);
 
   /// Disables data logging to all outputs.
   void DisableOutput(void);
@@ -376,6 +440,8 @@ public:
   void Resume(void) {holding = false;}
   /// Returns true if the simulation is Holding (i.e. simulation time is not moving).
   bool Holding(void) {return holding;}
+  /// Resets the initial conditions object and prepares the simulation to run again.
+  void ResetToInitialConditions(void);
   /// Sets the debug level.
   void SetDebugLevel(int level) {debug_lvl = level;}
 
@@ -398,57 +464,95 @@ public:
   *   @param check The string to search for in the property catalog.
   *   @return the carriage-return-delimited string containing all matching strings
   *               in the catalog.  */
-  string QueryPropertyCatalog(string check);
+  string QueryPropertyCatalog(const string& check);
 
   // Print the contents of the property catalog for the loaded aircraft.
   void PrintPropertyCatalog(void);
 
+  vector<string>& GetPropertyCatalog(void) {return PropertyCatalog;}
+
   /// Use the MSIS atmosphere model.
   void UseAtmosphereMSIS(void);
 
   /// Use the Mars atmosphere model. (Not operative yet.)
   void UseAtmosphereMars(void);
 
+  void SetTrimStatus(bool status){ trim_status = status; }
+  bool GetTrimStatus(void) const { return trim_status; }
+  void SetTrimMode(int mode){ ta_mode = mode; }
+  int GetTrimMode(void) const { return ta_mode; }
+
+  /// Returns the cumulative simulation time in seconds.
+  double GetSimTime(void) const { return sim_time; }
+
+  /// Returns the simulation delta T.
+  double GetDeltaT(void) {return dT;}
+
+  /// Suspends the simulation and sets the delta T to zero.
+  void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
+
+  /// Resumes the simulation by resetting delta T to the correct value.
+  void ResumeIntegration(void)  {dT = saved_dT;}
+
+  /** Returns the simulation suspension state.
+      @return true if suspended, false if executing  */
+  bool IntegrationSuspended(void) {return dT == 0.0;}
+
+  /** Sets the current sim time.
+      @param cur_time the current time
+      @return the current simulation time.      */
+  double Setsim_time(double cur_time) {
+    sim_time = cur_time;
+    return sim_time;
+  }
+
+  /** Sets the integration time step for the simulation executive.
+      @param delta_t the time step in seconds.     */
+  void Setdt(double delta_t) { dT = delta_t; }
+
+  /** Sets the root directory where JSBSim starts looking for its system directories.
+      @param rootDir the string containing the root directory. */
+  void SetRootDir(const string& rootDir) {RootDir = rootDir;}
+
+  /** Retrieves teh Root Directory.
+      @return the string representing the root (base) JSBSim directory. */
+  const string& GetRootDir(void) const {return RootDir;}
+
+  /** Increments the simulation time.
+      @return the new simulation time.     */
+  double IncrTime(void) {
+    sim_time += dT;
+    return sim_time;
+  }
+
+  /** Retrieves the current debug level setting. */
+  int GetDebugLevel(void) const {return debug_lvl;};
+
 private:
-  static unsigned int FDMctr;
   int Error;
   unsigned int Frame;
   unsigned int IdFDM;
+  unsigned short Terminate;
+  double dT;
+  double saved_dT;
+  double sim_time;
   bool holding;
   bool Constructing;
   bool modelLoaded;
-  bool IsSlave;
+  bool IsChild;
   string modelName;
   string AircraftPath;
   string FullAircraftPath;
   string EnginePath;
+  string SystemsPath;
   string CFGVersion;
   string Release;
+  string RootDir;
 
-  struct slaveData {
-    FGFDMExec* exec;
-    string info;
-    double x, y, z;
-    double roll, pitch, yaw;
-    bool mated;
-
-    slaveData(void) {
-      info = "";
-      x = y = z = 0.0;
-      roll = pitch = yaw = 0.0;
-      mated = true;
-    }
-
-    ~slaveData(void) {
-      delete exec;
-    }
-  };
-
-  static FGPropertyManager *master;
+  bool trim_status;
+  int ta_mode;
 
-  FGModel*            FirstModel;
   FGGroundCallback*   GroundCallback;
-  FGState*            State;
   FGAtmosphere*       Atmosphere;
   FGFCS*              FCS;
   FGPropulsion*       Propulsion;
@@ -456,6 +560,8 @@ private:
   FGAerodynamics*     Aerodynamics;
   FGInertial*         Inertial;
   FGGroundReactions*  GroundReactions;
+  FGExternalReactions* ExternalReactions;
+  FGBuoyantForces*    BuoyantForces;
   FGAircraft*         Aircraft;
   FGPropagate*        Propagate;
   FGAuxiliary*        Auxiliary;
@@ -465,17 +571,24 @@ private:
   FGTrim*             Trim;
 
   FGPropertyManager* Root;
+  bool StandAlone;
   FGPropertyManager* instance;
+  
+  // The FDM counter is used to give each child FDM an unique ID. The root FDM has the ID 0
+  unsigned int*      FDMctr;
 
   vector <string> PropertyCatalog;
   vector <FGOutput*> Outputs;
-  vector <slaveData*> SlaveFDMList;
+  vector <childData*> ChildFDMList;
+  vector <FGModel*> Models;
 
   bool ReadFileHeader(Element*);
-  bool ReadSlave(Element*);
+  bool ReadChild(Element*);
   bool ReadPrologue(Element*);
+  void ResetToInitialConditions(int mode);
   bool Allocate(void);
   bool DeAllocate(void);
+  void Initialize(FGInitialCondition *FGIC);
 
   void Debug(int from);
 };