JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGFDMExec Class Reference

Encapsulates the JSBSim simulation executive. More...

#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=0, unsigned int *fdmctr=0)
 Default constructor.
 
 ~FGFDMExec ()
 Default destructor.
 
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.
 
childData * GetChildFDM (int i) const
 Gets a particular child FDM.
 
int GetDebugLevel (void) const
 Retrieves the current debug level setting. More...
 
double GetDeltaT (void) const
 Returns the simulation delta T.
 
const SGPath & GetEnginePath (void)
 Retrieves the engine path.
 
int GetFDMCount (void) const
 Gets the number of child FDMs.
 
unsigned int GetFrame (void) const
 Retrieves the current frame count. More...
 
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...
 
std::vector< std::string > & GetPropertyCatalog (void)
 
FGPropertyManagerGetPropertyManager (void)
 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 SGPath & GetRootDir (void) const
 Retrieves the Root Directory. More...
 
double GetSimTime (void) const
 Returns the cumulative simulation time in seconds.
 
const SGPath & GetSystemsPath (void)
 Retrieves the systems path.
 
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 (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 LoadScript (const SGPath &Script, double deltaT=0.0, const SGPath &initfile=SGPath())
 Loads a script. More...
 
void PrintPropertyCatalog (void)
 
void PrintSimulationConfiguration (void) const
 
std::string QueryPropertyCatalog (const std::string &check)
 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)
 Sets 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)
 Sets the path to the engine config file directories. More...
 
void SetGroundCallback (FGGroundCallback *gc)
 Sets the ground callback pointer. 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). More...
 
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...
 
void SetPropertyValue (const std::string &property, double value)
 Sets a property value. More...
 
void SetRootDir (const SGPath &rootDir)
 Sets the root directory where JSBSim starts looking for its system directories. More...
 
double Setsim_time (double cur_time)
 Sets the current sim time. More...
 
bool SetSystemsPath (const SGPath &path)
 Sets 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. More...
 
Top-level executive State and Model retrieval mechanism

Returns the FGAtmosphere pointer.

FGAtmosphereGetAtmosphere (void)
 
FGAccelerationsGetAccelerations (void)
 Returns the FGAccelerations pointer.
 
FGWindsGetWinds (void)
 Returns the FGWinds pointer.
 
FGFCSGetFCS (void)
 Returns the FGFCS pointer.
 
FGPropulsionGetPropulsion (void)
 Returns the FGPropulsion pointer.
 
FGMassBalanceGetMassBalance (void)
 Returns the FGAircraft pointer.
 
FGAerodynamicsGetAerodynamics (void)
 Returns the FGAerodynamics pointer.
 
FGInertialGetInertial (void)
 Returns the FGInertial pointer.
 
FGGroundReactionsGetGroundReactions (void)
 Returns the FGGroundReactions pointer.
 
FGExternalReactionsGetExternalReactions (void)
 Returns the FGExternalReactions pointer.
 
FGBuoyantForcesGetBuoyantForces (void)
 Returns the FGBuoyantForces pointer.
 
FGAircraftGetAircraft (void)
 Returns the FGAircraft pointer.
 
FGPropagateGetPropagate (void)
 Returns the FGPropagate pointer.
 
FGAuxiliaryGetAuxiliary (void)
 Returns the FGAuxiliary pointer.
 
FGInputGetInput (void)
 Returns the FGInput pointer.
 
FGOutputGetOutput (void)
 Returns the FGOutput pointer.
 
FGGroundCallbackGetGroundCallback (void)
 Get a pointer to the ground callback currently used. More...
 
FGScriptGetScript (void)
 Retrieves the script object.
 
FGInitialConditionGetIC (void)
 Returns a pointer to the FGInitialCondition object.
 
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.
 
std::string GetVersion (void)
 Returns the version number of JSBSim. More...
 
void PutMessage (const Message &msg)
 Places a Message structure on the Message queue. More...
 
void PutMessage (const std::string &text)
 Creates a message with the given text and places it on the queue. More...
 
void PutMessage (const std::string &text, bool bVal)
 Creates a message with the given text and boolean value and places it on the queue. More...
 
void PutMessage (const std::string &text, int iVal)
 Creates a message with the given text and integer value and places it on the queue. More...
 
void PutMessage (const std::string &text, double dVal)
 Creates a message with the given text and double value and places it on the queue. More...
 
int SomeMessages (void)
 Reads the message on the queue (but does not delete it). More...
 
void ProcessMessage (void)
 Reads the message on the queue and removes it from the queue. More...
 
MessageProcessNextMessage (void)
 Reads the next message on the queue and removes it from the queue. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from FGJSBBase
static double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
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 double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double GaussianRandomNumber (void)
 
static double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static double MachFromVcalibrated (double vcas, double p, double psl, double rhosl)
 Calculate the Mach number from the calibrated airspeed. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static double sign (double num)
 
static double VcalibratedFromMach (double mach, double p, double psl, double rhosl)
 Calculate the calibrated airspeed from the Mach number. More...
 
- Static Public Attributes inherited from FGJSBBase
static short debug_lvl = 1
 
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
 
- Protected Member Functions inherited from FGJSBBase
void Debug (int)
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static const double degtorad = 0.017453292519943295769236907684886
 
static const double fpstokts = 1.0/ktstofps
 
static const double fttom = 0.3048
 
static int gaussian_random_number_phase = 0
 
static const double hptoftlbssec = 550.0
 
static const double in3tom3 = 1.638706E-5
 
static const double inchtoft = 0.08333333
 
static const double inhgtopa = 3386.38
 
static const std::string JSBSim_version = "1.0 " __DATE__ " " __TIME__
 
static const double kgtolb = 2.20462
 
static const double kgtoslug = 0.06852168
 
static const double ktstofps = 1.68781
 
static const double lbtoslug = 1.0/slugtolb
 
static Message localMsg
 
static const double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static double Mair = 28.9645
 
static unsigned int messageId = 0
 
static std::queue< MessageMessages
 
static const std::string needed_cfg_version = "2.0"
 
static const double psftoinhg = 0.014138
 
static const double psftopa = 47.88
 
static const double radtodeg = 57.295779513082320876798154814105
 
static double Reng = 1716.56
 
static double Rstar = 1545.348
 
static const double SHRatio = 1.40
 
static const double slugtolb = 32.174049
 

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( ... );

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
}

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 189 of file FGFDMExec.h.

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 904 of file FGFDMExec.cpp.

905 {
906  struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
907 
908  for (int i=0; i<pcs->node->nChildren(); i++) {
909  string access="";
910  pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
911  int node_idx = pcs->node->getChild(i)->getIndex();
912  if (node_idx != 0) {
913  pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
914  }
915  if (pcs->node->getChild(i)->nChildren() == 0) {
916  if (pcsNew->base_string.substr(0,12) == string("/fdm/jsbsim/")) {
917  pcsNew->base_string = pcsNew->base_string.erase(0,12);
918  }
919  if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::READ)) access="R";
920  if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::WRITE)) access+="W";
921  PropertyCatalog.push_back(pcsNew->base_string+" ("+access+")");
922  } else {
923  pcsNew->node = (FGPropertyNode*)pcs->node->getChild(i);
924  BuildPropertyCatalog(pcsNew);
925  }
926  }
927  delete pcsNew;
928 }
void BuildPropertyCatalog(struct PropertyCatalogStructure *pcs)
Builds a catalog of properties.
Definition: FGFDMExec.cpp:904
+ 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 1139 of file FGFDMExec.cpp.

1140 {
1141  if (Constructing) return;
1142 
1143  if (mode < 0 || mode > JSBSim::tNone)
1144  throw("Illegal trimming mode!");
1145 
1146  FGTrim trim(this, (JSBSim::TrimMode)mode);
1147  bool success = trim.DoTrim();
1148  trim.Report();
1149 
1150  if (!success)
1151  throw("Trim Failed");
1152 
1153  trim_completed = 1;
1154 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDebugLevel()

int GetDebugLevel ( void  ) const
inline

Retrieves the current debug level setting.

Definition at line 585 of file FGFDMExec.h.

585 {return debug_lvl;};
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetFrame()

unsigned int GetFrame ( void  ) const
inline

Retrieves the current frame count.

Definition at line 582 of file FGFDMExec.h.

582 {return Frame;}

◆ GetGroundCallback()

FGGroundCallback* GetGroundCallback ( void  )
inline

Get a pointer to the ground callback currently used.

It is recommanded to store the returned pointer in a 'smart pointer' FGGroundCallback_ptr.

Returns
A pointer to the current ground callback object.
See also
FGGroundCallback

Definition at line 381 of file FGFDMExec.h.

static FGGroundCallback * GetGroundCallback(void)
Get a pointer to the ground callback currently used.
Definition: FGLocation.h:404
+ Here is the call graph for this function:
+ 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 600 of file FGFDMExec.h.

600 {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 460 of file FGFDMExec.h.

460 { 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:174
+ Here is the call graph for this function:

◆ 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 402 of file FGFDMExec.h.

403  { return instance->GetNode()->GetDouble(property); }
double GetDouble(const std::string &name, double defaultValue=0.0) const
Get a double value for a property.

◆ GetRootDir()

const SGPath& GetRootDir ( void  ) const
inline

Retrieves the Root Directory.

Returns
the string representing the root (base) JSBSim directory.

Definition at line 567 of file FGFDMExec.h.

567 {return RootDir;}
+ Here is the caller graph for this function:

◆ IncrTime()

double IncrTime ( void  )
inline

Increments the simulation time if not in Holding mode.

The Frame counter is also incremented.

Returns
the new simulation time.

Definition at line 572 of file FGFDMExec.h.

572  {
573  if (!holding && !IntegrationSuspended()) {
574  sim_time += dT;
575  GetGroundCallback()->SetTime(sim_time);
576  Frame++;
577  }
578  return sim_time;
579  }
FGGroundCallback * GetGroundCallback(void)
Get a pointer to the ground callback currently used.
Definition: FGFDMExec.h:381
bool IntegrationSuspended(void) const
Returns the simulation suspension state.
Definition: FGFDMExec.h:546
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void Initialize ( FGInitialCondition FGIC)

Initializes the simulation with initial conditions.

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

Definition at line 591 of file FGFDMExec.cpp.

592 {
593  Propagate->SetInitialState(FGIC);
594  Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
595  Run();
596 }
virtual void SetWindNED(double wN, double wE, double wD)
Sets the wind components in NED frame.
Definition: FGWinds.h:148
bool Run(void)
This function executes each scheduled model in succession.
Definition: FGFDMExec.cpp:310
+ 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 546 of file FGFDMExec.h.

546 {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 666 of file FGFDMExec.cpp.

669 {
670  FGFDMExec::AircraftPath = GetFullPath(AircraftPath);
671  FGFDMExec::EnginePath = GetFullPath(EnginePath);
672  FGFDMExec::SystemsPath = GetFullPath(SystemsPath);
673 
674  return LoadModel(model, addModelToPath);
675 }
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:666
+ 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 679 of file FGFDMExec.cpp.

680 {
681  SGPath aircraftCfgFileName;
682  bool result = false; // initialize result to false, indicating input file not yet read
683 
684  modelName = model; // Set the class modelName attribute
685 
686  if( AircraftPath.isNull() || EnginePath.isNull() || SystemsPath.isNull()) {
687  cerr << "Error: attempted to load aircraft with undefined ";
688  cerr << "aircraft, engine, and system paths" << endl;
689  return false;
690  }
691 
692  FullAircraftPath = AircraftPath;
693  if (addModelToPath) FullAircraftPath.append(model);
694  aircraftCfgFileName = FullAircraftPath/(model + ".xml");
695 
696  if (modelLoaded) {
697  DeAllocate();
698  Allocate();
699  }
700 
701  int saved_debug_lvl = debug_lvl;
702  FGXMLFileRead XMLFileRead;
703  Element *document = XMLFileRead.LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
704 
705  if (document) {
706  if (IsChild) debug_lvl = 0;
707 
708  ReadPrologue(document);
709 
710  if (IsChild) debug_lvl = saved_debug_lvl;
711 
712  // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
713  Element* element = document->FindElement("fileheader");
714  if (element) {
715  result = ReadFileHeader(element);
716  if (!result) {
717  cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
718  return result;
719  }
720  }
721 
722  if (IsChild) debug_lvl = 0;
723 
724  // Process the metrics element. This element is REQUIRED.
725  element = document->FindElement("metrics");
726  if (element) {
727  result = ((FGAircraft*)Models[eAircraft])->Load(element);
728  if (!result) {
729  cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
730  return result;
731  }
732  } else {
733  cerr << endl << "No metrics element was found in the aircraft config file." << endl;
734  return false;
735  }
736 
737  // Process the mass_balance element. This element is REQUIRED.
738  element = document->FindElement("mass_balance");
739  if (element) {
740  result = ((FGMassBalance*)Models[eMassBalance])->Load(element);
741  if (!result) {
742  cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
743  return result;
744  }
745  } else {
746  cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
747  return false;
748  }
749 
750  // Process the ground_reactions element. This element is REQUIRED.
751  element = document->FindElement("ground_reactions");
752  if (element) {
753  result = ((FGGroundReactions*)Models[eGroundReactions])->Load(element);
754  if (!result) {
755  cerr << endl << element->ReadFrom()
756  << "Aircraft ground_reactions element has problems in file "
757  << aircraftCfgFileName << endl;
758  return result;
759  }
760  } else {
761  cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
762  return false;
763  }
764 
765  // Process the external_reactions element. This element is OPTIONAL.
766  element = document->FindElement("external_reactions");
767  if (element) {
768  result = ((FGExternalReactions*)Models[eExternalReactions])->Load(element);
769  if (!result) {
770  cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
771  return result;
772  }
773  }
774 
775  // Process the buoyant_forces element. This element is OPTIONAL.
776  element = document->FindElement("buoyant_forces");
777  if (element) {
778  result = ((FGBuoyantForces*)Models[eBuoyantForces])->Load(element);
779  if (!result) {
780  cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
781  return result;
782  }
783  }
784 
785  // Process the propulsion element. This element is OPTIONAL.
786  element = document->FindElement("propulsion");
787  if (element) {
788  result = ((FGPropulsion*)Models[ePropulsion])->Load(element);
789  if (!result) {
790  cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
791  return result;
792  }
793  for (unsigned int i=0; i<((FGPropulsion*)Models[ePropulsion])->GetNumEngines(); i++)
794  ((FGFCS*)Models[eSystems])->AddThrottle();
795  }
796 
797  // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
798  element = document->FindElement("system");
799  while (element) {
800  result = ((FGFCS*)Models[eSystems])->Load(element);
801  if (!result) {
802  cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
803  return result;
804  }
805  element = document->FindNextElement("system");
806  }
807 
808  // Process the autopilot element. This element is OPTIONAL.
809  element = document->FindElement("autopilot");
810  if (element) {
811  result = ((FGFCS*)Models[eSystems])->Load(element);
812  if (!result) {
813  cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
814  return result;
815  }
816  }
817 
818  // Process the flight_control element. This element is OPTIONAL.
819  element = document->FindElement("flight_control");
820  if (element) {
821  result = ((FGFCS*)Models[eSystems])->Load(element);
822  if (!result) {
823  cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
824  return result;
825  }
826  }
827 
828  // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
829  element = document->FindElement("aerodynamics");
830  if (element) {
831  result = ((FGAerodynamics*)Models[eAerodynamics])->Load(element);
832  if (!result) {
833  cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
834  return result;
835  }
836  } else {
837  cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
838  }
839 
840  // Process the input element. This element is OPTIONAL, and there may be more than one.
841  element = document->FindElement("input");
842  while (element) {
843  if (!static_cast<FGInput*>(Models[eInput])->Load(element))
844  return false;
845 
846  element = document->FindNextElement("input");
847  }
848 
849  // Process the output element[s]. This element is OPTIONAL, and there may be
850  // more than one.
851  element = document->FindElement("output");
852  while (element) {
853  if (!static_cast<FGOutput*>(Models[eOutput])->Load(element))
854  return false;
855 
856  element = document->FindNextElement("output");
857  }
858 
859  // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
860  element = document->FindElement("child");
861  if (element) {
862  result = ReadChild(element);
863  if (!result) {
864  cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
865  return result;
866  }
867  }
868 
869  // Since all vehicle characteristics have been loaded, place the values in the Inputs
870  // structure for the FGModel-derived classes.
871  LoadModelConstants();
872 
873  modelLoaded = true;
874 
875  if (IsChild) debug_lvl = saved_debug_lvl;
876 
877  } else {
878  cerr << fgred
879  << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
880  << fgdef << endl;
881  }
882 
883  for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i);
884 
885  if (result) {
886  struct PropertyCatalogStructure masterPCS;
887  masterPCS.base_string = "";
888  masterPCS.node = Root->GetNode();
889  BuildPropertyCatalog(&masterPCS);
890  }
891 
892  return result;
893 }
void BuildPropertyCatalog(struct PropertyCatalogStructure *pcs)
Builds a catalog of properties.
Definition: FGFDMExec.cpp:904
static char fgred[6]
red text
Definition: FGJSBBase.h:141
static char fgdef[6]
default text
Definition: FGJSBBase.h:145
+ Here is the call graph for this function:

◆ LoadScript()

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

Loads 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 653 of file FGFDMExec.cpp.

655 {
656  bool result;
657 
658  Script = new FGScript(this);
659  result = Script->LoadScript(GetFullPath(script), deltaT, initfile);
660 
661  return result;
662 }
bool LoadScript(const SGPath &script, double default_dT, const SGPath &initfile)
Loads a script to drive JSBSim (usually in standalone mode).
Definition: FGScript.cpp:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QueryPropertyCatalog()

string QueryPropertyCatalog ( const std::string &  check)

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.
Returns
the carriage-return-delimited string containing all matching strings in the catalog.

Definition at line 932 of file FGFDMExec.cpp.

933 {
934  string results="";
935  for (unsigned i=0; i<PropertyCatalog.size(); i++) {
936  if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
937  }
938  if (results.empty()) return "No matches found\n";
939  return results;
940 }
+ Here is the call graph for this function:
+ 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 mode is set to 1 the output instances will take special actions such as closing the current output file and open a new one with a different name.

Parameters
modeSets the reset mode.

Definition at line 600 of file FGFDMExec.cpp.

601 {
602  if (Constructing) return;
603 
604  if (mode == 1) Output->SetStartNewOutput();
605 
606  for (unsigned int i = 0; i < Models.size(); i++) {
607  // The Input/Output models will be initialized during the RunIC() execution
608  if (i == eInput || i == eOutput) continue;
609 
610  LoadInputs(i);
611  Models[i]->InitModel();
612  }
613 
614  if (Script)
615  Script->ResetEvents();
616  else
617  Setsim_time(0.0);
618 
619  RunIC();
620 }
bool RunIC(void)
Initializes the sim from the initial condition object and executes each scheduled model without integ...
Definition: FGFDMExec.cpp:552
double Setsim_time(double cur_time)
Sets the current sim time.
Definition: FGFDMExec.h:551
void SetStartNewOutput(void)
Reset the output prior to a restart of the simulation.
Definition: FGOutput.cpp:128
+ 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 310 of file FGFDMExec.cpp.

311 {
312  bool success=true;
313 
314  Debug(2);
315 
316  for (unsigned int i=1; i<ChildFDMList.size(); i++) {
317  ChildFDMList[i]->AssignState( (FGPropagate*)Models[ePropagate] ); // Transfer state to the child FDM
318  ChildFDMList[i]->Run();
319  }
320 
321  IncrTime();
322 
323  // returns true if success, false if complete
324  if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
325 
326  for (unsigned int i = 0; i < Models.size(); i++) {
327  LoadInputs(i);
328  Models[i]->Run(holding);
329  }
330 
331  if (ResetMode) {
332  unsigned int mode = ResetMode;
333 
334  ResetMode = 0;
336  }
337 
338  if (Terminate) success = false;
339 
340  return success;
341 }
bool RunScript(void)
This function is called each pass through the executive Run() method IF scripting is enabled...
Definition: FGScript.cpp:366
bool IntegrationSuspended(void) const
Returns the simulation suspension state.
Definition: FGFDMExec.h:546
void ResetToInitialConditions(int mode)
Resets the initial conditions object and prepares the simulation to run again.
Definition: FGFDMExec.cpp:600
double IncrTime(void)
Increments the simulation time if not in Holding mode.
Definition: FGFDMExec.h:572
+ 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 552 of file FGFDMExec.cpp.

553 {
554  FGPropulsion* propulsion = (FGPropulsion*)Models[ePropulsion];
555 
556  SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
557  Initialize(IC);
558 
559  Models[eInput]->InitModel();
560  Models[eOutput]->InitModel();
561 
562  Run();
563  Propagate->InitializeDerivatives();
564  ResumeIntegration(); // Restores the integration rate to what it was.
565 
566  if (debug_lvl > 0) {
567  MassBalance->GetMassPropertiesReport(0);
568 
569  cout << endl << fgblue << highint
570  << "End of vehicle configuration loading." << endl
571  << "-------------------------------------------------------------------------------"
572  << reset << std::setprecision(6) << endl;
573  }
574 
575  for (unsigned int n=0; n < propulsion->GetNumEngines(); ++n) {
576  if (IC->IsEngineRunning(n)) {
577  try {
578  propulsion->InitRunning(n);
579  } catch (const string& str) {
580  cerr << str << endl;
581  return false;
582  }
583  }
584  }
585 
586  return true;
587 }
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition: FGFDMExec.h:539
static char reset[5]
resets text properties
Definition: FGJSBBase.h:131
void Initialize(FGInitialCondition *FGIC)
Initializes the simulation with initial conditions.
Definition: FGFDMExec.cpp:591
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition: FGFDMExec.h:542
static char fgblue[6]
blue text
Definition: FGJSBBase.h:137
static char highint[5]
highlights text
Definition: FGJSBBase.h:125
bool IsEngineRunning(unsigned int n) const
Is an engine running ?
bool Run(void)
This function executes each scheduled model in succession.
Definition: FGFDMExec.cpp:310
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAircraftPath()

bool SetAircraftPath ( const SGPath &  path)
inline

Sets the path to the aircraft config file directories.

Parameters
pathpath to the aircraft directory. For instance: "aircraft". Under aircraft, then, would be directories for various modeled aircraft such as C172/, x15/, etc.

Definition at line 329 of file FGFDMExec.h.

329  {
330  AircraftPath = GetFullPath(path);
331  return true;
332  }

◆ 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 559 of file FGFDMExec.h.

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

◆ SetEnginePath()

bool SetEnginePath ( const SGPath &  path)
inline

Sets the path to the engine config file directories.

Parameters
pathpath to the directory under which engine config files are kept, for instance "engine"

Definition at line 320 of file FGFDMExec.h.

320  {
321  EnginePath = GetFullPath(path);
322  return true;
323  }

◆ SetGroundCallback()

void SetGroundCallback ( FGGroundCallback gc)
inline

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.

Parameters
gcA pointer to a ground callback object
See also
FGGroundCallback

Definition at line 271 of file FGFDMExec.h.

static void SetGroundCallback(FGGroundCallback *gc)
Sets the ground callback pointer.
Definition: FGLocation.h:393
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 624 of file FGFDMExec.cpp.

625 {
626  HoldDown = hd;
627  Accelerations->SetHoldDown(hd);
628  if (hd) {
629  Propagate->in.vPQRidot = Accelerations->GetPQRidot();
630  Propagate->in.vUVWidot = Accelerations->GetUVWidot();
631  }
632  Propagate->SetHoldDown(hd);
633 }
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:

◆ SetLoggingRate()

void SetLoggingRate ( double  rate)
inline

Sets the logging rate in Hz for all output objects (if any).

Definition at line 448 of file FGFDMExec.h.

448 { Output->SetRateHz(rate); }
void SetRateHz(double rate)
Modifies the output rate for all output instances.
Definition: FGOutput.cpp:147

◆ 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 441 of file FGFDMExec.h.

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

◆ 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 454 of file FGFDMExec.h.

454 { 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:164

◆ 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 408 of file FGFDMExec.h.

408  {
409  instance->GetNode()->SetDouble(property, value);
410  }
bool SetDouble(const std::string &name, double val)
Set a double value for a property.

◆ SetRootDir()

void SetRootDir ( const SGPath &  rootDir)
inline

Sets the root directory where JSBSim starts looking for its system directories.

Parameters
rootDirthe string containing the root directory.

Definition at line 563 of file FGFDMExec.h.

563 {RootDir = rootDir;}

◆ Setsim_time()

double Setsim_time ( double  cur_time)
inline

Sets the current sim time.

Parameters
cur_timethe current time
Returns
the current simulation time.

Definition at line 551 of file FGFDMExec.h.

551  {
552  sim_time = cur_time;
553  GetGroundCallback()->SetTime(sim_time);
554  return sim_time;
555  }
FGGroundCallback * GetGroundCallback(void)
Get a pointer to the ground callback currently used.
Definition: FGFDMExec.h:381
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSystemsPath()

bool SetSystemsPath ( const SGPath &  path)
inline

Sets the path to the systems config file directories.

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

Definition at line 337 of file FGFDMExec.h.

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

◆ Unbind()

void Unbind ( void  )
inline

Unbind all tied JSBSim properties.

Definition at line 253 of file FGFDMExec.h.

253 {instance->Unbind();}
void Unbind(void)
Unbind all properties bound by this manager to an external data source.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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