![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 Header: FGFDMExec.h 00003 Author: Jon Berndt 00004 Date started: 11/17/98 00005 file The header file for the JSBSim executive. 00006 00007 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------- 00008 00009 This program is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU Lesser General Public License as published by the Free Software 00011 Foundation; either version 2 of the License, or (at your option) any later 00012 version. 00013 00014 This program is distributed in the hope that it will be useful, but WITHOUT 00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00017 details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00023 Further information about the GNU Lesser General Public License can also be found on 00024 the world wide web at http://www.gnu.org. 00025 00026 HISTORY 00027 -------------------------------------------------------------------------------- 00028 11/17/98 JSB Created 00029 7/31/99 TP Added RunIC function that runs the sim so that every frame 00030 begins with the IC values from the given FGInitialCondition 00031 object and dt=0. 00032 00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00034 SENTRY 00035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00036 00037 #ifndef FGFDMEXEC_HEADER_H 00038 #define FGFDMEXEC_HEADER_H 00039 00040 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00041 INCLUDES 00042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00043 00044 #include <vector> 00045 #include <string> 00046 00047 #include "initialization/FGTrim.h" 00048 #include "FGJSBBase.h" 00049 #include "input_output/FGPropertyManager.h" 00050 #include "input_output/FGXMLFileRead.h" 00051 #include "models/FGPropagate.h" 00052 #include "math/FGColumnVector3.h" 00053 #include "models/FGOutput.h" 00054 00055 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00056 DEFINITIONS 00057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00058 00059 #define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.82 2013/01/26 17:06:49 bcoconni Exp $" 00060 00061 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00062 FORWARD DECLARATIONS 00063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00064 00065 namespace JSBSim { 00066 00067 class FGScript; 00068 class FGTrim; 00069 class FGAerodynamics; 00070 class FGAircraft; 00071 class FGAtmosphere; 00072 class FGAccelerations; 00073 class FGWinds; 00074 class FGAuxiliary; 00075 class FGBuoyantForces; 00076 class FGExternalReactions; 00077 class FGGroundReactions; 00078 class FGFCS; 00079 class FGInertial; 00080 class FGInput; 00081 class FGPropulsion; 00082 class FGMassBalance; 00083 00084 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00085 CLASS DOCUMENTATION 00086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00087 00185 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00186 CLASS DECLARATION 00187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00188 00189 class FGFDMExec : public FGJSBBase, public FGXMLFileRead 00190 { 00191 struct childData { 00192 FGFDMExec* exec; 00193 string info; 00194 FGColumnVector3 Loc; 00195 FGColumnVector3 Orient; 00196 bool mated; 00197 bool internal; 00198 00199 childData(void) { 00200 info = ""; 00201 Loc = FGColumnVector3(0,0,0); 00202 Orient = FGColumnVector3(0,0,0); 00203 mated = true; 00204 internal = false; 00205 } 00206 00207 void Run(void) {exec->Run();} 00208 void AssignState(FGPropagate* source_prop) { 00209 exec->GetPropagate()->SetVState(source_prop->GetVState()); 00210 } 00211 00212 ~childData(void) { 00213 delete exec; 00214 } 00215 }; 00216 00217 public: 00218 00220 FGFDMExec(FGPropertyManager* root = 0, unsigned int* fdmctr = 0); 00221 00223 ~FGFDMExec(); 00224 00225 // This list of enums is very important! The order in which models are listed here 00226 // determines the order of execution of the models. 00227 enum eModels { ePropagate=0, 00228 eInput, 00229 eInertial, 00230 eAtmosphere, 00231 eWinds, 00232 eAuxiliary, 00233 eSystems, 00234 ePropulsion, 00235 eAerodynamics, 00236 eGroundReactions, 00237 eExternalReactions, 00238 eBuoyantForces, 00239 eMassBalance, 00240 eAircraft, 00241 eAccelerations, 00242 eOutput, 00243 eNumStandardModels }; 00244 00246 void Unbind(void) {instance->Unbind();} 00247 00259 void Schedule(FGModel* model, int rate=1); 00260 00263 bool Run(void); 00264 00268 bool RunIC(void); 00269 00277 void SetGroundCallback(FGGroundCallback* gc) { FGLocation::SetGroundCallback(gc); } 00278 00294 bool LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath, 00295 const string& model, bool addModelToPath = true); 00296 00307 bool LoadModel(const string& model, bool addModelToPath = true); 00308 00319 bool LoadScript(const string& Script, double deltaT=0.0, const string initfile=""); 00320 00324 bool SetEnginePath(const string& path) { EnginePath = RootDir + path; return true; } 00325 00330 bool SetAircraftPath(const string& path) { AircraftPath = RootDir + path; return true; } 00331 00335 bool SetSystemsPath(const string& path) { SystemsPath = RootDir + path; return true; } 00336 00340 FGAtmosphere* GetAtmosphere(void) {return (FGAtmosphere*)Models[eAtmosphere];} 00342 FGAccelerations* GetAccelerations(void) {return (FGAccelerations*)Models[eAccelerations];} 00344 FGWinds* GetWinds(void) {return (FGWinds*)Models[eWinds];} 00346 FGFCS* GetFCS(void) {return (FGFCS*)Models[eSystems];} 00348 FGPropulsion* GetPropulsion(void) {return (FGPropulsion*)Models[ePropulsion];} 00350 FGMassBalance* GetMassBalance(void) {return (FGMassBalance*)Models[eMassBalance];} 00352 FGAerodynamics* GetAerodynamics(void){return (FGAerodynamics*)Models[eAerodynamics];} 00354 FGInertial* GetInertial(void) {return (FGInertial*)Models[eInertial];} 00356 FGGroundReactions* GetGroundReactions(void) {return (FGGroundReactions*)Models[eGroundReactions];} 00358 FGExternalReactions* GetExternalReactions(void) {return (FGExternalReactions*)Models[eExternalReactions];} 00360 FGBuoyantForces* GetBuoyantForces(void) {return (FGBuoyantForces*)Models[eBuoyantForces];} 00362 FGAircraft* GetAircraft(void) {return (FGAircraft*)Models[eAircraft];} 00364 FGPropagate* GetPropagate(void) {return (FGPropagate*)Models[ePropagate];} 00366 FGAuxiliary* GetAuxiliary(void) {return (FGAuxiliary*)Models[eAuxiliary];} 00368 FGInput* GetInput(void) {return (FGInput*)Models[eInput];} 00374 FGGroundCallback* GetGroundCallback(void) {return FGLocation::GetGroundCallback();} 00376 FGScript* GetScript(void) {return Script;} 00378 FGInitialCondition* GetIC(void) {return IC;} 00380 FGTrim* GetTrim(void); 00382 00384 const string& GetEnginePath(void) {return EnginePath;} 00386 const string& GetAircraftPath(void) {return AircraftPath;} 00388 const string& GetSystemsPath(void) {return SystemsPath;} 00390 const string& GetFullAircraftPath(void) {return FullAircraftPath;} 00391 00395 inline double GetPropertyValue(const string& property) 00396 { return instance->GetNode()->GetDouble(property); } 00397 00401 inline void SetPropertyValue(const string& property, double value) { 00402 instance->GetNode()->SetDouble(property, value); 00403 } 00404 00406 const string& GetModelName(void) const { return modelName; } 00407 /* 00409 double GetSimTime(void); 00410 00412 double GetDeltaT(void); 00413 */ 00415 FGPropertyManager* GetPropertyManager(void); 00417 vector <string> EnumerateFDMs(void); 00419 int GetFDMCount(void) const {return (int)ChildFDMList.size();} 00421 childData* GetChildFDM(int i) const {return ChildFDMList[i];} 00423 void SetChild(bool ch) {IsChild = ch;} 00424 00440 bool SetOutputDirectives(const string& fname) 00441 {return Output->SetDirectivesFile(RootDir + fname);} 00442 00444 void ForceOutput(int idx=0) { Output->ForceOutput(idx); } 00445 00447 void SetLoggingRate(double rate) { Output->SetRate(rate); } 00448 00452 bool SetOutputFileName(const string& fname) { return Output->SetOutputName(0, fname); } 00453 00457 string GetOutputFileName(void) const { return Output->GetOutputName(0); } 00458 00468 void DoTrim(int mode); 00469 void DoSimplexTrim(int mode); 00470 00474 void DoLinearization(int mode); 00475 00477 void DisableOutput(void) { Output->Disable(); } 00479 void EnableOutput(void) { Output->Enable(); } 00481 void Hold(void) {holding = true;} 00483 void EnableIncrementThenHold(int Timesteps) {TimeStepsUntilHold = Timesteps; IncrementThenHolding = true;} 00485 void CheckIncrementalHold(void); 00487 void Resume(void) {holding = false;} 00489 bool Holding(void) {return holding;} 00491 void ResetToInitialConditions(void); 00493 void SetDebugLevel(int level) {debug_lvl = level;} 00494 00495 struct PropertyCatalogStructure { 00497 string base_string; 00499 FGPropertyNode_ptr node; 00500 }; 00501 00506 void BuildPropertyCatalog(struct PropertyCatalogStructure* pcs); 00507 00514 string QueryPropertyCatalog(const string& check); 00515 00516 // Print the contents of the property catalog for the loaded aircraft. 00517 void PrintPropertyCatalog(void); 00518 00519 vector<string>& GetPropertyCatalog(void) {return PropertyCatalog;} 00520 00521 void SetTrimStatus(bool status){ trim_status = status; } 00522 bool GetTrimStatus(void) const { return trim_status; } 00523 void SetTrimMode(int mode){ ta_mode = mode; } 00524 int GetTrimMode(void) const { return ta_mode; } 00525 00526 string GetPropulsionTankReport(); 00527 00529 double GetSimTime(void) const { return sim_time; } 00530 00532 double GetDeltaT(void) const {return dT;} 00533 00535 void SuspendIntegration(void) { 00536 if (dT != 0.0) { // check if already suspended 00537 saved_dT = dT; 00538 dT = 0.0; 00539 } 00540 } 00541 00543 void ResumeIntegration(void) { 00544 dT = saved_dT; 00545 } 00546 00549 bool IntegrationSuspended(void) const {return dT == 0.0;} 00550 00554 double Setsim_time(double cur_time) { 00555 sim_time = cur_time; 00556 return sim_time; 00557 } 00558 00561 void Setdt(double delta_t) { dT = delta_t; } 00562 00565 void SetRootDir(const string& rootDir) {RootDir = rootDir;} 00566 00569 const string& GetRootDir(void) const {return RootDir;} 00570 00574 double IncrTime(void) { 00575 if (!holding) sim_time += dT; 00576 Frame++; 00577 return sim_time; 00578 } 00579 00581 int GetDebugLevel(void) const {return debug_lvl;}; 00582 00585 void Initialize(FGInitialCondition *FGIC); 00586 00587 private: 00588 int Error; 00589 unsigned int Frame; 00590 unsigned int IdFDM; 00591 unsigned short Terminate; 00592 double dT; 00593 double saved_dT; 00594 double sim_time; 00595 bool holding; 00596 bool IncrementThenHolding; 00597 int TimeStepsUntilHold; 00598 bool Constructing; 00599 bool modelLoaded; 00600 bool IsChild; 00601 string modelName; 00602 string AircraftPath; 00603 string FullAircraftPath; 00604 string EnginePath; 00605 string SystemsPath; 00606 string CFGVersion; 00607 string Release; 00608 string RootDir; 00609 00610 // Standard Model pointers - shortcuts for internal executive use only. 00611 FGPropagate* Propagate; 00612 FGInertial* Inertial; 00613 FGAtmosphere* Atmosphere; 00614 FGWinds* Winds; 00615 FGAuxiliary* Auxiliary; 00616 FGFCS* FCS; 00617 FGPropulsion* Propulsion; 00618 FGAerodynamics* Aerodynamics; 00619 FGGroundReactions* GroundReactions; 00620 FGExternalReactions* ExternalReactions; 00621 FGBuoyantForces* BuoyantForces; 00622 FGMassBalance* MassBalance; 00623 FGAircraft* Aircraft; 00624 FGAccelerations* Accelerations; 00625 FGOutput* Output; 00626 00627 bool trim_status; 00628 int ta_mode; 00629 00630 FGScript* Script; 00631 FGInitialCondition* IC; 00632 FGTrim* Trim; 00633 00634 FGPropertyManager* Root; 00635 bool StandAlone; 00636 FGPropertyManager* instance; 00637 00638 // The FDM counter is used to give each child FDM an unique ID. The root FDM has the ID 0 00639 unsigned int* FDMctr; 00640 00641 vector <string> PropertyCatalog; 00642 vector <childData*> ChildFDMList; 00643 vector <FGModel*> Models; 00644 00645 bool ReadFileHeader(Element*); 00646 bool ReadChild(Element*); 00647 bool ReadPrologue(Element*); 00648 void ResetToInitialConditions(int mode); 00649 void SRand(int sr); 00650 void LoadInputs(unsigned int idx); 00651 void LoadPlanetConstants(void); 00652 void LoadModelConstants(void); 00653 bool Allocate(void); 00654 bool DeAllocate(void); 00655 00656 void Debug(int from); 00657 }; 00658 } 00659 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00660 #endif