]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.h
Attached patches remove BORLANDC, and hence SG_MATH_EXCEPTION_CLASH and SG_INCOM
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
index 2425d42f77b3f17ccc5f317c47088c10a32f8c62..787a43d759f1387df2774a2279b7e8c30016de67 100644 (file)
@@ -2,24 +2,25 @@
  Header:       FGFDMExec.h
  Author:       Jon Berndt
  Date started: 11/17/98
+ file The header file for the JSBSim executive.
 
  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
+ the terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
 
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  details.
 
- You should have received a copy of the GNU General Public License along with
+ You should have received a copy of the GNU Lesser General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
 
- Further information about the GNU General Public License can also be found on
+ Further information about the GNU Lesser General Public License can also be found on
  the world wide web at http://www.gnu.org.
 
 HISTORY
@@ -47,11 +48,12 @@ INCLUDES
 #include <initialization/FGInitialCondition.h>
 #include <FGJSBBase.h>
 #include <input_output/FGPropertyManager.h>
-#include <input_output/FGXMLParse.h>
 #include <input_output/FGGroundCallback.h>
+#include <input_output/FGXMLFileRead.h>
 #include <models/FGPropagate.h>
 
 #include <vector>
+#include <string>
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
@@ -65,6 +67,9 @@ FORWARD DECLARATIONS
 
 namespace JSBSim {
 
+class FGScript;
+class FGTrim;
+
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DOCUMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -121,11 +126,9 @@ CLASS DOCUMENTATION
 
     @code
     FDMExec = new JSBSim::FGFDMExec();
-    Script = new JSBSim::FGScript( \85 );
-    Script->LoadScript( ScriptName ); // the script loads the aircraft and ICs
+    FDMExec->LoadScript( ScriptName ); // the script loads the aircraft and ICs
     result = FDMExec->Run();
     while (result) { // cyclic execution
-      if (Scripted) if (!Script->RunScript()) break; // execute script
       result = FDMExec->Run(); // execute JSBSim
     }
     @endcode
@@ -158,10 +161,11 @@ CLASS DOCUMENTATION
        a message is printed out when they go out of bounds
 
     <h3>Properties</h3>
-    @property simulator/do_trim Can be set to the integer equivalent to one of
+    @property simulator/do_trim (write only) Can be set to the integer equivalent to one of
                                 tLongitudinal (0), tFull (1), tGround (2), tPullup (3),
                                 tCustom (4), tTurn (5). Setting this to a legal value
-                                (such as by a script) causes a trim to be performed.
+                                (such as by a script) causes a trim to be performed. This
+                                property actually maps toa function call of DoTrim().
 
     @author Jon S. Berndt
     @version $Revision$
@@ -171,7 +175,7 @@ CLASS DOCUMENTATION
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGFDMExec : public FGJSBBase
+class FGFDMExec : public FGJSBBase, public FGXMLFileRead
 {
 public:
 
@@ -212,6 +216,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
@@ -219,8 +225,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(string AircraftPath, string EnginePath, string SystemsPath,
+                 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,6 +240,11 @@ public:
       @return true if successful*/
   bool LoadModel(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);
+
   /** 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"  */
@@ -244,7 +255,12 @@ public:
       "aircraft". Under aircraft, then, would be directories for various
       modeled aircraft such as C172/, x15/, etc.  */
   bool SetAircraftPath(string path) { AircraftPath = 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(string path)   { SystemsPath = path; return true; }
+  
   /// @name Top-level executive State and Model retrieval mechanism
   //@{
   /// Returns the FGAtmosphere pointer.
@@ -261,6 +277,10 @@ public:
   inline FGInertial* GetInertial(void)        {return Inertial;}
   /// Returns the FGGroundReactions pointer.
   inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+  /// Returns the FGExternalReactions pointer.
+  inline FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
+  /// Returns the FGBuoyantForces pointer.
+  inline FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
   /// Returns the FGAircraft pointer.
   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
   /// Returns the FGPropagate pointer.
@@ -273,26 +293,84 @@ public:
   inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
   /// Returns the FGState pointer.
   inline FGState* GetState(void)              {return State;}
+  /// Retrieves the script object
+  inline FGScript* GetScript(void) {return Script;}
   // Returns a pointer to the FGInitialCondition object
   inline 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;}
   /// Retrieves the aircraft path.
   inline string GetAircraftPath(void)        {return AircraftPath;}
+  /// Retrieves the systems path.
+  inline string GetSystemsPath(void)         {return SystemsPath;}
+  /// Retrieves the full aircraft path name.
+  inline 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);}
+
+  /** 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) {
+    instance->SetDouble(property, value);
+  }
 
   /// Returns the model name.
   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(void) {IsSlave = true;}
+  void SetSlave(bool s) {IsSlave = s;}
+
+  /** Sets the output (logging) mechanism for this run.
+      Calling this function passes the name of an output directives file to
+      the FGOutput object associated with this run. The call to this function
+      should be made prior to loading an aircraft model. This call results in an
+      FGOutput object being built as the first Output object in the FDMExec-managed
+      list of Output objects that may be created for an aircraft model. If this call
+      is made after an aircraft model is loaded, there is no effect. Any Output
+      objects added by the aircraft model itself (in an &lt;output> element) will be
+      added after this one. Care should be taken not to refer to the same file
+      name.
+      An output directives file contains an &lt;output> &lt;/output> element, within
+      which should be specified the parameters or parameter groups that should
+      be logged.
+      @param fname the filename of an output directives file.
+    */
+  bool SetOutputDirectives(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) {
+    if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
+    else return false;
+    return true;
+  }
+
+  /** Retrieves the current output filename.
+      @return the name of the output file for the first output specified by the flight model.
+              If none is specified, the empty string is returned. */
+  string GetOutputFileName(void) {
+    if (Outputs.size() > 0) return Outputs[0]->GetOutputFileName();
+    else return string("");
+  }
 
   /** Executes trimming in the selected mode.
   *   @param mode Specifies how to trim:
@@ -304,6 +382,7 @@ public:
   * - tTurn
   * - tNone  */
   void DoTrim(int mode);
+//  void DoTrimAnalysis(int mode);
 
   /// Disables data logging to all outputs.
   void DisableOutput(void);
@@ -315,6 +394,10 @@ 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;}
 
   struct PropertyCatalogStructure {
     /// Name of the property.
@@ -337,29 +420,41 @@ public:
   *               in the catalog.  */
   string QueryPropertyCatalog(string check);
 
+  // Print the contents of the property catalog for the loaded aircraft.
+  void PrintPropertyCatalog(void);
+
   /// Use the MSIS atmosphere model.
   void UseAtmosphereMSIS(void);
 
   /// Use the Mars atmosphere model. (Not operative yet.)
   void UseAtmosphereMars(void);
 
-private:
-  FGModel* FirstModel;
+  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; }
 
-  bool terminate;
-  bool holding;
-  bool Constructing;
-  int  Error;
+private:
+  static unsigned int FDMctr;
+  int Error;
   unsigned int Frame;
   unsigned int IdFDM;
-  FGPropertyManager* Root;
-  static unsigned int FDMctr;
+  unsigned short Terminate;
+  bool holding;
+  bool Constructing;
   bool modelLoaded;
-  string modelName;
   bool IsSlave;
-  static FGPropertyManager *master;
-  FGPropertyManager *instance;
-  vector <string> PropertyCatalog;
+  string modelName;
+  string AircraftPath;
+  string FullAircraftPath;
+  string EnginePath;
+  string SystemsPath;
+  string CFGVersion;
+  string Release;
+
+  bool trim_status;
+  int ta_mode;
+
 
   struct slaveData {
     FGFDMExec* exec;
@@ -380,41 +475,43 @@ private:
     }
   };
 
-  string AircraftPath;
-  string EnginePath;
-
-  string CFGVersion;
-  string Release;
-
-  FGGroundCallback*  GroundCallback;
-  FGState*           State;
-  FGAtmosphere*      Atmosphere;
-  FGFCS*             FCS;
-  FGPropulsion*      Propulsion;
-  FGMassBalance*     MassBalance;
-  FGAerodynamics*    Aerodynamics;
-  FGInertial*        Inertial;
-  FGGroundReactions* GroundReactions;
-  FGAircraft*        Aircraft;
-  FGPropagate*       Propagate;
-  FGAuxiliary*       Auxiliary;
-  FGInput*           Input;
-  vector <FGOutput*> Outputs;
+  static FGPropertyManager *master;
 
+  FGModel*            FirstModel;
+  FGGroundCallback*   GroundCallback;
+  FGState*            State;
+  FGAtmosphere*       Atmosphere;
+  FGFCS*              FCS;
+  FGPropulsion*       Propulsion;
+  FGMassBalance*      MassBalance;
+  FGAerodynamics*     Aerodynamics;
+  FGInertial*         Inertial;
+  FGGroundReactions*  GroundReactions;
+  FGExternalReactions* ExternalReactions;
+  FGBuoyantForces*    BuoyantForces;
+  FGAircraft*         Aircraft;
+  FGPropagate*        Propagate;
+  FGAuxiliary*        Auxiliary;
+  FGInput*            Input;
+  FGScript*           Script;
   FGInitialCondition* IC;
-  FGTrim *Trim;
+  FGTrim*             Trim;
 
+  FGPropertyManager* Root;
+  FGPropertyManager* instance;
+
+  vector <string> PropertyCatalog;
+  vector <FGOutput*> Outputs;
   vector <slaveData*> SlaveFDMList;
 
   bool ReadFileHeader(Element*);
   bool ReadSlave(Element*);
   bool ReadPrologue(Element*);
-
   bool Allocate(void);
   bool DeAllocate(void);
+
   void Debug(int from);
 };
 }
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 #endif
-