From: ehofman Date: Sun, 27 Jun 2004 19:35:54 +0000 (+0000) Subject: Sync. with JSBSim CVS again. This fixes some small issues. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5c685b34de6f51c35f8ade29f539cc1b18e1b92f;p=flightgear.git Sync. with JSBSim CVS again. This fixes some small issues. --- diff --git a/src/FDM/JSBSim/FGElectric.cpp b/src/FDM/JSBSim/FGElectric.cpp index c8a075fda..4cc12f006 100644 --- a/src/FDM/JSBSim/FGElectric.cpp +++ b/src/FDM/JSBSim/FGElectric.cpp @@ -50,12 +50,12 @@ static const char *IdHdr = ID_ELECTRIC; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGElectric::FGElectric(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec) +FGElectric::FGElectric(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number) + : FGEngine(exec, engine_number) { string token; Type = etElectric; - EngineNumber = 0; PowerWatts = 745.7; hptowatts = 745.7; diff --git a/src/FDM/JSBSim/FGElectric.h b/src/FDM/JSBSim/FGElectric.h index cef8a0f87..7e865e2db 100644 --- a/src/FDM/JSBSim/FGElectric.h +++ b/src/FDM/JSBSim/FGElectric.h @@ -74,7 +74,7 @@ class FGElectric : public FGEngine { public: /// Constructor - FGElectric(FGFDMExec* exec, FGConfigFile* Eng_cfg); + FGElectric(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number); /// Destructor ~FGElectric(); diff --git a/src/FDM/JSBSim/FGEngine.cpp b/src/FDM/JSBSim/FGEngine.cpp index b3a1b3929..1983708ef 100644 --- a/src/FDM/JSBSim/FGEngine.cpp +++ b/src/FDM/JSBSim/FGEngine.cpp @@ -68,7 +68,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGEngine::FGEngine(FGFDMExec* exec) +FGEngine::FGEngine(FGFDMExec* exec, int engine_number) : EngineNumber(engine_number) { Name = ""; Type = etUnknown; @@ -84,7 +84,6 @@ FGEngine::FGEngine(FGFDMExec* exec) FuelNeed = OxidizerNeed = 0.0; Starved = Running = Cranking = false; PctPower = 0.0; - EngineNumber = -1; TrimMode = false; FuelFlow_gph = 0.0; FuelFlow_pph = 0.0; @@ -124,7 +123,7 @@ void FGEngine::ConsumeFuel(void) if (TrimMode) return; Fshortage = Oshortage = TanksWithFuel = 0.0; - + // count how many assigned tanks have fuel for (unsigned int i=0; iGetTank(SourceTanks[i]); diff --git a/src/FDM/JSBSim/FGEngine.h b/src/FDM/JSBSim/FGEngine.h index e0d070dd5..a4d63c2d1 100644 --- a/src/FDM/JSBSim/FGEngine.h +++ b/src/FDM/JSBSim/FGEngine.h @@ -107,7 +107,7 @@ CLASS DECLARATION class FGEngine : public FGJSBBase { public: - FGEngine(FGFDMExec* exec); + FGEngine(FGFDMExec* exec, int engine_number); virtual ~FGEngine(); enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etElectric}; @@ -164,9 +164,6 @@ public: /// Sets engine placement information virtual void SetPlacement(double x, double y, double z, double pitch, double yaw); - /// Sets the engine number - virtual void SetEngineNumber(int nn) {EngineNumber = nn;} - virtual double GetPowerAvailable(void) {return 0.0;}; virtual bool GetTrimMode(void) {return TrimMode;} @@ -184,6 +181,7 @@ public: protected: FGPropertyManager* PropertyManager; string Name; + const int EngineNumber; EngineType Type; double X, Y, Z; double EnginePitch; @@ -199,7 +197,6 @@ protected: double FuelNeed; double OxidizerNeed; double PctPower; - int EngineNumber; bool Starter; bool Starved; bool Running; diff --git a/src/FDM/JSBSim/FGFCS.cpp b/src/FDM/JSBSim/FGFCS.cpp index cf1b8628f..b6a961a68 100644 --- a/src/FDM/JSBSim/FGFCS.cpp +++ b/src/FDM/JSBSim/FGFCS.cpp @@ -747,7 +747,6 @@ void FGFCS::bindModel(void) unsigned i; char tmp[80]; - for (i=0; iTie( tmp,this,i, diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 3002ec56b..dac9eedac 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -384,18 +384,22 @@ vector FGFDMExec::EnumerateFDMs(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model) +bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model, + bool addModelToPath) { + FGFDMExec::AircraftPath = AircraftPath; FGFDMExec::EnginePath = EnginePath; - return LoadModel(model); + return LoadModel(model, addModelToPath); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGFDMExec::LoadModel(string model) + +bool FGFDMExec::LoadModel(string model, bool addModelToPath) { + bool result = true; string token; string aircraftCfgFileName; @@ -406,10 +410,13 @@ bool FGFDMExec::LoadModel(string model) return false; } + aircraftCfgFileName = AircraftPath; # ifndef macintosh - aircraftCfgFileName = AircraftPath + "/" + model + ".xml"; + if (addModelToPath) aircraftCfgFileName += "/" + model; + aircraftCfgFileName += "/" + model + ".xml"; # else - aircraftCfgFileName = AircraftPath + ";" + model + ".xml"; + if (addModelToPath) aircraftCfgFileName += ";" + model; + aircraftCfgFileName += ";" + model + ".xml"; # endif FGConfigFile AC_cfg(aircraftCfgFileName); diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index fefe6cd37..9e2d0a093 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -152,8 +152,11 @@ public: be looked for in the directory specified in the AircraftPath variable, and in turn under the directory with the same name as the model. For instance: "aircraft/x15/x15.xml" + @param addModelToPath set to true to add the model name to the + AircraftPath, defaults to true @return true if successful*/ - bool LoadModel(string AircraftPath, string EnginePath, string model); + bool LoadModel(string AircraftPath, string EnginePath, string model, + bool addModelToPath = true); /** Loads an aircraft model. The paths to the aircraft and engine @@ -163,8 +166,10 @@ public: be looked for in the directory specified in the AircraftPath variable, and in turn under the directory with the same name as the model. For instance: "aircraft/x15/x15.xml" + @param addModelToPath set to true to add the model name to the + AircraftPath, defaults to true @return true if successful*/ - bool LoadModel(string model); + bool LoadModel(string model, bool addModelToPath = true); /** Sets the path to the engine config file directories. diff --git a/src/FDM/JSBSim/FGJSBBase.h b/src/FDM/JSBSim/FGJSBBase.h index d0f24e591..9e51d2456 100644 --- a/src/FDM/JSBSim/FGJSBBase.h +++ b/src/FDM/JSBSim/FGJSBBase.h @@ -199,7 +199,6 @@ public: return celsius * 1.8 + 32.0; } - /** Finite precision comparison. @param a first value to compare @param b second value to compare diff --git a/src/FDM/JSBSim/FGLGear.cpp b/src/FDM/JSBSim/FGLGear.cpp index dd0325b10..6c9d6b209 100644 --- a/src/FDM/JSBSim/FGLGear.cpp +++ b/src/FDM/JSBSim/FGLGear.cpp @@ -353,9 +353,9 @@ FGColumnVector3& FGLGear::Force(void) if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) { WheelSlip = 0.0; } else if (fabs(RollingWhlVel) < 1.0) { - WheelSlip = 0.05*radtodeg*atan2(SideWhlVel, RollingWhlVel) + 0.95*WheelSlip; + WheelSlip = 0.05*radtodeg*atan2(SideWhlVel, fabs(RollingWhlVel)) + 0.95*WheelSlip; } else { - WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel); + WheelSlip = radtodeg*atan2(SideWhlVel, fabs(RollingWhlVel)); } /* double maxdeltaSlip = 0.5*deltaT; diff --git a/src/FDM/JSBSim/FGPiston.cpp b/src/FDM/JSBSim/FGPiston.cpp index aa3cef21d..dde46eea4 100644 --- a/src/FDM/JSBSim/FGPiston.cpp +++ b/src/FDM/JSBSim/FGPiston.cpp @@ -54,7 +54,8 @@ static const char *IdHdr = ID_PISTON; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec), +FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number) + : FGEngine(exec, engine_number), R_air(287.3), rho_fuel(800), // estimate calorific_value_fuel(47.3e6), @@ -65,7 +66,6 @@ FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec), Type = etPiston; crank_counter = 0; - EngineNumber = 0; OilTemp_degK = 298; MinManifoldPressure_inHg = 6.5; MaxManifoldPressure_inHg = 28.5; diff --git a/src/FDM/JSBSim/FGPiston.h b/src/FDM/JSBSim/FGPiston.h index b2e65b5fc..197f36cc4 100644 --- a/src/FDM/JSBSim/FGPiston.h +++ b/src/FDM/JSBSim/FGPiston.h @@ -142,7 +142,7 @@ class FGPiston : public FGEngine { public: /// Constructor - FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg); + FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number); /// Destructor ~FGPiston(); diff --git a/src/FDM/JSBSim/FGPropulsion.cpp b/src/FDM/JSBSim/FGPropulsion.cpp index a7a31a38b..09cf080c8 100644 --- a/src/FDM/JSBSim/FGPropulsion.cpp +++ b/src/FDM/JSBSim/FGPropulsion.cpp @@ -108,7 +108,7 @@ bool FGPropulsion::Run(void) for (unsigned int i=0; iCalculate( dt * rate ); - } + } if (refuel) DoRefuel( dt * rate ); @@ -231,20 +231,20 @@ bool FGPropulsion::Load(FGConfigFile* AC_cfg) ThrottleAdded = true; if (engType == "FG_ROCKET") { - Engines.push_back(new FGRocket(FDMExec, Cfg_ptr)); + Engines.push_back(new FGRocket(FDMExec, Cfg_ptr, numEngines)); } else if (engType == "FG_PISTON") { - Engines.push_back(new FGPiston(FDMExec, Cfg_ptr)); + Engines.push_back(new FGPiston(FDMExec, Cfg_ptr, numEngines)); } else if (engType == "FG_TURBINE") { - Engines.push_back(new FGTurbine(FDMExec, Cfg_ptr)); + Engines.push_back(new FGTurbine(FDMExec, Cfg_ptr, numEngines)); } else if (engType == "FG_SIMTURBINE") { cerr << endl; cerr << "The FG_SIMTURBINE engine type has been renamed to FG_TURBINE." << endl; cerr << "To fix this problem, simply replace the FG_SIMTURBINE name " << endl; cerr << "in your engine file to FG_TURBINE." << endl; cerr << endl; - Engines.push_back(new FGTurbine(FDMExec, Cfg_ptr)); + Engines.push_back(new FGTurbine(FDMExec, Cfg_ptr, numEngines)); } else if (engType == "FG_ELECTRIC") { - Engines.push_back(new FGElectric(FDMExec, Cfg_ptr)); + Engines.push_back(new FGElectric(FDMExec, Cfg_ptr, numEngines)); } else { cerr << fgred << " Unrecognized engine type: " << underon << engType << underoff << " found in config file." << fgdef << endl; @@ -281,7 +281,6 @@ bool FGPropulsion::Load(FGConfigFile* AC_cfg) } Engines[numEngines]->SetPlacement(xLoc, yLoc, zLoc, Pitch, Yaw); - Engines[numEngines]->SetEngineNumber(numEngines); numEngines++; } else { @@ -328,7 +327,7 @@ string FGPropulsion::GetPropulsionStrings(void) if (firstime) firstime = false; else PropulsionStrings += ", "; - PropulsionStrings += Engines[i]->GetEngineLabels() + ", "; + PropulsionStrings += Engines[i]->GetEngineLabels(); } return PropulsionStrings; @@ -345,7 +344,7 @@ string FGPropulsion::GetPropulsionValues(void) if (firstime) firstime = false; else PropulsionValues += ", "; - PropulsionValues += Engines[i]->GetEngineValues() + ", "; + PropulsionValues += Engines[i]->GetEngineValues(); } return PropulsionValues; @@ -494,7 +493,7 @@ void FGPropulsion::DoRefuel(double time_slice) if (Tanks[i]->GetPctFull() < 99.99) Transfer(-1, i, fillrate/TanksNotFull); } - } + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGRocket.cpp b/src/FDM/JSBSim/FGRocket.cpp index dc9919192..0d0497b99 100644 --- a/src/FDM/JSBSim/FGRocket.cpp +++ b/src/FDM/JSBSim/FGRocket.cpp @@ -51,7 +51,8 @@ static const char *IdHdr = ID_ROCKET; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGRocket::FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec) +FGRocket::FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number) + : FGEngine(exec, engine_number) { string token; @@ -73,7 +74,6 @@ FGRocket::FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec) Debug(0); - EngineNumber = 0; Type = etRocket; Flameout = false; @@ -105,6 +105,10 @@ double FGRocket::Calculate(void) } else { PctPower = Throttle / MaxThrottle; PC = maxPC*PctPower * (1.0 + Variance * ((double)rand()/(double)RAND_MAX - 0.5)); + // The Cf (below) is CF from Eqn. 3-30, "Rocket Propulsion Elements", Fifth Edition, + // George P. Sutton. Note that the thruster function GetPowerRequired() might + // be better called GetResistance() or something; this function returns the + // nozzle exit pressure. Cf = sqrt(kFactor*(1 - pow(Thruster->GetPowerRequired()/(PC), (SHR-1)/SHR))); Flameout = false; } diff --git a/src/FDM/JSBSim/FGRocket.h b/src/FDM/JSBSim/FGRocket.h index 9d64c6ad4..a4d237e8b 100644 --- a/src/FDM/JSBSim/FGRocket.h +++ b/src/FDM/JSBSim/FGRocket.h @@ -103,8 +103,9 @@ class FGRocket : public FGEngine public: /** Constructor. @param exec pointer to JSBSim parent object, the FDM Executive. - @param Eng_cfg pointer to the config file object. */ - FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg); + @param Eng_cfg pointer to the config file object. + @param engine_number engine number */ + FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg, int engine_number); /** Destructor */ ~FGRocket(void); diff --git a/src/FDM/JSBSim/FGTurbine.cpp b/src/FDM/JSBSim/FGTurbine.cpp index 437b04917..69afe4778 100644 --- a/src/FDM/JSBSim/FGTurbine.cpp +++ b/src/FDM/JSBSim/FGTurbine.cpp @@ -54,7 +54,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec) +FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg, int engine_number) + : FGEngine(exec, engine_number) { SetDefaults(); @@ -66,6 +67,7 @@ FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec) FGTurbine::~FGTurbine() { + unbind(); Debug(1); } @@ -183,14 +185,16 @@ double FGTurbine::Run(void) NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8); } - if ((AugmentCmd > 0.0) && (AugMethod == 2)) { - Augmentation = true; - double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust; - thrust += (tdiff * AugmentCmd); - FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0); - NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8); - } else { - Augmentation = false; + if (AugMethod == 2) { + if (AugmentCmd > 0.0) { + Augmentation = true; + double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust; + thrust += (tdiff * AugmentCmd); + FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0); + NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8); + } else { + Augmentation = false; + } } if ((Injected == 1) && Injection) @@ -402,6 +406,7 @@ bool FGTurbine::Load(FGConfigFile *Eng_cfg) OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0; IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate + bindmodel(); return true; } @@ -431,6 +436,30 @@ string FGTurbine::GetEngineValues(void) return buf.str(); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGTurbine::bindmodel() +{ + char property_name[80]; + + snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber); + PropertyManager->Tie( property_name, &N1); + snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber); + PropertyManager->Tie( property_name, &N2); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGTurbine::unbind() +{ + char property_name[80]; + + snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber); + PropertyManager->Untie(property_name); + snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber); + PropertyManager->Untie(property_name); +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/FGTurbine.h b/src/FDM/JSBSim/FGTurbine.h index 8361595c7..fc87e2eeb 100644 --- a/src/FDM/JSBSim/FGTurbine.h +++ b/src/FDM/JSBSim/FGTurbine.h @@ -139,8 +139,9 @@ class FGTurbine : public FGEngine public: /** Constructor @param Executive pointer to executive structure - @param Eng_cfg pointer to engine config file instance */ - FGTurbine(FGFDMExec* Executive, FGConfigFile* Eng_cfg); + @param Eng_cfg pointer to engine config file instance + @param engine_number engine number*/ + FGTurbine(FGFDMExec* Executive, FGConfigFile* Eng_cfg, int engine_number); /// Destructor ~FGTurbine(); @@ -241,6 +242,8 @@ private: void SetDefaults(void); bool Load(FGConfigFile *ENG_cfg); + void bindmodel(void); + void unbind(void); void Debug(int from); }; diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index ec9eb014b..ff1f163c0 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -133,7 +133,7 @@ FGJSBsim::FGJSBsim( double dt ) result = fdmex->LoadModel( aircraft_path.str(), engine_path.str(), - fgGetString("/sim/aero") ); + fgGetString("/sim/aero"), false ); if (result) { SG_LOG( SG_FLIGHT, SG_INFO, " loaded aero."); diff --git a/src/FDM/JSBSim/filtersjb/FGFilter.cpp b/src/FDM/JSBSim/filtersjb/FGFilter.cpp index d2c2dd88a..a7fa9c5a3 100644 --- a/src/FDM/JSBSim/filtersjb/FGFilter.cpp +++ b/src/FDM/JSBSim/filtersjb/FGFilter.cpp @@ -165,7 +165,6 @@ bool FGFilter::Run(void) } else if (Trigger != 0) { test = Trigger->getIntValue(); if (test < 0) { - Output = PreviousOutput1 = PreviousOutput2 = 0.0; Input = PreviousInput1 = PreviousInput2 = 0.0; } else { Output = PreviousOutput1 = PreviousOutput2 = 0.0;