From: ehofman Date: Sun, 16 Aug 2009 19:36:55 +0000 (+0000) Subject: Update to the latest version of JSBSim X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cf25f69d3639c2e4c821ff7f8ed62b80e8ff495b;p=flightgear.git Update to the latest version of JSBSim --- diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 7f50d0590..da1b9deb0 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -650,16 +650,23 @@ bool FGFDMExec::LoadModel(string model, bool addModelToPath) } // Process the output element[s]. This element is OPTIONAL, and there may be more than one. + unsigned int idx=0; + typedef int (FGOutput::*iOPMF)(void) const; element = document->FindElement("output"); while (element) { + if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " "; FGOutput* Output = new FGOutput(this); Output->InitModel(); Schedule(Output, 1); result = Output->Load(element); - Outputs.push_back(Output); if (!result) { cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl; return result; + } else { + Outputs.push_back(Output); + string outputProp = CreateIndexedPropertyName("simulation/output",idx); + instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate); + idx++; } element = document->FindNextElement("output"); } @@ -931,6 +938,10 @@ bool FGFDMExec::SetOutputDirectives(string fname) result = Output->Load(0); Outputs.push_back(Output); + typedef int (FGOutput::*iOPMF)(void) const; + string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1); + instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate); + return result; } diff --git a/src/FDM/JSBSim/FGJSBBase.cpp b/src/FDM/JSBSim/FGJSBBase.cpp index 228fa8639..d0af549b8 100644 --- a/src/FDM/JSBSim/FGJSBBase.cpp +++ b/src/FDM/JSBSim/FGJSBBase.cpp @@ -38,6 +38,7 @@ INCLUDES #define BASE #include "FGJSBBase.h" +#include namespace JSBSim { @@ -109,6 +110,10 @@ unsigned int FGJSBBase::messageId = 0; short FGJSBBase::debug_lvl = 1; +using std::cerr; +using std::cout; +using std::endl; + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGJSBBase::PutMessage(const Message& msg) @@ -176,10 +181,43 @@ int FGJSBBase::SomeMessages(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGJSBBase::Message* FGJSBBase::ProcessMessage(void) +void FGJSBBase::ProcessMessage(void) +{ + if (Messages.empty()) return; + localMsg = Messages.front(); + + while (Messages.size() > 0) { + switch (localMsg.type) { + case JSBSim::FGJSBBase::Message::eText: + cout << localMsg.messageId << ": " << localMsg.text << endl; + break; + case JSBSim::FGJSBBase::Message::eBool: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl; + break; + case JSBSim::FGJSBBase::Message::eInteger: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl; + break; + case JSBSim::FGJSBBase::Message::eDouble: + cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl; + break; + default: + cerr << "Unrecognized message type." << endl; + break; + } + Messages.pop(); + if (Messages.size() > 0) localMsg = Messages.front(); + else break; + } + +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void) { if (Messages.empty()) return NULL; localMsg = Messages.front(); + Messages.pop(); return &localMsg; } diff --git a/src/FDM/JSBSim/FGJSBBase.h b/src/FDM/JSBSim/FGJSBBase.h index 7e56d5f5f..49b0aec9e 100644 --- a/src/FDM/JSBSim/FGJSBBase.h +++ b/src/FDM/JSBSim/FGJSBBase.h @@ -182,8 +182,12 @@ public: @return 1 if some messages */ int SomeMessages(void); /** Reads the message on the queue and removes it from the queue. - @return pointer to a Message structure (or NULL if no mesage) */ - Message* ProcessMessage(void); + This function also prints out the message.*/ + void ProcessMessage(void); + /** Reads the next message on the queue and removes it from the queue. + This function also prints out the message. + @return a pointer to the message, or NULL if there are no messages.*/ + Message* ProcessNextMessage(void); //@} /** Returns the version number of JSBSim. diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index b36c19657..f5dd9008e 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -489,8 +489,8 @@ void FGJSBsim::update( double dt ) } FGJSBBase::Message* msg; - while (fdmex->SomeMessages()) { - msg = fdmex->ProcessMessage(); + while (msg = fdmex->ProcessNextMessage()) { +// msg = fdmex->ProcessNextMessage(); switch (msg->type) { case FGJSBBase::Message::eText: if (msg->text == "Crash Detected: Simulation FREEZE.") diff --git a/src/FDM/JSBSim/initialization/FGInitialCondition.cpp b/src/FDM/JSBSim/initialization/FGInitialCondition.cpp index de904e0e1..10b4b7a3e 100644 --- a/src/FDM/JSBSim/initialization/FGInitialCondition.cpp +++ b/src/FDM/JSBSim/initialization/FGInitialCondition.cpp @@ -865,8 +865,14 @@ bool FGInitialCondition::Load(string rstfile, bool useStoredPath) SetLongitudeDegIC(document->FindElementValueAsNumberConvertTo("longitude", "DEG")); if (document->FindElement("elevation")) SetTerrainElevationFtIC(document->FindElementValueAsNumberConvertTo("elevation", "FT")); + if (document->FindElement("altitude")) // This is feet above ground level SetAltitudeAGLFtIC(document->FindElementValueAsNumberConvertTo("altitude", "FT")); + else if (document->FindElement("altitudeAGL")) // This is feet above ground level + SetAltitudeAGLFtIC(document->FindElementValueAsNumberConvertTo("altitudeAGL", "FT")); + else if (document->FindElement("altitudeMSL")) // This is feet above sea level + SetAltitudeASLFtIC(document->FindElementValueAsNumberConvertTo("altitudeMSL", "FT")); + if (document->FindElement("ubody")) SetUBodyFpsIC(document->FindElementValueAsNumberConvertTo("ubody", "FT/SEC")); if (document->FindElement("vbody")) diff --git a/src/FDM/JSBSim/initialization/FGInitialCondition.h b/src/FDM/JSBSim/initialization/FGInitialCondition.h index 330552e7f..86de126a0 100644 --- a/src/FDM/JSBSim/initialization/FGInitialCondition.h +++ b/src/FDM/JSBSim/initialization/FGInitialCondition.h @@ -140,7 +140,10 @@ CLASS DOCUMENTATION - beta (angle, degrees) - gamma (angle, degrees) - roc (vertical velocity, ft/sec) + - elevation (local terrain elevation, ft) - altitude (altitude AGL, ft) + - altitudeAGL (altitude AGL, ft) + - altitudeMSL (altitude MSL, ft) - winddir (wind from-angle, degrees) - vwind (magnitude wind speed, ft/sec) - hwind (headwind speed, knots) diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.h b/src/FDM/JSBSim/input_output/FGPropertyManager.h index 8f191fe87..52a64217b 100644 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.h +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.h @@ -35,14 +35,9 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include #include -#include #include "FGJSBBase.h" diff --git a/src/FDM/JSBSim/models/FGFCS.cpp b/src/FDM/JSBSim/models/FGFCS.cpp index 22ca19d77..47213f900 100644 --- a/src/FDM/JSBSim/models/FGFCS.cpp +++ b/src/FDM/JSBSim/models/FGFCS.cpp @@ -519,7 +519,7 @@ bool FGFCS::Load(Element* el, SystemType systype) { string name, file, fname="", interface_property_string, parent_name; vector *Components; - Element *component_element, *sensor_element; + Element *component_element; Element *channel_element; Components=0; diff --git a/src/FDM/JSBSim/models/FGLGear.cpp b/src/FDM/JSBSim/models/FGLGear.cpp index dcb140b8a..96d8d2308 100644 --- a/src/FDM/JSBSim/models/FGLGear.cpp +++ b/src/FDM/JSBSim/models/FGLGear.cpp @@ -652,6 +652,10 @@ void FGLGear::bind(void) Exec->GetPropertyManager()->Tie( property_name.c_str(), &compressLength ); property_name = base_property_name + "/side_friction_coeff"; Exec->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff ); + + property_name = base_property_name + "/static_friction_coeff"; + Exec->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff ); + } if( isRetractable ) { diff --git a/src/FDM/JSBSim/models/FGMassBalance.cpp b/src/FDM/JSBSim/models/FGMassBalance.cpp index eae637335..fd2fad3d5 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.cpp +++ b/src/FDM/JSBSim/models/FGMassBalance.cpp @@ -59,6 +59,9 @@ FGMassBalance::FGMassBalance(FGFDMExec* fdmex) : FGModel(fdmex) Weight = EmptyWeight = Mass = 0.0; vbaseXYZcg.InitMatrix(0.0); + vXYZcg.InitMatrix(0.0); + vLastXYZcg.InitMatrix(0.0); + vDeltaXYZcg.InitMatrix(0.0); baseJ.InitMatrix(); mJ.InitMatrix(); mJinv.InitMatrix(); @@ -85,6 +88,9 @@ bool FGMassBalance::InitModel(void) { if (!FGModel::InitModel()) return false; + vLastXYZcg.InitMatrix(0.0); + vDeltaXYZcg.InitMatrix(0.0); + return true; } @@ -172,6 +178,14 @@ bool FGMassBalance::Run(void) + GetPointMassMoment() + BuoyantForces->GetGasMassMoment()) / Weight; + // Track frame-by-frame delta CG, and move the EOM-tracked location + // by this amount. + if (vLastXYZcg.Magnitude() == 0.0) vLastXYZcg = vXYZcg; + vDeltaXYZcg = vXYZcg - vLastXYZcg; + vDeltaXYZcgBody = StructuralToBody(vLastXYZcg) - StructuralToBody(vXYZcg); + vLastXYZcg = vXYZcg; + Propagate->NudgeBodyLocation(vDeltaXYZcgBody); + // Calculate new total moments of inertia // At first it is the base configuration inertia matrix ... diff --git a/src/FDM/JSBSim/models/FGMassBalance.h b/src/FDM/JSBSim/models/FGMassBalance.h index 34f6f9cd6..c77400f37 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.h +++ b/src/FDM/JSBSim/models/FGMassBalance.h @@ -107,10 +107,12 @@ public: bool InitModel(void); bool Run(void); - inline double GetMass(void) const {return Mass;} - inline double GetWeight(void) const {return Weight;} - inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;} - inline double GetXYZcg(int axis) const {return vXYZcg(axis);} + double GetMass(void) const {return Mass;} + double GetWeight(void) const {return Weight;} + FGColumnVector3& GetXYZcg(void) {return vXYZcg;} + double GetXYZcg(int axis) const {return vXYZcg(axis);} + FGColumnVector3& GetDeltaXYZcg(void) {return vDeltaXYZcg;} + double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);} /** Computes the inertia contribution of a pointmass. Computes and returns the inertia matrix of a pointmass of mass @@ -166,6 +168,9 @@ private: FGMatrix33 pmJ; FGMatrix33 baseJ; FGColumnVector3 vXYZcg; + FGColumnVector3 vLastXYZcg; + FGColumnVector3 vDeltaXYZcg; + FGColumnVector3 vDeltaXYZcgBody; FGColumnVector3 vXYZtank; FGColumnVector3 vbaseXYZcg; FGColumnVector3 vPMxyz; diff --git a/src/FDM/JSBSim/models/FGOutput.cpp b/src/FDM/JSBSim/models/FGOutput.cpp index f8ef6a0b3..cb48ab554 100644 --- a/src/FDM/JSBSim/models/FGOutput.cpp +++ b/src/FDM/JSBSim/models/FGOutput.cpp @@ -465,9 +465,11 @@ void FGOutput::DelimitedOutput(string fname) outstream << Propulsion->GetPropulsionValues(delimeter); } + outstream.precision(18); for (unsigned int i=0;igetDoubleValue(); } + outstream.precision(10); outstream << endl; outstream.flush(); @@ -1016,14 +1018,27 @@ bool FGOutput::Load(Element* element) property_element = document->FindNextElement("property"); } - OutRate = OutRate>1000?1000:(OutRate<0?0:OutRate); - rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate)); + SetRate(OutRate); Debug(2); return true; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGOutput::SetRate(int rtHz) +{ + rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz); + if (rtHz > 0) { + rate = (int)(0.5 + 1.0/(State->Getdt()*rtHz)); + Enable(); + } else { + rate = 1; + Disable(); + } +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/FGOutput.h b/src/FDM/JSBSim/models/FGOutput.h index 51fcade39..8b3d1403c 100644 --- a/src/FDM/JSBSim/models/FGOutput.h +++ b/src/FDM/JSBSim/models/FGOutput.h @@ -150,12 +150,13 @@ public: void SetType(string); void SetStartNewFile(bool tt) {StartNewFile = tt;} void SetSubsystems(int tt) {SubSystems = tt;} - inline void Enable(void) { enabled = true; } - inline void Disable(void) { enabled = false; } - inline bool Toggle(void) {enabled = !enabled; return enabled;} + void Enable(void) { enabled = true; } + void Disable(void) { enabled = false; } + bool Toggle(void) {enabled = !enabled; return enabled;} bool Load(Element* el); void SetOutputFileName(string fname) {Filename = fname;} void SetDirectivesFile(string fname) {DirectivesFile = fname;} + void SetRate(int rt); string GetOutputFileName(void) const {return Filename;} /// Subsystem types for specifying which will be output in the FDM data logging diff --git a/src/FDM/JSBSim/models/FGPropagate.h b/src/FDM/JSBSim/models/FGPropagate.h index 63c2b42c3..a4ecd6c91 100644 --- a/src/FDM/JSBSim/models/FGPropagate.h +++ b/src/FDM/JSBSim/models/FGPropagate.h @@ -487,6 +487,11 @@ public: void SetInitialState(const FGInitialCondition *); void RecomputeLocalTerrainRadius(void); + void NudgeBodyLocation(FGColumnVector3 deltaLoc) { + vDeltaXYZEC = GetTb2ec()*deltaLoc; + VState.vLocation -= vDeltaXYZEC; + } + void CalculatePQRdot(void); void CalculateQuatdot(void); void CalculateLocationdot(void); @@ -504,6 +509,7 @@ private: FGColumnVector3 vUVWdot, last_vUVWdot, last2_vUVWdot; FGColumnVector3 vLocationDot, last_vLocationDot, last2_vLocationDot; FGColumnVector3 vLocation; + FGColumnVector3 vDeltaXYZEC; FGColumnVector3 vPQRi; // Inertial frame angular velocity FGColumnVector3 vOmega; // The Earth angular velocity vector FGColumnVector3 vOmegaLocal; // The local frame angular velocity vector diff --git a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp index 3a54175fc..f59846801 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp @@ -199,8 +199,6 @@ double FGPropeller::Calculate(double PowerAvailable) vH(eY) = 0.0; vH(eZ) = 0.0; - vH = Transform()*vH; // Transform rotational momentum to rotated frame (if any) - if (omega > 0.0) ExcessTorque = GearRatio * PowerAvailable / omega; else ExcessTorque = GearRatio * PowerAvailable / 1.0; @@ -208,9 +206,9 @@ double FGPropeller::Calculate(double PowerAvailable) if (RPM < 1.0) RPM = 0; // Engine friction stops rotation arbitrarily at 1 RPM. - // Transform Torque and momentum prior to this equation, as PQR is used in this + // Transform Torque and momentum first, as PQR is used in this // equation and cannot be transformed itself. - vMn = fdmex->GetPropagate()->GetPQR()*vH + Transform()*vTorque; + vMn = fdmex->GetPropagate()->GetPQR()*(Transform()*vH) + Transform()*vTorque; return Thrust; // return thrust in pounds }