]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.h
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
index b982654e7aa613158ec47548c21fbb0b5ac18d76..408abef1554b4b42c18e60f8a7cddfac693516cc 100644 (file)
@@ -44,23 +44,18 @@ INCLUDES
 #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"
+#include "models/FGOutput.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.56 2010/11/18 20:37:10 jberndt Exp $"
+#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.86 2014/01/02 21:37:14 bcoconni Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -73,6 +68,8 @@ class FGTrim;
 class FGAerodynamics;
 class FGAircraft;
 class FGAtmosphere;
+class FGAccelerations;
+class FGWinds;
 class FGAuxiliary;
 class FGBuoyantForces;
 class FGExternalReactions;
@@ -80,8 +77,6 @@ class FGGroundReactions;
 class FGFCS;
 class FGInertial;
 class FGInput;
-class FGOutput;
-class FGPropagate;
 class FGPropulsion;
 class FGMassBalance;
 
@@ -183,18 +178,18 @@ CLASS DOCUMENTATION
                                 property actually maps toa function call of DoTrim().
 
     @author Jon S. Berndt
-    @version $Revision: 1.56 $
+    @version $Revision: 1.86 $
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DECLARATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-class FGFDMExec : public FGJSBBase, public FGXMLFileRead
+class FGFDMExec : public FGJSBBase
 {
   struct childData {
     FGFDMExec* exec;
-    string info;
+    std::string info;
     FGColumnVector3 Loc;
     FGColumnVector3 Orient;
     bool mated;
@@ -226,6 +221,26 @@ public:
   /// Default destructor
   ~FGFDMExec();
 
+  // This list of enums is very important! The order in which models are listed here
+  // determines the order of execution of the models.
+  enum eModels { ePropagate=0,
+                 eInput,
+                 eInertial,
+                 eAtmosphere,
+                 eWinds,
+                 eAuxiliary,
+                 eSystems,
+                 ePropulsion,
+                 eAerodynamics,
+                 eGroundReactions,
+                 eExternalReactions,
+                 eBuoyantForces,
+                 eMassBalance,
+                 eAircraft,
+                 eAccelerations,
+                 eOutput,
+                 eNumStandardModels };
+
   /** Unbind all tied JSBSim properties. */
   void Unbind(void) {instance->Unbind();}
 
@@ -238,8 +253,9 @@ public:
       one is at this time not recommended.
       @param model A pointer to the model being scheduled.
       @param rate The rate at which to execute the model as described above.
+                  Default is every frame (rate=1).
       @return Currently returns 0 always. */
-  void Schedule(FGModel* model, int rate);
+  void Schedule(FGModel* model, int rate=1);
 
   /** This function executes each scheduled model in succession.
       @return true if successful, false if sim should be ended  */
@@ -250,9 +266,14 @@ public:
       @return true if successful */
   bool RunIC(void);
 
-  /** Sets the ground callback pointer.
-      @param gc A pointer to a ground callback object.  */
-  void SetGroundCallback(FGGroundCallback* gc);
+  /** Sets the ground callback pointer. For optimal memory management, a shared
+      pointer is used internally that maintains a reference counter. The calling
+      application must therefore use FGGroundCallback_ptr 'smart pointers' to
+      manage their copy of the ground callback.
+      @param gc A pointer to a ground callback object
+      @see FGGroundCallback
+   */
+  void SetGroundCallback(FGGroundCallback* gc) { FGLocation::SetGroundCallback(gc); }
 
   /** Loads an aircraft model.
       @param AircraftPath path to the aircraft/ directory. For instance:
@@ -269,8 +290,9 @@ public:
       @param addModelToPath set to true to add the model name to the
       AircraftPath, defaults to true
       @return true if successful */
-  bool LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
-                 const string& model, bool addModelToPath = true);
+  bool LoadModel(const std::string& AircraftPath, const std::string& EnginePath,
+                 const std::string& SystemsPath, const std::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
@@ -282,90 +304,107 @@ public:
       @param addModelToPath set to true to add the model name to the
       AircraftPath, defaults to true
       @return true if successful*/
-  bool LoadModel(const string& model, bool addModelToPath = true);
+  bool LoadModel(const std::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(const string& Script, double deltaT);
+      @param Script The full path name and file name for the script to be loaded.
+      @param deltaT The simulation integration step size, if given.  If no value is supplied
+                    then 0.0 is used and the value is expected to be supplied in
+                    the script file itself.
+      @param initfile The initialization file that will override the initialization file
+                      specified in the script file. If no file name is given on the command line,
+                      the file specified in the script will be used. If an initialization file 
+                      is not given in either place, an error will result.
+      @return true if successfully loads; false otherwise. */
+  bool LoadScript(const std::string& Script, double deltaT=0.0,
+                  const std::string initfile="");
 
   /** 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(const string& path)   { EnginePath = RootDir + path; return true; }
+  bool SetEnginePath(const std::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(const string& path) { AircraftPath = RootDir + path; return true; }
+  bool SetAircraftPath(const std::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; }
+  bool SetSystemsPath(const std::string& path)   { SystemsPath = RootDir + path; return true; }
   
   /// @name Top-level executive State and Model retrieval mechanism
-  //@{
+  ///@{
   /// Returns the FGAtmosphere pointer.
-  FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
+  FGAtmosphere* GetAtmosphere(void)    {return (FGAtmosphere*)Models[eAtmosphere];}
+  /// Returns the FGAccelerations pointer.
+  FGAccelerations* GetAccelerations(void)    {return (FGAccelerations*)Models[eAccelerations];}
+  /// Returns the FGWinds pointer.
+  FGWinds* GetWinds(void)    {return (FGWinds*)Models[eWinds];}
   /// Returns the FGFCS pointer.
-  FGFCS* GetFCS(void)                  {return FCS;}
+  FGFCS* GetFCS(void)                  {return (FGFCS*)Models[eSystems];}
   /// Returns the FGPropulsion pointer.
-  FGPropulsion* GetPropulsion(void)    {return Propulsion;}
+  FGPropulsion* GetPropulsion(void)    {return (FGPropulsion*)Models[ePropulsion];}
   /// Returns the FGAircraft pointer.
-  FGMassBalance* GetMassBalance(void)  {return MassBalance;}
+  FGMassBalance* GetMassBalance(void)  {return (FGMassBalance*)Models[eMassBalance];}
   /// Returns the FGAerodynamics pointer
-  FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
+  FGAerodynamics* GetAerodynamics(void){return (FGAerodynamics*)Models[eAerodynamics];}
   /// Returns the FGInertial pointer.
-  FGInertial* GetInertial(void)        {return Inertial;}
+  FGInertial* GetInertial(void)        {return (FGInertial*)Models[eInertial];}
   /// Returns the FGGroundReactions pointer.
-  FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+  FGGroundReactions* GetGroundReactions(void) {return (FGGroundReactions*)Models[eGroundReactions];}
   /// Returns the FGExternalReactions pointer.
-  FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
+  FGExternalReactions* GetExternalReactions(void) {return (FGExternalReactions*)Models[eExternalReactions];}
   /// Returns the FGBuoyantForces pointer.
-  FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
+  FGBuoyantForces* GetBuoyantForces(void) {return (FGBuoyantForces*)Models[eBuoyantForces];}
   /// Returns the FGAircraft pointer.
-  FGAircraft* GetAircraft(void)        {return Aircraft;}
+  FGAircraft* GetAircraft(void)        {return (FGAircraft*)Models[eAircraft];}
   /// Returns the FGPropagate pointer.
-  FGPropagate* GetPropagate(void)      {return Propagate;}
+  FGPropagate* GetPropagate(void)      {return (FGPropagate*)Models[ePropagate];}
   /// Returns the FGAuxiliary pointer.
-  FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
+  FGAuxiliary* GetAuxiliary(void)      {return (FGAuxiliary*)Models[eAuxiliary];}
   /// Returns the FGInput pointer.
-  FGInput* GetInput(void)              {return Input;}
-  /// Returns the FGGroundCallback pointer.
-  FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
+  FGInput* GetInput(void)              {return (FGInput*)Models[eInput];}
+  /** Get a pointer to the ground callback currently used. It is recommanded
+      to store the returned pointer in a 'smart pointer' FGGroundCallback_ptr.
+      @return A pointer to the current ground callback object.
+      @see FGGroundCallback
+   */
+  FGGroundCallback* GetGroundCallback(void) {return FGLocation::GetGroundCallback();}
   /// Retrieves the script object
   FGScript* GetScript(void) {return Script;}
-  // Returns a pointer to the FGInitialCondition object
+  /// Returns a pointer to the FGInitialCondition object
   FGInitialCondition* GetIC(void)      {return IC;}
-  // Returns a pointer to the FGTrim object
+  /// Returns a pointer to the FGTrim object
   FGTrim* GetTrim(void);
-  //@}
+  ///@}
 
   /// Retrieves the engine path.
-  const string& GetEnginePath(void)    {return EnginePath;}
+  const std::string& GetEnginePath(void)    {return EnginePath;}
   /// Retrieves the aircraft path.
-  const string& GetAircraftPath(void)  {return AircraftPath;}
+  const std::string& GetAircraftPath(void)  {return AircraftPath;}
   /// Retrieves the systems path.
-  const string& GetSystemsPath(void)   {return SystemsPath;}
+  const std::string& GetSystemsPath(void)   {return SystemsPath;}
   /// Retrieves the full aircraft path name.
-  const string& GetFullAircraftPath(void) {return FullAircraftPath;}
+  const std::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(const string& property) {return instance->GetDouble(property);}
+  inline double GetPropertyValue(const std::string& property)
+  { return instance->GetNode()->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(const string& property, double value) {
-    instance->SetDouble(property, value);
+  inline void SetPropertyValue(const std::string& property, double value) {
+    instance->GetNode()->SetDouble(property, value);
   }
 
   /// Returns the model name.
-  const string& GetModelName(void) { return modelName; }
+  const std::string& GetModelName(void) const { return modelName; }
 /*
   /// Returns the current time.
   double GetSimTime(void);
@@ -376,11 +415,11 @@ public:
   /// 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);
+  std::vector <std::string> EnumerateFDMs(void);
   /// Gets the number of child FDMs.
-  int GetFDMCount(void) {return (int)ChildFDMList.size();}
+  int GetFDMCount(void) const {return (int)ChildFDMList.size();}
   /// Gets a particular child FDM.
-  childData* GetChildFDM(int i) {return ChildFDMList[i];}
+  childData* GetChildFDM(int i) const {return ChildFDMList[i];}
   /// Marks this instance of the Exec object as a "child" object.
   void SetChild(bool ch) {IsChild = ch;}
 
@@ -399,24 +438,25 @@ public:
       be logged.
       @param fname the filename of an output directives file.
     */
-  bool SetOutputDirectives(const string& fname);
+  bool SetOutputDirectives(const std::string& fname)
+  {return Output->SetDirectivesFile(RootDir + fname);}
+
+  /** Forces the specified output object to print its items once */
+  void ForceOutput(int idx=0) { Output->ForceOutput(idx); }
+
+  /** Sets the logging rate for all output objects (if any). */
+  void SetLoggingRate(double rate) { Output->SetRate(rate); }
 
   /** 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(const string& fname) {
-    if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
-    else return false;
-    return true;
-  }
+  bool SetOutputFileName(const int n, const std::string& fname) { return Output->SetOutputName(n, fname); }
 
   /** Retrieves the current output filename.
-      @return the name of the output file for the first output specified by the flight model.
+      @param n index of file
+      @return the name of the output file for the 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("");
-  }
+  std::string GetOutputFileName(int n) const { return Output->GetOutputName(n); }
 
   /** Executes trimming in the selected mode.
   *   @param mode Specifies how to trim:
@@ -428,14 +468,23 @@ public:
   * - tTurn
   * - tNone  */
   void DoTrim(int mode);
-//  void DoTrimAnalysis(int mode);
+  void DoSimplexTrim(int mode);
+
+  /** Executes linearization with state-space output
+   * You must trim first to get an accurate state-space model
+   */
+  void DoLinearization(int mode);
 
   /// Disables data logging to all outputs.
-  void DisableOutput(void);
+  void DisableOutput(void) { Output->Disable(); }
   /// Enables data logging to all outputs.
-  void EnableOutput(void);
+  void EnableOutput(void) { Output->Enable(); }
   /// Pauses execution by preventing time from incrementing.
   void Hold(void) {holding = true;}
+  /// Turn on hold after increment
+  void EnableIncrementThenHold(int Timesteps) {TimeStepsUntilHold = Timesteps; IncrementThenHolding = true;}
+  /// Checks if required to hold afer increment
+  void CheckIncrementalHold(void);
   /// Resumes execution from a "Hold".
   void Resume(void) {holding = false;}
   /// Returns true if the simulation is Holding (i.e. simulation time is not moving).
@@ -447,9 +496,9 @@ public:
 
   struct PropertyCatalogStructure {
     /// Name of the property.
-    string base_string;
+    std::string base_string;
     /// The node for the property.
-    FGPropertyManager *node;
+    FGPropertyNode_ptr node;
   };
 
   /** Builds a catalog of properties.
@@ -464,29 +513,25 @@ 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(const string& check);
+  std::string QueryPropertyCatalog(const std::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);
+  std::vector<std::string>& GetPropertyCatalog(void) {return PropertyCatalog;}
 
   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; }
 
+  std::string GetPropulsionTankReport();
+
   /// Returns the cumulative simulation time in seconds.
   double GetSimTime(void) const { return sim_time; }
 
   /// Returns the simulation delta T.
-  double GetDeltaT(void) {return dT;}
+  double GetDeltaT(void) const {return dT;}
 
   /// Suspends the simulation and sets the delta T to zero.
   void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
@@ -496,7 +541,7 @@ public:
 
   /** Returns the simulation suspension state.
       @return true if suspended, false if executing  */
-  bool IntegrationSuspended(void) {return dT == 0.0;}
+  bool IntegrationSuspended(void) const {return dT == 0.0;}
 
   /** Sets the current sim time.
       @param cur_time the current time
@@ -512,22 +557,28 @@ public:
 
   /** 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;}
+  void SetRootDir(const std::string& rootDir) {RootDir = rootDir;}
 
-  /** Retrieves teh Root Directory.
+  /** Retrieves the Root Directory.
       @return the string representing the root (base) JSBSim directory. */
-  const string& GetRootDir(void) const {return RootDir;}
+  const std::string& GetRootDir(void) const {return RootDir;}
 
-  /** Increments the simulation time.
+  /** Increments the simulation time if not in Holding mode. The Frame counter
+      is also incremented.
       @return the new simulation time.     */
   double IncrTime(void) {
-    sim_time += dT;
+    if (!holding) sim_time += dT;
+    Frame++;
     return sim_time;
   }
 
   /** Retrieves the current debug level setting. */
   int GetDebugLevel(void) const {return debug_lvl;};
 
+  /** Initializes the simulation with initial conditions
+      @param FGIC The initial conditions that will be passed to the simulation. */
+  void Initialize(FGInitialCondition *FGIC);
+
 private:
   int Error;
   unsigned int Frame;
@@ -537,35 +588,41 @@ private:
   double saved_dT;
   double sim_time;
   bool holding;
+  bool IncrementThenHolding;
+  int TimeStepsUntilHold;
   bool Constructing;
   bool modelLoaded;
   bool IsChild;
-  string modelName;
-  string AircraftPath;
-  string FullAircraftPath;
-  string EnginePath;
-  string SystemsPath;
-  string CFGVersion;
-  string Release;
-  string RootDir;
+  std::string modelName;
+  std::string AircraftPath;
+  std::string FullAircraftPath;
+  std::string EnginePath;
+  std::string SystemsPath;
+  std::string CFGVersion;
+  std::string Release;
+  std::string RootDir;
+
+  // Standard Model pointers - shortcuts for internal executive use only.
+  FGPropagate* Propagate;
+  FGInertial* Inertial;
+  FGAtmosphere* Atmosphere;
+  FGWinds* Winds;
+  FGAuxiliary* Auxiliary;
+  FGFCS* FCS;
+  FGPropulsion* Propulsion;
+  FGAerodynamics* Aerodynamics;
+  FGGroundReactions* GroundReactions;
+  FGExternalReactions* ExternalReactions;
+  FGBuoyantForces* BuoyantForces;
+  FGMassBalance* MassBalance;
+  FGAircraft* Aircraft;
+  FGAccelerations* Accelerations;
+  FGOutput* Output;
 
   bool trim_status;
   int ta_mode;
+  unsigned int ResetMode;
 
-  FGGroundCallback*   GroundCallback;
-  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;
@@ -577,18 +634,19 @@ private:
   // 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 <childData*> ChildFDMList;
-  vector <FGModel*> Models;
+  std::vector <std::string> PropertyCatalog;
+  std::vector <childData*> ChildFDMList;
+  std::vector <FGModel*> Models;
 
   bool ReadFileHeader(Element*);
   bool ReadChild(Element*);
   bool ReadPrologue(Element*);
-  void ResetToInitialConditions(int mode);
+  void SRand(int sr);
+  void LoadInputs(unsigned int idx);
+  void LoadPlanetConstants(void);
+  void LoadModelConstants(void);
   bool Allocate(void);
   bool DeAllocate(void);
-  void Initialize(FGInitialCondition *FGIC);
 
   void Debug(int from);
 };