]> git.mxchange.org Git - flightgear.git/commitdiff
Sync. w. JSBSim
authorehofman <ehofman>
Fri, 20 Jan 2006 17:50:45 +0000 (17:50 +0000)
committerehofman <ehofman>
Fri, 20 Jan 2006 17:50:45 +0000 (17:50 +0000)
src/FDM/JSBSim/FGFDMExec.cpp
src/FDM/JSBSim/FGFDMExec.h
src/FDM/JSBSim/input_output/FGXMLParse.cpp
src/FDM/JSBSim/models/FGAtmosphere.cpp
src/FDM/JSBSim/models/FGAtmosphere.h

index 536baeee84c9690ae019d303e0d991ec7db326fd..12735d24b9db28b4cfb517ffd1bce4b870e0905e 100644 (file)
@@ -451,6 +451,12 @@ bool FGFDMExec::LoadModel(string model, bool addModelToPath)
   Element* document;
 
   ifstream input_file(aircraftCfgFileName.c_str());
+
+  if (!input_file.is_open()) { // file open failed
+    cerr << "Could not open file " << aircraftCfgFileName.c_str() << endl;
+    return false;
+  }
+
   readXML(input_file, *XMLParse);
   document = XMLParse->GetDocument();
 
index e440ab76365818fee8c3cf87f0d86936eae1a531..2425d42f77b3f17ccc5f317c47088c10a32f8c62 100644 (file)
@@ -70,16 +70,72 @@ CLASS DOCUMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 /** Encapsulates the JSBSim simulation executive.
-    This class is the interface class through which all other simulation classes
+    This class is the executive 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.
 
-    When an aircraft model is loaded the config file is parsed and for each of the
+    At the time of simulation initialization, the interface
+    class creates an instance of this executive class. The
+    executive is subsequently directed to load the chosen aircraft specification
+    file:
+
+    @code
+    fdmex = new FGFDMExec( \85 );
+    result = fdmex->LoadModel( \85 );
+    @endcode
+
+    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).
+    corresponding Load() method is called (e.g. FGFCS::Load()).
+
+    Subsequent to the creation of the executive and loading of the model,
+    initialization is performed. Initialization involves copying control inputs
+    into the appropriate JSBSim data storage locations, configuring it for the set
+    of user supplied initial conditions, and then copying state variables from
+    JSBSim. The state variables are used to drive the instrument displays and to
+    place the vehicle model in world space for visual rendering:
+
+    @code
+    copy_to_JSBsim(); // copy control inputs to JSBSim
+    fdmex->RunIC(); // loop JSBSim once w/o integrating
+    copy_from_JSBsim(); // update the bus
+    @endcode
+
+    Once initialization is complete, cyclic execution proceeds:
+
+    @code
+    copy_to_JSBsim(); // copy control inputs to JSBSim
+    fdmex->Run(); // execute JSBSim
+    copy_from_JSBsim(); // update the bus
+    @endcode
+
+    JSBSim can be used in a standalone mode by creating a compact stub program
+    that effectively performs the same progression of steps as outlined above for
+    the integrated version, but with two exceptions. First, the copy_to_JSBSim()
+    and copy_from_JSBSim() functions are not used because the control inputs are
+    handled directly by the scripting facilities and outputs are handled by the
+    output (data logging) class. Second, the name of a script file can be supplied
+    to the stub program. Scripting (see FGScript) provides a way to supply command
+    inputs to the simulation:
+
+    @code
+    FDMExec = new JSBSim::FGFDMExec();
+    Script = new JSBSim::FGScript( \85 );
+    Script->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
+
+    The standalone mode has been useful for verifying changes before committing
+    updates to the source code repository. It is also useful for running sets of
+    tests that reveal some aspects of simulated aircraft performance, such as
+    range, time-to-climb, takeoff distance, etc.
 
-    <h4>JSBSim Debugging Directives</h4>
+    <h3>JSBSim Debugging Directives</h3>
 
     This describes to any interested entity the debug level
     requested by setting the JSBSIM_DEBUG environment variable.
@@ -101,8 +157,14 @@ CLASS DOCUMENTATION
     - <b>16</b>: When set various parameters are sanity checked and
        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
+                                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.
+
     @author Jon S. Berndt
-    @version $Id$
+    @version $Revision$
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -124,13 +186,14 @@ public:
       FGFDMExec::Run() method must be made before the model is executed. A
       value of 1 means that the model will be executed for each call to the
       exec's Run() method. A value of 5 means that the model will only be
-      executed every 5th call to the exec's Run() method.
+      executed every 5th call to the exec's Run() method. Use of a rate other than
+      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.
       @return Currently returns 0 always. */
   int  Schedule(FGModel* model, int rate);
 
-  /** This executes each scheduled model in succession.
+  /** This function executes each scheduled model in succession.
       @return true if successful, false if sim should be ended  */
   bool Run(void);
 
@@ -144,7 +207,7 @@ public:
   void SetGroundCallback(FGGroundCallback* gc);
 
   /** Loads an aircraft model.
-      @param AircraftPath path to the aircraft directory. For instance:
+      @param AircraftPath path to the aircraft/ directory. For instance:
       "aircraft". Under aircraft, then, would be directories for various
       modeled aircraft such as C172/, x15/, etc.
       @param EnginePath path to the directory under which engine config
@@ -155,7 +218,7 @@ public:
       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*/
+      @return true if successful */
   bool LoadModel(string AircraftPath, string EnginePath, string model,
                  bool addModelToPath = true);
 
@@ -239,8 +302,7 @@ public:
   * - tPullup
   * - tCustom
   * - tTurn
-  * - tNone
-  */
+  * - tNone  */
   void DoTrim(int mode);
 
   /// Disables data logging to all outputs.
@@ -269,7 +331,7 @@ public:
 
   /** 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.
+  *   strings in the property catalog that matches the supplied check 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.  */
@@ -279,7 +341,7 @@ public:
   void UseAtmosphereMSIS(void);
 
   /// Use the Mars atmosphere model. (Not operative yet.)
-  void UseAtmosphereMars(void); 
+  void UseAtmosphereMars(void);
 
 private:
   FGModel* FirstModel;
index 6be5bf967e5c7875b8764ce3d6ef6166154fdb04..ec051f8d027efef1802714e96a9c6f18da80d46d 100755 (executable)
@@ -95,21 +95,18 @@ void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
 
 void FGXMLParse::endElement (const char * name)
 {
-  int size, pos;
   string local_work_string;
 
   while (!working_string.empty()) {
-     // clear leading newlines and spaces
-    while (working_string[0] == '\n' || working_string[0] == ' ')
-      working_string.erase(0,1);
+    // clear leading newlines and spaces
+    string::size_type pos = working_string.find_first_not_of( " \n");
+    if (pos > 0)
+      working_string.erase(0, pos);
 
     // remove spaces (only) from end of string
-    size = working_string.size();
-    while (working_string[size-1] == ' ')
-    {
-      working_string.erase(size-1,1);
-      size = working_string.size();
-    }
+    pos = working_string.find_last_not_of( " ");
+    if (pos != string::npos)
+      working_string.erase( ++pos);
 
     if (!working_string.empty()) {
       pos = working_string.find("\n");
index b7ad7660451e68006207578bf2a702b0839d535b..23d96f00da06f02385f3d7256c935aafc87f8061 100644 (file)
@@ -138,7 +138,7 @@ bool FGAtmosphere::Run(void)
     CalculateDerived();
   } else {
     CalculateDerived();
-  } 
+  }
 
   Debug(2);
   return false;
@@ -228,8 +228,8 @@ void FGAtmosphere::Calculate(double altitude)
   // If delta_T is set, then that is our temperature deviation at any altitude.
   // If not, then we'll estimate a deviation based on the sea level deviation (if set).
 
-  if(!StandardTempOnly) { 
-    T_dev = 0.0; 
+  if(!StandardTempOnly) {
+    T_dev = 0.0;
     if (delta_T != 0.0) {
       T_dev = delta_T;
     } else {
@@ -238,7 +238,7 @@ void FGAtmosphere::Calculate(double altitude)
       }
     }
     reftemp+=T_dev;
-  } 
+  }
 
   if (slope == 0) {
     intTemperature = reftemp;
@@ -458,44 +458,26 @@ void FGAtmosphere::UseInternal(void)
 void FGAtmosphere::bind(void)
 {
   typedef double (FGAtmosphere::*PMF)(int) const;
-  PropertyManager->Tie("atmosphere/T-R", this,
-                       &FGAtmosphere::GetTemperature);
-  PropertyManager->Tie("atmosphere/rho-slugs_ft3", this,
-                       &FGAtmosphere::GetDensity);
-//  PropertyManager->Tie("atmosphere/P-psf", this,
-//                       &FGAtmosphere::GetPressure);
-  PropertyManager->Tie("atmosphere/a-fps", this,
-                       &FGAtmosphere::GetSoundSpeed);
-  PropertyManager->Tie("atmosphere/T-sl-R", this,
-                       &FGAtmosphere::GetTemperatureSL);
-  PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this,
-                       &FGAtmosphere::GetDensitySL);
-  PropertyManager->Tie("atmosphere/P-sl-psf", this,
-                       &FGAtmosphere::GetPressureSL);
-  PropertyManager->Tie("atmosphere/a-sl-fps", this,
-                       &FGAtmosphere::GetSoundSpeedSL);
-  PropertyManager->Tie("atmosphere/theta", this,
-                       &FGAtmosphere::GetTemperatureRatio);
-  PropertyManager->Tie("atmosphere/sigma", this,
-                       &FGAtmosphere::GetDensityRatio);
-  PropertyManager->Tie("atmosphere/delta", this,
-                       &FGAtmosphere::GetPressureRatio);
-  PropertyManager->Tie("atmosphere/a-ratio", this,
-                       &FGAtmosphere::GetSoundSpeedRatio);
-  PropertyManager->Tie("atmosphere/psiw-rad", this,
-                       &FGAtmosphere::GetWindPsi);
-  PropertyManager->Tie("atmosphere/delta-T", this,
-                       &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT);
-  PropertyManager->Tie("atmosphere/T-sl-dev-F", this,
-                       &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev);
-  PropertyManager->Tie("atmosphere/density-altitude", this,
-                       &FGAtmosphere::GetDensityAltitude);
-  PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1,
-                       (PMF)&FGAtmosphere::GetTurbPQR);
-  PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2,
-                       (PMF)&FGAtmosphere::GetTurbPQR);
-  PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3,
-                       (PMF)&FGAtmosphere::GetTurbPQR);
+  typedef double (FGAtmosphere::*PMFv)(void) const;
+  PropertyManager->Tie("atmosphere/T-R", this, (PMFv)&FGAtmosphere::GetTemperature);
+  PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, (PMFv)&FGAtmosphere::GetDensity);
+  PropertyManager->Tie("atmosphere/P-psf", this, (PMFv)&FGAtmosphere::GetPressure);
+  PropertyManager->Tie("atmosphere/a-fps", this, &FGAtmosphere::GetSoundSpeed);
+  PropertyManager->Tie("atmosphere/T-sl-R", this, &FGAtmosphere::GetTemperatureSL);
+  PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, &FGAtmosphere::GetDensitySL);
+  PropertyManager->Tie("atmosphere/P-sl-psf", this, &FGAtmosphere::GetPressureSL);
+  PropertyManager->Tie("atmosphere/a-sl-fps", this, &FGAtmosphere::GetSoundSpeedSL);
+  PropertyManager->Tie("atmosphere/theta", this, &FGAtmosphere::GetTemperatureRatio);
+  PropertyManager->Tie("atmosphere/sigma", this, &FGAtmosphere::GetDensityRatio);
+  PropertyManager->Tie("atmosphere/delta", this, &FGAtmosphere::GetPressureRatio);
+  PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio);
+  PropertyManager->Tie("atmosphere/psiw-rad", this, &FGAtmosphere::GetWindPsi);
+  PropertyManager->Tie("atmosphere/delta-T", this, &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT);
+  PropertyManager->Tie("atmosphere/T-sl-dev-F", this, &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev);
+  PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude);
+  PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGAtmosphere::GetTurbPQR);
+  PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGAtmosphere::GetTurbPQR);
+  PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGAtmosphere::GetTurbPQR);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -504,7 +486,7 @@ void FGAtmosphere::unbind(void)
 {
   PropertyManager->Untie("atmosphere/T-R");
   PropertyManager->Untie("atmosphere/rho-slugs_ft3");
-//  PropertyManager->Untie("atmosphere/P-psf");
+  PropertyManager->Untie("atmosphere/P-psf");
   PropertyManager->Untie("atmosphere/a-fps");
   PropertyManager->Untie("atmosphere/T-sl-R");
   PropertyManager->Untie("atmosphere/rho-sl-slugs_ft3");
index fd0500a9e20ceee9a7198b4a4c4589bca38533bd..788d04c19c49bf2ec23817ba3109cd1a201f9be3 100644 (file)
@@ -1,36 +1,36 @@
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
  Header:       FGAtmosphere.h
  Author:       Jon Berndt
                Implementation of 1959 Standard Atmosphere added by Tony Peden
  Date started: 11/24/98
+
  ------------- 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
  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
  details.
+
  You should have received a copy of the GNU 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
  the world wide web at http://www.gnu.org.
+
 HISTORY
 --------------------------------------------------------------------------------
 11/24/98   JSB   Created
 07/23/99   TP    Added implementation of 1959 Standard Atmosphere
                  Moved calculation of Mach number to FGPropagate
                  Updated to '76 model
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 SENTRY
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -90,13 +90,13 @@ public:
       <i>This function may <b>only</b> be used if Run() is called first.</i> */
   inline double GetDensity(void)  const {return *density;}
   /// Returns the pressure in psf.
-  inline double GetPressure(void)  const {return *pressure;}
+  double GetPressure(void)  const {return *pressure;}
   /// Returns the standard pressure at a specified altitude
   double GetPressure(double altitude);
   /// Returns the standard temperature at a specified altitude
-  double GetTemperature(double altitude);
+  inline double GetTemperature(double altitude);
   /// Returns the standard density at a specified altitude
-  double GetDensity(double altitude);
+  inline double GetDensity(double altitude);
   /// Returns the speed of sound in ft/sec.
   inline double GetSoundSpeed(void) const {return soundspeed;}
 
@@ -137,9 +137,9 @@ public:
   /// Gets the temperature deviation at sea-level in degrees Fahrenheit
   inline double GetSLTempDev(void) const { return T_dev_sl; }
   /// Sets the current delta-T in degrees Fahrenheit
-  inline void SetDeltaT(double d)  { delta_T = d; } 
+  inline void SetDeltaT(double d)  { delta_T = d; }
   /// Gets the current delta-T in degrees Fahrenheit
-  inline double GetDeltaT(void) const  { return delta_T; } 
+  inline double GetDeltaT(void) const  { return delta_T; }
   /// Gets the at-altitude temperature deviation in degrees Fahrenheit
   inline double GetTempDev(void) const { return T_dev; }
   /// Gets the density altitude in feet
@@ -150,21 +150,21 @@ public:
 
   /// Retrieves the wind components in NED frame.
   inline FGColumnVector3& GetWindNED(void) { return vWindNED; }
-  
+
   /** Retrieves the wind direction. The direction is defined as north=0 and
       increases counterclockwise. The wind heading is returned in radians.*/
   inline double GetWindPsi(void) const { return psiw; }
-  
+
   inline void SetTurbGain(double tt) {TurbGain = tt;}
   inline void SetTurbRate(double tt) {TurbRate = tt;}
-  
+
   inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
   inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
-  
+
   void bind(void);
   void unbind(void);
 
-  
+
 protected:
   double rho;
 
@@ -177,7 +177,7 @@ protected:
   double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
   double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
   double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
-  double *temperature,*density,*pressure;
+  double *temperature, *density, *pressure;
   double soundspeed;
   bool useExternal;
   double exTemperature,exDensity,exPressure;