From: david Date: Mon, 24 Dec 2001 13:54:55 +0000 (+0000) Subject: Latest JSBSim changes. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d8a04291c948150de469cf7a7719e62f6d88f74;p=flightgear.git Latest JSBSim changes. --- diff --git a/src/FDM/JSBSim/FGAerodynamics.cpp b/src/FDM/JSBSim/FGAerodynamics.cpp index c72170954..c8466f42d 100644 --- a/src/FDM/JSBSim/FGAerodynamics.cpp +++ b/src/FDM/JSBSim/FGAerodynamics.cpp @@ -61,7 +61,7 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec) Coeff = new CoeffArray[6]; - if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -76,7 +76,7 @@ FGAerodynamics::~FGAerodynamics() } delete[] Coeff; - if (debug_lvl & 2) cout << "Destroyed: FGAerodynamics" << endl; + Debug(1); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -202,11 +202,49 @@ double FGAerodynamics::GetLoD(void) if (vFs(1) != 0.00) return vFs(3)/vFs(1); else return 0.00; } - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// 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 void FGAerodynamics::Debug(int from) { - //TODO: Add your source code here + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + if (from == 0) { // Constructor + + } + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGAerodynamics" << endl; + if (from == 1) cout << "Destroyed: FGAerodynamics" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index 5f0573b4f..6f61c7298 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -119,40 +119,6 @@ FGAircraft::~FGAircraft() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGAircraft::Load(FGConfigFile* AC_cfg) -{ - string token; - - if (!ReadPrologue(AC_cfg)) return false; - - while ((AC_cfg->GetNextConfigLine() != string("EOF")) && - (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) { - if (token == "METRICS") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl; - if (!ReadMetrics(AC_cfg)) return false; - } else if (token == "AERODYNAMICS") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl; - if (!ReadAerodynamics(AC_cfg)) return false; - } else if (token == "UNDERCARRIAGE") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl; - if (!ReadUndercarriage(AC_cfg)) return false; - } else if (token == "PROPULSION") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl; - if (!ReadPropulsion(AC_cfg)) return false; - } else if (token == "FLIGHT_CONTROL") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl; - if (!ReadFlightControls(AC_cfg)) return false; - } else if (token == "OUTPUT") { - if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl; - if (!ReadOutput(AC_cfg)) return false; - } - } - - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - bool FGAircraft::Run(void) { if (!FGModel::Run()) { // if false then execute this Run() @@ -197,33 +163,7 @@ float FGAircraft::GetNlf(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) -{ - string token = AC_cfg->GetValue(); - string scratch; - AircraftName = AC_cfg->GetValue("NAME"); - if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File" - << underoff << ": " << highint << AircraftName << normint << endl; - scratch = AC_cfg->GetValue("VERSION").c_str(); - - CFGVersion = AC_cfg->GetValue("VERSION"); - - if (debug_lvl > 0) - cout << " Version: " << highint << CFGVersion - << normint << endl; - if (CFGVersion != needed_cfg_version) { - cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." - " RESULTS WILL BE UNPREDICTABLE !!" << endl; - cerr << "Current version needed is: " << needed_cfg_version << endl; - cerr << " You have version: " << CFGVersion << endl << fgdef << endl; - return false; - } - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) +bool FGAircraft::Load(FGConfigFile* AC_cfg) { string token = ""; string parameter; @@ -318,61 +258,6 @@ bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) return true; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg) -{ - if (!Propulsion->Load(AC_cfg)) { - cerr << " Propulsion not successfully loaded" << endl; - return false; - } - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg) -{ - if (!FCS->Load(AC_cfg)) { - cerr << " Flight Controls not successfully loaded" << endl; - return false; - } - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) -{ - if (!Aerodynamics->Load(AC_cfg)) { - cerr << " Aerodynamics not successfully loaded" << endl; - return false; - } - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) -{ - if (!GroundReactions->Load(AC_cfg)) { - cerr << " Ground Reactions not successfully loaded" << endl; - return false; - } - return true; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -bool FGAircraft::ReadOutput(FGConfigFile* AC_cfg) -{ - if (!Output->Load(AC_cfg)) { - cerr << " Output not successfully loaded" << endl; - return false; - } - return true; -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print @@ -410,7 +295,11 @@ void FGAircraft::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } - if (debug_lvl & 32) { // Turbulence + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } } } diff --git a/src/FDM/JSBSim/FGAircraft.h b/src/FDM/JSBSim/FGAircraft.h index 3346de06d..240d75259 100644 --- a/src/FDM/JSBSim/FGAircraft.h +++ b/src/FDM/JSBSim/FGAircraft.h @@ -74,45 +74,6 @@ FORWARD DECLARATIONS COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Longitudinal - CL0 - Reference lift at zero alpha - CD0 - Reference drag at zero alpha - CDM - Drag due to Mach - CLa - Lift curve slope (w.r.t. alpha) - CDa - Drag curve slope (w.r.t. alpha) - CLq - Lift due to pitch rate - CLM - Lift due to Mach - CLadt - Lift due to alpha rate - - Cmadt - Pitching Moment due to alpha rate - Cm0 - Reference Pitching moment at zero alpha - Cma - Pitching moment slope (w.r.t. alpha) - Cmq - Pitch damping (pitch moment due to pitch rate) - CmM - Pitch Moment due to Mach - -Lateral - Cyb - Side force due to sideslip - Cyr - Side force due to yaw rate - - Clb - Dihedral effect (roll moment due to sideslip) - Clp - Roll damping (roll moment due to roll rate) - Clr - Roll moment due to yaw rate - Cnb - Weathercocking stability (yaw moment due to sideslip) - Cnp - Rudder adverse yaw (yaw moment due to roll rate) - Cnr - Yaw damping (yaw moment due to yaw rate) - -Control - CLDe - Lift due to elevator - CDDe - Drag due to elevator - CyDr - Side force due to rudder - CyDa - Side force due to aileron - - CmDe - Pitch moment due to elevator - ClDa - Roll moment due to aileron - ClDr - Roll moment due to rudder - CnDr - Yaw moment due to rudder - CnDa - Yaw moment due to aileron - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -123,10 +84,7 @@ CLASS DOCUMENTATION landing gear, etc. These constituent parts may actually run as separate JSBSim models themselves, but the responsibility for initializing them and for retrieving their force and moment contributions falls to FGAircraft.
- 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 "ReadXXX()" method is called. From within this method the - "Load()" method of that system is called (e.g. LoadFCS). + @author Jon S. Berndt @version $Id$ @see @@ -199,6 +157,7 @@ public: inline void SetAlphaCLMax(double tt) { alphaclmax=tt; } inline void SetAlphaCLMin(double tt) { alphaclmin=tt; } + inline void SetAircraftName(string name) {AircraftName = name;} inline double GetStallWarn(void) { return impending_stall; } @@ -222,16 +181,8 @@ private: double lbarh,lbarv,vbarh,vbarv; double alphaclmax,alphaclmin; double impending_stall; - string CFGVersion; string AircraftName; - bool ReadMetrics(FGConfigFile*); - bool ReadPropulsion(FGConfigFile*); - bool ReadFlightControls(FGConfigFile*); - bool ReadAerodynamics(FGConfigFile*); - bool ReadUndercarriage(FGConfigFile*); - bool ReadPrologue(FGConfigFile*); - bool ReadOutput(FGConfigFile*); void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGAtmosphere.cpp b/src/FDM/JSBSim/FGAtmosphere.cpp index 2f9f24066..3f6f9f2e8 100644 --- a/src/FDM/JSBSim/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/FGAtmosphere.cpp @@ -338,5 +338,11 @@ void FGAtmosphere::Debug(int from) cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl; } } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGAuxiliary.cpp b/src/FDM/JSBSim/FGAuxiliary.cpp index 4657cb34c..d744579d3 100644 --- a/src/FDM/JSBSim/FGAuxiliary.cpp +++ b/src/FDM/JSBSim/FGAuxiliary.cpp @@ -70,14 +70,14 @@ FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) psl = rhosl = 1; earthPosAngle = 0.0; - if (debug_lvl & 2) cout << "Instantiated: " << Name << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGAuxiliary::~FGAuxiliary() { - if (debug_lvl & 2) cout << "Destroyed: FGAuxiliary" << endl; + Debug(1); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -212,9 +212,48 @@ void FGAuxiliary::GetState(void) } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// 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 void FGAuxiliary::Debug(int from) { - //TODO: Add your source code here + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + if (from == 0) { // Constructor + + } + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGAuxiliary" << endl; + if (from == 1) cout << "Destroyed: FGAuxiliary" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGCoefficient.cpp b/src/FDM/JSBSim/FGCoefficient.cpp index 6838d86f0..fa6973a65 100644 --- a/src/FDM/JSBSim/FGCoefficient.cpp +++ b/src/FDM/JSBSim/FGCoefficient.cpp @@ -324,5 +324,11 @@ void FGCoefficient::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGColumnVector3.cpp b/src/FDM/JSBSim/FGColumnVector3.cpp index 70a785dff..4684da529 100644 --- a/src/FDM/JSBSim/FGColumnVector3.cpp +++ b/src/FDM/JSBSim/FGColumnVector3.cpp @@ -32,7 +32,7 @@ FGColumnVector3::FGColumnVector3(void) rowCtr = 1; data[0]=0; data[1]=0; data[2]=0; data[3]=0; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,14 +42,14 @@ FGColumnVector3::FGColumnVector3(double X, double Y, double Z) rowCtr = 1; data[0] = 0; data[eX] = X; data[eY] = Y; data[eZ] = Z; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGColumnVector3::~FGColumnVector3(void) { - if (debug_lvl & 2) cout << "Destroyed: FGColumnVector3" << endl; + Debug(1); } @@ -62,7 +62,7 @@ FGColumnVector3::FGColumnVector3(const FGColumnVector3& b) data[3] = b.data[3]; rowCtr = 1; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -74,8 +74,6 @@ FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b) data[3] = b.data[3]; rowCtr = 1; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; - return *this; } @@ -283,10 +281,46 @@ FGColumnVector3& FGColumnVector3::operator<<(const double ff) return *this; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +// 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 void FGColumnVector3::Debug(int from) { - //TODO: Add your source code here + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGColumnVector3" << endl; + if (from == 1) cout << "Destroyed: FGColumnVector3" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGColumnVector4.cpp b/src/FDM/JSBSim/FGColumnVector4.cpp index 30a100913..8a0cd99f2 100644 --- a/src/FDM/JSBSim/FGColumnVector4.cpp +++ b/src/FDM/JSBSim/FGColumnVector4.cpp @@ -32,7 +32,7 @@ FGColumnVector4::FGColumnVector4(void) rowCtr = 1; data[1]=0;data[2]=0;data[3]=0;data[4]=0; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,14 +42,14 @@ FGColumnVector4::FGColumnVector4(double A, double B, double C, double D) rowCtr = 1; data[1]=0;data[2]=0;data[3]=0;data[4]=0; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGColumnVector4::~FGColumnVector4(void) { - if (debug_lvl & 2) cout << "Destroyed: FGColumnVector4" << endl; + Debug(1); } @@ -64,7 +64,7 @@ FGColumnVector4::FGColumnVector4(const FGColumnVector4& b) rowCtr = 1; - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -76,9 +76,6 @@ FGColumnVector4 FGColumnVector4::operator=(const FGColumnVector4& b) data[3] = b.data[3]; data[4] = b.data[4]; rowCtr = 1; - - if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl; - return *this; } @@ -270,11 +267,47 @@ FGColumnVector4& FGColumnVector4::operator<<(const double ff) if (++rowCtr > 4) rowCtr = 1; return *this; } - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +// 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 void FGColumnVector4::Debug(int from) { - //TODO: Add your source code here + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGColumnVector4" << endl; + if (from == 1) cout << "Destroyed: FGColumnVector4" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { // Sanity checking + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGConfigFile.cpp b/src/FDM/JSBSim/FGConfigFile.cpp index 29dc717ac..488ec0b61 100644 --- a/src/FDM/JSBSim/FGConfigFile.cpp +++ b/src/FDM/JSBSim/FGConfigFile.cpp @@ -350,5 +350,11 @@ void FGConfigFile::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGEngine.cpp b/src/FDM/JSBSim/FGEngine.cpp index 7f7c2956c..f90587e70 100644 --- a/src/FDM/JSBSim/FGEngine.cpp +++ b/src/FDM/JSBSim/FGEngine.cpp @@ -191,4 +191,11 @@ void FGEngine::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGFCS.cpp b/src/FDM/JSBSim/FGFCS.cpp index 63d3a725d..d95e3d8c0 100644 --- a/src/FDM/JSBSim/FGFCS.cpp +++ b/src/FDM/JSBSim/FGFCS.cpp @@ -408,4 +408,11 @@ void FGFCS::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 806a08b21..fdf6eaf2c 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -4,7 +4,6 @@ Author: Jon S. Berndt Date started: 11/17/98 Purpose: Schedules and runs the model routines. - Called by: The GUI. ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- @@ -80,26 +79,6 @@ static const char *IdHdr = ID_FDMEXEC; GLOBAL DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -short debug_lvl; // This describes to any interested entity the debug level - // requested by setting the JSBSIM_DEBUG environment variable. - // The bitmasked value choices are as follows: - // a) 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 - // b) 0: This requests JSBSim not to output any messages - // whatsoever. - // c) 1: This value explicity requests the normal JSBSim - // startup messages - // d) 2: This value asks for a message to be printed out when - // a class is instantiated - // e) 4: When this value is set, a message is displayed when a - // FGModel object executes its Run() method - // f) 8: When this value is set, various runtime state variables - // are printed out periodically - // g) 16: When set various parameters are sanity checked and - // a message is printed out when they go out of bounds. - unsigned int FGFDMExec::FDMctr = 0; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -131,7 +110,6 @@ FGFDMExec::FGFDMExec(void) terminate = false; frozen = false; modelLoaded = false; - Scripted = false; IdFDM = FDMctr; FDMctr++; @@ -328,11 +306,6 @@ bool FGFDMExec::Run(void) model_iterator = FirstModel; if (model_iterator == 0L) return false; - if (Scripted) { - RunScript(); - if (State->Getsim_time() >= EndTime) return false; - } - Debug(2); while (!model_iterator->Run()) { @@ -361,8 +334,8 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic) bool FGFDMExec::LoadModel(string APath, string EPath, string model) { - bool result = false; - + bool result = true; + string token; string aircraftCfgFileName; AircraftPath = APath; @@ -382,7 +355,30 @@ bool FGFDMExec::LoadModel(string APath, string EPath, string model) Allocate(); } - result = Aircraft->Load(&AC_cfg); + if (!ReadPrologue(&AC_cfg)) return false; + + while ((AC_cfg.GetNextConfigLine() != string("EOF")) && + (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) { + if (token == "METRICS") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl; + if (!ReadMetrics(&AC_cfg)) result = false; + } else if (token == "AERODYNAMICS") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl; + if (!ReadAerodynamics(&AC_cfg)) result = false; + } else if (token == "UNDERCARRIAGE") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl; + if (!ReadUndercarriage(&AC_cfg)) result = false; + } else if (token == "PROPULSION") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl; + if (!ReadPropulsion(&AC_cfg)) result = false; + } else if (token == "FLIGHT_CONTROL") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl; + if (!ReadFlightControls(&AC_cfg)) result = false; + } else if (token == "OUTPUT") { + if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl; + if (!ReadOutput(&AC_cfg)) result = false; + } + } if (result) { modelLoaded = true; @@ -398,208 +394,98 @@ bool FGFDMExec::LoadModel(string APath, string EPath, string model) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGFDMExec::LoadScript(string script) +bool FGFDMExec::ReadPrologue(FGConfigFile* AC_cfg) { - FGConfigFile Script(script); - string token=""; - string aircraft=""; - string initialize=""; - bool result = false; - double dt = 0.0; - unsigned i; - struct condition *newCondition; - - if (!Script.IsOpen()) return false; - - Script.GetNextConfigLine(); - ScriptName = Script.GetValue("name"); - Scripted = true; - if (debug_lvl > 0) cout << "Reading Script File " << ScriptName << endl; - - while (Script.GetNextConfigLine() != string("EOF") && Script.GetValue() != string("/runscript")) { - token = Script.GetValue(); - if (token == "use") { - if ((token = Script.GetValue("aircraft")) != string("")) { - aircraft = token; - if (debug_lvl > 0) cout << " Use aircraft: " << token << endl; - } else if ((token = Script.GetValue("initialize")) != string("")) { - initialize = token; - if (debug_lvl > 0) cout << " Use reset file: " << token << endl; - } else { - cerr << "Unknown 'use' keyword: \"" << token << "\"" << endl; - } - } else if (token == "run") { - StartTime = strtod(Script.GetValue("start").c_str(), NULL); - State->Setsim_time(StartTime); - EndTime = strtod(Script.GetValue("end").c_str(), NULL); - dt = strtod(Script.GetValue("dt").c_str(), NULL); - State->Setdt(dt); - Script.GetNextConfigLine(); - token = Script.GetValue(); - while (token != string("/run")) { - - if (token == "when") { - Script.GetNextConfigLine(); - token = Script.GetValue(); - newCondition = new struct condition(); - while (token != string("/when")) { - if (token == "parameter") { - newCondition->TestParam.push_back(State->GetParameterIndex(Script.GetValue("name"))); - newCondition->TestValue.push_back(strtod(Script.GetValue("value").c_str(), NULL)); - newCondition->Comparison.push_back(Script.GetValue("comparison")); - } else if (token == "set") { - newCondition->SetParam.push_back(State->GetParameterIndex(Script.GetValue("name"))); - newCondition->SetValue.push_back(strtod(Script.GetValue("value").c_str(), NULL)); - newCondition->Triggered.push_back(false); - newCondition->OriginalValue.push_back(0.0); - newCondition->newValue.push_back(0.0); - newCondition->StartTime.push_back(0.0); - newCondition->EndTime.push_back(0.0); - string tempCompare = Script.GetValue("type"); - if (tempCompare == "FG_DELTA") newCondition->Type.push_back(FG_DELTA); - else if (tempCompare == "FG_BOOL") newCondition->Type.push_back(FG_BOOL); - else if (tempCompare == "FG_VALUE") newCondition->Type.push_back(FG_VALUE); - else newCondition->Type.push_back((eType)0); - tempCompare = Script.GetValue("action"); - if (tempCompare == "FG_RAMP") newCondition->Action.push_back(FG_RAMP); - else if (tempCompare == "FG_STEP") newCondition->Action.push_back(FG_STEP); - else if (tempCompare == "FG_EXP") newCondition->Action.push_back(FG_EXP); - else newCondition->Action.push_back((eAction)0); - - if (Script.GetValue("persistent") == "true") - newCondition->Persistent.push_back(true); - else - newCondition->Persistent.push_back(false); - - newCondition->TC.push_back(strtod(Script.GetValue("tc").c_str(), NULL)); - - } else { - cerr << "Unrecognized keyword in script file: \" [when] " << token << "\"" << endl; - } - Script.GetNextConfigLine(); - token = Script.GetValue(); - } - Conditions.push_back(*newCondition); - Script.GetNextConfigLine(); - token = Script.GetValue(); - - } else { - cerr << "Error reading script file: expected \"when\", got \"" << token << "\"" << endl; - } - - } - } else if (token.empty()) { - // do nothing - } else { - cerr << "Unrecognized keyword in script file: \"" << token << "\" [runscript] " << endl; - } + string token = AC_cfg->GetValue(); + string scratch; + string AircraftName; + + AircraftName = AC_cfg->GetValue("NAME"); + Aircraft->SetAircraftName(AircraftName); + + if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File" + << underoff << ": " << highint << AircraftName << normint << endl; + scratch = AC_cfg->GetValue("VERSION").c_str(); + + CFGVersion = AC_cfg->GetValue("VERSION"); + + if (debug_lvl > 0) + cout << " Version: " << highint << CFGVersion + << normint << endl; + if (CFGVersion != needed_cfg_version) { + cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." + " RESULTS WILL BE UNPREDICTABLE !!" << endl; + cerr << "Current version needed is: " << needed_cfg_version << endl; + cerr << " You have version: " << CFGVersion << endl << fgdef << endl; + return false; } + return true; +} - if (aircraft == "") { - cerr << "Aircraft file not loaded in script" << endl; - exit(-1); +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +bool FGFDMExec::ReadPropulsion(FGConfigFile* AC_cfg) +{ + if (!Propulsion->Load(AC_cfg)) { + cerr << " Propulsion not successfully loaded" << endl; + return false; } + return true; +} - Debug(4); +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - result = LoadModel("aircraft", "engine", aircraft); - if (!result) { - cerr << "Aircraft file " << aircraft << " was not found" << endl; - exit(-1); +bool FGFDMExec::ReadFlightControls(FGConfigFile* AC_cfg) +{ + if (!FCS->Load(AC_cfg)) { + cerr << " Flight Controls not successfully loaded" << endl; + return false; } + return true; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - FGInitialCondition IC(this); - if ( ! IC.Load("aircraft", aircraft, initialize)) { - cerr << "Initialization unsuccessful" << endl; - exit(-1); +bool FGFDMExec::ReadAerodynamics(FGConfigFile* AC_cfg) +{ + if (!Aerodynamics->Load(AC_cfg)) { + cerr << " Aerodynamics not successfully loaded" << endl; + return false; } + return true; +} +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +bool FGFDMExec::ReadUndercarriage(FGConfigFile* AC_cfg) +{ + if (!GroundReactions->Load(AC_cfg)) { + cerr << " Ground Reactions not successfully loaded" << endl; + return false; + } return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGFDMExec::RunScript(void) +bool FGFDMExec::ReadMetrics(FGConfigFile* AC_cfg) { - vector ::iterator iC = Conditions.begin(); - bool truth = false; - bool WholeTruth = false; - unsigned i; - - double currentTime = State->Getsim_time(); - double newSetValue = 0; - - while (iC < Conditions.end()) { - // determine whether the set of conditional tests for this condition equate - // to true - for (i=0; iTestValue.size(); i++) { - if (iC->Comparison[i] == "lt") - truth = State->GetParameter(iC->TestParam[i]) < iC->TestValue[i]; - else if (iC->Comparison[i] == "le") - truth = State->GetParameter(iC->TestParam[i]) <= iC->TestValue[i]; - else if (iC->Comparison[i] == "eq") - truth = State->GetParameter(iC->TestParam[i]) == iC->TestValue[i]; - else if (iC->Comparison[i] == "ge") - truth = State->GetParameter(iC->TestParam[i]) >= iC->TestValue[i]; - else if (iC->Comparison[i] == "gt") - truth = State->GetParameter(iC->TestParam[i]) > iC->TestValue[i]; - else if (iC->Comparison[i] == "ne") - truth = State->GetParameter(iC->TestParam[i]) != iC->TestValue[i]; - else - cerr << "Bad comparison" << endl; - - if (i == 0) WholeTruth = truth; - else WholeTruth = WholeTruth && truth; - - if (!truth && iC->Persistent[i] && iC->Triggered[i]) iC->Triggered[i] = false; - } + if (!Aircraft->Load(AC_cfg)) { + cerr << " Aircraft metrics not successfully loaded" << endl; + return false; + } + return true; +} - // if the conditions are true, do the setting of the desired parameters - - if (WholeTruth) { - for (i=0; iSetValue.size(); i++) { - if ( ! iC->Triggered[i]) { - iC->OriginalValue[i] = State->GetParameter(iC->SetParam[i]); - switch (iC->Type[i]) { - case FG_VALUE: - iC->newValue[i] = iC->SetValue[i]; - break; - case FG_DELTA: - iC->newValue[i] = iC->OriginalValue[i] + iC->SetValue[i]; - break; - case FG_BOOL: - iC->newValue[i] = iC->SetValue[i]; - break; - default: - cerr << "Invalid Type specified" << endl; - break; - } - iC->Triggered[i] = true; - iC->StartTime[i] = currentTime; - } - - switch (iC->Action[i]) { - case FG_RAMP: - newSetValue = (currentTime - iC->StartTime[i])/(iC->TC[i]) - * (iC->newValue[i] - iC->OriginalValue[i]) + iC->OriginalValue[i]; - if (newSetValue > iC->newValue[i]) newSetValue = iC->newValue[i]; - break; - case FG_STEP: - newSetValue = iC->newValue[i]; - break; - case FG_EXP: - newSetValue = (1 - exp(-(currentTime - iC->StartTime[i])/(iC->TC[i]))) - * (iC->newValue[i] - iC->OriginalValue[i]) + iC->OriginalValue[i]; - break; - default: - cerr << "Invalid Action specified" << endl; - break; - } - State->SetParameter(iC->SetParam[i], newSetValue); - } - } - iC++; +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg) +{ + if (!Output->Load(AC_cfg)) { + cerr << " Output not successfully loaded" << endl; + return false; } + return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -623,8 +509,6 @@ void FGFDMExec::RunScript(void) void FGFDMExec::Debug(int from) { - unsigned int i; - if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output @@ -635,73 +519,6 @@ void FGFDMExec::Debug(int from) cout << normint << "JSBSim startup beginning ...\n\n"; } else if (from == 3) { cout << "\n\nJSBSim startup complete\n\n"; - } else if (from == 4) { // print out script data - vector ::iterator iterConditions = Conditions.begin(); - int count=0; - - cout << "\n Script goes from " << StartTime << " to " << EndTime - << " with dt = " << State->Getdt() << endl << endl; - - while (iterConditions < Conditions.end()) { - cout << " Condition: " << count++ << endl; - cout << " if ("; - - for (i=0; iTestValue.size(); i++) { - if (i>0) cout << " and" << endl << " "; - cout << "(" << State->paramdef[iterConditions->TestParam[i]] - << iterConditions->Comparison[i] << " " - << iterConditions->TestValue[i] << ")"; - } - cout << ") then {"; - - for (i=0; iSetValue.size(); i++) { - cout << endl << " set" << State->paramdef[iterConditions->SetParam[i]] - << "to " << iterConditions->SetValue[i]; - - switch (iterConditions->Type[i]) { - case FG_VALUE: - cout << " (constant"; - break; - case FG_DELTA: - cout << " (delta"; - break; - case FG_BOOL: - cout << " (boolean"; - break; - default: - cout << " (unspecified type"; - } - - switch (iterConditions->Action[i]) { - case FG_RAMP: - cout << " via ramp"; - break; - case FG_STEP: - cout << " via step"; - break; - case FG_EXP: - cout << " via exponential approach"; - break; - default: - cout << " via unspecified action"; - } - - if (!iterConditions->Persistent[i]) cout << endl - << " once"; - else cout << endl - << " repeatedly"; - - if (iterConditions->Action[i] == FG_RAMP || - iterConditions->Action[i] == FG_EXP) cout << endl - << " with time constant " - << iterConditions->TC[i]; - } - cout << ")" << endl << " }" << endl << endl; - - iterConditions++; - } - - cout << endl; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification @@ -718,4 +535,11 @@ void FGFDMExec::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index dd9e63300..c7a8c7b50 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -55,20 +55,6 @@ DEFINITIONS FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class FGState; -class FGAtmosphere; -class FGFCS; -class FGPropulsion; -class FGMassBalance; -class FGAerodynamics; -class FGInertial; -class FGGroundReactions; -class FGAircraft; -class FGTranslation; -class FGRotation; -class FGPosition; -class FGAuxiliary; -class FGOutput; class FGInitialCondition; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -88,64 +74,10 @@ CLASS DOCUMENTATION other flight simulator) this class is typically instantiated by an interface class on the simulator side. -

Scripting support provided in the Executive

- -

There is simple scripting support provided in the FGFDMExec - class. Commands are specified using the Simple Scripting - Directives for JSBSim (SSDJ). The script file is in XML - format. A test condition (or conditions) can be set up in the - script and when the condition evaluates to true, the specified - action[s] is/are taken. A test condition can be persistent, - meaning that if a test condition evaluates to true, then passes - and evaluates to false, the condition is reset and may again be - triggered. When the set of tests evaluates to true for a given - condition, an item may be set to another value. This value might - be a boolean, a value, or a delta value, and the change from the - current value to the new value can be either via a step function, - a ramp, or an exponential approach. The speed of a ramp or - approach is specified via the time constant. Here is the format - of the script file:

- -
<?xml version="1.0"?>
-    <runscript name="C172-01A">
-
-    <!--
-    This run is for testing C172 runs
-    -->
-
-    <use aircraft="c172">
-    <use initialize="reset00">
-
-    <run start="0.0" end="4.5" dt="0.05">
-      <when>
-        <parameter name="FG_TIME" comparison="ge" value="0.25">
-        <parameter name="FG_TIME" comparison="le" value="0.50">
-        <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"
-        action="FG_STEP" persistent="false" tc ="0.25">
-      </when>
-      <when>
-        <parameter name="FG_TIME" comparison="ge" value="0.5">
-        <parameter name="FG_TIME" comparison="le" value="1.5">
-        <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"
-        action="FG_EXP" persistent="false" tc ="0.5">
-      </when>
-      <when>
-        <parameter name="FG_TIME" comparison="ge" value="1.5">
-        <parameter name="FG_TIME" comparison="le" value="2.5">
-        <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"
-        action="FG_RAMP" persistent="false" tc ="0.5">
-      </when>
-    </run>
-
-    </runscript>
- -

The first line must always be present. The second line - identifies this file as a script file, and gives a descriptive - name to the script file. Comments are next, delineated by the - <!-- and --> symbols. The aircraft and initialization files - to be used are specified in the "use" lines. Next, - comes the "run" section, where the conditions are - described in "when" clauses.

+ 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 "ReadXXX()" method is called. From within this method the + "Load()" method of that system is called (e.g. LoadFCS).

JSBSim Debugging Directives

@@ -196,8 +128,7 @@ public: @return Currently returns 0 always. */ int Schedule(FGModel* model, int rate); - /** This executes each scheduled model in succession, as well as running any - scripts which are loaded. + /** This executes each scheduled model in succession. @return true if successful, false if sim should be ended */ bool Run(void); @@ -227,19 +158,8 @@ public: @return true if successful*/ bool LoadModel(string AircraftPath, string EnginePath, string model); - /** Loads a script to drive JSBSim (usually in standalone mode). - The language is the Simple Script Directives for JSBSim (SSDJ). - @param script the filename (including path name, if any) for the script. - @return true if successful */ - bool LoadScript(string script); - - /** This function is called each pass through the executive Run() method IF - scripting is enabled. */ - void RunScript(void); - bool SetEnginePath(string path) {EnginePath = path; return true;} bool SetAircraftPath(string path) {AircraftPath = path; return true;} - bool SetScriptPath(string path) {ScriptPath = path; return true;} /// @name Top-level executive State and Model retrieval mechanism //@{ @@ -279,38 +199,6 @@ public: inline string GetAircraftPath(void) {return AircraftPath;} private: - enum eAction { - FG_RAMP = 1, - FG_STEP = 2, - FG_EXP = 3 - }; - - enum eType { - FG_VALUE = 1, - FG_DELTA = 2, - FG_BOOL = 3 - }; - - struct condition { - vector TestParam; - vector SetParam; - vector TestValue; - vector SetValue; - vector Comparison; - vector TC; - vector Persistent; - vector Action; - vector Type; - vector Triggered; - vector newValue; - vector OriginalValue; - vector StartTime; - vector EndTime; - - condition() { - } - }; - FGModel* FirstModel; bool frozen; @@ -320,15 +208,10 @@ private: unsigned int IdFDM; static unsigned int FDMctr; bool modelLoaded; - bool Scripted; string AircraftPath; string EnginePath; - string ScriptPath; - string ScriptName; - double StartTime; - double EndTime; - vector Conditions; + string CFGVersion; FGState* State; FGAtmosphere* Atmosphere; @@ -345,6 +228,14 @@ private: FGAuxiliary* Auxiliary; FGOutput* Output; + bool ReadMetrics(FGConfigFile*); + bool ReadPropulsion(FGConfigFile*); + bool ReadFlightControls(FGConfigFile*); + bool ReadAerodynamics(FGConfigFile*); + bool ReadUndercarriage(FGConfigFile*); + bool ReadPrologue(FGConfigFile*); + bool ReadOutput(FGConfigFile*); + bool Allocate(void); bool DeAllocate(void); void Debug(int from); diff --git a/src/FDM/JSBSim/FGFactorGroup.cpp b/src/FDM/JSBSim/FGFactorGroup.cpp index 5b3e0b9a0..497250284 100644 --- a/src/FDM/JSBSim/FGFactorGroup.cpp +++ b/src/FDM/JSBSim/FGFactorGroup.cpp @@ -166,4 +166,11 @@ void FGFactorGroup::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGForce.cpp b/src/FDM/JSBSim/FGForce.cpp index d2da596c2..91dd746e6 100644 --- a/src/FDM/JSBSim/FGForce.cpp +++ b/src/FDM/JSBSim/FGForce.cpp @@ -172,5 +172,11 @@ void FGForce::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGGroundReactions.cpp b/src/FDM/JSBSim/FGGroundReactions.cpp index b041df3bd..30f61113a 100644 --- a/src/FDM/JSBSim/FGGroundReactions.cpp +++ b/src/FDM/JSBSim/FGGroundReactions.cpp @@ -62,8 +62,8 @@ FGGroundReactions::~FGGroundReactions(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bool FGGroundReactions::Run(void) { - double steerAngle = 0.0; - double xForces = 0.0, yForces = 0.0; +// double steerAngle = 0.0; +// double xForces = 0.0, yForces = 0.0; if (!FGModel::Run()) { vForces.InitMatrix(); @@ -237,5 +237,11 @@ void FGGroundReactions::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGInertial.cpp b/src/FDM/JSBSim/FGInertial.cpp index 9f680d203..3afa4677d 100644 --- a/src/FDM/JSBSim/FGInertial.cpp +++ b/src/FDM/JSBSim/FGInertial.cpp @@ -160,5 +160,11 @@ void FGInertial::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGInitialCondition.cpp b/src/FDM/JSBSim/FGInitialCondition.cpp index 213a495f1..29dc1f10f 100644 --- a/src/FDM/JSBSim/FGInitialCondition.cpp +++ b/src/FDM/JSBSim/FGInitialCondition.cpp @@ -91,14 +91,14 @@ FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec) cout << "FGInitialCondition: This class requires a pointer to a valid FGFDMExec object" << endl; } - if (debug_lvl & 2) cout << "Instantiated: FGInitialCondition" << endl; + Debug(0); } //****************************************************************************** FGInitialCondition::~FGInitialCondition() { - if (debug_lvl & 2) cout << "Destroyed: FGInitialCondition" << endl; + Debug(1); } //****************************************************************************** @@ -764,4 +764,48 @@ bool FGInitialCondition::Load(string acpath, string acname, string rstfile) fdmex->RunIC(this); return true; -} +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// 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 + +void FGInitialCondition::Debug(int from) +{ + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGInitialCondition" << endl; + if (from == 1) cout << "Destroyed: FGInitialCondition" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } +} + diff --git a/src/FDM/JSBSim/FGInitialCondition.h b/src/FDM/JSBSim/FGInitialCondition.h index 7c33cee2f..b8806fd11 100644 --- a/src/FDM/JSBSim/FGInitialCondition.h +++ b/src/FDM/JSBSim/FGInitialCondition.h @@ -290,6 +290,7 @@ private: bool findInterval(double x,double guess); bool solve(double *y, double x); + void Debug(int from); }; #endif diff --git a/src/FDM/JSBSim/FGLGear.cpp b/src/FDM/JSBSim/FGLGear.cpp index dcd9b1c42..d899dbecb 100644 --- a/src/FDM/JSBSim/FGLGear.cpp +++ b/src/FDM/JSBSim/FGLGear.cpp @@ -497,5 +497,11 @@ void FGLGear::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGMassBalance.cpp b/src/FDM/JSBSim/FGMassBalance.cpp index 2770191ab..b6a4619d9 100644 --- a/src/FDM/JSBSim/FGMassBalance.cpp +++ b/src/FDM/JSBSim/FGMassBalance.cpp @@ -231,5 +231,11 @@ void FGMassBalance::Debug(int from) cout << "MassBalance::Mass out of bounds: " << Mass << endl; } } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGMatrix33.cpp b/src/FDM/JSBSim/FGMatrix33.cpp index 0c066df59..dc88dc2a3 100644 --- a/src/FDM/JSBSim/FGMatrix33.cpp +++ b/src/FDM/JSBSim/FGMatrix33.cpp @@ -433,5 +433,11 @@ void FGMatrix33::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGModel.cpp b/src/FDM/JSBSim/FGModel.cpp index c7f2d4de3..9462fe795 100644 --- a/src/FDM/JSBSim/FGModel.cpp +++ b/src/FDM/JSBSim/FGModel.cpp @@ -150,4 +150,48 @@ bool FGModel::Run() } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// 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 + +void FGModel::Debug(int from) +{ + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + if (from == 0) { // Constructor + + } + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGModel" << endl; + if (from == 1) cout << "Destroyed: FGModel" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } +} diff --git a/src/FDM/JSBSim/FGModel.h b/src/FDM/JSBSim/FGModel.h index 59d3224bd..189169c65 100644 --- a/src/FDM/JSBSim/FGModel.h +++ b/src/FDM/JSBSim/FGModel.h @@ -130,6 +130,8 @@ public: protected: int exe_ctr; int rate; + + virtual void Debug(int from); FGFDMExec* FDMExec; FGState* State; diff --git a/src/FDM/JSBSim/FGNozzle.cpp b/src/FDM/JSBSim/FGNozzle.cpp index 001df2463..b73401838 100644 --- a/src/FDM/JSBSim/FGNozzle.cpp +++ b/src/FDM/JSBSim/FGNozzle.cpp @@ -142,5 +142,11 @@ void FGNozzle::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGOutput.cpp b/src/FDM/JSBSim/FGOutput.cpp index 5cc3d6e13..5b1d3501a 100644 --- a/src/FDM/JSBSim/FGOutput.cpp +++ b/src/FDM/JSBSim/FGOutput.cpp @@ -522,5 +522,11 @@ void FGOutput::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGPiston.cpp b/src/FDM/JSBSim/FGPiston.cpp index 45abd5e50..d7f8d1c2b 100644 --- a/src/FDM/JSBSim/FGPiston.cpp +++ b/src/FDM/JSBSim/FGPiston.cpp @@ -570,5 +570,11 @@ void FGPiston::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGPosition.cpp b/src/FDM/JSBSim/FGPosition.cpp index 741d9cd4a..a5a278af0 100644 --- a/src/FDM/JSBSim/FGPosition.cpp +++ b/src/FDM/JSBSim/FGPosition.cpp @@ -263,5 +263,11 @@ void FGPosition::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGPropeller.cpp b/src/FDM/JSBSim/FGPropeller.cpp index b47ba0c7f..5804117fc 100644 --- a/src/FDM/JSBSim/FGPropeller.cpp +++ b/src/FDM/JSBSim/FGPropeller.cpp @@ -272,5 +272,11 @@ void FGPropeller::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGPropulsion.cpp b/src/FDM/JSBSim/FGPropulsion.cpp index 2b8767dd0..054753263 100644 --- a/src/FDM/JSBSim/FGPropulsion.cpp +++ b/src/FDM/JSBSim/FGPropulsion.cpp @@ -580,5 +580,11 @@ void FGPropulsion::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGRocket.cpp b/src/FDM/JSBSim/FGRocket.cpp index c5ca65d68..ec1bb7215 100644 --- a/src/FDM/JSBSim/FGRocket.cpp +++ b/src/FDM/JSBSim/FGRocket.cpp @@ -153,5 +153,11 @@ void FGRocket::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGRotation.cpp b/src/FDM/JSBSim/FGRotation.cpp index a3712e00c..73763e5a0 100644 --- a/src/FDM/JSBSim/FGRotation.cpp +++ b/src/FDM/JSBSim/FGRotation.cpp @@ -195,4 +195,11 @@ void FGRotation::Debug(int from) cout << "FGRotation::R (Yaw Rate) out of bounds: " << vPQR(eR) << endl; } } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGRotation.h b/src/FDM/JSBSim/FGRotation.h index 3952a4f39..50989e8ef 100644 --- a/src/FDM/JSBSim/FGRotation.h +++ b/src/FDM/JSBSim/FGRotation.h @@ -97,6 +97,9 @@ public: inline FGColumnVector3& GetEulerRates(void) { return vEulerRates; } inline double GetEulerRates(int axis) { return vEulerRates(axis); } inline void SetPQR(FGColumnVector3 tt) {vPQR = tt;} + inline void SetPQR(double p, double q, double r) {vPQR(eP)=p; + vPQR(eQ)=q; + vPQR(eR)=r;} inline void SetEuler(FGColumnVector3 tt) {vEuler = tt;} inline double Getphi(void) {return vEuler(1);} diff --git a/src/FDM/JSBSim/FGRotor.cpp b/src/FDM/JSBSim/FGRotor.cpp index 195795bbc..3d0c7f3e0 100644 --- a/src/FDM/JSBSim/FGRotor.cpp +++ b/src/FDM/JSBSim/FGRotor.cpp @@ -102,5 +102,11 @@ void FGRotor::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGScript.cpp b/src/FDM/JSBSim/FGScript.cpp index 690d5abb3..34e7b9f14 100644 --- a/src/FDM/JSBSim/FGScript.cpp +++ b/src/FDM/JSBSim/FGScript.cpp @@ -93,7 +93,6 @@ bool FGScript::LoadScript(string script) string initialize=""; bool result = false; double dt = 0.0; - unsigned i; struct condition *newCondition; if (!Script.IsOpen()) return false; @@ -405,5 +404,11 @@ void FGScript::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index 6e06b10fe..2dc11a08e 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -326,7 +326,7 @@ eParam FGState::GetParameterIndex(string val_string) void FGState::SetParameter(eParam val_idx, double val) { - int i; + unsigned i; switch(val_idx) { case FG_ELEVATOR_POS: @@ -888,5 +888,12 @@ void FGState::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGTable.cpp b/src/FDM/JSBSim/FGTable.cpp index 0c564a1c7..103e7e0f0 100644 --- a/src/FDM/JSBSim/FGTable.cpp +++ b/src/FDM/JSBSim/FGTable.cpp @@ -266,6 +266,13 @@ void FGTable::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGTank.cpp b/src/FDM/JSBSim/FGTank.cpp index 5ed969909..55b7d09ec 100644 --- a/src/FDM/JSBSim/FGTank.cpp +++ b/src/FDM/JSBSim/FGTank.cpp @@ -151,5 +151,11 @@ void FGTank::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGThruster.cpp b/src/FDM/JSBSim/FGThruster.cpp index ebe861803..1a574a6a5 100644 --- a/src/FDM/JSBSim/FGThruster.cpp +++ b/src/FDM/JSBSim/FGThruster.cpp @@ -98,5 +98,11 @@ void FGThruster::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGTranslation.cpp b/src/FDM/JSBSim/FGTranslation.cpp index d191b8c74..fe6714dfe 100644 --- a/src/FDM/JSBSim/FGTranslation.cpp +++ b/src/FDM/JSBSim/FGTranslation.cpp @@ -212,4 +212,11 @@ void FGTranslation::Debug(int from) if (qbar > 1e6 || qbar < 0.00) cout << "FGTranslation::qbar is out of bounds: " << qbar << endl; } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGTranslation.h b/src/FDM/JSBSim/FGTranslation.h index a49396380..faac818d2 100644 --- a/src/FDM/JSBSim/FGTranslation.h +++ b/src/FDM/JSBSim/FGTranslation.h @@ -88,11 +88,11 @@ public: ~FGTranslation(); inline FGColumnVector3& GetUVW (void) { return vUVW; } - inline double GetUVW (int idx) { return vUVW(idx); } + inline double GetUVW (int idx) { return vUVW(idx); } inline FGColumnVector3& GetUVWdot(void) { return vUVWdot; } - inline double GetUVWdot(int idx) { return vUVWdot(idx); } + inline double GetUVWdot(int idx) { return vUVWdot(idx); } inline FGColumnVector3& GetvAeroUVW (void) { return vAeroUVW; } - inline double GetvAeroUVW (int idx) { return vAeroUVW(idx); } + inline double GetvAeroUVW (int idx) { return vAeroUVW(idx); } inline double Getalpha(void) { return alpha; } inline double Getbeta (void) { return beta; } diff --git a/src/FDM/JSBSim/FGTrim.cpp b/src/FDM/JSBSim/FGTrim.cpp index f478ab6df..1e36a1abd 100644 --- a/src/FDM/JSBSim/FGTrim.cpp +++ b/src/FDM/JSBSim/FGTrim.cpp @@ -115,15 +115,17 @@ FGTrim::FGTrim(FGFDMExec *FDMExec,FGInitialCondition *FGIC, TrimMode tt ) { TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder )); break; case tTurn: - TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tNlf,tAlpha )); + TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tWdot,tAlpha )); TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tUdot,tThrottle )); TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tPitchTrim )); - TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tVdot,tBeta )); - TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tAileron )); - TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder )); + //TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tVdot,tBeta )); + //TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tAileron )); + //TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder )); break; - - } + case tCustom: + case tNone: + break; +} //cout << "TrimAxes.size(): " << TrimAxes.size() << endl; sub_iterations=new double[TrimAxes.size()]; successful=new double[TrimAxes.size()]; @@ -312,14 +314,14 @@ bool FGTrim::DoTrim(void) { cout << "nlf done" << endl; } else if (mode == tTurn) { setupTurn(); - TrimAxes[0]->SetStateTarget(targetNlf); + //TrimAxes[0]->SetStateTarget(targetNlf); } do { axis_count=0; for(current_axis=0;current_axisGetVtrueFpsIC() << endl; q=g*(targetNlf-cgamma)/fgic->GetVtrueFpsIC(); cout << targetNlf << ", " << q << endl; - vPQR.InitMatrix(); - vPQR(2)=q; - cout << vPQR << endl; - fdmex->GetRotation()->SetPQR(vPQR); + fdmex->GetRotation()->SetPQR(0,q,0); cout << "setPitchRateInPullup() complete" << endl; } void FGTrim::setupTurn(void){ - FGColumnVector3 vPQR; - float g,q,r,phi, psidot; + double g,phi; phi = fgic->GetRollAngleRadIC(); if( fabs(phi) > 0.01 && fabs(phi) < 1.56 ) { targetNlf = 1 / cos(phi); g = fdmex->GetInertial()->gravity(); psidot = g*tan(phi) / fgic->GetVtrueFpsIC(); - q = psidot*sin(phi); - r = psidot*cos(phi); - vPQR(1)=0;vPQR(2)=q;vPQR(3)=r; - fdmex->GetRotation()->SetPQR(vPQR); - cout << targetNlf << ", " << vPQR*57.29577 << endl; + cout << targetNlf << ", " << psidot << endl; } } +void FGTrim::updateRates(void){ + if(mode == tTurn) { + double p,q,r,theta,phi; + theta=fgic->GetPitchAngleRadIC(); + phi=fgic->GetRollAngleRadIC(); + p=-psidot*sin(theta); + q=psidot*cos(theta)*sin(phi); + r=psidot*cos(theta)*cos(phi); + fdmex->GetRotation()->SetPQR(p,q,r); + } +} void FGTrim::setDebug(void) { if(debug_axis == tAll || diff --git a/src/FDM/JSBSim/FGTrim.h b/src/FDM/JSBSim/FGTrim.h index ec53d57a6..0e6019efc 100644 --- a/src/FDM/JSBSim/FGTrim.h +++ b/src/FDM/JSBSim/FGTrim.h @@ -168,6 +168,8 @@ private: double xlo,xhi,alo,ahi; double targetNlf; int debug_axis; + + double psidot,thetadot; FGFDMExec* fdmex; FGInitialCondition* fgic; @@ -188,6 +190,8 @@ private: void setupPullup(void); void setupTurn(void); + void updateRates(void); + void setDebug(void); public: diff --git a/src/FDM/JSBSim/FGTrimAxis.cpp b/src/FDM/JSBSim/FGTrimAxis.cpp index 2fe3213f1..f8417f8c5 100644 --- a/src/FDM/JSBSim/FGTrimAxis.cpp +++ b/src/FDM/JSBSim/FGTrimAxis.cpp @@ -72,6 +72,7 @@ FGTrimAxis::FGTrimAxis(FGFDMExec* fdex, FGInitialCondition* ic, State st, case tRdot: tolerance = DEFAULT_TOLERANCE / 10; break; case tHmgt: tolerance = 0.01; break; case tNlf: state_target=1.0; tolerance = 1E-5; break; + case tAll: break; } solver_eps=tolerance; @@ -153,14 +154,15 @@ FGTrimAxis::~FGTrimAxis(void) void FGTrimAxis::getState(void) { switch(state) { - case tUdot: state_value=fdmex->GetTranslation()->GetUVWdot()(1)-state_target; break; - case tVdot: state_value=fdmex->GetTranslation()->GetUVWdot()(2)-state_target; break; - case tWdot: state_value=fdmex->GetTranslation()->GetUVWdot()(3)-state_target; break; + case tUdot: state_value=fdmex->GetTranslation()->GetUVWdot(1)-state_target; break; + case tVdot: state_value=fdmex->GetTranslation()->GetUVWdot(2)-state_target; break; + case tWdot: state_value=fdmex->GetTranslation()->GetUVWdot(3)-state_target; break; case tQdot: state_value=fdmex->GetRotation()->GetPQRdot(2)-state_target;break; case tPdot: state_value=fdmex->GetRotation()->GetPQRdot(1)-state_target; break; case tRdot: state_value=fdmex->GetRotation()->GetPQRdot(3)-state_target; break; case tHmgt: state_value=computeHmgt()-state_target; break; case tNlf: state_value=fdmex->GetAircraft()->GetNlf()-state_target; break; + case tAll: break; } } @@ -450,9 +452,9 @@ double FGTrimAxis::GetAvgStability( void ) { void FGTrimAxis::Debug(int from) { - if (debug_lvl <= 0) return; - if (debug_lvl & 1) { // Standard console startup message output + if (debug_lvl <= 0) return; + if (debug_lvl & 1 ) { // Standard console startup message output if (from == 0) { // Constructor } @@ -467,5 +469,12 @@ void FGTrimAxis::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } + diff --git a/src/FDM/JSBSim/FGTurboJet.cpp b/src/FDM/JSBSim/FGTurboJet.cpp index 3812fdc7f..8d6edf2cd 100644 --- a/src/FDM/JSBSim/FGTurboJet.cpp +++ b/src/FDM/JSBSim/FGTurboJet.cpp @@ -106,5 +106,11 @@ void FGTurboJet::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGTurboProp.cpp b/src/FDM/JSBSim/FGTurboProp.cpp index 1179cbfaf..fdbdf1708 100644 --- a/src/FDM/JSBSim/FGTurboProp.cpp +++ b/src/FDM/JSBSim/FGTurboProp.cpp @@ -105,5 +105,11 @@ void FGTurboProp::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGTurboShaft.cpp b/src/FDM/JSBSim/FGTurboShaft.cpp index ce414d274..ee4efb8b7 100644 --- a/src/FDM/JSBSim/FGTurboShaft.cpp +++ b/src/FDM/JSBSim/FGTurboShaft.cpp @@ -104,5 +104,11 @@ void FGTurboShaft::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGUtility.cpp b/src/FDM/JSBSim/FGUtility.cpp index 7e275a8e4..5ec59baab 100644 --- a/src/FDM/JSBSim/FGUtility.cpp +++ b/src/FDM/JSBSim/FGUtility.cpp @@ -118,5 +118,11 @@ void FGUtility::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } } diff --git a/src/FDM/JSBSim/FGfdmSocket.cpp b/src/FDM/JSBSim/FGfdmSocket.cpp index 457ddcfcf..01f14a930 100644 --- a/src/FDM/JSBSim/FGfdmSocket.cpp +++ b/src/FDM/JSBSim/FGfdmSocket.cpp @@ -87,10 +87,11 @@ FGfdmSocket::FGfdmSocket(string address, int port) cout << "Could not create socket for FDM, error = " << errno << endl; } } - - if (debug_lvl & 2) cout << "Instantiated: FGfdmSocket" << endl; + Debug(0); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + FGfdmSocket::~FGfdmSocket() { #ifndef macintosh @@ -100,14 +101,19 @@ FGfdmSocket::~FGfdmSocket() #ifdef __BORLANDC__ WSACleanup(); #endif + Debug(1); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGfdmSocket::Clear(void) { buffer = ""; size = 0; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGfdmSocket::Append(const char* item) { if (size == 0) buffer += string(item); @@ -115,28 +121,34 @@ void FGfdmSocket::Append(const char* item) size++; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGfdmSocket::Append(double item) { char s[25]; - sprintf(s,"%12.7f\0",item); + sprintf(s,"%12.7f",item); if (size == 0) buffer += string(s); else buffer += string(",") + string(s); size++; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGfdmSocket::Append(long item) { char s[25]; - sprintf(s,"%12d\0",item); + sprintf(s,"%12d",item); if (size == 0) buffer += string(s); else buffer += string(",") + string(s); size++; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGfdmSocket::Send(void) { buffer += string("\n"); @@ -146,3 +158,48 @@ void FGfdmSocket::Send(void) } } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// 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 + +void FGfdmSocket::Debug(int from) +{ + if (debug_lvl <= 0) return; + + if (debug_lvl & 1) { // Standard console startup message output + if (from == 0) { // Constructor + } + } + if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (from == 0) cout << "Instantiated: FGfdmSocket" << endl; + if (from == 1) cout << "Destroyed: FGfdmSocket" << endl; + } + if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + } + if (debug_lvl & 8 ) { // Runtime state variables + } + if (debug_lvl & 16) { // Sanity checking + } + if (debug_lvl & 64) { + if (from == 0) { // Constructor + cout << IdSrc << endl; + cout << IdHdr << endl; + } + } +} + diff --git a/src/FDM/JSBSim/FGfdmSocket.h b/src/FDM/JSBSim/FGfdmSocket.h index 1aa09bda3..0a405f32b 100644 --- a/src/FDM/JSBSim/FGfdmSocket.h +++ b/src/FDM/JSBSim/FGfdmSocket.h @@ -107,7 +107,7 @@ private: struct sockaddr_in scktName; struct hostent *host; string buffer; - void Debug(int from) {} + void Debug(int from); }; #endif diff --git a/src/FDM/JSBSim/JSBSim.cpp b/src/FDM/JSBSim/JSBSim.cpp index 8d3db58bc..e79d96fc7 100644 --- a/src/FDM/JSBSim/JSBSim.cpp +++ b/src/FDM/JSBSim/JSBSim.cpp @@ -50,6 +50,7 @@ INCLUDES #include "FGAuxiliary.h" #include "FGOutput.h" #include "FGConfigFile.h" +#include "FGScript.h" #ifdef FGFS #include @@ -97,42 +98,35 @@ IMPLEMENTATION int main(int argc, char** argv) { FGFDMExec* FDMExec; - float cmd = 0.0; bool result = false; - bool scripted = false; + bool Scripted = false; + FGScript* Script; - if (argc == 2) { - FGConfigFile testFile(argv[1]); - - if (!testFile.IsOpen()) { - cout << "Script file not opened" << endl; - exit(-1); - } - - testFile.GetNextConfigLine(); - if (testFile.GetValue("runscript").length() <= 0) { - cout << "File: " << argv[1] << " is not a script file" << endl; - exit(-1); - } - scripted = true; - } else if (argc != 3) { - cout << endl + if (argc != 3 && argc != 2) { + cerr << endl << " You must enter the name of a registered aircraft and reset point:" << endl << endl << " FDM " << endl; - cout << endl << " Alternatively, you may specify only the name of a script file:" + cerr << endl << " Alternatively, you may specify only the name of a script file:" << endl << endl << " FDM