00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef FGFDMEXEC_HEADER_H
00038 #define FGFDMEXEC_HEADER_H
00039
00040
00041
00042
00043
00044 #include <models/FGModel.h>
00045 #include <models/FGOutput.h>
00046 #include <models/FGInput.h>
00047 #include <initialization/FGTrim.h>
00048 #include <initialization/FGInitialCondition.h>
00049 #include <FGJSBBase.h>
00050 #include <input_output/FGPropertyManager.h>
00051 #include <input_output/FGGroundCallback.h>
00052 #include <input_output/FGXMLFileRead.h>
00053 #include <models/FGPropagate.h>
00054 #include <math/FGColumnVector3.h>
00055
00056 #include <vector>
00057 #include <string>
00058
00059
00060
00061
00062
00063 #define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.43 2009/05/17 13:55:48 jberndt Exp $"
00064
00065
00066
00067
00068
00069 namespace JSBSim {
00070
00071 class FGScript;
00072 class FGTrim;
00073
00074
00075
00076
00077
00175
00176
00177
00178
00179 class FGFDMExec : public FGJSBBase, public FGXMLFileRead
00180 {
00181 struct childData {
00182 FGFDMExec* exec;
00183 string info;
00184 FGColumnVector3 Loc;
00185 FGColumnVector3 Orient;
00186 bool mated;
00187 bool internal;
00188
00189 childData(void) {
00190 info = "";
00191 Loc = FGColumnVector3(0,0,0);
00192 Orient = FGColumnVector3(0,0,0);
00193 mated = true;
00194 internal = false;
00195 }
00196
00197 void Run(void) {exec->Run();}
00198 void AssignState(FGPropagate* source_prop) {
00199 exec->GetPropagate()->SetVState(source_prop->GetVState());
00200 }
00201
00202 ~childData(void) {
00203 delete exec;
00204 }
00205 };
00206
00207 public:
00208
00210 FGFDMExec(FGPropertyManager* root = 0);
00211
00213 ~FGFDMExec();
00214
00225 int Schedule(FGModel* model, int rate);
00226
00229 bool Run(void);
00230
00234 bool RunIC(void);
00235
00238 void SetGroundCallback(FGGroundCallback* gc);
00239
00255 bool LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
00256 string model, bool addModelToPath = true);
00257
00268 bool LoadModel(string model, bool addModelToPath = true);
00269
00273 bool LoadScript(string Script);
00274
00278 bool SetEnginePath(string path) { EnginePath = path; return true; }
00279
00284 bool SetAircraftPath(string path) { AircraftPath = path; return true; }
00285
00289 bool SetSystemsPath(string path) { SystemsPath = path; return true; }
00290
00292
00293
00294 inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
00296 inline FGFCS* GetFCS(void) {return FCS;}
00298 inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
00300 inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
00302 inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
00304 inline FGInertial* GetInertial(void) {return Inertial;}
00306 inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
00308 inline FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
00310 inline FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
00312 inline FGAircraft* GetAircraft(void) {return Aircraft;}
00314 inline FGPropagate* GetPropagate(void) {return Propagate;}
00316 inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
00318 inline FGInput* GetInput(void) {return Input;}
00320 inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
00322 inline FGState* GetState(void) {return State;}
00324 inline FGScript* GetScript(void) {return Script;}
00325
00326 inline FGInitialCondition* GetIC(void) {return IC;}
00327
00328 FGTrim* GetTrim(void);
00330
00332 inline string GetEnginePath(void) {return EnginePath;}
00334 inline string GetAircraftPath(void) {return AircraftPath;}
00336 inline string GetSystemsPath(void) {return SystemsPath;}
00338 inline string GetFullAircraftPath(void) {return FullAircraftPath;}
00339
00343 inline double GetPropertyValue(string property) {return instance->GetDouble(property);}
00344
00348 inline void SetPropertyValue(string property, double value) {
00349 instance->SetDouble(property, value);
00350 }
00351
00353 string GetModelName(void) { return modelName; }
00354
00356 double GetSimTime(void);
00357
00359 double GetDeltaT(void);
00360
00362 FGPropertyManager* GetPropertyManager(void);
00364 vector <string> EnumerateFDMs(void);
00366 int GetFDMCount(void) {return ChildFDMList.size();}
00368 childData* GetChildFDM(int i) {return ChildFDMList[i];}
00370 void SetChild(bool ch) {IsChild = ch;}
00371
00387 bool SetOutputDirectives(string fname);
00388
00392 bool SetOutputFileName(string fname) {
00393 if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
00394 else return false;
00395 return true;
00396 }
00397
00401 string GetOutputFileName(void) {
00402 if (Outputs.size() > 0) return Outputs[0]->GetOutputFileName();
00403 else return string("");
00404 }
00405
00415 void DoTrim(int mode);
00416
00417
00419 void DisableOutput(void);
00421 void EnableOutput(void);
00423 void Hold(void) {holding = true;}
00425 void Resume(void) {holding = false;}
00427 bool Holding(void) {return holding;}
00429 void ResetToInitialConditions(void);
00431 void SetDebugLevel(int level) {debug_lvl = level;}
00432
00433 struct PropertyCatalogStructure {
00435 string base_string;
00437 FGPropertyManager *node;
00438 };
00439
00444 void BuildPropertyCatalog(struct PropertyCatalogStructure* pcs);
00445
00452 string QueryPropertyCatalog(string check);
00453
00454
00455 void PrintPropertyCatalog(void);
00456
00458 void UseAtmosphereMSIS(void);
00459
00461 void UseAtmosphereMars(void);
00462
00463 void SetTrimStatus(bool status){ trim_status = status; }
00464 bool GetTrimStatus(void) const { return trim_status; }
00465 void SetTrimMode(int mode){ ta_mode = mode; }
00466 int GetTrimMode(void) const { return ta_mode; }
00467
00468 private:
00469 static unsigned int FDMctr;
00470 int Error;
00471 unsigned int Frame;
00472 unsigned int IdFDM;
00473 unsigned short Terminate;
00474 bool holding;
00475 bool Constructing;
00476 bool modelLoaded;
00477 bool IsChild;
00478 string modelName;
00479 string AircraftPath;
00480 string FullAircraftPath;
00481 string EnginePath;
00482 string SystemsPath;
00483 string CFGVersion;
00484 string Release;
00485
00486 bool trim_status;
00487 int ta_mode;
00488
00489 static FGPropertyManager *master;
00490
00491 FGModel* FirstModel;
00492 FGGroundCallback* GroundCallback;
00493 FGState* State;
00494 FGAtmosphere* Atmosphere;
00495 FGFCS* FCS;
00496 FGPropulsion* Propulsion;
00497 FGMassBalance* MassBalance;
00498 FGAerodynamics* Aerodynamics;
00499 FGInertial* Inertial;
00500 FGGroundReactions* GroundReactions;
00501 FGExternalReactions* ExternalReactions;
00502 FGBuoyantForces* BuoyantForces;
00503 FGAircraft* Aircraft;
00504 FGPropagate* Propagate;
00505 FGAuxiliary* Auxiliary;
00506 FGInput* Input;
00507 FGScript* Script;
00508 FGInitialCondition* IC;
00509 FGTrim* Trim;
00510
00511 FGPropertyManager* Root;
00512 FGPropertyManager* instance;
00513
00514 vector <string> PropertyCatalog;
00515 vector <FGOutput*> Outputs;
00516 vector <childData*> ChildFDMList;
00517
00518 bool ReadFileHeader(Element*);
00519 bool ReadChild(Element*);
00520 bool ReadPrologue(Element*);
00521 void ResetToInitialConditions(int mode);
00522 bool Allocate(void);
00523 bool DeAllocate(void);
00524
00525 void Debug(int from);
00526 };
00527 }
00528
00529 #endif