JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGFDMExec Class Reference

Detailed Description

Encapsulates the JSBSim simulation executive.

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.

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:

fdmex = new FGFDMExec( ... );
result = fdmex->LoadModel( ... );
FGFDMExec(FGPropertyManager *root=nullptr, std::shared_ptr< unsigned int > fdmctr=nullptr)
Default constructor.
Definition: FGFDMExec.cpp:78

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. 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:

copy_to_JSBsim(); // copy control inputs to JSBSim
fdmex->RunIC(); // loop JSBSim once w/o integrating
copy_from_JSBsim(); // update the bus

Once initialization is complete, cyclic execution proceeds:

copy_to_JSBsim(); // copy control inputs to JSBSim
fdmex->Run(); // execute JSBSim
copy_from_JSBsim(); // update the bus

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:

FDMExec = new JSBSim::FGFDMExec();
FDMExec->LoadScript( ScriptName ); // the script loads the aircraft and ICs
result = FDMExec->Run();
while (result) { // cyclic execution
result = FDMExec->Run(); // execute JSBSim
}
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:184
bool LoadScript(const SGPath &Script, double deltaT=0.0, const SGPath &initfile=SGPath())
Load a script.
Definition: FGFDMExec.cpp:736
bool Run(void)
This function executes each scheduled model in succession.
Definition: FGFDMExec.cpp:413

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.

JSBSim Debugging Directives

This describes to any interested entity the debug level requested by setting the JSBSIM_DEBUG environment variable. The bitmasked value choices are as follows:

  • unset: 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
  • 0: This requests JSBSim not to output any messages whatsoever
  • 1: This value explicity requests the normal JSBSim startup messages
  • 2: This value asks for a message to be printed out when a class is instantiated
  • 4: When this value is set, a message is displayed when a FGModel object executes its Run() method
  • 8: When this value is set, various runtime state variables are printed out periodically
  • 16: When set various parameters are sanity checked and a message is printed out when they go out of bounds

Properties

  • 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. This property actually maps toa function call of DoTrim().
Author
Jon S. Berndt
Version
Revision
1.106

Definition at line 183 of file FGFDMExec.h.

#include <FGFDMExec.h>

+ Inheritance diagram for FGFDMExec:
+ Collaboration diagram for FGFDMExec:

Classes

struct  PropertyCatalogStructure
 

Public Types

enum  eModels {
  ePropagate =0 , eInput , eInertial , eAtmosphere ,
  eWinds , eSystems , eMassBalance , eAuxiliary ,
  ePropulsion , eAerodynamics , eGroundReactions , eExternalReactions ,
  eBuoyantForces , eAircraft , eAccelerations , eOutput ,
  eNumStandardModels
}
 
- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N.
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R.
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W.
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers.
 

Public Member Functions

 FGFDMExec (FGPropertyManager *root=nullptr, std::shared_ptr< unsigned int > fdmctr=nullptr)
 Default constructor.
 
 ~FGFDMExec ()
 Default destructor.
 
void AddTemplateFunc (const std::string &name, Element *el)
 
void BuildPropertyCatalog (struct PropertyCatalogStructure *pcs)
 Builds a catalog of properties. More...
 
void CheckIncrementalHold (void)
 Checks if required to hold afer increment.
 
void DisableOutput (void)
 Disables data logging to all outputs.
 
void DoTrim (int mode)
 Executes trimming in the selected mode. More...
 
void EnableIncrementThenHold (int Timesteps)
 Turn on hold after increment.
 
void EnableOutput (void)
 Enables data logging to all outputs.
 
std::vector< std::string > EnumerateFDMs (void)
 Returns a vector of strings representing the names of all loaded models (future)
 
void ForceOutput (int idx=0)
 Forces the specified output object to print its items once.
 
const SGPath & GetAircraftPath (void)
 Retrieves the aircraft path.
 
auto GetChildFDM (int i) const
 Gets a particular child FDM.
 
int GetDebugLevel (void) const
 Retrieves the current debug level setting.
 
double GetDeltaT (void) const
 Returns the simulation delta T.
 
const SGPath & GetEnginePath (void)
 Retrieves the engine path.
 
size_t GetFDMCount (void) const
 Gets the number of child FDMs.
 
unsigned int GetFrame (void) const
 Retrieves the current frame count.
 
const SGPath & GetFullAircraftPath (void)
 Retrieves the full aircraft path name.
 
bool GetHoldDown (void) const
 Gets the value of the property forces/hold-down. More...
 
const std::string & GetModelName (void) const
 Returns the model name.
 
std::string GetOutputFileName (int n) const
 Retrieves the current output filename. More...
 
const SGPath & GetOutputPath (void)
 Retrieves the path to the output files.
 
std::vector< std::string > & GetPropertyCatalog (void)
 
std::shared_ptr< FGPropertyManagerGetPropertyManager (void) const
 Returns a pointer to the property manager object.
 
double GetPropertyValue (const std::string &property)
 Retrieves the value of a property. More...
 
std::string GetPropulsionTankReport () const
 
auto GetRandomGenerator (void) const
 
const SGPath & GetRootDir (void) const
 Retrieve the Root Directory. More...
 
double GetSimTime (void) const
 Returns the cumulative simulation time in seconds.
 
const SGPath & GetSystemsPath (void)
 Retrieves the systems path.
 
FGTemplateFunc_ptr GetTemplateFunc (const std::string &name)
 
int GetTrimMode (void) const
 
bool GetTrimStatus (void) const
 
void Hold (void)
 Pauses execution by preventing time from incrementing.
 
bool Holding (void)
 Returns true if the simulation is Holding (i.e. simulation time is not moving).
 
double IncrTime (void)
 Increments the simulation time if not in Holding mode. More...
 
void Initialize (const FGInitialCondition *FGIC)
 Initializes the simulation with initial conditions. More...
 
bool IntegrationSuspended (void) const
 Returns the simulation suspension state. More...
 
bool LoadModel (const SGPath &AircraftPath, const SGPath &EnginePath, const SGPath &SystemsPath, const std::string &model, bool addModelToPath=true)
 Loads an aircraft model. More...
 
bool LoadModel (const std::string &model, bool addModelToPath=true)
 Loads an aircraft model. More...
 
bool LoadPlanet (const SGPath &PlanetPath, bool useAircraftPath=true)
 Loads the planet. More...
 
bool LoadScript (const SGPath &Script, double deltaT=0.0, const SGPath &initfile=SGPath())
 Load a script. More...
 
void PrintPropertyCatalog (void)
 
void PrintSimulationConfiguration (void) const
 
std::string QueryPropertyCatalog (const std::string &check, const std::string &end_of_line="\n")
 Retrieves property or properties matching the supplied string. More...
 
void ResetToInitialConditions (int mode)
 Resets the initial conditions object and prepares the simulation to run again. More...
 
void Resume (void)
 Resumes execution from a "Hold".
 
void ResumeIntegration (void)
 Resumes the simulation by resetting delta T to the correct value.
 
bool Run (void)
 This function executes each scheduled model in succession. More...
 
bool RunIC (void)
 Initializes the sim from the initial condition object and executes each scheduled model without integrating i.e. More...
 
bool SetAircraftPath (const SGPath &path)
 Set the path to the aircraft config file directories. More...
 
void SetChild (bool ch)
 Marks this instance of the Exec object as a "child" object.
 
void SetDebugLevel (int level)
 Sets the debug level.
 
void Setdt (double delta_t)
 Sets the integration time step for the simulation executive. More...
 
bool SetEnginePath (const SGPath &path)
 Set the path to the engine config file directories. More...
 
void SetHoldDown (bool hd)
 Sets the property forces/hold-down. More...
 
void SetLoggingRate (double rate)
 Sets the logging rate in Hz for all output objects (if any).
 
bool SetOutputDirectives (const SGPath &fname)
 Sets the output (logging) mechanism for this run. More...
 
bool SetOutputFileName (const int n, const std::string &fname)
 Sets (or overrides) the output filename. More...
 
bool SetOutputPath (const SGPath &path)
 Set the directory where the output files will be written. More...
 
void SetPropertyValue (const std::string &property, double value)
 Sets a property value. More...
 
void SetRootDir (const SGPath &rootDir)
 Set the root directory that is used to obtain absolute paths from relative paths. More...
 
double Setsim_time (double cur_time)
 Sets the current sim time. More...
 
bool SetSystemsPath (const SGPath &path)
 Set the path to the systems config file directories. More...
 
void SetTrimMode (int mode)
 
void SetTrimStatus (bool status)
 
void SuspendIntegration (void)
 Suspends the simulation and sets the delta T to zero.
 
void Unbind (void)
 Unbind all tied JSBSim properties.
 
Top-level executive State and Model retrieval mechanism

Returns the FGAtmosphere pointer.

std::shared_ptr< FGAtmosphereGetAtmosphere (void) const
 
std::shared_ptr< FGAccelerationsGetAccelerations (void) const
 Returns the FGAccelerations pointer.
 
std::shared_ptr< FGWindsGetWinds (void) const
 Returns the FGWinds pointer.
 
std::shared_ptr< FGFCSGetFCS (void) const
 Returns the FGFCS pointer.
 
std::shared_ptr< FGPropulsionGetPropulsion (void) const
 Returns the FGPropulsion pointer.
 
std::shared_ptr< FGMassBalanceGetMassBalance (void) const
 Returns the FGAircraft pointer.
 
std::shared_ptr< FGAerodynamicsGetAerodynamics (void) const
 Returns the FGAerodynamics pointer.
 
std::shared_ptr< FGInertialGetInertial (void) const
 Returns the FGInertial pointer.
 
std::shared_ptr< FGGroundReactionsGetGroundReactions (void) const
 Returns the FGGroundReactions pointer.
 
std::shared_ptr< FGExternalReactionsGetExternalReactions (void) const
 Returns the FGExternalReactions pointer.
 
std::shared_ptr< FGBuoyantForcesGetBuoyantForces (void) const
 Returns the FGBuoyantForces pointer.
 
std::shared_ptr< FGAircraftGetAircraft (void) const
 Returns the FGAircraft pointer.
 
std::shared_ptr< FGPropagateGetPropagate (void) const
 Returns the FGPropagate pointer.
 
std::shared_ptr< FGAuxiliaryGetAuxiliary (void) const
 Returns the FGAuxiliary pointer.
 
std::shared_ptr< FGInputGetInput (void) const
 Returns the FGInput pointer.
 
std::shared_ptr< FGOutputGetOutput (void) const
 Returns the FGOutput pointer.
 
std::shared_ptr< FGScriptGetScript (void) const
 Retrieves the script object.
 
std::shared_ptr< FGInitialConditionGetIC (void) const
 Returns a pointer to the FGInitialCondition object.
 
std::shared_ptr< FGTrimGetTrim (void)
 Returns a pointer to the FGTrim object.
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Static Public Attributes

static const int DONT_EXECUTE_RUN_IC = 0x2
 
static const int START_NEW_OUTPUT = 0x1
 Mode flags for ResetToInitialConditions.
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 

Additional Inherited Members

- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim. More...
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff. More...
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Member Function Documentation

◆ BuildPropertyCatalog()

void BuildPropertyCatalog ( struct PropertyCatalogStructure pcs)

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.

Parameters
pcsThe "root" property catalog structure pointer.

Definition at line 1069 of file FGFDMExec.cpp.

1070 {
1071  auto pcsNew = std::make_unique<struct PropertyCatalogStructure>();
1072 
1073  for (int i=0; i<pcs->node->nChildren(); i++) {
1074  string access="";
1075  pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getNameString();
1076  int node_idx = pcs->node->getChild(i)->getIndex();
1077  if (node_idx != 0) {
1078  pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
1079  }
1080  if (pcs->node->getChild(i)->nChildren() == 0) {
1081  if (pcsNew->base_string.substr(0,12) == string("/fdm/jsbsim/")) {
1082  pcsNew->base_string = pcsNew->base_string.erase(0,12);
1083  }
1084  if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::READ)) access="R";
1085  if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::WRITE)) access+="W";
1086  PropertyCatalog.push_back(pcsNew->base_string+" ("+access+")");
1087  } else {
1088  pcsNew->node = (FGPropertyNode*)pcs->node->getChild(i);
1089  BuildPropertyCatalog(pcsNew.get());
1090  }
1091  }
1092 }
void BuildPropertyCatalog(struct PropertyCatalogStructure *pcs)
Builds a catalog of properties.
Definition: FGFDMExec.cpp:1069
+ Here is the caller graph for this function:

◆ DoTrim()

void DoTrim ( int  mode)

Executes trimming in the selected mode.

Parameters
modeSpecifies how to trim:
  • tLongitudinal=0
  • tFull
  • tGround
  • tPullup
  • tCustom
  • tTurn
  • tNone

Definition at line 1297 of file FGFDMExec.cpp.

1298 {
1299  if (Constructing) return;
1300 
1301  if (mode < 0 || mode > JSBSim::tNone)
1302  throw("Illegal trimming mode!");
1303 
1304  FGTrim trim(this, (JSBSim::TrimMode)mode);
1305  bool success = trim.DoTrim();
1306 
1307  if (debug_lvl > 0)
1308  trim.Report();
1309 
1310  if (!success)
1311  throw TrimFailureException("Trim Failed");
1312 
1313  trim_completed = 1;
1314 }
+ Here is the caller graph for this function:

◆ GetHoldDown()

bool GetHoldDown ( void  ) const
inline

Gets the value of the property forces/hold-down.

Returns
zero if the 'hold-down' function is disabled, non-zero otherwise.

Definition at line 611 of file FGFDMExec.h.

611 {return HoldDown;}
+ Here is the caller graph for this function:

◆ GetOutputFileName()

std::string GetOutputFileName ( int  n) const
inline

Retrieves the current output filename.

Parameters
nindex of file
Returns
the name of the output file for the output specified by the flight model. If none is specified, the empty string is returned.

Definition at line 465 of file FGFDMExec.h.

465 { return Output->GetOutputName(n); }
std::string GetOutputName(unsigned int idx) const
Get the name identifier to which the output will be directed.
Definition: FGOutput.cpp:161

◆ GetPropertyValue()

double GetPropertyValue ( const std::string &  property)
inline

Retrieves the value of a property.

Parameters
propertythe name of the property
Returns
the value of the specified property

Definition at line 408 of file FGFDMExec.h.

409  { return instance->GetNode()->GetDouble(property); }

◆ GetRootDir()

const SGPath& GetRootDir ( void  ) const
inline

Retrieve the Root Directory.

Returns
the path to the root (base) JSBSim directory.
See also
SetRootDir

Definition at line 585 of file FGFDMExec.h.

585 {return RootDir;}

◆ IncrTime()

double IncrTime ( void  )

Increments the simulation time if not in Holding mode.

The Frame counter is also incremented.

Returns
the new simulation time.

Definition at line 202 of file FGFDMExec.cpp.

202  {
203  if (!holding && !IntegrationSuspended()) {
204  sim_time += dT;
205  Inertial->SetTime(sim_time);
206  Frame++;
207  }
208  return sim_time;
209 }
bool IntegrationSuspended(void) const
Returns the simulation suspension state.
Definition: FGFDMExec.h:557
void SetTime(double time)
Set the simulation time.
Definition: FGInertial.h:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void Initialize ( const FGInitialCondition FGIC)

Initializes the simulation with initial conditions.

Parameters
FGICThe initial conditions that will be passed to the simulation.

Definition at line 680 of file FGFDMExec.cpp.

681 {
682  Propagate->SetInitialState(FGIC);
683  Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
684  Run();
685 }
virtual void SetWindNED(double wN, double wE, double wD)
Sets the wind components in NED frame.
Definition: FGWinds.h:195
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IntegrationSuspended()

bool IntegrationSuspended ( void  ) const
inline

Returns the simulation suspension state.

Returns
true if suspended, false if executing

Definition at line 557 of file FGFDMExec.h.

557 {return dT == 0.0;}
+ Here is the caller graph for this function:

◆ LoadModel() [1/2]

bool LoadModel ( const SGPath &  AircraftPath,
const SGPath &  EnginePath,
const SGPath &  SystemsPath,
const std::string &  model,
bool  addModelToPath = true 
)

Loads an aircraft model.

Parameters
AircraftPathpath to the aircraft/ directory. For instance: "aircraft". Under aircraft, then, would be directories for various modeled aircraft such as C172/, x15/, etc.
EnginePathpath to the directory under which engine config files are kept, for instance "engine"
SystemsPathpath to the directory under which systems config files are kept, for instance "systems"
modelthe 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"
addModelToPathset to true to add the model name to the AircraftPath, defaults to true
Returns
true if successful

Definition at line 821 of file FGFDMExec.cpp.

824 {
825  FGFDMExec::AircraftPath = GetFullPath(AircraftPath);
826  FGFDMExec::EnginePath = GetFullPath(EnginePath);
827  FGFDMExec::SystemsPath = GetFullPath(SystemsPath);
828 
829  return LoadModel(model, addModelToPath);
830 }
bool LoadModel(const SGPath &AircraftPath, const SGPath &EnginePath, const SGPath &SystemsPath, const std::string &model, bool addModelToPath=true)
Loads an aircraft model.
Definition: FGFDMExec.cpp:821
+ Here is the caller graph for this function:

◆ LoadModel() [2/2]

bool LoadModel ( 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 below.

Parameters
modelthe 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"
addModelToPathset to true to add the model name to the AircraftPath, defaults to true
Returns
true if successful

Definition at line 834 of file FGFDMExec.cpp.

835 {
836  SGPath aircraftCfgFileName;
837  bool result = false; // initialize result to false, indicating input file not yet read
838 
839  modelName = model; // Set the class modelName attribute
840 
841  if( AircraftPath.isNull() || EnginePath.isNull() || SystemsPath.isNull()) {
842  cerr << "Error: attempted to load aircraft with undefined "
843  << "aircraft, engine, and system paths" << endl;
844  return false;
845  }
846 
847  FullAircraftPath = AircraftPath;
848  if (addModelToPath) FullAircraftPath.append(model);
849  aircraftCfgFileName = FullAircraftPath/(model + ".xml");
850 
851  if (modelLoaded) {
852  DeAllocate();
853  Allocate();
854  }
855 
856  int saved_debug_lvl = debug_lvl;
857  FGXMLFileRead XMLFileRead;
858  Element *document = XMLFileRead.LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
859 
860  if (document) {
861  if (IsChild) debug_lvl = 0;
862 
863  ReadPrologue(document);
864 
865  if (IsChild) debug_lvl = saved_debug_lvl;
866 
867  // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
868  Element* element = document->FindElement("fileheader");
869  if (element) {
870  result = ReadFileHeader(element);
871  if (!result) {
872  cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
873  return result;
874  }
875  }
876 
877  if (IsChild) debug_lvl = 0;
878 
879  // Process the planet element. This element is OPTIONAL.
880  element = document->FindElement("planet");
881  if (element) {
882  result = LoadPlanet(element);
883  if (!result) {
884  cerr << endl << "Planet element has problems in file " << aircraftCfgFileName << endl;
885  return result;
886  }
887  }
888 
889  // Process the metrics element. This element is REQUIRED.
890  element = document->FindElement("metrics");
891  if (element) {
892  result = Models[eAircraft]->Load(element);
893  if (!result) {
894  cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
895  return result;
896  }
897  } else {
898  cerr << endl << "No metrics element was found in the aircraft config file." << endl;
899  return false;
900  }
901 
902  // Process the mass_balance element. This element is REQUIRED.
903  element = document->FindElement("mass_balance");
904  if (element) {
905  result = Models[eMassBalance]->Load(element);
906  if (!result) {
907  cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
908  return result;
909  }
910  } else {
911  cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
912  return false;
913  }
914 
915  // Process the ground_reactions element. This element is REQUIRED.
916  element = document->FindElement("ground_reactions");
917  if (element) {
918  result = Models[eGroundReactions]->Load(element);
919  if (!result) {
920  cerr << endl << element->ReadFrom()
921  << "Aircraft ground_reactions element has problems in file "
922  << aircraftCfgFileName << endl;
923  return result;
924  }
925  } else {
926  cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
927  return false;
928  }
929 
930  // Process the external_reactions element. This element is OPTIONAL.
931  element = document->FindElement("external_reactions");
932  if (element) {
933  result = Models[eExternalReactions]->Load(element);
934  if (!result) {
935  cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
936  return result;
937  }
938  }
939 
940  // Process the buoyant_forces element. This element is OPTIONAL.
941  element = document->FindElement("buoyant_forces");
942  if (element) {
943  result = Models[eBuoyantForces]->Load(element);
944  if (!result) {
945  cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
946  return result;
947  }
948  }
949 
950  // Process the propulsion element. This element is OPTIONAL.
951  element = document->FindElement("propulsion");
952  if (element) {
953  result = Propulsion->Load(element);
954  if (!result) {
955  cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
956  return result;
957  }
958  for (unsigned int i=0; i < Propulsion->GetNumEngines(); i++)
959  FCS->AddThrottle();
960  }
961 
962  // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
963  element = document->FindElement("system");
964  while (element) {
965  result = Models[eSystems]->Load(element);
966  if (!result) {
967  cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
968  return result;
969  }
970  element = document->FindNextElement("system");
971  }
972 
973  // Process the autopilot element. This element is OPTIONAL.
974  element = document->FindElement("autopilot");
975  if (element) {
976  result = Models[eSystems]->Load(element);
977  if (!result) {
978  cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
979  return result;
980  }
981  }
982 
983  // Process the flight_control element. This element is OPTIONAL.
984  element = document->FindElement("flight_control");
985  if (element) {
986  result = Models[eSystems]->Load(element);
987  if (!result) {
988  cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
989  return result;
990  }
991  }
992 
993  // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
994  element = document->FindElement("aerodynamics");
995  if (element) {
996  result = Models[eAerodynamics]->Load(element);
997  if (!result) {
998  cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
999  return result;
1000  }
1001  } else {
1002  cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
1003  }
1004 
1005  // Process the input element. This element is OPTIONAL, and there may be more than one.
1006  element = document->FindElement("input");
1007  while (element) {
1008  if (!Input->Load(element))
1009  return false;
1010 
1011  element = document->FindNextElement("input");
1012  }
1013 
1014  // Process the output element[s]. This element is OPTIONAL, and there may be
1015  // more than one.
1016  element = document->FindElement("output");
1017  while (element) {
1018  if (!Output->Load(element))
1019  return false;
1020 
1021  element = document->FindNextElement("output");
1022  }
1023 
1024  // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
1025  element = document->FindElement("child");
1026  if (element) {
1027  result = ReadChild(element);
1028  if (!result) {
1029  cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
1030  return result;
1031  }
1032  }
1033 
1034  // Since all vehicle characteristics have been loaded, place the values in the Inputs
1035  // structure for the FGModel-derived classes.
1036  LoadModelConstants();
1037 
1038  modelLoaded = true;
1039 
1040  if (IsChild) debug_lvl = saved_debug_lvl;
1041 
1042  } else {
1043  cerr << fgred
1044  << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
1045  << fgdef << endl;
1046  }
1047 
1048  for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i);
1049 
1050  if (result) {
1051  struct PropertyCatalogStructure masterPCS;
1052  masterPCS.base_string = "";
1053  masterPCS.node = Root;
1054  BuildPropertyCatalog(&masterPCS);
1055  }
1056 
1057  return result;
1058 }
bool LoadPlanet(const SGPath &PlanetPath, bool useAircraftPath=true)
Loads the planet.
Definition: FGFDMExec.cpp:745
bool Load(Element *el) override
Load the input directives and adds a new input instance to the Input Manager list.
Definition: FGInput.cpp:76
static char fgred[6]
red text
Definition: FGJSBBase.h:167
static char fgdef[6]
default text
Definition: FGJSBBase.h:171
bool Load(Element *el, const SGPath &dir=SGPath())
Load the output directives and adds a new output instance to the Output Manager list.
Definition: FGOutput.cpp:238
bool Load(Element *el) override
Loads the propulsion system (engine[s] and tank[s]).
size_t GetNumEngines(void) const
Retrieves the number of engines defined for the aircraft.
Definition: FGPropulsion.h:126
+ Here is the call graph for this function:

◆ LoadPlanet()

bool LoadPlanet ( const SGPath &  PlanetPath,
bool  useAircraftPath = true 
)

Loads the planet.

Loads the definition of the planet on which the vehicle will evolve such as its radius, gravity or its atmosphere characteristics.

Parameters
PlanetPathThe name of a planet definition file
useAircraftPathtrue if path is given relative to the aircraft path.
Returns
true if successful

Definition at line 745 of file FGFDMExec.cpp.

746 {
747  SGPath PlanetFileName;
748 
749  if(useAircraftPath && PlanetPath.isRelative()) {
750  PlanetFileName = AircraftPath/PlanetPath.utf8Str();
751  } else {
752  PlanetFileName = PlanetPath;
753  }
754 
755  FGXMLFileRead XMLFileRead;
756  Element* document = XMLFileRead.LoadXMLDocument(PlanetFileName);
757 
758  // Make sure that the document is valid
759  if (!document) {
760  stringstream s;
761  s << "File: " << PlanetFileName << " could not be read.";
762  cerr << s.str() << endl;
763  throw BaseException(s.str());
764  }
765 
766  if (document->GetName() != "planet") {
767  stringstream s;
768  s << "File: " << PlanetFileName << " is not a planet file.";
769  cerr << s.str() << endl;
770  throw BaseException(s.str());
771  }
772 
773  bool result = LoadPlanet(document);
774 
775  if (!result)
776  cerr << endl << "Planet element has problems in file " << PlanetFileName << endl;
777 
778  return result;
779 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadScript()

bool LoadScript ( const SGPath &  Script,
double  deltaT = 0.0,
const SGPath &  initfile = SGPath() 
)

Load a script.

Parameters
ScriptThe full path name and file name for the script to be loaded.
deltaTThe 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.
initfileThe 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.
Returns
true if successfully loads; false otherwise.

Definition at line 736 of file FGFDMExec.cpp.

738 {
739  Script = std::make_shared<FGScript>(this);
740  return Script->LoadScript(GetFullPath(script), deltaT, initfile);
741 }

◆ QueryPropertyCatalog()

string QueryPropertyCatalog ( const std::string &  check,
const std::string &  end_of_line = "\n" 
)

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 check string.

Parameters
checkThe string to search for in the property catalog.
end_of_lineEnd of line (CR+LF if needed for Windows).
Returns
the carriage-return-delimited string containing all matching strings in the catalog.

Definition at line 1096 of file FGFDMExec.cpp.

1097 {
1098  string results;
1099  for (auto &catalogElm: PropertyCatalog) {
1100  if (catalogElm.find(in) != string::npos) results += catalogElm + end_of_line;
1101  }
1102  if (results.empty()) return "No matches found"+end_of_line;
1103  return results;
1104 }
+ Here is the caller graph for this function:

◆ ResetToInitialConditions()

void ResetToInitialConditions ( int  mode)

Resets the initial conditions object and prepares the simulation to run again.

If the mode's first bit is set the output instances will take special actions such as closing the current output file and open a new one with a different name. If the second bit is set then RunIC() won't be executed, leaving it to the caller to call RunIC(), e.g. in case the caller wants to set some other state like control surface deflections which would've been reset.

Parameters
modeSets the reset mode.

Definition at line 689 of file FGFDMExec.cpp.

690 {
691  if (Constructing) return;
692 
693  // mode flags
694 
695  if (mode & START_NEW_OUTPUT) Output->SetStartNewOutput();
696 
697  InitializeModels();
698 
699  if (Script)
700  Script->ResetEvents();
701  else
702  Setsim_time(0.0);
703 
704  if (!(mode & DONT_EXECUTE_RUN_IC))
705  RunIC();
706 }
static const int START_NEW_OUTPUT
Mode flags for ResetToInitialConditions.
Definition: FGFDMExec.h:493
double Setsim_time(double cur_time)
Sets the current sim time.
Definition: FGFDMExec.cpp:194
bool RunIC(void)
Initializes the sim from the initial condition object and executes each scheduled model without integ...
Definition: FGFDMExec.cpp:643
void SetStartNewOutput(void)
Reset the output prior to a restart of the simulation.
Definition: FGOutput.cpp:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Run()

bool Run ( void  )

This function executes each scheduled model in succession.

Returns
true if successful, false if sim should be ended

Definition at line 413 of file FGFDMExec.cpp.

414 {
415  bool success=true;
416 
417  Debug(2);
418 
419  for (auto &ChildFDM: ChildFDMList) {
420  ChildFDM->AssignState(Propagate); // Transfer state to the child FDM
421  ChildFDM->Run();
422  }
423 
424  IncrTime();
425 
426  // returns true if success, false if complete
427  if (Script && !IntegrationSuspended()) success = Script->RunScript();
428 
429  for (unsigned int i = 0; i < Models.size(); i++) {
430  LoadInputs(i);
431  Models[i]->Run(holding);
432  }
433 
434  if (Terminate) success = false;
435 
436  return success;
437 }
double IncrTime(void)
Increments the simulation time if not in Holding mode.
Definition: FGFDMExec.cpp:202
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RunIC()

bool RunIC ( void  )

Initializes the sim from the initial condition object and executes each scheduled model without integrating i.e.

dt=0.

Returns
true if successful

Definition at line 643 of file FGFDMExec.cpp.

644 {
645  SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
646  Initialize(IC.get());
647 
648  Models[eInput]->InitModel();
649  Models[eOutput]->InitModel();
650 
651  Run();
652  Propagate->InitializeDerivatives();
653  ResumeIntegration(); // Restores the integration rate to what it was.
654 
655  if (debug_lvl > 0) {
656  MassBalance->GetMassPropertiesReport(0);
657 
658  cout << endl << fgblue << highint
659  << "End of vehicle configuration loading." << endl
660  << "-------------------------------------------------------------------------------"
661  << reset << std::setprecision(6) << endl;
662  }
663 
664  for (unsigned int n=0; n < Propulsion->GetNumEngines(); ++n) {
665  if (IC->IsEngineRunning(n)) {
666  try {
667  Propulsion->InitRunning(n);
668  } catch (const string& str) {
669  cerr << str << endl;
670  return false;
671  }
672  }
673  }
674 
675  return true;
676 }
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition: FGFDMExec.h:550
void Initialize(const FGInitialCondition *FGIC)
Initializes the simulation with initial conditions.
Definition: FGFDMExec.cpp:680
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition: FGFDMExec.h:553
static char fgblue[6]
blue text
Definition: FGJSBBase.h:163
static char reset[5]
resets text properties
Definition: FGJSBBase.h:157
static char highint[5]
highlights text
Definition: FGJSBBase.h:151
void InitRunning(int n)
Sets up the engines as running.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAircraftPath()

bool SetAircraftPath ( const SGPath &  path)
inline

Set the path to the aircraft config file directories.

Under this path, then, would be directories for various modeled aircraft such as C172/, x15/, etc. Relative paths are taken from the root directory.

Parameters
pathpath to the aircraft directory, for instance "aircraft".
See also
SetRootDir
GetAircraftPath

Definition at line 325 of file FGFDMExec.h.

325  {
326  AircraftPath = GetFullPath(path);
327  return true;
328  }

◆ Setdt()

void Setdt ( double  delta_t)
inline

Sets the integration time step for the simulation executive.

Parameters
delta_tthe time step in seconds.

Definition at line 566 of file FGFDMExec.h.

566 { dT = delta_t; }
+ Here is the caller graph for this function:

◆ SetEnginePath()

bool SetEnginePath ( const SGPath &  path)
inline

Set the path to the engine config file directories.

Relative paths are taken from the root directory.

Parameters
pathpath to the directory under which engine config files are kept, for instance "engine".
See also
SetRootDir
GetEnginePath

Definition at line 313 of file FGFDMExec.h.

313  {
314  EnginePath = GetFullPath(path);
315  return true;
316  }

◆ SetHoldDown()

void SetHoldDown ( bool  hd)

Sets the property forces/hold-down.

This allows to do hard 'hold-down' such as for rockets on a launch pad with engines ignited.

Parameters
hdenables the 'hold-down' function if non-zero

Definition at line 710 of file FGFDMExec.cpp.

711 {
712  HoldDown = hd;
713  Accelerations->SetHoldDown(hd);
714  if (hd) {
715  Propagate->in.vPQRidot = Accelerations->GetPQRidot();
716  Propagate->in.vUVWidot = Accelerations->GetUVWidot();
717  }
718  Propagate->SetHoldDown(hd);
719 }
const FGColumnVector3 & GetPQRidot(void) const
Retrieves the axis angular acceleration vector in the ECI frame.
const FGColumnVector3 & GetUVWidot(void) const
Retrieves the body axis acceleration in the ECI frame.
void SetHoldDown(bool hd)
Sets the property forces/hold-down.
void SetHoldDown(bool hd)
Sets the property forces/hold-down.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetOutputDirectives()

bool SetOutputDirectives ( const SGPath &  fname)
inline

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 <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 <output> </output> element, within which should be specified the parameters or parameter groups that should be logged.

Parameters
fnamethe filename of an output directives file.

Definition at line 446 of file FGFDMExec.h.

447  { return Output->SetDirectivesFile(GetFullPath(fname)); }
bool SetDirectivesFile(const SGPath &fname)
Adds a new output instance to the Output Manager.
Definition: FGOutput.cpp:172

◆ SetOutputFileName()

bool SetOutputFileName ( const int  n,
const std::string &  fname 
)
inline

Sets (or overrides) the output filename.

Parameters
nindex of file
fnamethe name of the file to output data to
Returns
true if successful, false if there is no output specified for the flight model

Definition at line 459 of file FGFDMExec.h.

459 { return Output->SetOutputName(n, fname); }
bool SetOutputName(unsigned int idx, const std::string &name)
Overwrites the name identifier under which the output will be logged.
Definition: FGOutput.cpp:151

◆ SetOutputPath()

bool SetOutputPath ( const SGPath &  path)
inline

Set the directory where the output files will be written.

Relative paths are taken from the root directory.

Parameters
pathpath to the directory under which the output files will be written.
See also
SetRootDir
GetOutputPath

Definition at line 347 of file FGFDMExec.h.

347  {
348  OutputPath = GetFullPath(path);
349  return true;
350  }

◆ SetPropertyValue()

void SetPropertyValue ( const std::string &  property,
double  value 
)
inline

Sets a property value.

Parameters
propertythe property to be set
valuethe value to set the property to

Definition at line 414 of file FGFDMExec.h.

415  { instance->GetNode()->SetDouble(property, value); }

◆ SetRootDir()

void SetRootDir ( const SGPath &  rootDir)
inline

Set the root directory that is used to obtain absolute paths from relative paths.

Aircraft, engine, systems and output paths are not updated by this method. You must call each methods (SetAircraftPath(), SetEnginePath(), etc.) individually if you need to update these paths as well.

Parameters
rootDirthe path to the root directory.
See also
GetRootDir
SetAircraftPath
SetEnginePath
SetSystemsPath
SetOutputPath

Definition at line 580 of file FGFDMExec.h.

580 {RootDir = rootDir;}

◆ Setsim_time()

double Setsim_time ( double  cur_time)

Sets the current sim time.

Parameters
cur_timethe current time
Returns
the current simulation time.

Definition at line 194 of file FGFDMExec.cpp.

194  {
195  sim_time = cur_time;
196  Inertial->SetTime(sim_time);
197  return sim_time;
198 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSystemsPath()

bool SetSystemsPath ( const SGPath &  path)
inline

Set the path to the systems config file directories.

Relative paths are taken from the root directory.

Parameters
pathpath to the directory under which systems config files are kept, for instance "systems"
See also
SetRootDir
GetSystemsPath

Definition at line 336 of file FGFDMExec.h.

336  {
337  SystemsPath = GetFullPath(path);
338  return true;
339  }

The documentation for this class was generated from the following files: