JSBSim Flight Dynamics Model
1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
|
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:
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:
Once initialization is complete, cyclic execution proceeds:
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:
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.
This describes to any interested entity the debug level requested by setting the JSBSIM_DEBUG environment variable. The bitmasked value choices are as follows:
Definition at line 183 of file FGFDMExec.h.
#include <FGFDMExec.h>
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< FGPropertyManager > | GetPropertyManager (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< FGAtmosphere > | GetAtmosphere (void) const |
std::shared_ptr< FGAccelerations > | GetAccelerations (void) const |
Returns the FGAccelerations pointer. | |
std::shared_ptr< FGWinds > | GetWinds (void) const |
Returns the FGWinds pointer. | |
std::shared_ptr< FGFCS > | GetFCS (void) const |
Returns the FGFCS pointer. | |
std::shared_ptr< FGPropulsion > | GetPropulsion (void) const |
Returns the FGPropulsion pointer. | |
std::shared_ptr< FGMassBalance > | GetMassBalance (void) const |
Returns the FGAircraft pointer. | |
std::shared_ptr< FGAerodynamics > | GetAerodynamics (void) const |
Returns the FGAerodynamics pointer. | |
std::shared_ptr< FGInertial > | GetInertial (void) const |
Returns the FGInertial pointer. | |
std::shared_ptr< FGGroundReactions > | GetGroundReactions (void) const |
Returns the FGGroundReactions pointer. | |
std::shared_ptr< FGExternalReactions > | GetExternalReactions (void) const |
Returns the FGExternalReactions pointer. | |
std::shared_ptr< FGBuoyantForces > | GetBuoyantForces (void) const |
Returns the FGBuoyantForces pointer. | |
std::shared_ptr< FGAircraft > | GetAircraft (void) const |
Returns the FGAircraft pointer. | |
std::shared_ptr< FGPropagate > | GetPropagate (void) const |
Returns the FGPropagate pointer. | |
std::shared_ptr< FGAuxiliary > | GetAuxiliary (void) const |
Returns the FGAuxiliary pointer. | |
std::shared_ptr< FGInput > | GetInput (void) const |
Returns the FGInput pointer. | |
std::shared_ptr< FGOutput > | GetOutput (void) const |
Returns the FGOutput pointer. | |
std::shared_ptr< FGScript > | GetScript (void) const |
Retrieves the script object. | |
std::shared_ptr< FGInitialCondition > | GetIC (void) const |
Returns a pointer to the FGInitialCondition object. | |
std::shared_ptr< FGTrim > | GetTrim (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__ |
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.
pcs | The "root" property catalog structure pointer. |
Definition at line 1069 of file FGFDMExec.cpp.
void DoTrim | ( | int | mode | ) |
Executes trimming in the selected mode.
mode | Specifies how to trim:
|
Definition at line 1297 of file FGFDMExec.cpp.
|
inline |
Gets the value of the property forces/hold-down.
Definition at line 611 of file FGFDMExec.h.
|
inline |
Retrieves the current output filename.
n | index of file |
Definition at line 465 of file FGFDMExec.h.
|
inline |
Retrieves the value of a property.
property | the name of the property |
Definition at line 408 of file FGFDMExec.h.
|
inline |
Retrieve the Root Directory.
Definition at line 585 of file FGFDMExec.h.
double IncrTime | ( | void | ) |
Increments the simulation time if not in Holding mode.
The Frame counter is also incremented.
Definition at line 202 of file FGFDMExec.cpp.
void Initialize | ( | const FGInitialCondition * | FGIC | ) |
Initializes the simulation with initial conditions.
FGIC | The initial conditions that will be passed to the simulation. |
Definition at line 680 of file FGFDMExec.cpp.
|
inline |
Returns the simulation suspension state.
Definition at line 557 of file FGFDMExec.h.
bool LoadModel | ( | const SGPath & | AircraftPath, |
const SGPath & | EnginePath, | ||
const SGPath & | SystemsPath, | ||
const std::string & | model, | ||
bool | addModelToPath = true |
||
) |
Loads an aircraft model.
AircraftPath | path to the aircraft/ directory. For instance: "aircraft". Under aircraft, then, would be directories for various modeled aircraft such as C172/, x15/, etc. |
EnginePath | path to the directory under which engine config files are kept, for instance "engine" |
SystemsPath | path to the directory under which systems config files are kept, for instance "systems" |
model | the name of the aircraft model itself. This file will be looked for in the directory specified in the AircraftPath variable, and in turn under the directory with the same name as the model. For instance: "aircraft/x15/x15.xml" |
addModelToPath | set to true to add the model name to the AircraftPath, defaults to true |
Definition at line 821 of file FGFDMExec.cpp.
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.
model | the name of the aircraft model itself. This file will be looked for in the directory specified in the AircraftPath variable, and in turn under the directory with the same name as the model. For instance: "aircraft/x15/x15.xml" |
addModelToPath | set to true to add the model name to the AircraftPath, defaults to true |
Definition at line 834 of file FGFDMExec.cpp.
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.
PlanetPath | The name of a planet definition file |
useAircraftPath | true if path is given relative to the aircraft path. |
Definition at line 745 of file FGFDMExec.cpp.
bool LoadScript | ( | const SGPath & | Script, |
double | deltaT = 0.0 , |
||
const SGPath & | initfile = SGPath() |
||
) |
Load a script.
Script | The full path name and file name for the script to be loaded. |
deltaT | The simulation integration step size, if given. If no value is supplied then 0.0 is used and the value is expected to be supplied in the script file itself. |
initfile | The initialization file that will override the initialization file specified in the script file. If no file name is given on the command line, the file specified in the script will be used. If an initialization file is not given in either place, an error will result. |
Definition at line 736 of file FGFDMExec.cpp.
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.
check | The string to search for in the property catalog. |
end_of_line | End of line (CR+LF if needed for Windows). |
Definition at line 1096 of file FGFDMExec.cpp.
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.
mode | Sets the reset mode. |
Definition at line 689 of file FGFDMExec.cpp.
bool Run | ( | void | ) |
This function executes each scheduled model in succession.
Definition at line 413 of file FGFDMExec.cpp.
bool RunIC | ( | void | ) |
Initializes the sim from the initial condition object and executes each scheduled model without integrating i.e.
dt=0.
Definition at line 643 of file FGFDMExec.cpp.
|
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.
path | path to the aircraft directory, for instance "aircraft". |
Definition at line 325 of file FGFDMExec.h.
|
inline |
Sets the integration time step for the simulation executive.
delta_t | the time step in seconds. |
Definition at line 566 of file FGFDMExec.h.
|
inline |
Set the path to the engine config file directories.
Relative paths are taken from the root directory.
path | path to the directory under which engine config files are kept, for instance "engine". |
Definition at line 313 of file FGFDMExec.h.
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.
hd | enables the 'hold-down' function if non-zero |
Definition at line 710 of file FGFDMExec.cpp.
|
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.
fname | the filename of an output directives file. |
Definition at line 446 of file FGFDMExec.h.
|
inline |
Sets (or overrides) the output filename.
n | index of file |
fname | the name of the file to output data to |
Definition at line 459 of file FGFDMExec.h.
|
inline |
Set the directory where the output files will be written.
Relative paths are taken from the root directory.
path | path to the directory under which the output files will be written. |
Definition at line 347 of file FGFDMExec.h.
|
inline |
Sets a property value.
property | the property to be set |
value | the value to set the property to |
Definition at line 414 of file FGFDMExec.h.
|
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.
rootDir | the path to the root directory. |
Definition at line 580 of file FGFDMExec.h.
double Setsim_time | ( | double | cur_time | ) |
Sets the current sim time.
cur_time | the current time |
Definition at line 194 of file FGFDMExec.cpp.
|
inline |
Set the path to the systems config file directories.
Relative paths are taken from the root directory.
path | path to the directory under which systems config files are kept, for instance "systems" |
Definition at line 336 of file FGFDMExec.h.