]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.h
Remove a bunch of unneede files.
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
index 973bc37b3d559d9684c244a6ff28454f4d6356f5..e440ab76365818fee8c3cf87f0d86936eae1a531 100644 (file)
@@ -27,7 +27,7 @@ HISTORY
 11/17/98   JSB   Created
 7/31/99     TP   Added RunIC function that runs the sim so that every frame
                  begins with the IC values from the given FGInitialCondition
-                                  object and dt=0.
+                 object and dt=0.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 SENTRY
@@ -40,19 +40,18 @@ SENTRY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#ifdef FGFS
-#  include <simgear/compiler.h>
-#  ifdef FG_HAVE_STD_INCLUDES
-#    include <vector>
-#  else
-#    include <vector.h>
-#  endif
-#else
-#  include <vector>
-#endif
+#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 "FGModel.h"
-#include "FGInitialCondition.h"
+#include <vector>
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
@@ -64,146 +63,58 @@ DEFINITIONS
 FORWARD DECLARATIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGState;
-class FGAtmosphere;
-class FGFCS;
-class FGPropulsion;
-class FGAircraft;
-class FGTranslation;
-class FGRotation;
-class FGPosition;
-class FGAuxiliary;
-class FGOutput;
-class FGInitialCondition;
-
-struct condition {
-  vector <eParam>  TestParam;
-  vector <eParam>  SetParam;
-  vector <float>   TestValue;
-  vector <float>   SetValue;
-  vector <string>  Comparison;
-  vector <float>   TC;
-  vector <bool>    Persistent;
-  vector <eAction> Action;
-  vector <eType>   Type;
-  vector <bool>    Triggered;
-  vector <float>   newValue;
-  vector <float>   OriginalValue;
-  vector <float>   StartTime;
-  vector <float>   EndTime;
-
-  condition() {
-  }
-};
-
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+namespace JSBSim {
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DOCUMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 /** Encapsulates the JSBSim simulation executive.
-    @author Jon S. Berndt
-    @version $Id$
-
-    @doc This class is the interface class through which all other simulation classes
+    This class is the interface class through which all other simulation classes
     are instantiated, initialized, and run. When integrated with FlightGear (or
     other flight simulator) this class is typically instantiated by an interface
     class on the simulator side.
 
-    <h4>Scripting support provided in the Executive</h4>
-
-    <p>There is simple scripting support provided in the FGFDMExec
-    class. Commands are specified using the <u>Simple Scripting
-    Directives for JSBSim</u> (SSDJ). The script file is in XML
-    format. A test condition (or conditions) can be set up in the
-    script and when the condition evaluates to true, the specified
-    action[s] is/are taken. A test condition can be <em>persistent</em>,
-    meaning that if a test condition evaluates to true, then passes
-    and evaluates to false, the condition is reset and may again be
-    triggered. When the set of tests evaluates to true for a given
-    condition, an item may be set to another value. This value might
-    be a boolean, a value, or a delta value, and the change from the
-    current value to the new value can be either via a step function,
-    a ramp, or an exponential approach. The speed of a ramp or
-    approach is specified via the time constant. Here is the format
-    of the script file:</p>
-
-    <pre><strong>&lt;?xml version=&quot;1.0&quot;?&gt;
-    &lt;runscript name=&quot;C172-01A&quot;&gt;
-
-    &lt;!--
-    This run is for testing C172 runs
-    --&gt;
-
-    &lt;use aircraft=&quot;c172&quot;&gt;
-    &lt;use initialize=&quot;reset00&quot;&gt;
-
-    &lt;run start=&quot;0.0&quot; end=&quot;4.5&quot; dt=&quot;0.05&quot;&gt;
-      &lt;when&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.25&quot;&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;0.50&quot;&gt;
-        &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_VALUE&quot; value=&quot;0.25&quot;
-        action=&quot;FG_STEP&quot; persistent=&quot;false&quot; tc =&quot;0.25&quot;&gt;
-      &lt;/when&gt;
-      &lt;when&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.5&quot;&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;1.5&quot;&gt;
-        &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;
-        action=&quot;FG_EXP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;
-      &lt;/when&gt;
-      &lt;when&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;1.5&quot;&gt;
-        &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;2.5&quot;&gt;
-        &lt;set name=&quot;FG_RUDDER_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;
-        action=&quot;FG_RAMP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;
-      &lt;/when&gt;
-    &lt;/run&gt;
-
-    &lt;/runscript&gt;</strong></pre>
-
-    <p>The first line must always be present. The second line
-    identifies this file as a script file, and gives a descriptive
-    name to the script file. Comments are next, delineated by the
-    &lt;!-- and --&gt; symbols. The aircraft and initialization files
-    to be used are specified in the &quot;use&quot; lines. Next,
-    comes the &quot;run&quot; section, where the conditions are
-    described in &quot;when&quot; clauses.</p>
+    When an aircraft model is loaded the config file is parsed and for each of the
+    sections of the config file (propulsion, flight control, etc.) the
+    corresponding Load() method is called (e.g. LoadFCS).
 
     <h4>JSBSim Debugging Directives</h4>
 
     This describes to any interested entity the debug level
     requested by setting the JSBSIM_DEBUG environment variable.
-    The bitmasked value choices are as follows:<ol>
-    <li><b>unset</b>: In this case (the default) JSBSim would only print
+    The bitmasked value choices are as follows:
+    <b>unset</b>: In this case (the default) JSBSim would only print
        out the normally expected messages, essentially echoing
        the config files as they are read. If the environment
-       variable is not set, debug_lvl is set to 1 internally</li>
-    <li><b>0</b>: This requests JSBSim not to output any messages
-       whatsoever.</li>
-    <li><b>1</b>: This value explicity requests the normal JSBSim
-       startup messages</li>
-    <li><b>2</b>: This value asks for a message to be printed out when
-       a class is instantiated</li>
-    <li><b>4</b>: When this value is set, a message is displayed when a
-       FGModel object executes its Run() method</li>
-    <li><b>8</b>: When this value is set, various runtime state variables
-       are printed out periodically</li>
-    </ol>
+       variable is not set, debug_lvl is set to 1 internally
+    - <b>0</b>: This requests JSBSim not to output any messages
+       whatsoever
+    - <b>1</b>: This value explicity requests the normal JSBSim
+       startup messages
+    - <b>2</b>: This value asks for a message to be printed out when
+       a class is instantiated
+    - <b>4</b>: When this value is set, a message is displayed when a
+       FGModel object executes its Run() method
+    - <b>8</b>: When this value is set, various runtime state variables
+       are printed out periodically
+    - <b>16</b>: When set various parameters are sanity checked and
+       a message is printed out when they go out of bounds
 
+    @author Jon S. Berndt
+    @version $Id$
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGFDMExec
+class FGFDMExec : public FGJSBBase
 {
 public:
+
   /// Default constructor
-  FGFDMExec(void);
+  FGFDMExec(FGPropertyManager* root = 0);
 
   /// Default destructor
   ~FGFDMExec();
@@ -219,23 +130,18 @@ public:
       @return Currently returns 0 always. */
   int  Schedule(FGModel* model, int rate);
 
-  /** This executes each scheduled model in succession, as well as running any
-      scripts which are loaded.
+  /** This executes each scheduled model in succession.
       @return true if successful, false if sim should be ended  */
   bool Run(void);
 
-  /** Initializes the sim with a set of initial conditions.
-      @param fgic A pointer to a filled out initial conditions class which
-      describes the desired initial conditions.
-      @return true if successful
-       */
-  bool RunIC(FGInitialCondition *fgic);
-
-  /// Freezes the sim
-  void Freeze(void) {frozen = true;}
+  /** Initializes the sim from the initial condition object and executes
+      each scheduled model without integrating i.e. dt=0.
+      @return true if successful */
+  bool RunIC(void);
 
-  /// Resumes the sim
-  void Resume(void) {frozen = false;}
+  /** Sets the ground callback pointer.
+      @param gc A pointer to a ground callback object.  */
+  void SetGroundCallback(FGGroundCallback* gc);
 
   /** Loads an aircraft model.
       @param AircraftPath path to the aircraft directory. For instance:
@@ -247,27 +153,37 @@ public:
       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
       instance: "aircraft/x15/x15.xml"
+      @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 LoadModel(string AircraftPath, string EnginePath, string model,
+                 bool addModelToPath = true);
 
-  /** Loads a script to drive JSBSim (usually in standalone mode).
-      The language is the Simple Script Directives for JSBSim (SSDJ).
-      @param script the filename (including path name, if any) for the script.
-      @return true if successful */
-  bool LoadScript(string script);
+  /** Loads an aircraft model.  The paths to the aircraft and engine
+      config file directories must be set prior to calling this.  See
+      below.
+      @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
+      instance: "aircraft/x15/x15.xml"
+      @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);
 
-  /** This function is called each pass through the executive Run() method IF
-      scripting is enabled. */
-  void RunScript(void);
+  /** 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(string path)   {EnginePath = path; return true;}
-  bool SetAircraftPath(string path) {AircraftPath = path; return true;}
-  bool SetScriptPath(string path)   {ScriptPath = 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; }
 
   /// @name Top-level executive State and Model retrieval mechanism
   //@{
-  /// Returns the FGState pointer.
-  inline FGState* GetState(void)              {return State;}
   /// Returns the FGAtmosphere pointer.
   inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
   /// Returns the FGFCS pointer.
@@ -275,17 +191,29 @@ public:
   /// Returns the FGPropulsion pointer.
   inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
   /// Returns the FGAircraft pointer.
+  inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
+  /// Returns the FGAerodynamics pointer
+  inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
+  /// Returns the FGInertial pointer.
+  inline FGInertial* GetInertial(void)        {return Inertial;}
+  /// Returns the FGGroundReactions pointer.
+  inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+  /// Returns the FGAircraft pointer.
   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
-  /// Returns the FGTranslation pointer.
-  inline FGTranslation* GetTranslation(void)  {return Translation;}
-  /// Returns the FGRotation pointer.
-  inline FGRotation* GetRotation(void)        {return Rotation;}
-  /// Returns the FGPosition pointer.
-  inline FGPosition* GetPosition(void)        {return Position;}
+  /// Returns the FGPropagate pointer.
+  inline FGPropagate* GetPropagate(void)      {return Propagate;}
   /// Returns the FGAuxiliary pointer.
   inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
-  /// Returns the FGOutput pointer.
-  inline FGOutput* GetOutput(void)            {return Output;}
+  /// Returns the FGInput pointer.
+  inline 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;}
+  // Returns a pointer to the FGInitialCondition object
+  inline FGInitialCondition* GetIC(void)      {return IC;}
+  // Returns a pointer to the FGTrim object
+  inline FGTrim* GetTrim(void);
   //@}
 
   /// Retrieves the engine path.
@@ -293,40 +221,138 @@ public:
   /// Retrieves the aircraft path.
   inline string GetAircraftPath(void)        {return AircraftPath;}
 
+  /// Returns the model name.
+  string GetModelName(void) { return modelName; }
+
+  /// 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;}
+
+  /** Executes trimming in the selected mode.
+  *   @param mode Specifies how to trim:
+  * - tLongitudinal=0
+  * - tFull
+  * - tGround
+  * - tPullup
+  * - tCustom
+  * - tTurn
+  * - tNone
+  */
+  void DoTrim(int mode);
+
+  /// Disables data logging to all outputs.
+  void DisableOutput(void);
+  /// Enables data logging to all outputs.
+  void EnableOutput(void);
+  /// Pauses execution by preventing time from incrementing.
+  void Hold(void) {holding = true;}
+  /// Resumes execution from a "Hold".
+  void Resume(void) {holding = false;}
+  /// Returns true if the simulation is Holding (i.e. simulation time is not moving).
+  bool Holding(void) {return holding;}
+
+  struct PropertyCatalogStructure {
+    /// Name of the property.
+    string base_string;
+    /// The node for the property.
+    FGPropertyManager *node;
+  };
+
+  /** Builds a catalog of properties.
+  *   This function descends the property tree and creates a list (an STL vector)
+  *   containing the name and node for all properties.
+  *   @param pcs The "root" property catalog structure pointer.  */
+  void BuildPropertyCatalog(struct PropertyCatalogStructure* pcs);
+
+  /** Retrieves property or properties matching the supplied string.
+  *   A string is returned that contains a carriage return delimited list of all
+  *   strings in the property catalog that matches the supplied chack string.
+  *   @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);
+
+  /// Use the MSIS atmosphere model.
+  void UseAtmosphereMSIS(void);
+
+  /// Use the Mars atmosphere model. (Not operative yet.)
+  void UseAtmosphereMars(void); 
+
 private:
   FGModel* FirstModel;
 
-  bool frozen;
   bool terminate;
+  bool holding;
+  bool Constructing;
   int  Error;
-  int  Frame;
+  unsigned int Frame;
+  unsigned int IdFDM;
+  FGPropertyManager* Root;
+  static unsigned int FDMctr;
   bool modelLoaded;
-  bool Scripted;
+  string modelName;
+  bool IsSlave;
+  static FGPropertyManager *master;
+  FGPropertyManager *instance;
+  vector <string> PropertyCatalog;
+
+  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;
+    }
+  };
 
   string AircraftPath;
   string EnginePath;
-  string ScriptPath;
-  string ScriptName;
-  float  StartTime;
-  float  EndTime;
-  vector <struct condition> Conditions;
-
-  FGState*       State;
-  FGAtmosphere*  Atmosphere;
-  FGFCS*         FCS;
-  FGPropulsion*  Propulsion;
-  FGAircraft*    Aircraft;
-  FGTranslation* Translation;
-  FGRotation*    Rotation;
-  FGPosition*    Position;
-  FGAuxiliary*   Auxiliary;
-  FGOutput*      Output;
+
+  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;
+
+  FGInitialCondition* IC;
+  FGTrim *Trim;
+
+  vector <slaveData*> SlaveFDMList;
+
+  bool ReadFileHeader(Element*);
+  bool ReadSlave(Element*);
+  bool ReadPrologue(Element*);
 
   bool Allocate(void);
   bool DeAllocate(void);
-  void Debug(void);
+  void Debug(int from);
 };
-
+}
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 #endif