INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#include "models/FGModel.h"
-#include "models/FGOutput.h"
-#include "models/FGInput.h"
+#include <vector>
+#include <string>
+
#include "initialization/FGTrim.h"
-#include "initialization/FGInitialCondition.h"
#include "FGJSBBase.h"
#include "input_output/FGPropertyManager.h"
-#include "input_output/FGGroundCallback.h"
#include "input_output/FGXMLFileRead.h"
#include "models/FGPropagate.h"
#include "math/FGColumnVector3.h"
-#include <vector>
-#include <string>
-
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.54 2010/10/07 03:17:29 jberndt Exp $"
+#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.74 2011/11/09 21:58:26 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
class FGScript;
class FGTrim;
+class FGAerodynamics;
+class FGAircraft;
+class FGAtmosphere;
+class FGAccelerations;
+class FGWinds;
+class FGAuxiliary;
+class FGBuoyantForces;
+class FGExternalReactions;
+class FGGroundReactions;
+class FGFCS;
+class FGInertial;
+class FGInput;
+class FGOutput;
+class FGPropagate;
+class FGPropulsion;
+class FGMassBalance;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
file:
@code
- fdmex = new FGFDMExec( \85 );
- result = fdmex->LoadModel( \85 );
+ fdmex = new FGFDMExec( ... );
+ result = fdmex->LoadModel( ... );
@endcode
When an aircraft model is loaded, the config file is parsed and for each of the
property actually maps toa function call of DoTrim().
@author Jon S. Berndt
- @version $Revision: 1.54 $
+ @version $Revision: 1.74 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
public:
- /// Default constructors
- FGFDMExec(FGPropertyManager* root = 0);
- FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr);
+ /// Default constructor
+ FGFDMExec(FGPropertyManager* root = 0, unsigned int* fdmctr = 0);
/// Default destructor
~FGFDMExec();
+ // This list of enums is very important! The order in which models are listed here
+ // determines the order of execution of the models.
+ enum eModels { ePropagate=0,
+ eInput,
+ eInertial,
+ eAtmosphere,
+ eWinds,
+ eAuxiliary,
+ eSystems,
+ ePropulsion,
+ eAerodynamics,
+ eGroundReactions,
+ eExternalReactions,
+ eBuoyantForces,
+ eMassBalance,
+ eAircraft,
+ eAccelerations,
+ eNumStandardModels };
+
+ /** Unbind all tied JSBSim properties. */
+ void Unbind(void) {instance->Unbind();}
+
/** This routine places a model into the runlist at the specified rate. The
"rate" is not really a clock rate. It represents how many calls to the
FGFDMExec::Run() method must be made before the model is executed. A
one is at this time not recommended.
@param model A pointer to the model being scheduled.
@param rate The rate at which to execute the model as described above.
+ Default is every frame (rate=1).
@return Currently returns 0 always. */
- void Schedule(FGModel* model, int rate);
+ void Schedule(FGModel* model, int rate=1);
/** This function executes each scheduled model in succession.
@return true if successful, false if sim should be ended */
@return true if successful */
bool RunIC(void);
- /** Sets the ground callback pointer.
- @param gc A pointer to a ground callback object. */
- void SetGroundCallback(FGGroundCallback* gc);
+ /** Sets the ground callback pointer. For optimal memory management, a shared
+ pointer is used internally that maintains a reference counter. The calling
+ application must therefore use FGGroundCallback_ptr 'smart pointers' to
+ manage their copy of the ground callback.
+ @param gc A pointer to a ground callback object
+ @see FGGroundCallback
+ */
+ void SetGroundCallback(FGGroundCallback* gc) { FGLocation::SetGroundCallback(gc); }
/** Loads an aircraft model.
@param AircraftPath path to the aircraft/ directory. For instance:
/** Loads a script
@param Script the full path name and file name for the script to be loaded.
+ @param deltaT The simulation integration step size, if given. If no value is supplied
+ then 0.0 is used and the value is expected to be supplied in
+ the script file itself.
@return true if successfully loadsd; false otherwise. */
- bool LoadScript(const string& Script, double deltaT);
+ bool LoadScript(const string& Script, double deltaT=0.0);
/** Sets the path to the engine config file directories.
@param path path to the directory under which engine config
bool SetSystemsPath(const string& path) { SystemsPath = RootDir + path; return true; }
/// @name Top-level executive State and Model retrieval mechanism
- //@{
+ ///@{
/// Returns the FGAtmosphere pointer.
- inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
+ FGAtmosphere* GetAtmosphere(void) {return (FGAtmosphere*)Models[eAtmosphere];}
+ /// Returns the FGAccelerations pointer.
+ FGAccelerations* GetAccelerations(void) {return (FGAccelerations*)Models[eAccelerations];}
+ /// Returns the FGWinds pointer.
+ FGWinds* GetWinds(void) {return (FGWinds*)Models[eWinds];}
/// Returns the FGFCS pointer.
- inline FGFCS* GetFCS(void) {return FCS;}
+ FGFCS* GetFCS(void) {return (FGFCS*)Models[eSystems];}
/// Returns the FGPropulsion pointer.
- inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
+ FGPropulsion* GetPropulsion(void) {return (FGPropulsion*)Models[ePropulsion];}
/// Returns the FGAircraft pointer.
- inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
+ FGMassBalance* GetMassBalance(void) {return (FGMassBalance*)Models[eMassBalance];}
/// Returns the FGAerodynamics pointer
- inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
+ FGAerodynamics* GetAerodynamics(void){return (FGAerodynamics*)Models[eAerodynamics];}
/// Returns the FGInertial pointer.
- inline FGInertial* GetInertial(void) {return Inertial;}
+ FGInertial* GetInertial(void) {return (FGInertial*)Models[eInertial];}
/// Returns the FGGroundReactions pointer.
- inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
+ FGGroundReactions* GetGroundReactions(void) {return (FGGroundReactions*)Models[eGroundReactions];}
/// Returns the FGExternalReactions pointer.
- inline FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
+ FGExternalReactions* GetExternalReactions(void) {return (FGExternalReactions*)Models[eExternalReactions];}
/// Returns the FGBuoyantForces pointer.
- inline FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
+ FGBuoyantForces* GetBuoyantForces(void) {return (FGBuoyantForces*)Models[eBuoyantForces];}
/// Returns the FGAircraft pointer.
- inline FGAircraft* GetAircraft(void) {return Aircraft;}
+ FGAircraft* GetAircraft(void) {return (FGAircraft*)Models[eAircraft];}
/// Returns the FGPropagate pointer.
- inline FGPropagate* GetPropagate(void) {return Propagate;}
+ FGPropagate* GetPropagate(void) {return (FGPropagate*)Models[ePropagate];}
/// Returns the FGAuxiliary pointer.
- inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
+ FGAuxiliary* GetAuxiliary(void) {return (FGAuxiliary*)Models[eAuxiliary];}
/// Returns the FGInput pointer.
- inline FGInput* GetInput(void) {return Input;}
- /// Returns the FGGroundCallback pointer.
- inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
+ FGInput* GetInput(void) {return (FGInput*)Models[eInput];}
+ /** Get a pointer to the ground callback currently used. It is recommanded
+ to store the returned pointer in a 'smart pointer' FGGroundCallback_ptr.
+ @return A pointer to the current ground callback object.
+ @see FGGroundCallback
+ */
+ FGGroundCallback* GetGroundCallback(void) {return FGLocation::GetGroundCallback();}
/// Retrieves the script object
- inline FGScript* GetScript(void) {return Script;}
- // Returns a pointer to the FGInitialCondition object
- inline FGInitialCondition* GetIC(void) {return IC;}
- // Returns a pointer to the FGTrim object
+ FGScript* GetScript(void) {return Script;}
+ /// Returns a pointer to the FGInitialCondition object
+ FGInitialCondition* GetIC(void) {return IC;}
+ /// Returns a pointer to the FGTrim object
FGTrim* GetTrim(void);
- //@}
+ ///@}
/// Retrieves the engine path.
- inline const string& GetEnginePath(void) {return EnginePath;}
+ const string& GetEnginePath(void) {return EnginePath;}
/// Retrieves the aircraft path.
- inline const string& GetAircraftPath(void) {return AircraftPath;}
+ const string& GetAircraftPath(void) {return AircraftPath;}
/// Retrieves the systems path.
- inline const string& GetSystemsPath(void) {return SystemsPath;}
+ const string& GetSystemsPath(void) {return SystemsPath;}
/// Retrieves the full aircraft path name.
- inline const string& GetFullAircraftPath(void) {return FullAircraftPath;}
+ const string& GetFullAircraftPath(void) {return FullAircraftPath;}
/** Retrieves the value of a property.
@param property the name of the property
}
/// Returns the model name.
- const string& GetModelName(void) { return modelName; }
+ const string& GetModelName(void) const { return modelName; }
/*
/// Returns the current time.
double GetSimTime(void);
/// Returns a vector of strings representing the names of all loaded models (future)
vector <string> EnumerateFDMs(void);
/// Gets the number of child FDMs.
- int GetFDMCount(void) {return (int)ChildFDMList.size();}
+ int GetFDMCount(void) const {return (int)ChildFDMList.size();}
/// Gets a particular child FDM.
- childData* GetChildFDM(int i) {return ChildFDMList[i];}
+ childData* GetChildFDM(int i) const {return ChildFDMList[i];}
/// Marks this instance of the Exec object as a "child" object.
void SetChild(bool ch) {IsChild = ch;}
*/
bool SetOutputDirectives(const string& fname);
+ /** Forces the specified output object to print its items once */
+ void ForceOutput(int idx=0);
+
/** Sets (or overrides) the output filename
@param fname the name of the file to output data to
@return true if successful, false if there is no output specified for the flight model */
- bool SetOutputFileName(const string& fname) {
- if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
- else return false;
- return true;
- }
+ bool SetOutputFileName(const string& fname);
/** Retrieves the current output filename.
@return the name of the output file for the first output specified by the flight model.
If none is specified, the empty string is returned. */
- string GetOutputFileName(void) {
- if (Outputs.size() > 0) return Outputs[0]->GetOutputFileName();
- else return string("");
- }
+ string GetOutputFileName(void);
/** Executes trimming in the selected mode.
* @param mode Specifies how to trim:
* - tTurn
* - tNone */
void DoTrim(int mode);
-// void DoTrimAnalysis(int mode);
/// Disables data logging to all outputs.
void DisableOutput(void);
vector<string>& GetPropertyCatalog(void) {return PropertyCatalog;}
- /// Use the MSIS atmosphere model.
- void UseAtmosphereMSIS(void);
-
- /// Use the Mars atmosphere model. (Not operative yet.)
- void UseAtmosphereMars(void);
-
void SetTrimStatus(bool status){ trim_status = status; }
bool GetTrimStatus(void) const { return trim_status; }
void SetTrimMode(int mode){ ta_mode = mode; }
int GetTrimMode(void) const { return ta_mode; }
+ string GetPropulsionTankReport();
+
/// Returns the cumulative simulation time in seconds.
double GetSimTime(void) const { return sim_time; }
/// Returns the simulation delta T.
- double GetDeltaT(void) {return dT;}
+ double GetDeltaT(void) const {return dT;}
/// Suspends the simulation and sets the delta T to zero.
void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
/** Returns the simulation suspension state.
@return true if suspended, false if executing */
- bool IntegrationSuspended(void) {return dT == 0.0;}
+ bool IntegrationSuspended(void) const {return dT == 0.0;}
/** Sets the current sim time.
@param cur_time the current time
@param rootDir the string containing the root directory. */
void SetRootDir(const string& rootDir) {RootDir = rootDir;}
- /** Retrieves teh Root Directory.
+ /** Retrieves the Root Directory.
@return the string representing the root (base) JSBSim directory. */
const string& GetRootDir(void) const {return RootDir;}
- /** Increments the simulation time.
+ /** Increments the simulation time if not in Holding mode. The Frame counter
+ is also incremented.
@return the new simulation time. */
double IncrTime(void) {
- sim_time += dT;
+ if (!holding) sim_time += dT;
+ Frame++;
return sim_time;
}
bool Constructing;
bool modelLoaded;
bool IsChild;
- bool root_overload;
+ bool firstPass;
string modelName;
string AircraftPath;
string FullAircraftPath;
string Release;
string RootDir;
+ // Standard Model pointers - shortcuts for internal executive use only.
+ FGPropagate* Propagate;
+ FGInertial* Inertial;
+ FGAtmosphere* Atmosphere;
+ FGWinds* Winds;
+ FGAuxiliary* Auxiliary;
+ FGFCS* FCS;
+ FGPropulsion* Propulsion;
+ FGAerodynamics* Aerodynamics;
+ FGGroundReactions* GroundReactions;
+ FGExternalReactions* ExternalReactions;
+ FGBuoyantForces* BuoyantForces;
+ FGMassBalance* MassBalance;
+ FGAircraft* Aircraft;
+ FGAccelerations* Accelerations;
+
bool trim_status;
int ta_mode;
- FGGroundCallback* GroundCallback;
- FGAtmosphere* Atmosphere;
- FGFCS* FCS;
- FGPropulsion* Propulsion;
- FGMassBalance* MassBalance;
- FGAerodynamics* Aerodynamics;
- FGInertial* Inertial;
- FGGroundReactions* GroundReactions;
- FGExternalReactions* ExternalReactions;
- FGBuoyantForces* BuoyantForces;
- FGAircraft* Aircraft;
- FGPropagate* Propagate;
- FGAuxiliary* Auxiliary;
- FGInput* Input;
FGScript* Script;
FGInitialCondition* IC;
FGTrim* Trim;
FGPropertyManager* Root;
- bool delete_root;
+ bool StandAlone;
FGPropertyManager* instance;
// The FDM counter is used to give each child FDM an unique ID. The root FDM has the ID 0
vector <childData*> ChildFDMList;
vector <FGModel*> Models;
- void Initialize();
bool ReadFileHeader(Element*);
bool ReadChild(Element*);
bool ReadPrologue(Element*);
void ResetToInitialConditions(int mode);
+ void LoadInputs(unsigned int idx);
+ void LoadPlanetConstants(void);
+ void LoadModelConstants(void);
bool Allocate(void);
bool DeAllocate(void);
void Initialize(FGInitialCondition *FGIC);