diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index c6740b4b6..227c0267f 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -43,29 +43,32 @@ INCLUDES #include "FGFDMExec.h" #include "FGState.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include // Remove until later -#include -#include +#include "models/FGAtmosphere.h" +#include "models/atmosphere/FGMSIS.h" +#include "models/atmosphere/FGMars.h" +#include "models/FGFCS.h" +#include "models/FGPropulsion.h" +#include "models/FGMassBalance.h" +#include "models/FGGroundReactions.h" +#include "models/FGExternalReactions.h" +#include "models/FGBuoyantForces.h" +#include "models/FGAerodynamics.h" +#include "models/FGInertial.h" +#include "models/FGAircraft.h" +#include "models/FGPropagate.h" +#include "models/FGAuxiliary.h" +#include "models/FGInput.h" +#include "models/FGOutput.h" +#include "initialization/FGInitialCondition.h" +//#include "initialization/FGTrimAnalysis.h" // Remove until later +#include "input_output/FGPropertyManager.h" +#include "input_output/FGScript.h" #include #include +#include + +using namespace std; namespace JSBSim { @@ -713,13 +716,13 @@ void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs) { struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure; int node_idx = 0; - char int_buf[10]; - for (unsigned int i=0; inode->nChildren(); i++) { + for (int i=0; inode->nChildren(); i++) { pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName(); node_idx = pcs->node->getChild(i)->getIndex(); - sprintf(int_buf, "[%d]", node_idx); - if (node_idx != 0) pcsNew->base_string += string(int_buf); + if (node_idx != 0) { + pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx); + } if (pcs->node->getChild(i)->nChildren() == 0) { if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) { pcsNew->base_string = pcsNew->base_string.erase(0,12); diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 50bffeaf5..5e1ee0719 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -41,17 +41,17 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "models/FGModel.h" +#include "models/FGOutput.h" +#include "models/FGInput.h" +#include "initialization/FGTrim.h" +#include "initialization/FGInitialCondition.h" +#include "FGJSBBase.h" +#include "input_output/FGPropertyManager.h" +#include "input_output/FGGroundCallback.h" +#include "input_output/FGXMLFileRead.h" +#include "models/FGPropagate.h" +#include "math/FGColumnVector3.h" #include #include diff --git a/src/FDM/JSBSim/FGJSBBase.cpp b/src/FDM/JSBSim/FGJSBBase.cpp index 4e02407a4..f07a4f081 100644 --- a/src/FDM/JSBSim/FGJSBBase.cpp +++ b/src/FDM/JSBSim/FGJSBBase.cpp @@ -39,6 +39,8 @@ INCLUDES #include "FGJSBBase.h" #include +#include +#include namespace JSBSim { @@ -240,5 +242,43 @@ void FGJSBBase::disableHighLighting(void) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index) +{ + std::ostringstream buf; + buf << Property << '[' << index << ']'; + return buf.str(); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +double FGJSBBase::GaussianRandomNumber(void) +{ + static double V1, V2, S; + static int phase = 0; + double X; + + if (phase == 0) { + V1 = V2 = S = X = 0.0; + + do { + double U1 = (double)rand() / RAND_MAX; + double U2 = (double)rand() / RAND_MAX; + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while(S >= 1 || S == 0); + + X = V1 * sqrt(-2 * log(S) / S); + } else + X = V2 * sqrt(-2 * log(S) / S); + + phase = 1 - phase; + + return X; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + } // namespace JSBSim diff --git a/src/FDM/JSBSim/FGJSBBase.h b/src/FDM/JSBSim/FGJSBBase.h index 6ed8832f8..d4ceb2c97 100644 --- a/src/FDM/JSBSim/FGJSBBase.h +++ b/src/FDM/JSBSim/FGJSBBase.h @@ -41,21 +41,22 @@ INCLUDES #include #include #include -#include #include -#include #include "input_output/string_utilities.h" -using std::fabs; -using std::string; - #ifndef M_PI # define M_PI 3.14159265358979323846 #endif -#if !defined(WIN32) || defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300)) - using std::max; +#if defined(_MSC_VER) && (_MSC_VER < 1300) +namespace std +{ + template inline T max(const T& a, const T& b) + { + return (a > b) ? a : b; + } +} #endif /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -98,8 +99,8 @@ public: public: unsigned int fdmId; unsigned int messageId; - string text; - string subsystem; + std::string text; + std::string subsystem; enum mType {eText, eInteger, eDouble, eBool} type; bool bVal; int iVal; @@ -162,22 +163,22 @@ public: /** Creates a message with the given text and places it on the queue. @param text message text @return pointer to a Message structure */ - void PutMessage(const string& text); + void PutMessage(const std::string& text); /** Creates a message with the given text and boolean value and places it on the queue. @param text message text @param bVal boolean value associated with the message @return pointer to a Message structure */ - void PutMessage(const string& text, bool bVal); + void PutMessage(const std::string& text, bool bVal); /** Creates a message with the given text and integer value and places it on the queue. @param text message text @param iVal integer value associated with the message @return pointer to a Message structure */ - void PutMessage(const string& text, int iVal); + void PutMessage(const std::string& text, int iVal); /** Creates a message with the given text and double value and places it on the queue. @param text message text @param dVal double value associated with the message @return pointer to a Message structure */ - void PutMessage(const string& text, double dVal); + void PutMessage(const std::string& text, double dVal); /** Reads the message on the queue (but does not delete it). @return 1 if some messages */ int SomeMessages(void); @@ -192,7 +193,7 @@ public: /** Returns the version number of JSBSim. * @return The version number of JSBSim. */ - string GetVersion(void) {return JSBSim_version;} + std::string GetVersion(void) {return JSBSim_version;} /// Disables highlighting in the console output. void disableHighLighting(void); @@ -268,7 +269,7 @@ public: @return if the two values can be considered equal up to roundoff */ static bool EqualToRoundoff(double a, double b) { double eps = 2.0*DBL_EPSILON; - return fabs(a - b) <= eps*max(fabs(a), fabs(b)); + return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b)); } /** Finite precision comparison. @@ -277,7 +278,7 @@ public: @return if the two values can be considered equal up to roundoff */ static bool EqualToRoundoff(float a, float b) { float eps = 2.0*FLT_EPSILON; - return fabs(a - b) <= eps*max(fabs(a), fabs(b)); + return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b)); } /** Finite precision comparison. @@ -331,44 +332,12 @@ protected: static const double slugtolb; static const double kgtolb; static const double kgtoslug; - static const string needed_cfg_version; - static const string JSBSim_version; + static const std::string needed_cfg_version; + static const std::string JSBSim_version; - static string CreateIndexedPropertyName(string Property, int index) - { - std::stringstream str; - str << index; - string tmp; - str >> tmp; - return Property + "[" + tmp + "]"; - } + static std::string CreateIndexedPropertyName(const std::string& Property, int index); - static double GaussianRandomNumber(void) - { - static double V1, V2, S; - static int phase = 0; - double X; - - if (phase == 0) { - V1 = V2 = S = X = 0.0; - - do { - double U1 = (double)rand() / RAND_MAX; - double U2 = (double)rand() / RAND_MAX; - - V1 = 2 * U1 - 1; - V2 = 2 * U2 - 1; - S = V1 * V1 + V2 * V2; - } while(S >= 1 || S == 0); - - X = V1 * sqrt(-2 * log(S) / S); - } else - X = V2 * sqrt(-2 * log(S) / S); - - phase = 1 - phase; - - return X; - } + static double GaussianRandomNumber(void); public: /// Moments L, M, N diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index f9c19d37f..372d01e79 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -37,9 +37,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include +#include #include "FGState.h" +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; diff --git a/src/FDM/JSBSim/FGState.h b/src/FDM/JSBSim/FGState.h index c1b6f7281..9fd627eba 100644 --- a/src/FDM/JSBSim/FGState.h +++ b/src/FDM/JSBSim/FGState.h @@ -45,18 +45,18 @@ INCLUDES #include #include #include "FGJSBBase.h" -#include -#include -#include +#include "initialization/FGInitialCondition.h" +#include "math/FGColumnVector3.h" +#include "math/FGQuaternion.h" #include "FGFDMExec.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "models/FGAtmosphere.h" +#include "models/FGFCS.h" +#include "models/FGPropagate.h" +#include "models/FGAuxiliary.h" +#include "models/FGAerodynamics.h" +#include "models/FGAircraft.h" +#include "models/FGGroundReactions.h" +#include "models/FGPropulsion.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index abab0414d..15daa8e22 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -258,6 +258,10 @@ FGJSBsim::FGJSBsim( double dt ) speedbrake_pos_pct->setDoubleValue(0); spoilers_pos_pct->setDoubleValue(0); + ab_brake_engaged = fgGetNode("/autopilot/autobrake/engaged", true); + ab_brake_left_pct = fgGetNode("/autopilot/autobrake/brake-left-output", true); + ab_brake_right_pct = fgGetNode("/autopilot/autobrake/brake-right-output", true); + temperature = fgGetNode("/environment/temperature-degc",true); pressure = fgGetNode("/environment/pressure-inhg",true); density = fgGetNode("/environment/density-slugft3",true); @@ -542,8 +546,18 @@ bool FGJSBsim::copy_to_JSBsim() // Parking brake sets minimum braking // level for mains. double parking_brake = globals->get_controls()->get_brake_parking(); - FCS->SetLBrake(FMAX(globals->get_controls()->get_brake_left(), parking_brake)); - FCS->SetRBrake(FMAX(globals->get_controls()->get_brake_right(), parking_brake)); + double left_brake = globals->get_controls()->get_brake_left(); + double right_brake = globals->get_controls()->get_brake_right(); + + if (ab_brake_engaged->getBoolValue()) { + left_brake = ab_brake_left_pct->getDoubleValue(); + right_brake = ab_brake_right_pct->getDoubleValue(); + } + + FCS->SetLBrake(FMAX(left_brake, parking_brake)); + FCS->SetRBrake(FMAX(right_brake, parking_brake)); + + FCS->SetCBrake( 0.0 ); // FCS->SetCBrake( globals->get_controls()->get_brake(2) ); @@ -741,9 +755,7 @@ bool FGJSBsim::copy_from_JSBsim() // Copy the engine values from JSBSim. for ( i=0; i < Propulsion->GetNumEngines(); i++ ) { SGPropertyNode * node = fgGetNode("engines/engine", i, true); - char buf[30]; - sprintf(buf, "engines/engine[%d]/thruster", i); - SGPropertyNode * tnode = fgGetNode(buf, true); + SGPropertyNode * tnode = node->getChild("thruster", 0, true); FGThruster * thruster = Propulsion->GetEngine(i)->GetThruster(); switch (Propulsion->GetEngine(i)->GetType()) { diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx index 084d53d4c..d6f5f1b8c 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -254,6 +254,10 @@ private: SGPropertyNode_ptr speedbrake_pos_pct; SGPropertyNode_ptr spoilers_pos_pct; + SGPropertyNode_ptr ab_brake_engaged; + SGPropertyNode_ptr ab_brake_left_pct; + SGPropertyNode_ptr ab_brake_right_pct; + SGPropertyNode_ptr gear_pos_pct; SGPropertyNode_ptr wing_fold_pos_pct; SGPropertyNode_ptr tailhook_pos_pct; diff --git a/src/FDM/JSBSim/initialization/FGInitialCondition.cpp b/src/FDM/JSBSim/initialization/FGInitialCondition.cpp index 10b4b7a3e..7eb3f7f66 100644 --- a/src/FDM/JSBSim/initialization/FGInitialCondition.cpp +++ b/src/FDM/JSBSim/initialization/FGInitialCondition.cpp @@ -43,16 +43,21 @@ INCLUDES *******************************************************************************/ #include "FGInitialCondition.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "FGFDMExec.h" +#include "models/FGInertial.h" +#include "models/FGAtmosphere.h" +#include "models/FGAerodynamics.h" +#include "models/FGPropagate.h" +#include "input_output/FGPropertyManager.h" +#include "input_output/FGXMLElement.h" +#include "models/FGPropulsion.h" +#include "input_output/FGXMLParse.h" +#include "math/FGQuaternion.h" +#include #include +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/initialization/FGInitialCondition.h b/src/FDM/JSBSim/initialization/FGInitialCondition.h index 86de126a0..898acc3fd 100644 --- a/src/FDM/JSBSim/initialization/FGInitialCondition.h +++ b/src/FDM/JSBSim/initialization/FGInitialCondition.h @@ -47,10 +47,10 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include +#include "FGFDMExec.h" +#include "FGJSBBase.h" +#include "math/FGColumnVector3.h" +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/initialization/FGTrim.cpp b/src/FDM/JSBSim/initialization/FGTrim.cpp index ed69050cd..2f425b769 100644 --- a/src/FDM/JSBSim/initialization/FGTrim.cpp +++ b/src/FDM/JSBSim/initialization/FGTrim.cpp @@ -44,19 +44,21 @@ INCLUDES #include #include #include "FGTrim.h" -#include +#include "models/FGAtmosphere.h" #include "FGInitialCondition.h" -#include -#include -#include -#include -#include -#include +#include "models/FGAircraft.h" +#include "models/FGMassBalance.h" +#include "models/FGGroundReactions.h" +#include "models/FGInertial.h" +#include "models/FGAerodynamics.h" +#include "math/FGColumnVector3.h" #if _MSC_VER #pragma warning (disable : 4786 4788) #endif +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; diff --git a/src/FDM/JSBSim/initialization/FGTrimAxis.cpp b/src/FDM/JSBSim/initialization/FGTrimAxis.cpp index 5124c31bb..186b9b1df 100644 --- a/src/FDM/JSBSim/initialization/FGTrimAxis.cpp +++ b/src/FDM/JSBSim/initialization/FGTrimAxis.cpp @@ -38,13 +38,20 @@ INCLUDES #include #include -#include -#include +#include +#include "FGFDMExec.h" +#include "models/FGAtmosphere.h" #include "FGInitialCondition.h" #include "FGTrimAxis.h" -#include -#include -#include +#include "models/FGAircraft.h" +#include "models/FGPropulsion.h" +#include "models/FGAerodynamics.h" +#include "models/FGFCS.h" +#include "models/propulsion/FGEngine.h" +#include "models/FGAuxiliary.h" +#include "models/FGGroundReactions.h" + +using namespace std; namespace JSBSim { @@ -427,13 +434,11 @@ void FGTrimAxis::setThrottlesPct(void) { /*****************************************************************************/ void FGTrimAxis::AxisReport(void) { - - char out[80]; - - sprintf(out," %20s: %6.2f %5s: %9.2e Tolerance: %3.0e", - GetControlName().c_str(), GetControl()*control_convert, - GetStateName().c_str(), GetState()+state_target, GetTolerance()); - cout << out; + cout << " " << setw(20) << GetControlName() << ": "; + cout << setw(6) << setprecision(2) << GetControl()*control_convert << ' '; + cout << setw(5) << GetStateName() << ": "; + cout << setw(9) << setprecision(2) << scientific << GetState()+state_target; + cout << " Tolerance: " << setw(3) << setprecision(0) << scientific << GetTolerance(); if( fabs(GetState()+state_target) < fabs(GetTolerance()) ) cout << " Passed" << endl; diff --git a/src/FDM/JSBSim/input_output/FGGroundCallback.cpp b/src/FDM/JSBSim/input_output/FGGroundCallback.cpp index 8976d7a52..d1484115c 100644 --- a/src/FDM/JSBSim/input_output/FGGroundCallback.cpp +++ b/src/FDM/JSBSim/input_output/FGGroundCallback.cpp @@ -31,8 +31,8 @@ HISTORY SENTRY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include +#include "math/FGColumnVector3.h" +#include "math/FGLocation.h" #include "FGGroundCallback.h" namespace JSBSim { diff --git a/src/FDM/JSBSim/input_output/FGGroundCallback.h b/src/FDM/JSBSim/input_output/FGGroundCallback.h index bb36e650c..4def8c1ca 100644 --- a/src/FDM/JSBSim/input_output/FGGroundCallback.h +++ b/src/FDM/JSBSim/input_output/FGGroundCallback.h @@ -38,8 +38,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include +#include "math/FGColumnVector3.h" +#include "math/FGLocation.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.h b/src/FDM/JSBSim/input_output/FGPropertyManager.h index 40c173fcd..2db5408e3 100644 --- a/src/FDM/JSBSim/input_output/FGPropertyManager.h +++ b/src/FDM/JSBSim/input_output/FGPropertyManager.h @@ -42,10 +42,9 @@ INCLUDES #endif #include -#include -#include +#include "simgear/props/props.hxx" #if !PROPS_STANDALONE -# include +# include "simgear/math/SGMath.hxx" #endif #include "FGJSBBase.h" @@ -60,8 +59,6 @@ DEFINITIONS FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -using namespace std; - namespace JSBSim { /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -93,7 +90,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * NOTE: this function changes its argument and thus relies * on pass by value */ - string mkPropertyName(string name, bool lowercase); + std::string mkPropertyName(std::string name, bool lowercase); /** * Get a property node. @@ -103,10 +100,10 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @return The node, or 0 if none exists and none was created. */ FGPropertyManager* - GetNode (const string &path, bool create = false); + GetNode (const std::string &path, bool create = false); FGPropertyManager* - GetNode (const string &relpath, int index, bool create = false); + GetNode (const std::string &relpath, int index, bool create = false); /** * Test whether a given node exists. @@ -114,23 +111,23 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param path The path of the node, relative to root. * @return true if the node exists, false otherwise. */ - bool HasNode (const string &path); + bool HasNode (const std::string &path); /** * Get the name of a node */ - string GetName( void ); + std::string GetName( void ); /** * Get the name of a node without underscores, etc. */ - string GetPrintableName( void ); + std::string GetPrintableName( void ); /** * Get the fully qualified name of a node * This function is very slow, so is probably useful for debugging only. */ - string GetFullyQualifiedName(void); + std::string GetFullyQualifiedName(void); /** * Get a bool value for a property. @@ -146,7 +143,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as a bool, or the default value provided. */ - bool GetBool (const string &name, bool defaultValue = false); + bool GetBool (const std::string &name, bool defaultValue = false); /** @@ -163,7 +160,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as an int, or the default value provided. */ - int GetInt (const string &name, int defaultValue = 0); + int GetInt (const std::string &name, int defaultValue = 0); /** @@ -180,7 +177,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as a long, or the default value provided. */ - int GetLong (const string &name, long defaultValue = 0L); + int GetLong (const std::string &name, long defaultValue = 0L); /** @@ -197,7 +194,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as a float, or the default value provided. */ - float GetFloat (const string &name, float defaultValue = 0.0); + float GetFloat (const std::string &name, float defaultValue = 0.0); /** @@ -214,7 +211,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as a double, or the default value provided. */ - double GetDouble (const string &name, double defaultValue = 0.0); + double GetDouble (const std::string &name, double defaultValue = 0.0); /** @@ -231,7 +228,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * does not exist. * @return The property's value as a string, or the default value provided. */ - string GetString (const string &name, string defaultValue = ""); + std::string GetString (const std::string &name, std::string defaultValue = ""); /** @@ -247,7 +244,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetBool (const string &name, bool val); + bool SetBool (const std::string &name, bool val); /** @@ -263,7 +260,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetInt (const string &name, int val); + bool SetInt (const std::string &name, int val); /** @@ -279,7 +276,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetLong (const string &name, long val); + bool SetLong (const std::string &name, long val); /** @@ -295,7 +292,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetFloat (const string &name, float val); + bool SetFloat (const std::string &name, float val); /** @@ -311,7 +308,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetDouble (const string &name, double val); + bool SetDouble (const std::string &name, double val); /** @@ -327,7 +324,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param val The new value for the property. * @return true if the assignment succeeded, false otherwise. */ - bool SetString (const string &name, const string &val); + bool SetString (const std::string &name, const std::string &val); //////////////////////////////////////////////////////////////////////// @@ -347,7 +344,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param name The property name. * @param state The state of the archive attribute (defaults to true). */ - void SetArchivable (const string &name, bool state = true); + void SetArchivable (const std::string &name, bool state = true); /** @@ -362,7 +359,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param name The property name. * @param state The state of the read attribute (defaults to true). */ - void SetReadable (const string &name, bool state = true); + void SetReadable (const std::string &name, bool state = true); /** @@ -377,7 +374,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * @param name The property name. * @param state The state of the write attribute (defaults to true). */ - void SetWritable (const string &name, bool state = true); + void SetWritable (const std::string &name, bool state = true); //////////////////////////////////////////////////////////////////////// @@ -391,7 +388,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * Classes should use this function to release control of any * properties they are managing. */ - void Untie (const string &name); + void Untie (const std::string &name); // Templates cause ambiguity here @@ -409,7 +406,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * be modified; defaults to true. */ void - Tie (const string &name, bool *pointer, bool useDefault = true); + Tie (const std::string &name, bool *pointer, bool useDefault = true); /** @@ -425,7 +422,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * be modified; defaults to true. */ void - Tie (const string &name, int *pointer, bool useDefault = true); + Tie (const std::string &name, int *pointer, bool useDefault = true); /** @@ -441,7 +438,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * be modified; defaults to true. */ void - Tie (const string &name, long *pointer, bool useDefault = true); + Tie (const std::string &name, long *pointer, bool useDefault = true); /** @@ -457,7 +454,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * be modified; defaults to true. */ void - Tie (const string &name, float *pointer, bool useDefault = true); + Tie (const std::string &name, float *pointer, bool useDefault = true); /** * Tie a property to an external double variable. @@ -472,7 +469,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * be modified; defaults to true. */ void - Tie (const string &name, double *pointer, bool useDefault = true); + Tie (const std::string &name, double *pointer, bool useDefault = true); //============================================================================ // @@ -482,19 +479,19 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase //============================================================================ /* template void - Tie (const string &name, V (*getter)(), void (*setter)(V) = 0, + Tie (const std::string &name, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true); template void - Tie (const string &name, int index, V (*getter)(int), + Tie (const std::string &name, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true); template void - Tie (const string &name, T * obj, V (T::*getter)() const, + Tie (const std::string &name, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true); template void - Tie (const string &name, T * obj, int index, + Tie (const std::string &name, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true); */ @@ -516,12 +513,12 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase */ template inline void - Tie (const string &name, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true) + Tie (const std::string &name, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true) { if (!tie(name.c_str(), SGRawValueFunctions(getter, setter), useDefault)) - cout << "Failed to tie property " << name << " to functions" << endl; + std::cout << "Failed to tie property " << name << " to functions" << std::endl; else if (debug_lvl & 0x20) - cout << name << endl; + std::cout << name << std::endl; } @@ -543,13 +540,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * property value should there be one; false if the old value should be * discarded; defaults to true. */ - template inline void Tie (const string &name, int index, V (*getter)(int), + template inline void Tie (const std::string &name, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true) { if (!tie(name.c_str(), SGRawValueFunctionsIndexed(index, getter, setter), useDefault)) - cout << "Failed to tie property " << name << " to indexed functions" << endl; + std::cout << "Failed to tie property " << name << " to indexed functions" << std::endl; else if (debug_lvl & 0x20) - cout << name << endl; + std::cout << name << std::endl; } @@ -573,13 +570,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * discarded; defaults to true. */ template inline void - Tie (const string &name, T * obj, V (T::*getter)() const, + Tie (const std::string &name, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) { if (!tie(name.c_str(), SGRawValueMethods(*obj, getter, setter), useDefault)) - cout << "Failed to tie property " << name << " to object methods" << endl; + std::cout << "Failed to tie property " << name << " to object methods" << std::endl; else if (debug_lvl & 0x20) - cout << name << endl; + std::cout << name << std::endl; } /** @@ -602,13 +599,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase * discarded; defaults to true. */ template inline void - Tie (const string &name, T * obj, int index, V (T::*getter)(int) const, + Tie (const std::string &name, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true) { if (!tie(name.c_str(), SGRawValueMethodsIndexed(*obj, index, getter, setter), useDefault)) - cout << "Failed to tie property " << name << " to indexed object methods" << endl; + std::cout << "Failed to tie property " << name << " to indexed object methods" << std::endl; else if (debug_lvl & 0x20) - cout << name << endl; + std::cout << name << std::endl; } }; } diff --git a/src/FDM/JSBSim/input_output/FGScript.cpp b/src/FDM/JSBSim/input_output/FGScript.cpp index e0fff6a13..dde76de95 100755 --- a/src/FDM/JSBSim/input_output/FGScript.cpp +++ b/src/FDM/JSBSim/input_output/FGScript.cpp @@ -42,10 +42,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGScript.h" -#include -#include +#include "input_output/FGXMLParse.h" +#include "initialization/FGTrim.h" #include +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/input_output/FGScript.h b/src/FDM/JSBSim/input_output/FGScript.h index 41037c1d9..4dc5c8cf9 100644 --- a/src/FDM/JSBSim/input_output/FGScript.h +++ b/src/FDM/JSBSim/input_output/FGScript.h @@ -40,10 +40,10 @@ INCLUDES #include "FGJSBBase.h" #include "FGState.h" #include "FGFDMExec.h" -#include -#include +#include "math/FGFunction.h" +#include "math/FGCondition.h" #include -#include +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/input_output/FGXMLElement.cpp b/src/FDM/JSBSim/input_output/FGXMLElement.cpp index f4f628e8b..df541fa3a 100755 --- a/src/FDM/JSBSim/input_output/FGXMLElement.cpp +++ b/src/FDM/JSBSim/input_output/FGXMLElement.cpp @@ -32,6 +32,9 @@ INCLUDES #include #include +#include + +using namespace std; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -42,159 +45,171 @@ namespace JSBSim { static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_XMLELEMENT; +bool Element::converterIsInitialized = false; +map > Element::convert; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -Element::Element(string nm) +Element::Element(const string& nm) { name = nm; parent = 0L; element_index = 0; - // convert ["from"]["to"] = factor, so: from * factor = to - // Length - convert["M"]["FT"] = 3.2808399; - convert["FT"]["M"] = 1.0/convert["M"]["FT"]; - convert["FT"]["IN"] = 12.0; - convert["IN"]["FT"] = 1.0/convert["FT"]["IN"]; - convert["IN"]["M"] = convert["IN"]["FT"] * convert["FT"]["M"]; - convert["M"]["IN"] = convert["M"]["FT"] * convert["FT"]["IN"]; - // Area - convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"]; - convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"]; - convert["M2"]["IN2"] = convert["M"]["IN"]*convert["M"]["IN"]; - convert["IN2"]["M2"] = 1.0/convert["M2"]["IN2"]; - convert["FT2"]["IN2"] = 144.0; - convert["IN2"]["FT2"] = 1.0/convert["FT2"]["IN2"]; - // Volume - convert["IN3"]["CC"] = 16.387064; - convert["CC"]["IN3"] = 1.0/convert["IN3"]["CC"]; - convert["FT3"]["IN3"] = 1728.0; - convert["IN3"]["FT3"] = 1.0/convert["FT3"]["IN3"]; - convert["M3"]["FT3"] = 35.3146667; - convert["FT3"]["M3"] = 1.0/convert["M3"]["FT3"]; - convert["LTR"]["IN3"] = 61.0237441; - convert["IN3"]["LTR"] = 1.0/convert["LTR"]["IN3"]; - // Mass & Weight - convert["LBS"]["KG"] = 0.45359237; - convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"]; - convert["SLUG"]["KG"] = 14.59390; - convert["KG"]["SLUG"] = 1.0/convert["SLUG"]["KG"]; - // Moments of Inertia - convert["SLUG*FT2"]["KG*M2"] = 1.35594; - convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"]; - // Angles - convert["RAD"]["DEG"] = 360.0/(2.0*3.1415926); - convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"]; - // Spring force - convert["LBS/FT"]["N/M"] = 14.5939; - convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"]; - // Damping force - convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939; - convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"]; - // Damping force (Square Law) - convert["LBS/FT2/SEC2"]["N/M2/SEC2"] = 47.880259; - convert["N/M2/SEC2"]["LBS/FT2/SEC2"] = 1.0/convert["LBS/FT2/SEC2"]["N/M2/SEC2"]; - // Power - convert["WATTS"]["HP"] = 0.001341022; - convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"]; - // Force - convert["N"]["LBS"] = 0.22482; - convert["LBS"]["N"] = 1.0/convert["N"]["LBS"]; - // Velocity - convert["KTS"]["FT/SEC"] = 1.68781; - convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"]; - convert["M/S"]["FT/S"] = 3.2808399; - convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"]; - // Torque - convert["FT*LBS"]["N*M"] = 1.35581795; - convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"]; - // Valve - convert["M4*SEC/KG"]["FT4*SEC/SLUG"] = convert["M"]["FT"]*convert["M"]["FT"]* - convert["M"]["FT"]*convert["M"]["FT"]/convert["KG"]["SLUG"]; - convert["FT4*SEC/SLUG"]["M4*SEC/KG"] = - 1.0/convert["M4*SEC/KG"]["FT4*SEC/SLUG"]; - // Pressure - convert["INHG"]["PSF"] = 70.7180803; - convert["PSF"]["INHG"] = 1.0/convert["INHG"]["PSF"]; - convert["ATM"]["INHG"] = 29.9246899; - convert["INHG"]["ATM"] = 1.0/convert["ATM"]["INHG"]; - convert["PSI"]["INHG"] = 2.03625437; - convert["INHG"]["PSI"] = 1.0/convert["PSI"]["INHG"]; - convert["INHG"]["PA"] = 3386.0; // inches Mercury to pascals - convert["PA"]["INHG"] = 1.0/convert["INHG"]["PA"]; - convert["LBS/FT2"]["N/M2"] = 14.5939/convert["FT"]["M"]; - convert["N/M2"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["N/M2"]; - convert["LBS/FT2"]["PA"] = convert["LBS/FT2"]["N/M2"]; - convert["PA"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["PA"]; - // Mass flow - convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"]; - // Fuel Consumption - convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083; - convert["KG/KW*HR"]["LBS/HP*HR"] = 1.0/convert["LBS/HP*HR"]["KG/KW*HR"]; + if (!converterIsInitialized) { + converterIsInitialized = true; + // convert ["from"]["to"] = factor, so: from * factor = to + // Length + convert["M"]["FT"] = 3.2808399; + convert["FT"]["M"] = 1.0/convert["M"]["FT"]; + convert["FT"]["IN"] = 12.0; + convert["IN"]["FT"] = 1.0/convert["FT"]["IN"]; + convert["IN"]["M"] = convert["IN"]["FT"] * convert["FT"]["M"]; + convert["M"]["IN"] = convert["M"]["FT"] * convert["FT"]["IN"]; + // Area + convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"]; + convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"]; + convert["M2"]["IN2"] = convert["M"]["IN"]*convert["M"]["IN"]; + convert["IN2"]["M2"] = 1.0/convert["M2"]["IN2"]; + convert["FT2"]["IN2"] = 144.0; + convert["IN2"]["FT2"] = 1.0/convert["FT2"]["IN2"]; + // Volume + convert["IN3"]["CC"] = 16.387064; + convert["CC"]["IN3"] = 1.0/convert["IN3"]["CC"]; + convert["FT3"]["IN3"] = 1728.0; + convert["IN3"]["FT3"] = 1.0/convert["FT3"]["IN3"]; + convert["M3"]["FT3"] = 35.3146667; + convert["FT3"]["M3"] = 1.0/convert["M3"]["FT3"]; + convert["LTR"]["IN3"] = 61.0237441; + convert["IN3"]["LTR"] = 1.0/convert["LTR"]["IN3"]; + // Mass & Weight + convert["LBS"]["KG"] = 0.45359237; + convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"]; + convert["SLUG"]["KG"] = 14.59390; + convert["KG"]["SLUG"] = 1.0/convert["SLUG"]["KG"]; + // Moments of Inertia + convert["SLUG*FT2"]["KG*M2"] = 1.35594; + convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"]; + // Angles + convert["RAD"]["DEG"] = 360.0/(2.0*3.1415926); + convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"]; + // Spring force + convert["LBS/FT"]["N/M"] = 14.5939; + convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"]; + // Damping force + convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939; + convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"]; + // Damping force (Square Law) + convert["LBS/FT2/SEC2"]["N/M2/SEC2"] = 47.880259; + convert["N/M2/SEC2"]["LBS/FT2/SEC2"] = 1.0/convert["LBS/FT2/SEC2"]["N/M2/SEC2"]; + // Power + convert["WATTS"]["HP"] = 0.001341022; + convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"]; + // Force + convert["N"]["LBS"] = 0.22482; + convert["LBS"]["N"] = 1.0/convert["N"]["LBS"]; + // Velocity + convert["KTS"]["FT/SEC"] = 1.68781; + convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"]; + convert["M/S"]["FT/S"] = 3.2808399; + convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"]; + // Torque + convert["FT*LBS"]["N*M"] = 1.35581795; + convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"]; + // Valve + convert["M4*SEC/KG"]["FT4*SEC/SLUG"] = convert["M"]["FT"]*convert["M"]["FT"]* + convert["M"]["FT"]*convert["M"]["FT"]/convert["KG"]["SLUG"]; + convert["FT4*SEC/SLUG"]["M4*SEC/KG"] = + 1.0/convert["M4*SEC/KG"]["FT4*SEC/SLUG"]; + // Pressure + convert["INHG"]["PSF"] = 70.7180803; + convert["PSF"]["INHG"] = 1.0/convert["INHG"]["PSF"]; + convert["ATM"]["INHG"] = 29.9246899; + convert["INHG"]["ATM"] = 1.0/convert["ATM"]["INHG"]; + convert["PSI"]["INHG"] = 2.03625437; + convert["INHG"]["PSI"] = 1.0/convert["PSI"]["INHG"]; + convert["INHG"]["PA"] = 3386.0; // inches Mercury to pascals + convert["PA"]["INHG"] = 1.0/convert["INHG"]["PA"]; + convert["LBS/FT2"]["N/M2"] = 14.5939/convert["FT"]["M"]; + convert["N/M2"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["N/M2"]; + convert["LBS/FT2"]["PA"] = convert["LBS/FT2"]["N/M2"]; + convert["PA"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["PA"]; + // Mass flow + convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"]; + // Fuel Consumption + convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083; + convert["KG/KW*HR"]["LBS/HP*HR"] = 1.0/convert["LBS/HP*HR"]["KG/KW*HR"]; + // Density + convert["KG/L"]["LBS/GAL"] = 8.3454045; + convert["LBS/GAL"]["KG/L"] = 1.0/convert["KG/L"]["LBS/GAL"]; - // Length - convert["M"]["M"] = 1.00; - convert["FT"]["FT"] = 1.00; - convert["IN"]["IN"] = 1.00; - // Area - convert["M2"]["M2"] = 1.00; - convert["FT2"]["FT2"] = 1.00; - // Volume - convert["IN3"]["IN3"] = 1.00; - convert["CC"]["CC"] = 1.0; - convert["M3"]["M3"] = 1.0; - convert["FT3"]["FT3"] = 1.0; - convert["LTR"]["LTR"] = 1.0; - // Mass & Weight - convert["KG"]["KG"] = 1.00; - convert["LBS"]["LBS"] = 1.00; - // Moments of Inertia - convert["KG*M2"]["KG*M2"] = 1.00; - convert["SLUG*FT2"]["SLUG*FT2"] = 1.00; - // Angles - convert["DEG"]["DEG"] = 1.00; - convert["RAD"]["RAD"] = 1.00; - // Spring force - convert["LBS/FT"]["LBS/FT"] = 1.00; - convert["N/M"]["N/M"] = 1.00; - // Damping force - convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00; - convert["N/M/SEC"]["N/M/SEC"] = 1.00; - // Damping force (Square law) - convert["LBS/FT2/SEC2"]["LBS/FT2/SEC2"] = 1.00; - convert["N/M2/SEC2"]["N/M2/SEC2"] = 1.00; - // Power - convert["HP"]["HP"] = 1.00; - convert["WATTS"]["WATTS"] = 1.00; - // Force - convert["N"]["N"] = 1.00; - // Velocity - convert["FT/SEC"]["FT/SEC"] = 1.00; - convert["KTS"]["KTS"] = 1.00; - convert["M/S"]["M/S"] = 1.0; - // Torque - convert["FT*LBS"]["FT*LBS"] = 1.00; - convert["N*M"]["N*M"] = 1.00; - // Valve - convert["M4*SEC/KG"]["M4*SEC/KG"] = 1.0; - convert["FT4*SEC/SLUG"]["FT4*SEC/SLUG"] = 1.0; - // Pressure - convert["PSI"]["PSI"] = 1.00; - convert["PSF"]["PSF"] = 1.00; - convert["INHG"]["INHG"] = 1.00; - convert["ATM"]["ATM"] = 1.0; - convert["PA"]["PA"] = 1.0; - convert["N/M2"]["N/M2"] = 1.00; - convert["LBS/FT2"]["LBS/FT2"] = 1.00; - // Mass flow - convert["LBS/SEC"]["LBS/SEC"] = 1.00; - convert["KG/MIN"]["KG/MIN"] = 1.0; - convert["LBS/MIN"]["LBS/MIN"] = 1.0; - // Fuel Consumption - convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0; - convert["KG/KW*HR"]["KG/KW*HR"] = 1.0; + // Length + convert["M"]["M"] = 1.00; + convert["FT"]["FT"] = 1.00; + convert["IN"]["IN"] = 1.00; + // Area + convert["M2"]["M2"] = 1.00; + convert["FT2"]["FT2"] = 1.00; + // Volume + convert["IN3"]["IN3"] = 1.00; + convert["CC"]["CC"] = 1.0; + convert["M3"]["M3"] = 1.0; + convert["FT3"]["FT3"] = 1.0; + convert["LTR"]["LTR"] = 1.0; + // Mass & Weight + convert["KG"]["KG"] = 1.00; + convert["LBS"]["LBS"] = 1.00; + // Moments of Inertia + convert["KG*M2"]["KG*M2"] = 1.00; + convert["SLUG*FT2"]["SLUG*FT2"] = 1.00; + // Angles + convert["DEG"]["DEG"] = 1.00; + convert["RAD"]["RAD"] = 1.00; + // Spring force + convert["LBS/FT"]["LBS/FT"] = 1.00; + convert["N/M"]["N/M"] = 1.00; + // Damping force + convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00; + convert["N/M/SEC"]["N/M/SEC"] = 1.00; + // Damping force (Square law) + convert["LBS/FT2/SEC2"]["LBS/FT2/SEC2"] = 1.00; + convert["N/M2/SEC2"]["N/M2/SEC2"] = 1.00; + // Power + convert["HP"]["HP"] = 1.00; + convert["WATTS"]["WATTS"] = 1.00; + // Force + convert["N"]["N"] = 1.00; + // Velocity + convert["FT/SEC"]["FT/SEC"] = 1.00; + convert["KTS"]["KTS"] = 1.00; + convert["M/S"]["M/S"] = 1.0; + // Torque + convert["FT*LBS"]["FT*LBS"] = 1.00; + convert["N*M"]["N*M"] = 1.00; + // Valve + convert["M4*SEC/KG"]["M4*SEC/KG"] = 1.0; + convert["FT4*SEC/SLUG"]["FT4*SEC/SLUG"] = 1.0; + // Pressure + convert["PSI"]["PSI"] = 1.00; + convert["PSF"]["PSF"] = 1.00; + convert["INHG"]["INHG"] = 1.00; + convert["ATM"]["ATM"] = 1.0; + convert["PA"]["PA"] = 1.0; + convert["N/M2"]["N/M2"] = 1.00; + convert["LBS/FT2"]["LBS/FT2"] = 1.00; + // Mass flow + convert["LBS/SEC"]["LBS/SEC"] = 1.00; + convert["KG/MIN"]["KG/MIN"] = 1.0; + convert["LBS/MIN"]["LBS/MIN"] = 1.0; + // Fuel Consumption + convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0; + convert["KG/KW*HR"]["KG/KW*HR"] = 1.0; + // Density + convert["KG/L"]["KG/L"] = 1.0; + convert["LBS/GAL"]["LBS/GAL"] = 1.0; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -209,7 +224,7 @@ Element::~Element(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string Element::GetAttributeValue(string attr) +string Element::GetAttributeValue(const string& attr) { int select=-1; for (unsigned int i=0; i= 1) { element_index = 1; @@ -311,7 +326,7 @@ Element* Element::FindElement(string el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Element* Element::FindNextElement(string el) +Element* Element::FindNextElement(const string& el) { if (el.empty()) { if (element_index < children.size()) { @@ -333,7 +348,7 @@ Element* Element::FindNextElement(string el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double Element::FindElementValueAsNumber(string el) +double Element::FindElementValueAsNumber(const string& el) { Element* element = FindElement(el); if (element) { @@ -346,7 +361,7 @@ double Element::FindElementValueAsNumber(string el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string Element::FindElementValue(string el) +string Element::FindElementValue(const string& el) { Element* element = FindElement(el); if (element) { @@ -358,7 +373,7 @@ string Element::FindElementValue(string el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double Element::FindElementValueAsNumberConvertTo(string el, string target_units) +double Element::FindElementValueAsNumberConvertTo(const string& el, const string& target_units) { Element* element = FindElement(el); @@ -392,9 +407,9 @@ double Element::FindElementValueAsNumberConvertTo(string el, string target_units //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double Element::FindElementValueAsNumberConvertFromTo( string el, - string supplied_units, - string target_units) +double Element::FindElementValueAsNumberConvertFromTo( const string& el, + const string& supplied_units, + const string& target_units) { Element* element = FindElement(el); @@ -426,7 +441,7 @@ double Element::FindElementValueAsNumberConvertFromTo( string el, //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGColumnVector3 Element::FindElementTripletConvertTo( string target_units) +FGColumnVector3 Element::FindElementTripletConvertTo( const string& target_units) { FGColumnVector3 triplet; Element* item; @@ -506,7 +521,7 @@ void Element::Print(unsigned int level) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void Element::AddAttribute(string name, string value) +void Element::AddAttribute(const string& name, const string& value) { attribute_key.push_back(name); attributes[name] = value; @@ -516,8 +531,8 @@ void Element::AddAttribute(string name, string value) void Element::AddData(string d) { - unsigned int string_start = (unsigned int)d.find_first_not_of(" \t"); - if (string_start > 0) { + string::size_type string_start = d.find_first_not_of(" \t"); + if (string_start != string::npos && string_start > 0) { d.erase(0,string_start); } data_lines.push_back(d); diff --git a/src/FDM/JSBSim/input_output/FGXMLElement.h b/src/FDM/JSBSim/input_output/FGXMLElement.h index f8a85bbcd..75add86b7 100755 --- a/src/FDM/JSBSim/input_output/FGXMLElement.h +++ b/src/FDM/JSBSim/input_output/FGXMLElement.h @@ -36,16 +36,9 @@ INCLUDES #include #include -#include #include -using std::string; -using std::map; -using std::vector; -using std::cout; -using std::endl; - -#include +#include "math/FGColumnVector3.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -92,6 +85,7 @@ CLASS DOCUMENTATION - convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"]; - convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083; - convert["KG/KW*HR"]["LBS/HP*HR"] = 1/convert["LBS/HP*HR"]["KG/KW*HR"]; + - convert["KG/L"]["LBS/GAL"] = 8.3454045; - convert["M"]["M"] = 1.00; - convert["FT"]["FT"] = 1.00; @@ -119,6 +113,8 @@ CLASS DOCUMENTATION - convert["LBS/MIN"]["LBS/MIN"] = 1.0; - convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0; - convert["KG/KW*HR"]["KG/KW*HR"] = 1.0; + - convert["KG/L"]["KG/L"] = 1.0; + - convert["LBS/GAL"]["LBS/GAL"] = 1.0; Where: - N = newtons @@ -136,6 +132,8 @@ CLASS DOCUMENTATION - WATTS = watts - HP = horsepower - HR = hour + - L = liter + - GAL = gallon (U.S. liquid) @author Jon S. Berndt @version $Id$ @@ -150,7 +148,7 @@ public: /** Constructor @param nm the name of this element (if given) */ - Element(string nm); + Element(const std::string& nm); /// Destructor ~Element(void); @@ -158,23 +156,23 @@ public: @param key specifies the attribute key to retrieve the value of. @return the key value (as a string), or the empty string if no such attribute exists. */ - string GetAttributeValue(string key); + std::string GetAttributeValue(const std::string& key); /** Retrieves an attribute value as a double precision real number. @param key specifies the attribute key to retrieve the value of. @return the key value (as a number), or the HUGE_VAL if no such attribute exists. */ - double GetAttributeValueAsNumber(string key); + double GetAttributeValueAsNumber(const std::string& key); /** Retrieves the element name. @return the element name, or the empty string if no name has been set.*/ - string GetName(void) {return name;} + const std::string& GetName(void) const {return name;} /** Gets a line of data belonging to an element. @param i the index of the data line to return (0 by default). @return a string representing the data line requested, or the empty string if none exists.*/ - string GetDataLine(unsigned int i=0); + std::string GetDataLine(unsigned int i=0); /// Returns the number of lines of data stored unsigned int GetNumDataLines(void) {return (unsigned int)data_lines.size();} @@ -183,7 +181,7 @@ public: unsigned int GetNumElements(void) {return (unsigned int)children.size();} /// Returns the number of named child elements for this element. - unsigned int GetNumElements(string); + unsigned int GetNumElements(const std::string& element_name); /** Converts the element data to a number. This function attempts to convert the first (and presumably only) line of @@ -221,7 +219,7 @@ public: element counter to the first element. @param el the search string (empty string by default). @return a pointer to the first element that matches the supplied search string. */ - Element* FindElement(string el=""); + Element* FindElement(const std::string& el=""); /** Searches for the next element as specified. This function would be called after FindElement() is first called (in order to @@ -232,7 +230,7 @@ public: @param el the name of the next element to find. @return the pointer to the found element, or 0 if no appropriate element us found.*/ - Element* FindNextElement(string el=""); + Element* FindNextElement(const std::string& el=""); /** Searches for the named element and returns the string data belonging to it. This function allows the data belonging to a named element to be returned @@ -242,7 +240,7 @@ public: default) @return the data value for the named element as a string, or the empty string if the element cannot be found. */ - string FindElementValue(string el=""); + std::string FindElementValue(const std::string& el=""); /** Searches for the named element and returns the data belonging to it as a number. This function allows the data belonging to a named element to be returned @@ -252,7 +250,7 @@ public: default) @return the data value for the named element as a double, or HUGE_VAL if the data is missing. */ - double FindElementValueAsNumber(string el=""); + double FindElementValueAsNumber(const std::string& el=""); /** Searches for the named element and converts and returns the data belonging to it. This function allows the data belonging to a named element to be returned @@ -269,7 +267,7 @@ public: to which the value returned will be converted. @return the unit-converted data value for the named element as a double, or HUGE_VAL if the data is missing. */ - double FindElementValueAsNumberConvertTo(string el, string target_units); + double FindElementValueAsNumberConvertTo(const std::string& el, const std::string& target_units); /** Searches for the named element and converts and returns the data belonging to it. This function allows the data belonging to a named element to be returned @@ -288,9 +286,9 @@ public: to which the value returned will be converted. @return the unit-converted data value for the named element as a double, or HUGE_VAL if the data is missing. */ - double FindElementValueAsNumberConvertFromTo( string el, - string supplied_units, - string target_units); + double FindElementValueAsNumberConvertFromTo( const std::string& el, + const std::string& supplied_units, + const std::string& target_units); /** Composes a 3-element column vector for the supplied location or orientation. This function processes a LOCATION or ORIENTATION construct, returning a @@ -301,7 +299,7 @@ public: @param target_units the string representing the native units used by JSBSim to which the value returned will be converted. @return a column vector object built from the LOCATION or ORIENT components. */ - FGColumnVector3 FindElementTripletConvertTo( string target_units); + FGColumnVector3 FindElementTripletConvertTo( const std::string& target_units); /** This function sets the value of the parent class attribute to the supplied Element pointer. @@ -315,11 +313,11 @@ public: /** Stores an attribute belonging to this element. * @param name The string name of the attribute. * @param value The string value of the attribute. */ - void AddAttribute(string name, string value); + void AddAttribute(const std::string& name, const std::string& value); /** Stores data belonging to this element. * @param d the data to store. */ - void AddData(string d); + void AddData(std::string d); /** Prints the element. * Prints this element and calls the Print routine for child elements. @@ -327,15 +325,16 @@ public: void Print(unsigned int level=0); private: - string name; - map attributes; - vector data_lines; - vector children; - vector attribute_key; + std::string name; + std::map attributes; + std::vector data_lines; + std::vector children; + std::vector attribute_key; Element *parent; unsigned int element_index; - typedef map > tMapConvert; - tMapConvert convert; + typedef std::map > tMapConvert; + static tMapConvert convert; + static bool converterIsInitialized; }; } // namespace JSBSim diff --git a/src/FDM/JSBSim/input_output/FGXMLFileRead.h b/src/FDM/JSBSim/input_output/FGXMLFileRead.h index ce33d8c5b..472a79adc 100755 --- a/src/FDM/JSBSim/input_output/FGXMLFileRead.h +++ b/src/FDM/JSBSim/input_output/FGXMLFileRead.h @@ -35,7 +35,9 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include "input_output/FGXMLParse.h" +#include +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -56,19 +58,19 @@ public: protected: Element* document; - Element* LoadXMLDocument(string XML_filename) + Element* LoadXMLDocument(std::string XML_filename) { - ifstream infile; + std::ifstream infile; if ( !XML_filename.empty() ) { - if (XML_filename.find(".xml") == string::npos) XML_filename += ".xml"; + if (XML_filename.find(".xml") == std::string::npos) XML_filename += ".xml"; infile.open(XML_filename.c_str()); if ( !infile.is_open()) { - cerr << "Could not open file: " << XML_filename << endl; + std::cerr << "Could not open file: " << XML_filename << std::endl; return 0L; } } else { - cerr << "No filename given." << endl; + std::cerr << "No filename given." << std::endl; return 0L; } diff --git a/src/FDM/JSBSim/input_output/FGXMLParse.cpp b/src/FDM/JSBSim/input_output/FGXMLParse.cpp index ffc3d173b..7eefba94f 100755 --- a/src/FDM/JSBSim/input_output/FGXMLParse.cpp +++ b/src/FDM/JSBSim/input_output/FGXMLParse.cpp @@ -30,9 +30,14 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGXMLParse.h" +#include "FGXMLElement.h" +#include +#include #include #include "input_output/string_utilities.h" +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; diff --git a/src/FDM/JSBSim/input_output/FGXMLParse.h b/src/FDM/JSBSim/input_output/FGXMLParse.h index 74580060b..5fdd92b06 100755 --- a/src/FDM/JSBSim/input_output/FGXMLParse.h +++ b/src/FDM/JSBSim/input_output/FGXMLParse.h @@ -34,15 +34,6 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include - -using std::string; -using std::cout; -using std::cerr; -using std::endl; - -#include "FGXMLElement.h" #include "simgear/xml/easyxml.hxx" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -58,6 +49,8 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/input_output/FGfdmSocket.cpp b/src/FDM/JSBSim/input_output/FGfdmSocket.cpp index 365c1916f..85cb88c4f 100644 --- a/src/FDM/JSBSim/input_output/FGfdmSocket.cpp +++ b/src/FDM/JSBSim/input_output/FGfdmSocket.cpp @@ -38,8 +38,17 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include "FGfdmSocket.h" +#include +#include #include +#include +#include "FGfdmSocket.h" +#include "string_utilities.h" + +using std::cout; +using std::cerr; +using std::endl; +using std::string; namespace JSBSim { @@ -50,9 +59,9 @@ static const char *IdHdr = ID_FDMSOCKET; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGfdmSocket::FGfdmSocket(string address, int port, int protocol) +FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol) { - sckt = sckt_in = size = 0; + sckt = sckt_in = 0; connected = false; #if defined(_MSC_VER) || defined(__MINGW32__) @@ -104,9 +113,9 @@ FGfdmSocket::FGfdmSocket(string address, int port, int protocol) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGfdmSocket::FGfdmSocket(string address, int port) +FGfdmSocket::FGfdmSocket(const string& address, int port) { - sckt = sckt_in = size = 0; + sckt = sckt_in = 0; connected = false; #if defined(_MSC_VER) || defined(__MINGW32__) @@ -158,7 +167,6 @@ FGfdmSocket::FGfdmSocket(string address, int port) FGfdmSocket::FGfdmSocket(int port) { - size = 0; connected = false; unsigned long NoBlock = true; @@ -217,9 +225,8 @@ string FGfdmSocket::Receive(void) char buf[1024]; int len = sizeof(struct sockaddr_in); int num_chars=0; - int total_chars = 0; unsigned long NoBlock = true; - string data = ""; // todo: should allocate this with a standard size as a + string data; // todo: should allocate this with a standard size as a // class attribute and pass as a reference? if (sckt_in <= 0) { @@ -239,9 +246,8 @@ string FGfdmSocket::Receive(void) } if (sckt_in > 0) { - while ((num_chars = recv(sckt_in, buf, 1024, 0)) > 0) { - data += string(buf).substr(0,num_chars); - total_chars += num_chars; + while ((num_chars = recv(sckt_in, buf, sizeof buf, 0)) > 0) { + data.append(buf, num_chars); } #if defined(_MSC_VER) @@ -258,12 +264,12 @@ string FGfdmSocket::Receive(void) #endif } - return data.substr(0, total_chars); + return data; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -int FGfdmSocket::Reply(string text) +int FGfdmSocket::Reply(const string& text) { int num_chars_sent=0; @@ -288,71 +294,58 @@ void FGfdmSocket::Close(void) void FGfdmSocket::Clear(void) { - buffer = ""; - size = 0; + buffer.str(string()); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGfdmSocket::Clear(string s) +void FGfdmSocket::Clear(const string& s) { - buffer = s + " "; - size = buffer.size(); + Clear(); + buffer << s << ' '; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGfdmSocket::Append(const char* item) { - if (size == 0) buffer += string(item); - else buffer += string(",") + string(item); - size++; + if (buffer.tellp() > 0) buffer << ','; + buffer << item; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGfdmSocket::Append(double item) { - char s[25]; - - sprintf(s,"%12.7f",item); - - if (size == 0) buffer += string(s); - else buffer += string(",") + string(s); - size++; + if (buffer.tellp() > 0) buffer << ','; + buffer << std::setw(12) << std::setprecision(7) << item; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGfdmSocket::Append(long item) { - char s[25]; - - sprintf(s,"%12ld",item); - - if (size == 0) buffer += string(s); - else buffer += string(",") + string(s); - size++; + if (buffer.tellp() > 0) buffer << ','; + buffer << std::setw(12) << item; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGfdmSocket::Send(void) { - buffer += string("\n"); - if ((send(sckt,buffer.c_str(),buffer.size(),0)) <= 0) { + buffer << '\n'; + string str = buffer.str(); + if ((send(sckt,str.c_str(),str.size(),0)) <= 0) { perror("send"); - } else { } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGfdmSocket::Send(char *data, int length) +void FGfdmSocket::Send(const char *data, int length) { if ((send(sckt,data,length,0)) <= 0) { perror("send"); - } else { } } diff --git a/src/FDM/JSBSim/input_output/FGfdmSocket.h b/src/FDM/JSBSim/input_output/FGfdmSocket.h index fc133473d..46b41ad56 100644 --- a/src/FDM/JSBSim/input_output/FGfdmSocket.h +++ b/src/FDM/JSBSim/input_output/FGfdmSocket.h @@ -39,16 +39,11 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include #include -#include -#include +#include #include #include "FGJSBBase.h" -using std::cout; -using std::endl; - #if defined(_MSC_VER) || defined(__MINGW32__) #include #include @@ -90,27 +85,24 @@ CLASS DOCUMENTATION CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -using std::string; -using std::cerr; - class FGfdmSocket : public FGJSBBase { public: - FGfdmSocket(string, int); - FGfdmSocket(string, int, int); + FGfdmSocket(const std::string&, int); + FGfdmSocket(const std::string&, int, int); FGfdmSocket(int); ~FGfdmSocket(); void Send(void); - void Send(char *data, int length); + void Send(const char *data, int length); - string Receive(void); - int Reply(string text); - void Append(const string s) {Append(s.c_str());} + std::string Receive(void); + int Reply(const std::string& text); + void Append(const std::string& s) {Append(s.c_str());} void Append(const char*); void Append(double); void Append(long); void Clear(void); - void Clear(string s); + void Clear(const std::string& s); void Close(void); bool GetConnectStatus(void) {return connected;} @@ -119,10 +111,9 @@ public: private: int sckt; int sckt_in; - int size; struct sockaddr_in scktName; struct hostent *host; - string buffer; + std::ostringstream buffer; bool connected; void Debug(int from); }; diff --git a/src/FDM/JSBSim/input_output/net_fdm.hxx b/src/FDM/JSBSim/input_output/net_fdm.hxx index 4b4f19741..f649a5f2e 100644 --- a/src/FDM/JSBSim/input_output/net_fdm.hxx +++ b/src/FDM/JSBSim/input_output/net_fdm.hxx @@ -15,12 +15,7 @@ #include // time_t -#ifdef _MSC_VER -typedef unsigned long uint32_t; -typedef long int32_t; -#endif - -//--->>>#include //not required for JSBSim +#include //not required for JSBSim // NOTE: this file defines an external interface structure. Due to diff --git a/src/FDM/JSBSim/input_output/string_utilities.h b/src/FDM/JSBSim/input_output/string_utilities.h index 38ab80628..bc3a152a9 100644 --- a/src/FDM/JSBSim/input_output/string_utilities.h +++ b/src/FDM/JSBSim/input_output/string_utilities.h @@ -4,7 +4,7 @@ Author: Jon S. Berndt Date started: 06/01/09 - ------------- Copyright (C) 2009 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 2009 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -38,8 +38,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -51,8 +51,6 @@ DEFINITIONS FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -using namespace std; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -63,29 +61,30 @@ CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #if !defined(BASE) - extern string& trim_left(string& str); - extern string& trim_right(string& str); - extern string& trim(string& str); - extern string& to_upper(string& str); - extern string& to_lower(string& str); - extern bool is_number(string& str); - vector split(string str, char d); + extern std::string& trim_left(std::string& str); + extern std::string& trim_right(std::string& str); + extern std::string& trim(std::string& str); + extern std::string& to_upper(std::string& str); + extern std::string& to_lower(std::string& str); + extern bool is_number(const std::string& str); + std::vector split(std::string str, char d); #else + #include + + using namespace std; string& trim_left(string& str) { - while ( !isgraph(str[0]) ) { + while (str.size() && !isgraph(str[0])) { str = str.erase(0,1); - if (str.size() == 0) break; } return str; } string& trim_right(string& str) { - while (!isgraph(str[str.size()-1])) { + while (str.size() && !isgraph(str[str.size()-1])) { str = str.erase(str.size()-1,1); - if (str.size() == 0) break; } return str; } @@ -99,17 +98,17 @@ CLASS DECLARATION string& to_upper(string& str) { - for (int i=0; i split(string str, char d) { vector str_array; - int index=0; + size_t index=0; string temp = ""; trim(str); @@ -142,3 +141,4 @@ CLASS DECLARATION //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #endif + diff --git a/src/FDM/JSBSim/math/FGColumnVector3.cpp b/src/FDM/JSBSim/math/FGColumnVector3.cpp index fc7b80595..8a85454e2 100644 --- a/src/FDM/JSBSim/math/FGColumnVector3.cpp +++ b/src/FDM/JSBSim/math/FGColumnVector3.cpp @@ -38,7 +38,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGColumnVector3.h" -#include +#include +#include +#include +#include + +using namespace std; namespace JSBSim { @@ -57,11 +62,13 @@ FGColumnVector3::FGColumnVector3(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGColumnVector3::Dump(string delimeter) const +string FGColumnVector3::Dump(const string& delimiter) const { - char buffer[256]; - sprintf(buffer, "%18.16f%s%18.16f%s%18.16f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3)); - return string(buffer); + ostringstream buffer; + buffer << std::setw(18) << std::setprecision(16) << Entry(1) << delimiter; + buffer << std::setw(18) << std::setprecision(16) << Entry(2) << delimiter; + buffer << std::setw(18) << std::setprecision(16) << Entry(3); + return buffer.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/math/FGColumnVector3.h b/src/FDM/JSBSim/math/FGColumnVector3.h index 9b16a6df1..2817f9571 100644 --- a/src/FDM/JSBSim/math/FGColumnVector3.h +++ b/src/FDM/JSBSim/math/FGColumnVector3.h @@ -39,20 +39,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include #include -#include -#include -#include - -using std::ostream; -using std::istream; -using std::cerr; -using std::cout; -using std::endl; -using std::sqrt; -using std::string; - #include "FGJSBBase.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -149,7 +137,7 @@ public: /** Prints the contents of the vector @param delimeter the item separator (tab or comma) @return a string with the delimeter-separated contents of the vector */ - string Dump(string delimeter) const; + std::string Dump(const std::string& delimeter) const; /** Assignment operator. @param b source vector. @@ -291,7 +279,7 @@ inline FGColumnVector3 operator*(double scalar, const FGColumnVector3& A) { @param os Stream to write to. @param M Matrix to write. Write the matrix to a stream.*/ -ostream& operator<<(ostream& os, const FGColumnVector3& col); +std::ostream& operator<<(std::ostream& os, const FGColumnVector3& col); } // namespace JSBSim diff --git a/src/FDM/JSBSim/math/FGCondition.cpp b/src/FDM/JSBSim/math/FGCondition.cpp index 6f40a72df..ff2f77543 100644 --- a/src/FDM/JSBSim/math/FGCondition.cpp +++ b/src/FDM/JSBSim/math/FGCondition.cpp @@ -35,7 +35,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGCondition.h" -#include +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -91,7 +96,7 @@ FGCondition::FGCondition(Element* element, FGPropertyManager* PropertyManager) : // This constructor is called when there are no nested test groups inside the // condition -FGCondition::FGCondition(string test, FGPropertyManager* PropertyManager) : +FGCondition::FGCondition(const string& test, FGPropertyManager* PropertyManager) : PropertyManager(PropertyManager), isGroup(false) { string property1, property2, compare_string; diff --git a/src/FDM/JSBSim/math/FGCondition.h b/src/FDM/JSBSim/math/FGCondition.h index cc63d117a..6272a8371 100644 --- a/src/FDM/JSBSim/math/FGCondition.h +++ b/src/FDM/JSBSim/math/FGCondition.h @@ -38,9 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include -#include -#include -#include +#include "FGJSBBase.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -54,6 +52,9 @@ FORWARD DECLARATIONS namespace JSBSim { +class FGPropertyManager; +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -69,7 +70,7 @@ class FGCondition : public FGJSBBase { public: FGCondition(Element* element, FGPropertyManager* PropertyManager); - FGCondition(string test, FGPropertyManager* PropertyManager); + FGCondition(const std::string& test, FGPropertyManager* PropertyManager); ~FGCondition(void); bool Evaluate(void); @@ -78,18 +79,18 @@ public: private: enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE}; enum eLogic {elUndef=0, eAND, eOR}; - map mComparison; + std::map mComparison; eLogic Logic; FGPropertyManager *TestParam1, *TestParam2, *PropertyManager; double TestValue; eComparison Comparison; bool isGroup; - string conditional; + std::string conditional; - static string indent; + static std::string indent; - vector conditions; + std::vector conditions; void InitializeConditionals(void); void Debug(int from); diff --git a/src/FDM/JSBSim/math/FGFunction.cpp b/src/FDM/JSBSim/math/FGFunction.cpp index 7a185ec01..1db1e6aec 100755 --- a/src/FDM/JSBSim/math/FGFunction.cpp +++ b/src/FDM/JSBSim/math/FGFunction.cpp @@ -28,12 +28,17 @@ Purpose: Stores various parameter types for functions INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include - +#include +#include +#include #include "FGFunction.h" #include "FGTable.h" #include "FGPropertyValue.h" #include "FGRealValue.h" +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" + +using namespace std; namespace JSBSim { @@ -44,12 +49,11 @@ static const char *IdHdr = ID_FUNCTION; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, string prefix) +FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& prefix) : PropertyManager(propMan), Prefix(prefix) { Element* element; string operation, property_name; - int size = el->GetNumElements(); cached = false; cachedValue = -HUGE_VAL; @@ -320,12 +324,10 @@ double FGFunction::GetValue(void) const string FGFunction::GetValueAsString(void) const { - char buffer[20]; - string value; + ostringstream buffer; - sprintf(buffer,"%9.6f",GetValue()); - value = string(buffer); - return value; + buffer << setw(9) << setprecision(6) << GetValue(); + return buffer.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/math/FGFunction.h b/src/FDM/JSBSim/math/FGFunction.h index a4ba9694b..4c67ba46e 100755 --- a/src/FDM/JSBSim/math/FGFunction.h +++ b/src/FDM/JSBSim/math/FGFunction.h @@ -37,8 +37,6 @@ INCLUDES #include #include #include "FGParameter.h" -#include -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -52,6 +50,9 @@ FORWARD DECLARATIONS namespace JSBSim { +class FGPropertyManager; +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -165,7 +166,7 @@ public: @param prefix an optional prefix to prepend to the name given to the property that represents this function (if given). */ - FGFunction(FGPropertyManager* PropertyManager, Element* element, string prefix=""); + FGFunction(FGPropertyManager* PropertyManager, Element* element, const std::string& prefix=""); /// Destructor. virtual ~FGFunction(); @@ -175,10 +176,10 @@ public: /** The value that the function evaluates to, as a string. @return the value of the function as a string. */ - string GetValueAsString(void) const; + std::string GetValueAsString(void) const; /// Retrieves the name of the function. - string GetName(void) const {return Name;} + std::string GetName(void) const {return Name;} /** Specifies whether to cache the value of the function, so it is calculated only once per frame. @@ -189,44 +190,44 @@ public: void cacheValue(bool shouldCache); private: - vector Parameters; + std::vector Parameters; FGPropertyManager* const PropertyManager; bool cached; - string Prefix; - string description_string; - string property_string; - string value_string; - string table_string; - string p_string; - string v_string; - string t_string; - string function_string; - string sum_string; - string difference_string; - string product_string; - string quotient_string; - string pow_string; - string exp_string; - string abs_string; - string sin_string; - string cos_string; - string tan_string; - string asin_string; - string acos_string; - string atan_string; - string atan2_string; - string min_string; - string max_string; - string avg_string; - string fraction_string; - string mod_string; - string random_string; - string integer_string; + std::string Prefix; + std::string description_string; + std::string property_string; + std::string value_string; + std::string table_string; + std::string p_string; + std::string v_string; + std::string t_string; + std::string function_string; + std::string sum_string; + std::string difference_string; + std::string product_string; + std::string quotient_string; + std::string pow_string; + std::string exp_string; + std::string abs_string; + std::string sin_string; + std::string cos_string; + std::string tan_string; + std::string asin_string; + std::string acos_string; + std::string atan_string; + std::string atan2_string; + std::string min_string; + std::string max_string; + std::string avg_string; + std::string fraction_string; + std::string mod_string; + std::string random_string; + std::string integer_string; double cachedValue; enum functionType {eTopLevel=0, eProduct, eDifference, eSum, eQuotient, ePow, eExp, eAbs, eSin, eCos, eTan, eASin, eACos, eATan, eATan2, eMin, eMax, eAvg, eFrac, eInteger, eMod, eRandom} Type; - string Name; + std::string Name; void bind(void); void Debug(int from); }; diff --git a/src/FDM/JSBSim/math/FGLocation.cpp b/src/FDM/JSBSim/math/FGLocation.cpp index d740d01b1..42619b93f 100644 --- a/src/FDM/JSBSim/math/FGLocation.cpp +++ b/src/FDM/JSBSim/math/FGLocation.cpp @@ -41,7 +41,7 @@ INCLUDES #include #include "FGLocation.h" -#include +#include "input_output/FGPropertyManager.h" namespace JSBSim { diff --git a/src/FDM/JSBSim/math/FGLocation.h b/src/FDM/JSBSim/math/FGLocation.h index e55f31c81..b61ffa966 100644 --- a/src/FDM/JSBSim/math/FGLocation.h +++ b/src/FDM/JSBSim/math/FGLocation.h @@ -39,8 +39,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include +#include "FGJSBBase.h" +#include "input_output/FGPropertyManager.h" #include "FGColumnVector3.h" #include "FGMatrix33.h" diff --git a/src/FDM/JSBSim/math/FGMatrix33.cpp b/src/FDM/JSBSim/math/FGMatrix33.cpp index 91976f100..8f27e88a5 100644 --- a/src/FDM/JSBSim/math/FGMatrix33.cpp +++ b/src/FDM/JSBSim/math/FGMatrix33.cpp @@ -40,6 +40,10 @@ INCLUDES #include "FGMatrix33.h" #include "FGColumnVector3.h" +#include + +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; diff --git a/src/FDM/JSBSim/math/FGMatrix33.h b/src/FDM/JSBSim/math/FGMatrix33.h index 98babfcd0..a31e05d88 100644 --- a/src/FDM/JSBSim/math/FGMatrix33.h +++ b/src/FDM/JSBSim/math/FGMatrix33.h @@ -40,18 +40,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include #include -#include -#include -#include - -using std::ostream; -using std::istream; -using std::cerr; -using std::cout; -using std::endl; -using std::string; +#include #include "FGColumnVector3.h" #include "FGJSBBase.h" @@ -84,7 +74,7 @@ DECLARATION: MatrixException class MatrixException : public FGJSBBase { public: - string Message; + std::string Message; }; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -450,7 +440,7 @@ inline FGMatrix33 operator*(double scalar, const FGMatrix33& A) { Write the matrix to a stream. */ -ostream& operator<<(ostream& os, const FGMatrix33& M); +std::ostream& operator<<(std::ostream& os, const FGMatrix33& M); /** Read matrix from a stream. @@ -459,7 +449,7 @@ ostream& operator<<(ostream& os, const FGMatrix33& M); Read matrix from a stream. */ -istream& operator>>(istream& is, FGMatrix33& M); +std::istream& operator>>(std::istream& is, FGMatrix33& M); } // namespace JSBSim diff --git a/src/FDM/JSBSim/math/FGPropertyValue.h b/src/FDM/JSBSim/math/FGPropertyValue.h index 60ad5f5ce..82803f558 100755 --- a/src/FDM/JSBSim/math/FGPropertyValue.h +++ b/src/FDM/JSBSim/math/FGPropertyValue.h @@ -35,7 +35,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGParameter.h" -#include +#include "input_output/FGPropertyManager.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/math/FGQuaternion.h b/src/FDM/JSBSim/math/FGQuaternion.h index 3607c2064..73c0e009a 100644 --- a/src/FDM/JSBSim/math/FGQuaternion.h +++ b/src/FDM/JSBSim/math/FGQuaternion.h @@ -40,10 +40,10 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include "FGJSBBase.h" #include "FGMatrix33.h" #include "FGColumnVector3.h" -#include +#include "input_output/FGPropertyManager.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/math/FGTable.cpp b/src/FDM/JSBSim/math/FGTable.cpp index 079631db5..f19669191 100644 --- a/src/FDM/JSBSim/math/FGTable.cpp +++ b/src/FDM/JSBSim/math/FGTable.cpp @@ -37,7 +37,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGTable.h" -#include +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" +#include +#include +#include using namespace std; @@ -307,7 +311,7 @@ FGTable::~FGTable() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -unsigned int FGTable::FindNumColumns(string test_line) +unsigned int FGTable::FindNumColumns(const string& test_line) { // determine number of data columns in table (first column is row lookup - don't count) size_t position=0; @@ -466,7 +470,7 @@ double FGTable::GetValue(double rowKey, double colKey, double tableKey) const //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGTable::operator<<(stringstream& in_stream) +void FGTable::operator<<(istream& in_stream) { int startRow=0; int startCol=0; @@ -488,7 +492,7 @@ void FGTable::operator<<(stringstream& in_stream) FGTable& FGTable::operator<<(const double n) { Data[rowCounter][colCounter] = n; - if (colCounter == nCols) { + if (colCounter == (int)nCols) { colCounter = 0; rowCounter++; } else { diff --git a/src/FDM/JSBSim/math/FGTable.h b/src/FDM/JSBSim/math/FGTable.h index a90654a18..1b0d22e16 100644 --- a/src/FDM/JSBSim/math/FGTable.h +++ b/src/FDM/JSBSim/math/FGTable.h @@ -38,11 +38,10 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include #include "FGParameter.h" -#include -#include +#include #include +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -54,11 +53,11 @@ DEFINITIONS FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -using std::vector; -using std::stringstream; - namespace JSBSim { +class FGPropertyManager; +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -280,7 +279,7 @@ public: */ - void operator<<(stringstream&); + void operator<<(std::istream&); FGTable& operator<<(const double n); FGTable& operator<<(const int n); @@ -298,16 +297,16 @@ private: bool internal; FGPropertyManager *lookupProperty[3]; double** Data; - vector Tables; - unsigned int FindNumColumns(string); + std::vector Tables; unsigned int nRows, nCols, nTables, dimension; int colCounter, rowCounter, tableCounter; mutable int lastRowIndex, lastColumnIndex, lastTableIndex; double** Allocate(void); FGPropertyManager* const PropertyManager; - string Name; + std::string Name; void bind(void); + unsigned int FindNumColumns(const std::string&); void Debug(int from); }; } diff --git a/src/FDM/JSBSim/models/FGAerodynamics.cpp b/src/FDM/JSBSim/models/FGAerodynamics.cpp index 829697024..5083bf7bc 100644 --- a/src/FDM/JSBSim/models/FGAerodynamics.cpp +++ b/src/FDM/JSBSim/models/FGAerodynamics.cpp @@ -36,13 +36,19 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include +#include +#include +#include #include #include "FGAerodynamics.h" #include "FGPropagate.h" #include "FGAircraft.h" #include "FGAuxiliary.h" #include "FGMassBalance.h" -#include +#include "input_output/FGPropertyManager.h" + +using namespace std; namespace JSBSim { @@ -324,21 +330,21 @@ bool FGAerodynamics::Load(Element *element) Debug(2); - if (temp_element = document->FindElement("alphalimits")) { + if ((temp_element = document->FindElement("alphalimits"))) { scratch_unit = temp_element->GetAttributeValue("unit"); if (scratch_unit.empty()) scratch_unit = "RAD"; alphaclmin = temp_element->FindElementValueAsNumberConvertFromTo("min", scratch_unit, "RAD"); alphaclmax = temp_element->FindElementValueAsNumberConvertFromTo("max", scratch_unit, "RAD"); } - if (temp_element = document->FindElement("hysteresis_limits")) { + if ((temp_element = document->FindElement("hysteresis_limits"))) { scratch_unit = temp_element->GetAttributeValue("unit"); if (scratch_unit.empty()) scratch_unit = "RAD"; alphahystmin = temp_element->FindElementValueAsNumberConvertFromTo("min", scratch_unit, "RAD"); alphahystmax = temp_element->FindElementValueAsNumberConvertFromTo("max", scratch_unit, "RAD"); } - if (temp_element = document->FindElement("aero_ref_pt_shift_x")) { + if ((temp_element = document->FindElement("aero_ref_pt_shift_x"))) { function_element = temp_element->FindElement("function"); AeroRPShift = new FGFunction(PropertyManager, function_element); } @@ -415,7 +421,7 @@ void FGAerodynamics::DetermineAxisSystem() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGAerodynamics::GetCoefficientStrings(string delimeter) +string FGAerodynamics::GetCoefficientStrings(const string& delimeter) const { string CoeffStrings = ""; bool firstime = true; @@ -445,33 +451,24 @@ string FGAerodynamics::GetCoefficientStrings(string delimeter) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGAerodynamics::GetCoefficientValues(string delimeter) +string FGAerodynamics::GetCoefficientValues(const string& delimeter) const { - string SDValues = ""; - bool firstime = true; - unsigned int sd; + ostringstream buf; - for (sd = 0; sd < variables.size(); sd++) { - if (firstime) { - firstime = false; - } else { - SDValues += delimeter; - } - SDValues += variables[sd]->GetValueAsString(); + buf.precision(6); + for (unsigned int sd = 0; sd < variables.size(); sd++) { + if (buf.tellp() > 0) buf << delimeter; + buf << setw(9) << variables[sd]->GetValue(); } for (unsigned int axis = 0; axis < 6; axis++) { for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) { - if (firstime) { - firstime = false; - } else { - SDValues += delimeter; - } - SDValues += Coeff[axis][sd]->GetValueAsString(); + if (buf.tellp() > 0) buf << delimeter; + buf << setw(9) << Coeff[axis][sd]->GetValue(); } } - return SDValues; + return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -558,6 +555,9 @@ void FGAerodynamics::Debug(int from) case (atBodyXYZ): cout << endl << " Aerodynamics (X|Y|Z axes):" << endl << endl; break; + case (atNone): + cout << endl << " Aerodynamics (undefined axes):" << endl << endl; + break; } } } diff --git a/src/FDM/JSBSim/models/FGAerodynamics.h b/src/FDM/JSBSim/models/FGAerodynamics.h index 9e2e47b22..8c26e5277 100644 --- a/src/FDM/JSBSim/models/FGAerodynamics.h +++ b/src/FDM/JSBSim/models/FGAerodynamics.h @@ -38,14 +38,15 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include #include #include "FGModel.h" -#include -#include -#include -#include +#include "math/FGFunction.h" +#include "math/FGColumnVector3.h" +#include "math/FGMatrix33.h" +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -188,13 +189,13 @@ public: /** Gets the strings for the current set of coefficients. @param delimeter either a tab or comma string depending on output type @return a string containing the descriptive names for all coefficients */ - string GetCoefficientStrings(string delimeter); + std::string GetCoefficientStrings(const std::string& delimeter) const; /** Gets the coefficient values. @param delimeter either a tab or comma string depending on output type @return a string containing the numeric values for the current set of coefficients */ - string GetCoefficientValues(string delimeter); + std::string GetCoefficientValues(const std::string& delimeter) const; /** Calculates and returns the wind-to-body axis transformation matrix. @return a reference to the wind-to-body transformation matrix. @@ -206,14 +207,14 @@ public: */ FGMatrix33& GetTb2w(void); - vector * GetCoeff(void) const { return Coeff; } + std::vector * GetCoeff(void) const { return Coeff; } private: enum eAxisType {atNone, atLiftDrag, atAxialNormal, atBodyXYZ} axisType; - typedef map AxisIndex; + typedef std::map AxisIndex; AxisIndex AxisIdx; FGFunction* AeroRPShift; - vector variables; + std::vector variables; typedef vector CoeffArray; CoeffArray* Coeff; FGColumnVector3 vFnative; diff --git a/src/FDM/JSBSim/models/FGAircraft.cpp b/src/FDM/JSBSim/models/FGAircraft.cpp index 9c6ffef85..83a1bf177 100644 --- a/src/FDM/JSBSim/models/FGAircraft.cpp +++ b/src/FDM/JSBSim/models/FGAircraft.cpp @@ -50,9 +50,13 @@ INCLUDES #include "FGExternalReactions.h" #include "FGBuoyantForces.h" #include "FGAerodynamics.h" -#include +#include "FGFDMExec.h" #include "FGPropagate.h" -#include +#include "FGPropulsion.h" +#include "input_output/FGPropertyManager.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGAircraft.h b/src/FDM/JSBSim/models/FGAircraft.h index bc32b1afb..a66665c06 100644 --- a/src/FDM/JSBSim/models/FGAircraft.h +++ b/src/FDM/JSBSim/models/FGAircraft.h @@ -38,11 +38,12 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include #include "FGModel.h" -#include -#include +#include "input_output/FGXMLElement.h" +#include "math/FGColumnVector3.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -131,7 +132,7 @@ public: /** Gets the aircraft name @return the name of the aircraft as a string type */ - inline string GetAircraftName(void) { return AircraftName; } + const std::string& GetAircraftName(void) const { return AircraftName; } /// Gets the wing area double GetWingArea(void) const { return WingArea; } @@ -163,7 +164,7 @@ public: inline double GetXYZrp(int idx) const { return vXYZrp(idx); } inline double GetXYZvrp(int idx) const { return vXYZvrp(idx); } inline double GetXYZep(int idx) const { return vXYZep(idx); } - inline void SetAircraftName(string name) {AircraftName = name;} + inline void SetAircraftName(const std::string& name) {AircraftName = name;} inline void SetHoldDown(int hd) {HoldDown = hd;} inline int GetHoldDown(void) const {return HoldDown;} @@ -193,7 +194,7 @@ private: double HTailArea, VTailArea, HTailArm, VTailArm; double lbarh,lbarv,vbarh,vbarv; int HoldDown; - string AircraftName; + std::string AircraftName; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/FGAtmosphere.cpp b/src/FDM/JSBSim/models/FGAtmosphere.cpp index b1826b716..c21e45cbc 100644 --- a/src/FDM/JSBSim/models/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/models/FGAtmosphere.cpp @@ -48,12 +48,16 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGAtmosphere.h" -#include -#include +#include "FGState.h" +#include "FGFDMExec.h" #include "FGAircraft.h" #include "FGPropagate.h" #include "FGInertial.h" -#include +#include "input_output/FGPropertyManager.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -454,10 +458,12 @@ void FGAtmosphere::Turbulence(void) vDirectiondAccelDt(eX) = GaussianRandomNumber(); vDirectiondAccelDt(eY) = GaussianRandomNumber(); vDirectiondAccelDt(eZ) = GaussianRandomNumber(); - +/* MagnitudedAccelDt = GaussianRandomNumber(); MagnitudeAccel += MagnitudedAccelDt * DeltaT; Magnitude += MagnitudeAccel * DeltaT; +*/ + Magnitude += GaussianRandomNumber() * DeltaT; vDirectiondAccelDt.Normalize(); vDirectionAccel += TurbRate * vDirectiondAccelDt * DeltaT; diff --git a/src/FDM/JSBSim/models/FGAtmosphere.h b/src/FDM/JSBSim/models/FGAtmosphere.h index bd550246e..2a7443e5d 100644 --- a/src/FDM/JSBSim/models/FGAtmosphere.h +++ b/src/FDM/JSBSim/models/FGAtmosphere.h @@ -43,7 +43,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGModel.h" -#include +#include "math/FGColumnVector3.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/FGAuxiliary.cpp b/src/FDM/JSBSim/models/FGAuxiliary.cpp index be578ae1c..d8a8d77c0 100755 --- a/src/FDM/JSBSim/models/FGAuxiliary.cpp +++ b/src/FDM/JSBSim/models/FGAuxiliary.cpp @@ -44,14 +44,18 @@ INCLUDES #include "FGAerodynamics.h" #include "FGPropagate.h" #include "FGAtmosphere.h" -#include +#include "FGFDMExec.h" #include "FGAircraft.h" #include "FGInertial.h" #include "FGExternalReactions.h" #include "FGBuoyantForces.h" #include "FGGroundReactions.h" #include "FGPropulsion.h" -#include +#include "FGMassBalance.h" +#include "input_output/FGPropertyManager.h" +#include + +using namespace std; namespace JSBSim { @@ -392,6 +396,13 @@ void FGAuxiliary::CalculateRelativePosition(void) relative_position = sqrt(lat_relative_position*lat_relative_position + lon_relative_position*lon_relative_position); }; +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +double FGAuxiliary::BadUnits(void) const +{ + cerr << "Bad units" << endl; return 0.0; +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/FGAuxiliary.h b/src/FDM/JSBSim/models/FGAuxiliary.h index 6420e3b97..e3baa4911 100644 --- a/src/FDM/JSBSim/models/FGAuxiliary.h +++ b/src/FDM/JSBSim/models/FGAuxiliary.h @@ -40,9 +40,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGModel.h" -#include -#include -#include +#include "math/FGColumnVector3.h" +#include "math/FGLocation.h" #include "FGPropagate.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -172,15 +171,15 @@ public: double GetMagBeta (void) const { return fabs(beta); } double Getalpha (int unit) const { if (unit == inDegrees) return alpha*radtodeg; - else cerr << "Bad units" << endl; return 0.0;} + else return BadUnits(); } double Getbeta (int unit) const { if (unit == inDegrees) return beta*radtodeg; - else cerr << "Bad units" << endl; return 0.0;} + else return BadUnits(); } double Getadot (int unit) const { if (unit == inDegrees) return adot*radtodeg; - else cerr << "Bad units" << endl; return 0.0;} + else return BadUnits(); } double Getbdot (int unit) const { if (unit == inDegrees) return bdot*radtodeg; - else cerr << "Bad units" << endl; return 0.0;} + else return BadUnits(); } double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg; - else cerr << "Bad units" << endl; return 0.0;} + else return BadUnits(); } double Getqbar (void) const { return qbar; } double GetqbarUW (void) const { return qbarUW; } @@ -281,6 +280,7 @@ private: void CalculateRelativePosition(void); void bind(void); + double BadUnits(void) const; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/FGBuoyantForces.cpp b/src/FDM/JSBSim/models/FGBuoyantForces.cpp index 129797549..44ecd6595 100644 --- a/src/FDM/JSBSim/models/FGBuoyantForces.cpp +++ b/src/FDM/JSBSim/models/FGBuoyantForces.cpp @@ -38,7 +38,10 @@ INCLUDES #include "FGBuoyantForces.h" #include "FGMassBalance.h" -#include // Need? +#include "input_output/FGPropertyManager.h" // Need? +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGBuoyantForces.h b/src/FDM/JSBSim/models/FGBuoyantForces.h index f03a00df2..ec664b3ab 100644 --- a/src/FDM/JSBSim/models/FGBuoyantForces.h +++ b/src/FDM/JSBSim/models/FGBuoyantForces.h @@ -44,8 +44,8 @@ INCLUDES #include "FGModel.h" #include "FGGasCell.h" -#include -#include +#include "math/FGColumnVector3.h" +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/FGExternalForce.cpp b/src/FDM/JSBSim/models/FGExternalForce.cpp index 48884c4d1..fa1d35d22 100755 --- a/src/FDM/JSBSim/models/FGExternalForce.cpp +++ b/src/FDM/JSBSim/models/FGExternalForce.cpp @@ -53,6 +53,10 @@ */ #include "FGExternalForce.h" +#include "input_output/FGXMLElement.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGExternalForce.h b/src/FDM/JSBSim/models/FGExternalForce.h index c65739248..d4a90db83 100755 --- a/src/FDM/JSBSim/models/FGExternalForce.h +++ b/src/FDM/JSBSim/models/FGExternalForce.h @@ -39,13 +39,13 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include +#include "FGFDMExec.h" +#include "FGJSBBase.h" +#include "models/propulsion/FGForce.h" #include -#include -#include -#include +#include "input_output/FGPropertyManager.h" +#include "math/FGColumnVector3.h" +#include "math/FGFunction.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/FGExternalReactions.cpp b/src/FDM/JSBSim/models/FGExternalReactions.cpp index 6bff2bb46..58a334364 100755 --- a/src/FDM/JSBSim/models/FGExternalReactions.cpp +++ b/src/FDM/JSBSim/models/FGExternalReactions.cpp @@ -37,8 +37,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGExternalReactions.h" +#include "input_output/FGXMLElement.h" +#include #include +using namespace std; + namespace JSBSim { /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/FGExternalReactions.h b/src/FDM/JSBSim/models/FGExternalReactions.h index 60cca4440..c6f65fe10 100755 --- a/src/FDM/JSBSim/models/FGExternalReactions.h +++ b/src/FDM/JSBSim/models/FGExternalReactions.h @@ -40,7 +40,7 @@ INCLUDES #include "FGModel.h" #include "FGExternalForce.h" -#include +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -54,6 +54,8 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -154,7 +156,7 @@ public: private: - vector Forces; + std::vector Forces; unsigned int numForces; FGColumnVector3 vTotalForces; FGColumnVector3 vTotalMoments; diff --git a/src/FDM/JSBSim/models/FGFCS.cpp b/src/FDM/JSBSim/models/FGFCS.cpp index e1b7b9fb4..3ee958110 100644 --- a/src/FDM/JSBSim/models/FGFCS.cpp +++ b/src/FDM/JSBSim/models/FGFCS.cpp @@ -38,24 +38,28 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCS.h" -#include -#include +#include "FGFDMExec.h" +#include "FGGroundReactions.h" +#include "input_output/FGPropertyManager.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "models/flight_control/FGFilter.h" +#include "models/flight_control/FGDeadBand.h" +#include "models/flight_control/FGGain.h" +#include "models/flight_control/FGPID.h" +#include "models/flight_control/FGSwitch.h" +#include "models/flight_control/FGSummer.h" +#include "models/flight_control/FGKinemat.h" +#include "models/flight_control/FGFCSFunction.h" +#include "models/flight_control/FGSensor.h" +#include "models/flight_control/FGActuator.h" +#include "models/flight_control/FGAccelerometer.h" +#include "models/flight_control/FGMagnetometer.h" +#include "models/flight_control/FGGyro.h" + +using namespace std; namespace JSBSim { @@ -643,6 +647,8 @@ bool FGFCS::Load(Element* el, SystemType systype) Components->push_back(new FGSensor(this, component_element)); } else if (component_element->GetName() == string("accelerometer")) { Components->push_back(new FGAccelerometer(this, component_element)); + } else if (component_element->GetName() == string("magnetometer")) { + Components->push_back(new FGMagnetometer(this, component_element)); } else if (component_element->GetName() == string("gyro")) { Components->push_back(new FGGyro(this, component_element)); } else { @@ -682,7 +688,7 @@ double FGFCS::GetBrake(FGLGear::BrakeGroup bg) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGFCS::FindSystemFullPathname(string system_filename) +string FGFCS::FindSystemFullPathname(const string& system_filename) { string fullpath, localpath; string systemPath = FDMExec->GetSystemsPath(); @@ -710,7 +716,7 @@ string FGFCS::FindSystemFullPathname(string system_filename) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ifstream* FGFCS::FindSystemFile(string system_filename) +ifstream* FGFCS::FindSystemFile(const string& system_filename) { string fullpath, localpath; string systemPath = FDMExec->GetSystemsPath(); @@ -735,7 +741,7 @@ ifstream* FGFCS::FindSystemFile(string system_filename) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGFCS::GetComponentStrings(string delimeter) +string FGFCS::GetComponentStrings(const string& delimiter) { unsigned int comp; string CompStrings = ""; @@ -744,7 +750,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (unsigned int i=0; iGetName(); total_count++; @@ -753,7 +759,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (comp = 0; comp < APComponents.size(); comp++) { if (firstime) firstime = false; - else CompStrings += delimeter; + else CompStrings += delimiter; CompStrings += APComponents[comp]->GetName(); total_count++; @@ -761,7 +767,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (comp = 0; comp < FCSComponents.size(); comp++) { if (firstime) firstime = false; - else CompStrings += delimeter; + else CompStrings += delimiter; CompStrings += FCSComponents[comp]->GetName(); total_count++; @@ -772,7 +778,7 @@ string FGFCS::GetComponentStrings(string delimeter) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGFCS::GetComponentValues(string delimeter) +string FGFCS::GetComponentValues(const string& delimiter) { std::ostringstream buf; @@ -782,7 +788,7 @@ string FGFCS::GetComponentValues(string delimeter) for (unsigned int i=0; iGetOutput(); total_count++; @@ -790,7 +796,7 @@ string FGFCS::GetComponentValues(string delimeter) for (comp = 0; comp < APComponents.size(); comp++) { if (firstime) firstime = false; - else buf << delimeter; + else buf << delimiter; buf << setprecision(9) << APComponents[comp]->GetOutput(); total_count++; @@ -798,7 +804,7 @@ string FGFCS::GetComponentValues(string delimeter) for (comp = 0; comp < FCSComponents.size(); comp++) { if (firstime) firstime = false; - else buf << delimeter; + else buf << delimiter; buf << setprecision(9) << FCSComponents[comp]->GetOutput(); total_count++; diff --git a/src/FDM/JSBSim/models/FGFCS.h b/src/FDM/JSBSim/models/FGFCS.h index 79535f261..b00c037a9 100644 --- a/src/FDM/JSBSim/models/FGFCS.h +++ b/src/FDM/JSBSim/models/FGFCS.h @@ -38,13 +38,14 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include #include -#include -#include -#include -#include +#include "models/flight_control/FGFCSComponent.h" +#include "models/FGModel.h" +#include "models/FGLGear.h" +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -352,15 +353,15 @@ public: FGState* GetState(void) { return State; } /** Retrieves all component names for inclusion in output stream - @param delimeter either a tab or comma string depending on output type + @param delimiter either a tab or comma string depending on output type @return a string containing the descriptive names for all components */ - string GetComponentStrings(string delimeter); + std::string GetComponentStrings(const std::string& delimiter); /** Retrieves all component outputs for inclusion in output stream - @param delimeter either a tab or comma string depending on output type + @param delimiter either a tab or comma string depending on output type @return a string containing the numeric values for the current set of component outputs */ - string GetComponentValues(string delimeter); + std::string GetComponentValues(const std::string& delimiter); /// @name Pilot input command setting //@{ @@ -537,8 +538,8 @@ public: @return true if succesful */ bool Load(Element* el, SystemType systype); - ifstream* FindSystemFile(string system_filename); - string FindSystemFullPathname(string system_filename); + std::ifstream* FindSystemFile(const std::string& system_filename); + std::string FindSystemFullPathname(const std::string& system_filename); void AddThrottle(void); void AddGear(void); @@ -551,20 +552,20 @@ private: double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms]; double DfPos[NForms], DsbPos[NForms], DspPos[NForms]; double PTrimCmd, YTrimCmd, RTrimCmd; - vector ThrottleCmd; - vector ThrottlePos; - vector MixtureCmd; - vector MixturePos; - vector PropAdvanceCmd; - vector PropAdvance; - vector PropFeatherCmd; - vector PropFeather; - vector SteerPosDeg; + std::vector ThrottleCmd; + std::vector ThrottlePos; + std::vector MixtureCmd; + std::vector MixturePos; + std::vector PropAdvanceCmd; + std::vector PropAdvance; + std::vector PropFeatherCmd; + std::vector PropFeather; + std::vector SteerPosDeg; double LeftBrake, RightBrake, CenterBrake; // Brake settings double GearCmd,GearPos; double TailhookPos, WingFoldPos; - typedef vector FCSCompVec; + typedef std::vector FCSCompVec; FCSCompVec Systems; FCSCompVec FCSComponents; FCSCompVec APComponents; diff --git a/src/FDM/JSBSim/models/FGGasCell.cpp b/src/FDM/JSBSim/models/FGGasCell.cpp index e6b32b6e0..73c5091dd 100644 --- a/src/FDM/JSBSim/models/FGGasCell.cpp +++ b/src/FDM/JSBSim/models/FGGasCell.cpp @@ -35,16 +35,21 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include -#include +#include "FGFDMExec.h" +#include "models/FGAuxiliary.h" +#include "models/FGAtmosphere.h" +#include "models/FGInertial.h" +#include "models/FGMassBalance.h" #include "FGGasCell.h" +#include "input_output/FGXMLElement.h" +#include +#include using std::cerr; using std::endl; using std::cout; +using std::string; +using std::max; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGGasCell.h b/src/FDM/JSBSim/models/FGGasCell.h index fa7021ff4..0aae911b1 100644 --- a/src/FDM/JSBSim/models/FGGasCell.h +++ b/src/FDM/JSBSim/models/FGGasCell.h @@ -39,17 +39,12 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include -#include +#include "FGJSBBase.h" +#include "math/FGColumnVector3.h" +#include "models/propulsion/FGForce.h" +#include "math/FGFunction.h" #include -using std::string; -using std::cerr; -using std::endl; -using std::cout; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -64,6 +59,7 @@ FORWARD DECLARATIONS namespace JSBSim { class FGBallonet; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -230,7 +226,7 @@ private: enum GasType {ttUNKNOWN, ttHYDROGEN, ttHELIUM, ttAIR}; GasType Type; - string type; + std::string type; int CellNum; // Structural constants double MaxVolume; // [ft�] diff --git a/src/FDM/JSBSim/models/FGGroundReactions.cpp b/src/FDM/JSBSim/models/FGGroundReactions.cpp index 4a430144d..4de1c1960 100644 --- a/src/FDM/JSBSim/models/FGGroundReactions.cpp +++ b/src/FDM/JSBSim/models/FGGroundReactions.cpp @@ -39,7 +39,10 @@ INCLUDES #include #include "FGGroundReactions.h" -#include +#include "FGFCS.h" +#include "input_output/FGPropertyManager.h" + +using namespace std; namespace JSBSim { @@ -95,8 +98,8 @@ bool FGGroundReactions::Run(void) // Perhaps there is some commonality for things which only need to be // calculated once. for (unsigned int i=0; iForce(); - vMoments += lGear[i]->Moment(); + vForces += lGear[i]->GetBodyForces(); + vMoments += lGear[i]->GetMoments(); } return false; diff --git a/src/FDM/JSBSim/models/FGGroundReactions.h b/src/FDM/JSBSim/models/FGGroundReactions.h index 9ad5ae836..a5785d6ca 100644 --- a/src/FDM/JSBSim/models/FGGroundReactions.h +++ b/src/FDM/JSBSim/models/FGGroundReactions.h @@ -42,8 +42,8 @@ INCLUDES #include "FGModel.h" #include "FGLGear.h" -#include -#include +#include "math/FGColumnVector3.h" +#include "input_output/FGXMLElement.h" #define ID_GROUNDREACTIONS "$Id$" diff --git a/src/FDM/JSBSim/models/FGInertial.cpp b/src/FDM/JSBSim/models/FGInertial.cpp index 6db0555e0..9bff3f6e8 100644 --- a/src/FDM/JSBSim/models/FGInertial.cpp +++ b/src/FDM/JSBSim/models/FGInertial.cpp @@ -36,10 +36,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGInertial.h" -#include +#include "FGFDMExec.h" #include "FGPropagate.h" #include "FGState.h" #include "FGMassBalance.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGInertial.h b/src/FDM/JSBSim/models/FGInertial.h index f17d0c7ff..cf4579236 100644 --- a/src/FDM/JSBSim/models/FGInertial.h +++ b/src/FDM/JSBSim/models/FGInertial.h @@ -41,7 +41,7 @@ INCLUDES #include #include "FGModel.h" -#include +#include "math/FGColumnVector3.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/FGInput.cpp b/src/FDM/JSBSim/models/FGInput.cpp index e36abc271..6ba43df4e 100755 --- a/src/FDM/JSBSim/models/FGInput.cpp +++ b/src/FDM/JSBSim/models/FGInput.cpp @@ -42,8 +42,14 @@ INCLUDES #include "FGState.h" #include "FGFDMExec.h" -#include +#include "input_output/FGfdmSocket.h" +#include "input_output/FGXMLElement.h" + +#include #include +#include + +using namespace std; namespace JSBSim { @@ -89,10 +95,8 @@ bool FGInput::InitModel(void) bool FGInput::Run(void) { - string line, token, info_string; - int start=0, string_start=0, string_end=0; - int token_start=0, token_end=0; - char buf[100]; + string line, token; + size_t start=0, string_start=0, string_end=0; double value=0; FGPropertyManager* node=0; @@ -158,8 +162,9 @@ bool FGInput::Run(void) socket->Reply("Must be in HOLD to search properties\n"); } } else if (node > 0) { - sprintf(buf, "%s = %12.6f\n", argument.c_str(), node->getDoubleValue()); - socket->Reply(buf); + ostringstream buf; + buf << argument << " = " << setw(12) << setprecision(6) << node->getDoubleValue() << endl; + socket->Reply(buf.str()); } } else if (command == "hold") { // PAUSE @@ -181,12 +186,12 @@ bool FGInput::Run(void) } else if (command == "info") { // INFO // get info about the sim run and/or aircraft, etc. - sprintf(buf, "%8.3f\0", State->Getsim_time()); - info_string = "JSBSim version: " + JSBSim_version + "\n"; - info_string += "Config File version: " + needed_cfg_version + "\n"; - info_string += "Aircraft simulated: " + Aircraft->GetAircraftName() + "\n"; - info_string += "Simulation time: " + string(buf) + "\n"; - socket->Reply(info_string); + ostringstream info; + info << "JSBSim version: " << JSBSim_version << endl; + info << "Config File version: " << needed_cfg_version << endl; + info << "Aircraft simulated: " << Aircraft->GetAircraftName() << endl; + info << "Simulation time: " << setw(8) << setprecision(3) << State->Getsim_time() << endl; + socket->Reply(info.str()); } else if (command == "help") { // HELP diff --git a/src/FDM/JSBSim/models/FGInput.h b/src/FDM/JSBSim/models/FGInput.h index 2344c3a79..58aa9ebdb 100755 --- a/src/FDM/JSBSim/models/FGInput.h +++ b/src/FDM/JSBSim/models/FGInput.h @@ -40,11 +40,7 @@ INCLUDES #include "FGModel.h" -#include -#include - -#include -#include +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -58,6 +54,10 @@ FORWARD DECLARATIONS namespace JSBSim { +class FGFDMExec; +class Element; +class FGfdmSocket; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -78,7 +78,6 @@ public: bool InitModel(void); bool Run(void); - void SetType(string); inline void Enable(void) { enabled = true; } inline void Disable(void) { enabled = false; } inline bool Toggle(void) {enabled = !enabled; return enabled;} @@ -88,7 +87,7 @@ private: bool sFirstPass, dFirstPass, enabled; unsigned int port; FGfdmSocket* socket; - string data; + std::string data; void Debug(int from); }; } diff --git a/src/FDM/JSBSim/models/FGLGear.cpp b/src/FDM/JSBSim/models/FGLGear.cpp index e3cfeadf2..b0c448b41 100644 --- a/src/FDM/JSBSim/models/FGLGear.cpp +++ b/src/FDM/JSBSim/models/FGLGear.cpp @@ -41,6 +41,16 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGLGear.h" +#include "FGState.h" +#include "FGGroundReactions.h" +#include "FGFCS.h" +#include "FGAuxiliary.h" +#include "FGAtmosphere.h" +#include "FGMassBalance.h" +#include "math/FGTable.h" +#include + +using namespace std; namespace JSBSim { @@ -55,13 +65,18 @@ GLOBAL DATA static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_LGEAR; +// Body To Structural (body frame is rotated 180 deg about Y and lengths are given in +// ft instead of inches) +const FGMatrix33 FGLGear::Tb2s(-1./inchtoft, 0., 0., 0., 1./inchtoft, 0., 0., 0., -1./inchtoft); + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : + FGForce(fdmex), GearNumber(number), - Exec(fdmex) + SteerAngle(0.0) { Element *force_table=0; Element *dampCoeff=0; @@ -81,7 +96,8 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : } else if (sContactType == "STRUCTURE") { eContactType = ctSTRUCTURE; } else { - eContactType = ctUNKNOWN; + // Unknown contact point types will be treated as STRUCTURE. + eContactType = ctSTRUCTURE; } if (el->FindElement("spring_coeff")) @@ -125,7 +141,7 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : while (force_table) { force_type = force_table->GetAttributeValue("type"); if (force_type == "CORNERING_COEFF") { - ForceY_Table = new FGTable(Exec->GetPropertyManager(), force_table); + ForceY_Table = new FGTable(fdmex->GetPropertyManager(), force_table); } else { cerr << "Undefined force table for " << name << " contact point" << endl; } @@ -139,8 +155,37 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : else sSteerType = "STEERABLE"; Element* element = el->FindElement("location"); - if (element) vXYZ = element->FindElementTripletConvertTo("IN"); + if (element) vXYZn = element->FindElementTripletConvertTo("IN"); else {cerr << "No location given for contact " << name << endl; exit(-1);} + SetTransformType(FGForce::tCustom); + + element = el->FindElement("orientation"); + if (element && (eContactType == ctBOGEY)) { + vGearOrient = element->FindElementTripletConvertTo("RAD"); + + double cp,sp,cr,sr,cy,sy; + + cp=cos(vGearOrient(ePitch)); sp=sin(vGearOrient(ePitch)); + cr=cos(vGearOrient(eRoll)); sr=sin(vGearOrient(eRoll)); + cy=cos(vGearOrient(eYaw)); sy=sin(vGearOrient(eYaw)); + + mTGear(1,1) = cp*cy; + mTGear(2,1) = cp*sy; + mTGear(3,1) = -sp; + + mTGear(1,2) = sr*sp*cy - cr*sy; + mTGear(2,2) = sr*sp*sy + cr*cy; + mTGear(3,2) = sr*cp; + + mTGear(1,3) = cr*sp*cy + sr*sy; + mTGear(2,3) = cr*sp*sy - sr*cy; + mTGear(3,3) = cr*cp; + } + else { + mTGear(1,1) = 1.; + mTGear(2,2) = 1.; + mTGear(3,3) = 1.; + } if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft; else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight; @@ -178,7 +223,13 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : } } - State = Exec->GetState(); + State = fdmex->GetState(); + Aircraft = fdmex->GetAircraft(); + Propagate = fdmex->GetPropagate(); + Auxiliary = fdmex->GetAuxiliary(); + FCS = fdmex->GetFCS(); + MassBalance = fdmex->GetMassBalance(); + LongForceLagFilterCoeff = 1/State->Getdt(); // default longitudinal force filter coefficient LatForceLagFilterCoeff = 1/State->Getdt(); // default lateral force filter coefficient @@ -213,13 +264,6 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : // Add some AI here to determine if gear is located properly according to its // brake group type ?? - State = Exec->GetState(); - Aircraft = Exec->GetAircraft(); - Propagate = Exec->GetPropagate(); - Auxiliary = Exec->GetAuxiliary(); - FCS = Exec->GetFCS(); - MassBalance = Exec->GetMassBalance(); - WOW = lastWOW = false; ReportEnable = true; FirstContact = false; @@ -229,11 +273,9 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : MaximumStrutForce = MaximumStrutTravel = 0.0; SinkRate = GroundSpeed = 0.0; - vWhlBodyVec = MassBalance->StructuralToBody(vXYZ); - + vWhlBodyVec = MassBalance->StructuralToBody(vXYZn); vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; - - vLocalWhlVel.InitMatrix(); + vWhlVelVec.InitMatrix(); compressLength = 0.0; compressSpeed = 0.0; @@ -263,36 +305,38 @@ FGLGear::~FGLGear() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGColumnVector3& FGLGear::Force(void) +FGColumnVector3& FGLGear::GetBodyForces(void) { - double t = Exec->GetState()->Getsim_time(); - dT = State->Getdt()*Exec->GetGroundReactions()->GetRate(); + double t = fdmex->GetState()->Getsim_time(); + dT = State->Getdt()*fdmex->GetGroundReactions()->GetRate(); - vForce.InitMatrix(); - vLocalForce.InitMatrix(); - vMoment.InitMatrix(); + vFn.InitMatrix(); if (isRetractable) ComputeRetractionState(); if (GearDown) { + double verticalZProj = 0.; - vWhlBodyVec = MassBalance->StructuralToBody(vXYZ); // Get wheel in body frame + vWhlBodyVec = MassBalance->StructuralToBody(vXYZn); // Get wheel in body frame vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear); // Compute the height of the theoretical location of the wheel (if strut is not compressed) with // respect to the ground level - double height = Exec->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel); + double height = fdmex->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel); vGroundNormal = -1. * Propagate->GetTec2b() * normal; + // The height returned above is the AGL and is expressed in the Z direction of the local + // coordinate frame. We now need to transform this height in actual compression of the strut (BOGEY) + // of in the normal direction to the ground (STRUCTURE) switch (eContactType) { case ctBOGEY: - // Project the height in the local coordinate frame of the strut to compute the actual compression - // length. The strut is assumed to be parallel to Z in the body frame. - compressLength = vGroundNormal(eZ) < 0.0 ? height / vGroundNormal(eZ) : 0.0; + verticalZProj = (Propagate->GetTb2l()*mTGear*FGColumnVector3(0.,0.,1.))(eZ); + compressLength = verticalZProj > 0.0 ? -height / verticalZProj : 0.0; break; case ctSTRUCTURE: - compressLength = -height; + verticalZProj = (Propagate->GetTec2l()*normal)(eZ); + compressLength = fabs(verticalZProj) > 0.0 ? -height / verticalZProj : 0.0; break; } @@ -303,20 +347,28 @@ FGColumnVector3& FGLGear::Force(void) // [The next equation should really use the vector to the contact patch of // the tire including the strut compression and not the original vWhlBodyVec.] - FGColumnVector3 vWhlContactVec = vWhlBodyVec - FGColumnVector3(0., 0., compressLength); - vWhlVelVec = Propagate->GetPQR() * vWhlContactVec; - vWhlVelVec += Propagate->GetUVW() - Propagate->GetTec2b() * cvel; + FGColumnVector3 vWhlDisplVec = mTGear * FGColumnVector3(0., 0., compressLength); + FGColumnVector3 vWhlContactVec = vWhlBodyVec - vWhlDisplVec; + vActingXYZn = vXYZn - Tb2s * vWhlDisplVec; + FGColumnVector3 vBodyWhlVel = Propagate->GetPQR() * vWhlContactVec; + vBodyWhlVel += Propagate->GetUVW() - Propagate->GetTec2b() * cvel; + + vWhlVelVec = mTGear.Transposed() * vBodyWhlVel; InitializeReporting(); ComputeSteeringAngle(); ComputeGroundCoordSys(); - vLocalWhlVel = Tb2g * vWhlVelVec; + vLocalWhlVel = Transform().Transposed() * vBodyWhlVel; - compressSpeed = -vLocalWhlVel(eZ); - if (eContactType == ctBOGEY) - // Project the compression speed in the local coordinate frame of the strut - compressSpeed /= -vGroundNormal(eZ); + switch (eContactType) { + case ctBOGEY: + // Compression speed along the strut + compressSpeed = -vWhlVelVec(eZ); + case ctSTRUCTURE: + // Compression speed along the ground normal + compressSpeed = -vLocalWhlVel(eX); + } ComputeVerticalStrutForce(); @@ -325,15 +377,15 @@ FGColumnVector3& FGLGear::Force(void) ComputeSlipAngle(); ComputeBrakeForceCoefficient(); ComputeSideForceCoefficient(); - double sign = vLocalWhlVel(eX)>0?1.0:(vLocalWhlVel(eX)<0?-1.0:0.0); - vLocalForce(eX) = - ((1.0 - TirePressureNorm) * 30 + vLocalForce(eZ) * BrakeFCoeff) * sign; - vLocalForce(eY) = vLocalForce(eZ) * FCoeff; + double sign = vLocalWhlVel(eY)>0?1.0:(vLocalWhlVel(eY)<0?-1.0:0.0); + vFn(eY) = - ((1.0 - TirePressureNorm) * 30 + vFn(eX) * BrakeFCoeff) * sign; + vFn(eZ) = vFn(eX) * FCoeff; } else if (eContactType == ctSTRUCTURE) { FGColumnVector3 vSlipVec = vLocalWhlVel; - vSlipVec(eZ) = 0.; + vSlipVec(eX) = 0.; vSlipVec.Normalize(); - vLocalForce -= staticFCoeff * vLocalForce(eZ) * vSlipVec; + vFn -= staticFCoeff * vFn(eX) * vSlipVec; } // Lag and attenuate the XY-plane forces dependent on velocity. This code @@ -343,28 +395,25 @@ FGColumnVector3& FGLGear::Force(void) // If a coefficient is set to something equal to or less than zero, the // filter is bypassed. - if (LongForceLagFilterCoeff > 0) vLocalForce(eX) = LongForceFilter.execute(vLocalForce(eX)); - if (LatForceLagFilterCoeff > 0) vLocalForce(eY) = LatForceFilter.execute(vLocalForce(eY)); + if (LongForceLagFilterCoeff > 0) vFn(eY) = LongForceFilter.execute(vFn(eY)); + if (LatForceLagFilterCoeff > 0) vFn(eZ) = LatForceFilter.execute(vFn(eZ)); - if ((fabs(vLocalWhlVel(eX)) <= RFRV) && RFRV > 0) vLocalForce(eX) *= fabs(vLocalWhlVel(eX))/RFRV; - if ((fabs(vLocalWhlVel(eY)) <= SFRV) && SFRV > 0) vLocalForce(eY) *= fabs(vLocalWhlVel(eY))/SFRV; + if ((fabs(vLocalWhlVel(eY)) <= RFRV) && RFRV > 0) vFn(eY) *= fabs(vLocalWhlVel(eY))/RFRV; + if ((fabs(vLocalWhlVel(eZ)) <= SFRV) && SFRV > 0) vFn(eZ) *= fabs(vLocalWhlVel(eZ))/SFRV; // End section for attenuating gear jitter - // Transform the forces back to the body frame and compute the moment. - - vForce = Tg2b * vLocalForce; - vMoment = vWhlContactVec * vForce; - } else { // Gear is NOT compressed WOW = false; compressLength = 0.0; compressSpeed = 0.0; + WheelSlip = 0.0; + StrutForce = 0.0; // Let wheel spin down slowly - vLocalWhlVel(eX) -= 13.0*dT; - if (vLocalWhlVel(eX) < 0.0) vLocalWhlVel(eX) = 0.0; + vWhlVelVec(eX) -= 13.0*dT; + if (vWhlVelVec(eX) < 0.0) vWhlVelVec(eX) = 0.0; // Return to neutral position between 1.0 and 0.8 gear pos. SteerAngle *= max(GetGearUnitPos()-0.8, 0.0)/0.2; @@ -381,64 +430,46 @@ FGColumnVector3& FGLGear::Force(void) lastWOW = WOW; - return vForce; + return FGForce::GetBodyForces(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Build a local "ground" coordinate system defined by -// eX : projection of the rolling direction on the ground -// eY : projection of the sliping direction on the ground -// eZ : normal to the ground +// eX : normal to the ground +// eY : projection of the rolling direction on the ground +// eZ : projection of the sliping direction on the ground void FGLGear::ComputeGroundCoordSys(void) { - FGColumnVector3 vRollingGroundVec; + // Euler angles are built up to create a local frame to describe the forces + // applied to the gear by the ground. Here pitch, yaw and roll do not have + // any physical meaning. It is just a convenient notation. + // First, "pitch" and "yaw" are determined in order to align eX with the + // ground normal. + if (vGroundNormal(eZ) < -1.0) + vOrient(ePitch) = 0.5*M_PI; + else if (1.0 < vGroundNormal(eZ)) + vOrient(ePitch) = -0.5*M_PI; + else + vOrient(ePitch) = asin(-vGroundNormal(eZ)); + + if (fabs(vOrient(ePitch)) == 0.5*M_PI) + vOrient(eYaw) = 0.; + else + vOrient(eYaw) = atan2(vGroundNormal(eY), vGroundNormal(eX)); + + vOrient(eRoll) = 0.; + UpdateCustomTransformMatrix(); if (eContactType == ctBOGEY) { - // Compute the rolling direction projected on the ground - // It consists in finding a vector 'r' such that 'r' lies in the plane (w,z) and r.n = 0 (scalar - // product) where: - // 'n' is the normal to the ground, - // (x,y,z) are the directions defined in the body coord system - // and 'w' is 'x' rotated by the steering angle (SteerAngle) in the plane (x,y). - // r = u * w + v * z and r.n = 0 => v/u = -w.n/z.n = a - // We also want u**2+v**2=1 and u > 0 (i.e. r orientated in the same 'direction' than w) - // after some arithmetic, one finds that : - double a = -(vGroundNormal(eX)*cos(SteerAngle)+vGroundNormal(eY)*sin(SteerAngle)) / vGroundNormal(eZ); - double u = 1. / sqrt(1. + a*a); - double v = a * u; - vRollingGroundVec = FGColumnVector3(u * cos(SteerAngle), u * sin(SteerAngle), v); + // In the case of a bogey, the third angle "roll" is used to align the axis eY and eZ + // to the rolling and sliping direction respectively. + FGColumnVector3 updatedRollingAxis = Transform().Transposed() * mTGear + * FGColumnVector3(-sin(SteerAngle), cos(SteerAngle), 0.); + + vOrient(eRoll) = atan2(updatedRollingAxis(eY), -updatedRollingAxis(eZ)); + UpdateCustomTransformMatrix(); } - else { - // Here the only significant direction is the normal to the ground "vGroundNormal". Since there is - // no wheel the 2 other vectors of the orthonormal basis are not meaningful and are only used to - // create the transformation matrix Tg2b. So we are building vRollingGroundVec as an arbitrary - // vector normal to vGroundNormal - if (fabs(vGroundNormal(eX)) > 0.) - vRollingGroundVec = FGColumnVector3(-vGroundNormal(eZ)/vGroundNormal(eX), 0., 1.); - else if (fabs(vGroundNormal(eY)) > 0.) - vRollingGroundVec = FGColumnVector3(0., -vGroundNormal(eZ)/vGroundNormal(eY), 1.); - else - vRollingGroundVec = FGColumnVector3(1., 0., -vGroundNormal(eX)/vGroundNormal(eZ)); - - vRollingGroundVec.Normalize(); - } - - // The sliping direction is the cross product multiplication of the ground normal and rolling - // directions - FGColumnVector3 vSlipGroundVec = vGroundNormal * vRollingGroundVec; - - Tg2b(1,1) = vRollingGroundVec(eX); - Tg2b(2,1) = vRollingGroundVec(eY); - Tg2b(3,1) = vRollingGroundVec(eZ); - Tg2b(1,2) = vSlipGroundVec(eX); - Tg2b(2,2) = vSlipGroundVec(eY); - Tg2b(3,2) = vSlipGroundVec(eZ); - Tg2b(1,3) = vGroundNormal(eX); - Tg2b(2,3) = vGroundNormal(eY); - Tg2b(3,3) = vGroundNormal(eZ); - - Tb2g = Tg2b.Transposed(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -450,7 +481,7 @@ void FGLGear::ComputeRetractionState(void) GearUp = true; WOW = false; GearDown = false; - vLocalWhlVel.InitMatrix(); + vWhlVelVec.InitMatrix(); } else if (gearPos > 0.99) { GearDown = true; GearUp = false; @@ -465,7 +496,7 @@ void FGLGear::ComputeRetractionState(void) void FGLGear::ComputeSlipAngle(void) { // Calculate tire slip angle. - WheelSlip = -atan2(vLocalWhlVel(eY), fabs(vLocalWhlVel(eX)))*radtodeg; + WheelSlip = -atan2(vLocalWhlVel(eZ), fabs(vLocalWhlVel(eY)))*radtodeg; // Filter the wheel slip angle if (WheelSlipLagFilterCoeff > 0) WheelSlip = WheelSlipFilter.execute(WheelSlip); @@ -485,7 +516,7 @@ void FGLGear::ComputeSteeringAngle(void) SteerAngle = 0.0; break; case stCaster: - SteerAngle = atan2(fabs(vWhlVelVec(eX)), vWhlVelVec(eY)); + SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX))); break; default: cerr << "Improper steering type membership detected for this gear." << endl; @@ -540,7 +571,7 @@ void FGLGear::InitializeReporting(void) void FGLGear::ReportTakeoffOrLanding(void) { - double deltaT = State->Getdt()*Exec->GetGroundReactions()->GetRate(); + double deltaT = State->Getdt()*fdmex->GetGroundReactions()->GetRate(); if (FirstContact) LandingDistanceTraveled += Auxiliary->GetVground()*deltaT; @@ -553,7 +584,7 @@ void FGLGear::ReportTakeoffOrLanding(void) if ( ReportEnable && Auxiliary->GetVground() <= 0.05 && !LandingReported - && Exec->GetGroundReactions()->GetWOW()) + && fdmex->GetGroundReactions()->GetWOW()) { if (debug_lvl > 0) Report(erLand); } @@ -561,7 +592,7 @@ void FGLGear::ReportTakeoffOrLanding(void) if ( ReportEnable && !TakeoffReported && (Propagate->GetDistanceAGL() - vLocalGear(eZ)) > 50.0 - && !Exec->GetGroundReactions()->GetWOW()) + && !fdmex->GetGroundReactions()->GetWOW()) { if (debug_lvl > 0) Report(erTakeoff); } @@ -575,8 +606,8 @@ void FGLGear::ReportTakeoffOrLanding(void) void FGLGear::CrashDetect(void) { if ( (compressLength > 500.0 || - vForce.Magnitude() > 100000000.0 || - vMoment.Magnitude() > 5000000000.0 || + vFn.Magnitude() > 100000000.0 || + GetMoments().Magnitude() > 5000000000.0 || SinkRate > 1.4666*30 ) && !State->IntegrationSuspended()) { PutMessage("Crash Detected: Simulation FREEZE."); @@ -678,10 +709,10 @@ void FGLGear::ComputeVerticalStrutForce(void) switch (eContactType) { case ctBOGEY: // Project back the strut force in the local coordinate frame of the ground - vLocalForce(eZ) = StrutForce / vGroundNormal(eZ); + vFn(eX) = StrutForce / (mTGear.Transposed()*vGroundNormal)(eZ); break; case ctSTRUCTURE: - vLocalForce(eZ) = -StrutForce; + vFn(eX) = -StrutForce; break; } @@ -711,30 +742,33 @@ void FGLGear::bind(void) base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber); if (eContactType == ctBOGEY) { property_name = base_property_name + "/slip-angle-deg"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &WheelSlip ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WheelSlip ); property_name = base_property_name + "/WOW"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &WOW ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WOW ); property_name = base_property_name + "/wheel-speed-fps"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this, + fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this, &FGLGear::GetWheelRollVel); property_name = base_property_name + "/z-position"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this, - &FGLGear::GetZPosition, &FGLGear::SetZPosition); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGForce*)this, + &FGForce::GetLocationZ, &FGForce::SetLocationZ); property_name = base_property_name + "/compression-ft"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &compressLength ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &compressLength ); property_name = base_property_name + "/side_friction_coeff"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff ); property_name = base_property_name + "/static_friction_coeff"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff ); + if (eSteerType == stCaster) { + property_name = base_property_name + "/steering-angle-rad"; + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &SteerAngle ); + } } if( isRetractable ) { property_name = base_property_name + "/pos-norm"; - Exec->GetPropertyManager()->Tie( property_name.c_str(), &GearPos ); + fdmex->GetPropertyManager()->Tie( property_name.c_str(), &GearPos ); } - } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -746,7 +780,7 @@ void FGLGear::Report(ReportType repType) switch(repType) { case erLand: cout << endl << "Touchdown report for " << name << " (WOW at time: " - << Exec->GetState()->Getsim_time() << " seconds)" << endl; + << fdmex->GetState()->Getsim_time() << " seconds)" << endl; cout << " Sink rate at contact: " << SinkRate << " fps, " << SinkRate*0.3048 << " mps" << endl; cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, " @@ -761,18 +795,20 @@ void FGLGear::Report(ReportType repType) break; case erTakeoff: cout << endl << "Takeoff report for " << name << " (Liftoff at time: " - << Exec->GetState()->Getsim_time() << " seconds)" << endl; + << fdmex->GetState()->Getsim_time() << " seconds)" << endl; cout << " Distance traveled: " << TakeoffDistanceTraveled << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl; cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl; - cout << " [Altitude (ASL): " << Exec->GetPropagate()->GetAltitudeASL() << " ft. / " - << Exec->GetPropagate()->GetAltitudeASLmeters() << " m | Temperature: " - << Exec->GetAtmosphere()->GetTemperature() - 459.67 << " F / " - << RankineToCelsius(Exec->GetAtmosphere()->GetTemperature()) << " C]" << endl; - cout << " [Velocity (KCAS): " << Exec->GetAuxiliary()->GetVcalibratedKTS() << "]" << endl; + cout << " [Altitude (ASL): " << fdmex->GetPropagate()->GetAltitudeASL() << " ft. / " + << fdmex->GetPropagate()->GetAltitudeASLmeters() << " m | Temperature: " + << fdmex->GetAtmosphere()->GetTemperature() - 459.67 << " F / " + << RankineToCelsius(fdmex->GetAtmosphere()->GetTemperature()) << " C]" << endl; + cout << " [Velocity (KCAS): " << fdmex->GetAuxiliary()->GetVcalibratedKTS() << "]" << endl; TakeoffReported = true; break; + case erNone: + break; } } @@ -802,7 +838,7 @@ void FGLGear::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - loading and initialization cout << " " << sContactType << " " << name << endl; - cout << " Location: " << vXYZ << endl; + cout << " Location: " << vXYZn << endl; cout << " Spring Constant: " << kSpring << endl; if (eDampType == dtLinear) diff --git a/src/FDM/JSBSim/models/FGLGear.h b/src/FDM/JSBSim/models/FGLGear.h index b7e2f1b83..dfba5bbf0 100644 --- a/src/FDM/JSBSim/models/FGLGear.h +++ b/src/FDM/JSBSim/models/FGLGear.h @@ -38,11 +38,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include -#include +#include "models/propulsion/FGForce.h" +#include "math/FGColumnVector3.h" #include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -63,6 +60,8 @@ class FGFCS; class FGState; class FGMassBalance; class FGAuxiliary; +class FGTable; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -199,7 +198,7 @@ CLASS DOCUMENTATION CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class FGLGear : public FGJSBBase +class FGLGear : public FGForce { public: /// Brake grouping enumerators @@ -207,7 +206,7 @@ public: /// Steering group membership enumerators enum SteerType {stSteer, stFixed, stCaster}; /// Contact point type - enum ContactType {ctBOGEY, ctSTRUCTURE, ctUNKNOWN}; + enum ContactType {ctBOGEY, ctSTRUCTURE}; /// Report type enumerators enum ReportType {erNone=0, erTakeoff, erLand}; /// Damping types @@ -222,9 +221,7 @@ public: ~FGLGear(); /// The Force vector for this gear - FGColumnVector3& Force(void); - /// The Moment vector for this gear - FGColumnVector3& Moment(void) {return vMoment;} + FGColumnVector3& GetBodyForces(void); /// Gets the location of the gear in Body axes FGColumnVector3& GetBodyLocation(void) { return vWhlBodyVec; } @@ -269,35 +266,34 @@ public: int GetBrakeGroup(void) const { return (int)eBrakeGrp; } int GetSteerType(void) const { return (int)eSteerType; } - double GetZPosition(void) const { return vXYZ(3); } - void SetZPosition(double z) { vXYZ(3) = z; } - - bool GetSteerable(void) const { return eSteerType != stFixed; } + bool GetSteerable(void) const { return eSteerType != stFixed; } bool GetRetractable(void) const { return isRetractable; } bool GetGearUnitUp(void) const { return GearUp; } bool GetGearUnitDown(void) const { return GearDown; } - double GetWheelSideForce(void) const { return vLocalForce(eY); } - double GetWheelRollForce(void) const { return vLocalForce(eX); } - double GetWheelSideVel(void) const { return vWhlVelVec(eY); } - double GetWheelRollVel(void) const { return vWhlVelVec(eX); } - double GetBodyXForce(void) const { return vForce(eX); } - double GetBodyYForce(void) const { return vForce(eY); } + double GetWheelRollForce(void) { + FGColumnVector3 vForce = mTGear.Transposed() * FGForce::GetBodyForces(); + return vForce(eX)*cos(SteerAngle) + vForce(eY)*sin(SteerAngle); } + double GetWheelSideForce(void) { + FGColumnVector3 vForce = mTGear.Transposed() * FGForce::GetBodyForces(); + return vForce(eY)*cos(SteerAngle) - vForce(eX)*sin(SteerAngle); } + double GetWheelRollVel(void) const { return vWhlVelVec(eX)*cos(SteerAngle) + + vWhlVelVec(eY)*sin(SteerAngle); } + double GetWheelSideVel(void) const { return vWhlVelVec(eY)*cos(SteerAngle) + - vWhlVelVec(eX)*sin(SteerAngle); } double GetWheelSlipAngle(void) const { return WheelSlip; } - double GetWheelVel(int axis) const { return vWhlVelVec(axis);} - bool IsBogey(void) const { return (eContactType == ctBOGEY);} + double GetWheelVel(int axis) const { return vWhlVelVec(axis);} + bool IsBogey(void) const { return (eContactType == ctBOGEY);} double GetGearUnitPos(void); void bind(void); private: int GearNumber; - FGMatrix33 Tg2b, Tb2g; - FGColumnVector3 vXYZ; - FGColumnVector3 vMoment; + static const FGMatrix33 Tb2s; + FGMatrix33 mTGear; + FGColumnVector3 vGearOrient; FGColumnVector3 vWhlBodyVec; FGColumnVector3 vLocalGear; - FGColumnVector3 vForce; - FGColumnVector3 vLocalForce; FGColumnVector3 vWhlVelVec, vLocalWhlVel; // Velocity of this wheel FGColumnVector3 normal, cvel, vGroundNormal; FGLocation contact, gearLoc; @@ -336,11 +332,11 @@ private: bool isRetractable; bool GearUp, GearDown; bool Servicable; - string name; - string sSteerType; - string sBrakeGroup; - string sRetractable; - string sContactType; + std::string name; + std::string sSteerType; + std::string sBrakeGroup; + std::string sRetractable; + std::string sContactType; BrakeGroup eBrakeGrp; ContactType eContactType; @@ -358,7 +354,6 @@ private: Filter LatForceFilter; Filter WheelSlipFilter; - FGFDMExec* Exec; FGState* State; FGAircraft* Aircraft; FGPropagate* Propagate; @@ -381,12 +376,6 @@ private: void Debug(int from); }; } -#include "FGAircraft.h" -#include "FGPropagate.h" -#include "FGAuxiliary.h" -#include "FGFCS.h" -#include "FGMassBalance.h" -#include "FGState.h" //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/FGMassBalance.cpp b/src/FDM/JSBSim/models/FGMassBalance.cpp index 2b599ffcc..c866fa40a 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.cpp +++ b/src/FDM/JSBSim/models/FGMassBalance.cpp @@ -41,7 +41,11 @@ INCLUDES #include "FGMassBalance.h" #include "FGPropulsion.h" #include "FGBuoyantForces.h" -#include +#include "input_output/FGPropertyManager.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -338,6 +342,24 @@ void FGMassBalance::bind(void) (PMF)&FGMassBalance::GetXYZcg); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGMassBalance::PointMass::bind(FGPropertyManager* PropertyManager, int num) { + string tmp = CreateIndexedPropertyName("inertia/pointmass-weight-lbs", num); + PropertyManager->Tie( tmp.c_str(), this, &PointMass::GetPointMassWeight, + &PointMass::SetPointMassWeight); + + tmp = CreateIndexedPropertyName("inertia/pointmass-location-X-inches", num); + PropertyManager->Tie( tmp.c_str(), this, eX, &PointMass::GetPointMassLocation, + &PointMass::SetPointMassLocation); + tmp = CreateIndexedPropertyName("inertia/pointmass-location-Y-inches", num); + PropertyManager->Tie( tmp.c_str(), this, eY, &PointMass::GetPointMassLocation, + &PointMass::SetPointMassLocation); + tmp = CreateIndexedPropertyName("inertia/pointmass-location-Z-inches", num); + PropertyManager->Tie( tmp.c_str(), this, eZ, &PointMass::GetPointMassLocation, + &PointMass::SetPointMassLocation); +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/FGMassBalance.h b/src/FDM/JSBSim/models/FGMassBalance.h index 9abb19172..686b27b74 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.h +++ b/src/FDM/JSBSim/models/FGMassBalance.h @@ -39,9 +39,9 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGModel.h" -#include -#include -#include +#include "math/FGColumnVector3.h" +#include "math/FGMatrix33.h" +#include "input_output/FGXMLElement.h" #include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -189,24 +189,10 @@ private: void SetPointMassWeight(double wt) {Weight = wt;} double GetPointMassWeight(void) const {return Weight;} - void bind(FGPropertyManager* PropertyManager, int num) { - string tmp = CreateIndexedPropertyName("inertia/pointmass-weight-lbs", num); - PropertyManager->Tie( tmp.c_str(), this, &PointMass::GetPointMassWeight, - &PointMass::SetPointMassWeight); - - tmp = CreateIndexedPropertyName("inertia/pointmass-location-X-inches", num); - PropertyManager->Tie( tmp.c_str(), this, eX, &PointMass::GetPointMassLocation, - &PointMass::SetPointMassLocation); - tmp = CreateIndexedPropertyName("inertia/pointmass-location-Y-inches", num); - PropertyManager->Tie( tmp.c_str(), this, eY, &PointMass::GetPointMassLocation, - &PointMass::SetPointMassLocation); - tmp = CreateIndexedPropertyName("inertia/pointmass-location-Z-inches", num); - PropertyManager->Tie( tmp.c_str(), this, eZ, &PointMass::GetPointMassLocation, - &PointMass::SetPointMassLocation); - } + void bind(FGPropertyManager* PropertyManager, int num); }; - vector PointMasses; + std::vector PointMasses; void bind(void); void Debug(int from); diff --git a/src/FDM/JSBSim/models/FGModel.cpp b/src/FDM/JSBSim/models/FGModel.cpp index bb41c22f8..3a16f493a 100644 --- a/src/FDM/JSBSim/models/FGModel.cpp +++ b/src/FDM/JSBSim/models/FGModel.cpp @@ -52,6 +52,9 @@ INCLUDES #include "FGAircraft.h" #include "FGPropagate.h" #include "FGAuxiliary.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGModel.h b/src/FDM/JSBSim/models/FGModel.h index 1464296aa..bfba0af48 100644 --- a/src/FDM/JSBSim/models/FGModel.h +++ b/src/FDM/JSBSim/models/FGModel.h @@ -38,11 +38,8 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include +#include "FGJSBBase.h" -#include #include #include @@ -52,8 +49,6 @@ DEFINITIONS #define ID_MODEL "$Id$" -using namespace std; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -74,6 +69,8 @@ class FGBuoyantForces; class FGAircraft; class FGPropagate; class FGAuxiliary; +class Element; +class FGPropertyManager; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -102,7 +99,7 @@ public: virtual bool Load(Element* el); FGModel* NextModel; - string Name; + std::string Name; /** Runs the model; called by the Executive @see JSBSim.cpp documentation @@ -137,7 +134,7 @@ protected: FGAuxiliary* Auxiliary; FGPropertyManager* PropertyManager; - vector interface_properties; + std::vector interface_properties; }; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/FGOutput.cpp b/src/FDM/JSBSim/models/FGOutput.cpp index 4a34a5c22..2e509ff63 100644 --- a/src/FDM/JSBSim/models/FGOutput.cpp +++ b/src/FDM/JSBSim/models/FGOutput.cpp @@ -53,13 +53,16 @@ INCLUDES #include "FGPropagate.h" #include "FGAuxiliary.h" #include "FGInertial.h" -#include "FGPropulsion.h" //access to FGEngine, FGTank +#include "models/propulsion/FGEngine.h" +#include "models/propulsion/FGTank.h" #include "models/propulsion/FGPiston.h" -#include +#include #include #include +#include #include "input_output/net_fdm.hxx" +#include "input_output/FGfdmSocket.h" #if defined(WIN32) && !defined(__CYGWIN__) # include @@ -70,6 +73,8 @@ INCLUDES static const int endianTest = 1; #define isLittleEndian (*((char *) &endianTest ) != 0) +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; @@ -157,20 +162,17 @@ FGOutput::~FGOutput() bool FGOutput::InitModel(void) { - char fname[1000] = ""; - if (!FGModel::InitModel()) return false; if (Filename.size() > 0 && StartNewFile) { - int idx = BaseFilename.find_last_of("."); - int len = BaseFilename.length(); - string extension = ""; - if (idx != string::npos) { - extension = BaseFilename.substr(idx, len-idx); - len -= extension.length(); + ostringstream buf; + string::size_type dot = BaseFilename.find_last_of('.'); + if (dot != string::npos) { + buf << BaseFilename.substr(0, dot) << '_' << runID_postfix++ << BaseFilename.substr(dot); + } else { + buf << BaseFilename << '_' << runID_postfix++; } - sprintf(fname, "%s_%d%s", BaseFilename.substr(0,len).c_str(), runID_postfix++, extension.c_str()); - Filename = string(fname); + Filename = buf.str(); datafile.close(); StartNewFile = false; dFirstPass = true; @@ -205,7 +207,7 @@ bool FGOutput::Run(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::SetType(string type) +void FGOutput::SetType(const string& type) { if (type == "CSV") { Type = otCSV; @@ -227,7 +229,7 @@ void FGOutput::SetType(string type) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::DelimitedOutput(string fname) +void FGOutput::DelimitedOutput(const string& fname) { streambuf* buffer; string scratch = ""; @@ -918,7 +920,7 @@ void FGOutput::SocketOutput(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::SocketStatusOutput(string out_str) +void FGOutput::SocketStatusOutput(const string& out_str) { string asciiData; @@ -1084,6 +1086,7 @@ void FGOutput::Debug(int from) cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl; break; case otNone: + default: cout << " No log output" << endl; break; } diff --git a/src/FDM/JSBSim/models/FGOutput.h b/src/FDM/JSBSim/models/FGOutput.h index 1646dadb0..cd1ca6e30 100644 --- a/src/FDM/JSBSim/models/FGOutput.h +++ b/src/FDM/JSBSim/models/FGOutput.h @@ -41,14 +41,11 @@ INCLUDES #include "FGModel.h" -#include #include -#include "input_output/FGfdmSocket.h" #include "input_output/FGXMLFileRead.h" #include "input_output/net_fdm.hxx" - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -61,6 +58,8 @@ FORWARD DECLARATIONS namespace JSBSim { +class FGfdmSocket; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -140,22 +139,22 @@ public: bool InitModel(void); bool Run(void); - void DelimitedOutput(string); + void DelimitedOutput(const std::string&); void SocketOutput(void); void FlightGearSocketOutput(void); - void SocketStatusOutput(string); + void SocketStatusOutput(const std::string&); void SocketDataFill(FGNetFDM* net); - void SetType(string); + void SetType(const std::string& type); void SetStartNewFile(bool tt) {StartNewFile = tt;} void SetSubsystems(int tt) {SubSystems = tt;} 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 SetOutputFileName(const std::string& fname) {Filename = fname;} + void SetDirectivesFile(const std::string& fname) {DirectivesFile = fname;} void SetRate(int rt); string GetOutputFileName(void) const {return Filename;} @@ -185,11 +184,11 @@ private: int SubSystems; int runID_postfix; bool StartNewFile; - string output_file_name, delimeter, BaseFilename, Filename, DirectivesFile; - ofstream datafile; + std::string output_file_name, delimeter, BaseFilename, Filename, DirectivesFile; + std::ofstream datafile; FGfdmSocket* socket; FGfdmSocket* flightGearSocket; - vector OutputProperties; + std::vector OutputProperties; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/FGPropagate.cpp b/src/FDM/JSBSim/models/FGPropagate.cpp index 93d6d4749..f2a1251fc 100644 --- a/src/FDM/JSBSim/models/FGPropagate.cpp +++ b/src/FDM/JSBSim/models/FGPropagate.cpp @@ -54,15 +54,18 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include -#include +#include +#include #include "FGPropagate.h" -#include -#include +#include "FGFDMExec.h" +#include "FGState.h" #include "FGAircraft.h" #include "FGMassBalance.h" #include "FGInertial.h" -#include +#include "input_output/FGPropertyManager.h" + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/FGPropagate.h b/src/FDM/JSBSim/models/FGPropagate.h index 6de7d11c4..c84005318 100644 --- a/src/FDM/JSBSim/models/FGPropagate.h +++ b/src/FDM/JSBSim/models/FGPropagate.h @@ -38,11 +38,11 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include -#include +#include "models/FGModel.h" +#include "math/FGColumnVector3.h" +#include "math/FGLocation.h" +#include "math/FGQuaternion.h" +#include "math/FGMatrix33.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -538,6 +538,6 @@ private: } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -#include +#include "initialization/FGInitialCondition.h" #endif diff --git a/src/FDM/JSBSim/models/FGPropulsion.cpp b/src/FDM/JSBSim/models/FGPropulsion.cpp index ed066b26c..b6e6c14ea 100644 --- a/src/FDM/JSBSim/models/FGPropulsion.cpp +++ b/src/FDM/JSBSim/models/FGPropulsion.cpp @@ -45,15 +45,24 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGPropulsion.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "FGState.h" +#include "models/FGFCS.h" +#include "models/FGMassBalance.h" +#include "models/propulsion/FGThruster.h" +#include "models/propulsion/FGRocket.h" +#include "models/propulsion/FGTurbine.h" +#include "models/propulsion/FGPiston.h" +#include "models/propulsion/FGElectric.h" +#include "models/propulsion/FGTurboProp.h" +#include "models/propulsion/FGTank.h" +#include "input_output/FGPropertyManager.h" +#include "input_output/FGXMLParse.h" +#include "math/FGColumnVector3.h" +#include #include +#include + +using namespace std; namespace JSBSim { @@ -255,6 +264,20 @@ bool FGPropulsion::Load(Element* el) FGModel::Load(el); // Perform base class Load. + // Process tank definitions first to establish the number of fuel tanks + + Element* tank_element = el->FindElement("tank"); + while (tank_element) { + Tanks.push_back(new FGTank(FDMExec, tank_element, numTanks)); + if (Tanks.back()->GetType() == FGTank::ttFUEL) numFuelTanks++; + else if (Tanks.back()->GetType() == FGTank::ttOXIDIZER) numOxiTanks++; + else {cerr << "Unknown tank type specified." << endl; return false;} + numTanks++; + tank_element = el->FindNextElement("tank"); + } + numSelectedFuelTanks = numFuelTanks; + numSelectedOxiTanks = numOxiTanks; + Element* engine_element = el->FindElement("engine"); while (engine_element) { engine_filename = engine_element->GetAttributeValue("file"); @@ -303,20 +326,6 @@ bool FGPropulsion::Load(Element* el) ResetParser(); } - // Process tank definitions - - Element* tank_element = el->FindElement("tank"); - while (tank_element) { - Tanks.push_back(new FGTank(FDMExec, tank_element, numTanks)); - if (Tanks.back()->GetType() == FGTank::ttFUEL) numFuelTanks++; - else if (Tanks.back()->GetType() == FGTank::ttOXIDIZER) numOxiTanks++; - else {cerr << "Unknown tank type specified." << endl; return false;} - numTanks++; - tank_element = el->FindNextElement("tank"); - } - numSelectedFuelTanks = numFuelTanks; - numSelectedOxiTanks = numOxiTanks; - CalculateTankInertias(); if (!ThrottleAdded) FCS->AddThrottle(); // need to have at least one throttle @@ -330,7 +339,7 @@ bool FGPropulsion::Load(Element* el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGPropulsion::FindEngineFullPathname(string engine_filename) +string FGPropulsion::FindEngineFullPathname(const string& engine_filename) { string fullpath, localpath; string enginePath = FDMExec->GetEnginePath(); @@ -358,7 +367,7 @@ string FGPropulsion::FindEngineFullPathname(string engine_filename) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ifstream* FGPropulsion::FindEngineFile(string engine_filename) +ifstream* FGPropulsion::FindEngineFile(const string& engine_filename) { string fullpath, localpath; string enginePath = FDMExec->GetEnginePath(); @@ -383,7 +392,7 @@ ifstream* FGPropulsion::FindEngineFile(string engine_filename) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGPropulsion::GetPropulsionStrings(string delimeter) +string FGPropulsion::GetPropulsionStrings(const string& delimiter) { unsigned int i; @@ -393,13 +402,13 @@ string FGPropulsion::GetPropulsionStrings(string delimeter) for (i=0; iGetEngineLabels(delimeter); + PropulsionStrings += Engines[i]->GetEngineLabels(delimiter); } for (i=0; iGetType() == FGTank::ttFUEL) buf << delimeter << "Fuel Tank " << i; - else if (Tanks[i]->GetType() == FGTank::ttOXIDIZER) buf << delimeter << "Oxidizer Tank " << i; + if (Tanks[i]->GetType() == FGTank::ttFUEL) buf << delimiter << "Fuel Tank " << i; + else if (Tanks[i]->GetType() == FGTank::ttOXIDIZER) buf << delimiter << "Oxidizer Tank " << i; } return PropulsionStrings; @@ -407,7 +416,7 @@ string FGPropulsion::GetPropulsionStrings(string delimeter) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGPropulsion::GetPropulsionValues(string delimeter) +string FGPropulsion::GetPropulsionValues(const string& delimiter) { unsigned int i; @@ -417,12 +426,12 @@ string FGPropulsion::GetPropulsionValues(string delimeter) for (i=0; iGetEngineValues(delimeter); + PropulsionValues += Engines[i]->GetEngineValues(delimiter); } for (i=0; iGetContents(); } diff --git a/src/FDM/JSBSim/models/FGPropulsion.h b/src/FDM/JSBSim/models/FGPropulsion.h index e356c0b15..ce62a60ea 100644 --- a/src/FDM/JSBSim/models/FGPropulsion.h +++ b/src/FDM/JSBSim/models/FGPropulsion.h @@ -39,13 +39,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include -#include +#include #include "FGModel.h" -#include -#include -#include -#include +#include "math/FGMatrix33.h" +#include "input_output/FGXMLFileRead.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -59,6 +57,9 @@ FORWARD DECLARATIONS namespace JSBSim { +class FGTank; +class FGEngine; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -157,8 +158,8 @@ public: /** Sets up the engines as running */ void InitRunning(int n); - string GetPropulsionStrings(string delimeter); - string GetPropulsionValues(string delimeter); + std::string GetPropulsionStrings(const std::string& delimiter); + std::string GetPropulsionValues(const std::string& delimiter); inline FGColumnVector3& GetForces(void) {return vForces; } inline double GetForces(int n) const { return vForces(n);} @@ -176,8 +177,8 @@ public: FGColumnVector3& GetTanksMoment(void); double GetTanksWeight(void); - ifstream* FindEngineFile(string filename); - string FindEngineFullPathname(string engine_filename); + std::ifstream* FindEngineFile(const std::string& filename); + std::string FindEngineFullPathname(const std::string& engine_filename); inline int GetActiveEngine(void) const {return ActiveEngine;} inline bool GetFuelFreeze(void) {return fuel_freeze;} double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;} @@ -190,8 +191,8 @@ public: FGMatrix33& CalculateTankInertias(void); private: - vector Engines; - vector Tanks; + std::vector Engines; + std::vector Tanks; unsigned int numSelectedFuelTanks; unsigned int numSelectedOxiTanks; unsigned int numFuelTanks; diff --git a/src/FDM/JSBSim/models/atmosphere/FGMSIS.cpp b/src/FDM/JSBSim/models/atmosphere/FGMSIS.cpp index 590e3f6d3..032858101 100755 --- a/src/FDM/JSBSim/models/atmosphere/FGMSIS.cpp +++ b/src/FDM/JSBSim/models/atmosphere/FGMSIS.cpp @@ -59,11 +59,11 @@ INCLUDES #include "FGMSIS.h" #include "FGState.h" -#include /* maths functions */ -#include /* for malloc/free */ -#include /* for printf */ +#include /* maths functions */ #include // for cout, endl +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; @@ -322,7 +322,7 @@ double MSIS::dnet (double dd, double dm, double zhm, double xmm, double xm) double ylog; a = zhm / (xmm-xm); if (!((dm>0) && (dd>0))) { - printf("dnet log error %e %e %e\n",dm,dd,xm); + cerr << "dnet log error " << dm << ' ' << dd << ' ' << xm << ' ' << endl; if ((dd==0) && (dm==0)) dd=1; if (dm==0) @@ -400,7 +400,7 @@ void MSIS::splint (double *xa, double *ya, double *y2a, int n, double x, double } h = xa[khi] - xa[klo]; if (h==0.0) - printf("bad XA input to splint"); + cerr << "bad XA input to splint" << endl; a = (xa[khi] - x)/h; b = (x - xa[klo])/h; yi = a * ya[klo] + b * ya[khi] + ((a*a*a - a) * y2a[klo] + (b*b*b - b) * y2a[khi]) * h * h/6.0; @@ -422,9 +422,9 @@ void MSIS::spline (double *x, double *y, int n, double yp1, double ypn, double * double *u; double sig, p, qn, un; int i, k; - u=(double*)malloc(sizeof(double)*n); + u=new double[n]; if (u==NULL) { - printf("Out Of Memory in spline - ERROR"); + cerr << "Out Of Memory in spline - ERROR" << endl; return; } if (yp1>0.99E30) { @@ -451,7 +451,7 @@ void MSIS::spline (double *x, double *y, int n, double yp1, double ypn, double * for (k=n-2;k>=0;k--) y2[k] = y2[k] * y2[k+1] + u[k]; - free(u); + delete u; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -964,7 +964,7 @@ double MSIS::glob7s(double *p, struct nrlmsise_input *input, if (p[99]==0) p[99]=pset; if (p[99]!=pset) { - printf("Wrong parameter set for glob7s\n"); + cerr << "Wrong parameter set for glob7s" << endl; return -1; } for (j=0;j<14;j++) @@ -1247,7 +1247,7 @@ void MSIS::ghp7(struct nrlmsise_input *input, struct nrlmsise_flags *flags, if (sqrt(diff*diff)d[5] / xn / 1.66E-24; diff --git a/src/FDM/JSBSim/models/atmosphere/FGMSIS.h b/src/FDM/JSBSim/models/atmosphere/FGMSIS.h index 02de74903..1765388a7 100755 --- a/src/FDM/JSBSim/models/atmosphere/FGMSIS.h +++ b/src/FDM/JSBSim/models/atmosphere/FGMSIS.h @@ -40,7 +40,7 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include "models/FGAtmosphere.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/atmosphere/FGMars.cpp b/src/FDM/JSBSim/models/atmosphere/FGMars.cpp index 3bd737926..7bebc7d34 100755 --- a/src/FDM/JSBSim/models/atmosphere/FGMars.cpp +++ b/src/FDM/JSBSim/models/atmosphere/FGMars.cpp @@ -43,6 +43,9 @@ INCLUDES #include "FGMars.h" #include "FGState.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/atmosphere/FGMars.h b/src/FDM/JSBSim/models/atmosphere/FGMars.h index c07a78965..5f4bba350 100755 --- a/src/FDM/JSBSim/models/atmosphere/FGMars.h +++ b/src/FDM/JSBSim/models/atmosphere/FGMars.h @@ -38,7 +38,7 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include "models/FGAtmosphere.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/flight_control/FGAccelerometer.cpp b/src/FDM/JSBSim/models/flight_control/FGAccelerometer.cpp index b2c3ca573..1148c81b6 100755 --- a/src/FDM/JSBSim/models/flight_control/FGAccelerometer.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGAccelerometer.cpp @@ -38,6 +38,10 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGAccelerometer.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -48,7 +52,9 @@ static const char *IdHdr = ID_ACCELEROMETER; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) : FGSensor(fcs, element) +FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) + : FGSensor(fcs, element), + FGSensorOrientation(element) { Propagate = fcs->GetExec()->GetPropagate(); MassBalance = fcs->GetExec()->GetMassBalance(); @@ -60,27 +66,6 @@ FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) : FGSensor(fcs, e vRadius = MassBalance->StructuralToBody(vLocation); - Element* orient_element = element->FindElement("orientation"); - if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); - else {cerr << "No orientation given for accelerometer. " << endl;} - - Element* axis_element = element->FindElement("axis"); - if (axis_element) { - string sAxis = element->FindElementValue("axis"); - if (sAxis == "X" || sAxis == "x") { - axis = 1; - } else if (sAxis == "Y" || sAxis == "y") { - axis = 2; - } else if (sAxis == "Z" || sAxis == "z") { - axis = 3; - } else { - cerr << " Incorrect/no axis specified for accelerometer; assuming X axis" << endl; - axis = 1; - } - } - - CalculateTransformMatrix(); - Debug(0); } @@ -96,7 +81,7 @@ FGAccelerometer::~FGAccelerometer() bool FGAccelerometer::Run(void ) { // There is no input assumed. This is a dedicated acceleration sensor. - + vRadius = MassBalance->StructuralToBody(vLocation); //gravitational forces @@ -112,59 +97,11 @@ bool FGAccelerometer::Run(void ) Input = vAccel(axis); - Output = Input; // perfect accelerometer + ProcessSensorSignal(); - // Degrade signal as specified - - if (fail_stuck) { - Output = PreviousOutput; - return true; - } - - if (lag != 0.0) Lag(); // models accelerometer lag - if (noise_variance != 0.0) Noise(); // models noise - if (drift_rate != 0.0) Drift(); // models drift over time - if (bias != 0.0) Bias(); // models a finite bias - if (gain != 0.0) Gain(); // models a gain - - if (fail_low) Output = -HUGE_VAL; - if (fail_high) Output = HUGE_VAL; - - if (bits != 0) Quantize(); // models quantization degradation -// if (delay != 0.0) Delay(); // models system signal transport latencies - - Clip(); // Is it right to clip an accelerometer? return true; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGAccelerometer::CalculateTransformMatrix(void) -{ - double cp,sp,cr,sr,cy,sy; - - cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch)); - cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll)); - cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw)); - - mT(1,1) = cp*cy; - mT(1,2) = cp*sy; - mT(1,3) = -sp; - - mT(2,1) = sr*sp*cy - cr*sy; - mT(2,2) = sr*sp*sy + cr*cy; - mT(2,3) = sr*cp; - - mT(3,1) = cr*sp*cy + sr*sy; - mT(3,2) = cr*sp*sy - sr*cy; - mT(3,3) = cr*cp; - - // This transform is different than for FGForce, where we want a native nozzle - // force in body frame. Here we calculate the body frame accel and want it in - // the transformed accelerometer frame. So, the next line is commented out. - // mT = mT.Inverse(); -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/flight_control/FGAccelerometer.h b/src/FDM/JSBSim/models/flight_control/FGAccelerometer.h index bf3a58c6e..d552fe434 100755 --- a/src/FDM/JSBSim/models/flight_control/FGAccelerometer.h +++ b/src/FDM/JSBSim/models/flight_control/FGAccelerometer.h @@ -38,12 +38,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSensor.h" -#include +#include "input_output/FGXMLElement.h" #include "models/FGPropagate.h" #include "models/FGMassBalance.h" #include "models/FGInertial.h" #include "math/FGColumnVector3.h" #include "math/FGMatrix33.h" +#include "FGSensorOrientation.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -116,7 +117,7 @@ time. CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class FGAccelerometer : public FGSensor +class FGAccelerometer : public FGSensor, public FGSensorOrientation { public: FGAccelerometer(FGFCS* fcs, Element* element); @@ -129,12 +130,8 @@ private: FGMassBalance* MassBalance; FGInertial* Inertial; FGColumnVector3 vLocation; - FGColumnVector3 vOrient; FGColumnVector3 vRadius; FGColumnVector3 vAccel; - FGMatrix33 mT; - void CalculateTransformMatrix(void); - int axis; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/flight_control/FGActuator.cpp b/src/FDM/JSBSim/models/flight_control/FGActuator.cpp index 9b0a3cc8a..ae2aa38b7 100755 --- a/src/FDM/JSBSim/models/flight_control/FGActuator.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGActuator.cpp @@ -39,6 +39,8 @@ INCLUDES #include "FGActuator.h" +using namespace std; + namespace JSBSim { static const char *IdSrc = "$Id$"; @@ -52,7 +54,6 @@ CLASS IMPLEMENTATION FGActuator::FGActuator(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) { double denom; - dt = fcs->GetDt(); // inputs are read from the base class constructor @@ -101,8 +102,6 @@ FGActuator::~FGActuator() bool FGActuator::Run(void ) { - dt = fcs->GetDt(); - Input = InputNodes[0]->getDoubleValue() * InputSigns[0]; if (fail_zero) Input = 0; @@ -237,7 +236,10 @@ void FGActuator::Debug(int from) else cout << " INPUT: " << InputNodes[0]->getName() << endl; - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } if (bias != 0.0) cout << " Bias: " << bias << endl; if (rate_limit != 0) cout << " Rate limit: " << rate_limit << endl; if (lag != 0) cout << " Actuator lag: " << lag << endl; diff --git a/src/FDM/JSBSim/models/flight_control/FGActuator.h b/src/FDM/JSBSim/models/flight_control/FGActuator.h index 79571fbe6..ecfb3bf8a 100755 --- a/src/FDM/JSBSim/models/flight_control/FGActuator.h +++ b/src/FDM/JSBSim/models/flight_control/FGActuator.h @@ -38,7 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include +#include "input_output/FGXMLElement.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -144,7 +144,6 @@ public: inline bool GetFailStuck(void) const {return fail_stuck;} private: - double dt; double span; double bias; double rate_limit; diff --git a/src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp b/src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp index 745f8ad28..3d0689d38 100644 --- a/src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp @@ -38,6 +38,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGDeadBand.h" +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" +#include + +using namespace std; namespace JSBSim { @@ -144,7 +149,10 @@ void FGDeadBand::Debug(int from) cout << " DEADBAND WIDTH: " << width << endl; } cout << " GAIN: " << gain << endl; - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGDeadBand.h b/src/FDM/JSBSim/models/flight_control/FGDeadBand.h index d07b88cc4..9dd4a39a3 100644 --- a/src/FDM/JSBSim/models/flight_control/FGDeadBand.h +++ b/src/FDM/JSBSim/models/flight_control/FGDeadBand.h @@ -38,7 +38,6 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -53,6 +52,8 @@ FORWARD DECLARATIONS namespace JSBSim { class FGFCS; +class Element; +class FGPropertyManager; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp index 954be2354..d1f454555 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp @@ -38,6 +38,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" +#include "input_output/FGPropertyManager.h" +#include "input_output/FGXMLElement.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -52,11 +58,13 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) { Element *input_element, *clip_el; Input = Output = clipmin = clipmax = 0.0; - OutputNode = treenode = 0; + treenode = 0; + delay = index = 0; ClipMinPropertyNode = ClipMaxPropertyNode = 0; clipMinSign = clipMaxSign = 1.0; IsOutput = clip = false; string input, clip_string; + dt = fcs->GetDt(); PropertyManager = fcs->GetPropertyManager(); if (element->GetName() == string("lag_filter")) { @@ -91,6 +99,8 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) Type = "SENSOR"; } else if (element->GetName() == string("accelerometer")) { Type = "ACCELEROMETER"; + } else if (element->GetName() == string("magnetometer")) { + Type = "MAGNETOMETER"; } else if (element->GetName() == string("gyro")) { Type = "GYRO"; } else if (element->GetName() == string("actuator")) { @@ -123,13 +133,36 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) input_element = element->FindNextElement("input"); } - if (element->FindElement("output")) { + Element *out_elem = element->FindElement("output"); + while (out_elem) { IsOutput = true; - OutputNode = PropertyManager->GetNode( element->FindElementValue("output"), true ); + string output_node_name = out_elem->GetDataLine(); + FGPropertyManager* OutputNode = PropertyManager->GetNode( output_node_name, true ); + OutputNodes.push_back(OutputNode); if (!OutputNode) { - cerr << endl << " Unable to process property: " << element->FindElementValue("output") << endl; + cerr << endl << " Unable to process property: " << output_node_name << endl; throw(string("Invalid output property name in flight control definition")); } + out_elem = element->FindNextElement("output"); + } + + Element* delay_elem = element->FindElement("delay"); + if ( delay_elem ) { + delay = (unsigned int)delay_elem->GetDataAsNumber(); + string delayType = delay_elem->GetAttributeValue("type"); + if (delayType.length() > 0) { + if (delayType == "time") { + delay = (int)(delay / dt); + } else if (delayType == "frames") { + // no op. the delay type of "frames" is assumed and is the default. + } else { + cerr << "Unallowed delay type" << endl; + } + } else { + delay = (int)(delay / dt); + } + output_array.resize(delay); + for (int i=0; iFindElement("clipto"); @@ -171,7 +204,7 @@ FGFCSComponent::~FGFCSComponent() void FGFCSComponent::SetOutput(void) { - OutputNode->setDoubleValue(Output); + for (unsigned int i=0; isetDoubleValue(Output); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -183,6 +216,16 @@ bool FGFCSComponent::Run(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +void FGFCSComponent::Delay(void) +{ + output_array[index] = Output; + if (index == delay-1) index = 0; + else index++; + Output = output_array[index]; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGFCSComponent::Clip(void) { if (clip) { @@ -258,6 +301,8 @@ void FGFCSComponent::Debug(int from) cout << " Maximum limit: " << clipmax << endl; } } + if (delay > 0) cout <<" Frame delay: " << delay + << " frames (" << delay*dt << " sec)" << endl; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h index fa8506131..b1fc2c6c5 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h +++ b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h @@ -37,9 +37,7 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include +#include "FGJSBBase.h" #include #include @@ -49,9 +47,6 @@ DEFINITIONS #define ID_FCSCOMPONENT "$Id$" -using std::string; -using std::vector; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -59,6 +54,8 @@ FORWARD DECLARATIONS namespace JSBSim { class FGFCS; +class FGPropertyManager; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -101,30 +98,34 @@ public: virtual bool Run(void); virtual void SetOutput(void); - inline double GetOutput (void) const {return Output;} - inline FGPropertyManager* GetOutputNode(void) { return OutputNode; } - inline string GetName(void) const {return Name;} - inline string GetType(void) const { return Type; } + double GetOutput (void) const {return Output;} + std::string GetName(void) const {return Name;} + std::string GetType(void) const { return Type; } virtual double GetOutputPct(void) const { return 0; } protected: FGFCS* fcs; FGPropertyManager* PropertyManager; FGPropertyManager* treenode; - FGPropertyManager* OutputNode; + std::vector OutputNodes; FGPropertyManager* ClipMinPropertyNode; FGPropertyManager* ClipMaxPropertyNode; - vector InputNodes; - vector InputSigns; - string Type; - string Name; + std::vector InputNodes; + std::vector InputSigns; + std::vector output_array; + std::string Type; + std::string Name; double Input; double Output; double clipmax, clipmin; + int delay; + int index; float clipMinSign, clipMaxSign; + double dt; bool IsOutput; bool clip; + void Delay(void); void Clip(void); virtual void bind(); virtual void Debug(int from); diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSFunction.cpp b/src/FDM/JSBSim/models/flight_control/FGFCSFunction.cpp index ea86d4114..d8a91572e 100755 --- a/src/FDM/JSBSim/models/flight_control/FGFCSFunction.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGFCSFunction.cpp @@ -38,6 +38,10 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSFunction.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -119,7 +123,10 @@ void FGFCSFunction::Debug(int from) if (InputNodes.size()>0) cout << " INPUT: " << InputNodes[0]->getName() << endl; // cout << " Function: " << endl; - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSFunction.h b/src/FDM/JSBSim/models/flight_control/FGFCSFunction.h index 422d0b093..fe731e8c3 100755 --- a/src/FDM/JSBSim/models/flight_control/FGFCSFunction.h +++ b/src/FDM/JSBSim/models/flight_control/FGFCSFunction.h @@ -38,8 +38,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include +#include "input_output/FGXMLElement.h" +#include "math/FGFunction.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/flight_control/FGFilter.cpp b/src/FDM/JSBSim/models/flight_control/FGFilter.cpp index 997939238..f0ca49064 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFilter.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGFilter.cpp @@ -38,6 +38,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFilter.h" +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" + +#include +#include + +using namespace std; namespace JSBSim { @@ -50,14 +57,14 @@ CLASS IMPLEMENTATION FGFilter::FGFilter(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) { - dt = fcs->GetState()->Getdt(); Trigger = 0; DynamicFilter = false; C[1] = C[2] = C[3] = C[4] = C[5] = C[6] = 0.0; - for (int i=0; i<7; i++) { + for (int i=1; i<7; i++) { PropertySign[i] = 1.0; PropertyNode[i] = 0L; + ReadFilterCoefficients(element, i); } if (Type == "LAG_FILTER") FilterType = eLag ; @@ -67,13 +74,6 @@ FGFilter::FGFilter(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) else if (Type == "INTEGRATOR") FilterType = eIntegrator ; else FilterType = eUnknown ; - ReadFilterCoefficients(element, 1); - ReadFilterCoefficients(element, 2); - ReadFilterCoefficients(element, 3); - ReadFilterCoefficients(element, 4); - ReadFilterCoefficients(element, 5); - ReadFilterCoefficients(element, 6); - if (element->FindElement("trigger")) { Trigger = PropertyManager->GetNode(element->FindElementValue("trigger")); } @@ -98,13 +98,13 @@ FGFilter::~FGFilter() void FGFilter::ReadFilterCoefficients(Element* element, int index) { - char buf[3]; - sprintf(buf, "c%d", index); - string coefficient = string(buf); - string property_string=""; - + // index is known to be 1-7. + // A stringstream would be overkill, but also trying to avoid sprintf + string coefficient = "c0"; + coefficient[1] += index; + if ( element->FindElement(coefficient) ) { - property_string = element->FindElementValue(coefficient); + string property_string = element->FindElementValue(coefficient); if (!is_number(property_string)) { // property if (property_string[0] == '-') { PropertySign[index] = -1.0; @@ -323,8 +323,13 @@ void FGFilter::Debug(int from) if (PropertyNode[1] == 0L) cout << " C[1]: " << C[1] << endl; else cout << " C[1] is the value of property: " << sgn << PropertyNode[1]->GetName() << endl; break; + case eUnknown: + break; } - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGFilter.h b/src/FDM/JSBSim/models/flight_control/FGFilter.h index c7c0a4143..7aeafc202 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFilter.h +++ b/src/FDM/JSBSim/models/flight_control/FGFilter.h @@ -38,7 +38,6 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -52,6 +51,10 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; +class FGPropertyManager; +class FGFCS; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -249,7 +252,6 @@ public: enum {eLag, eLeadLag, eOrder2, eWashout, eIntegrator, eUnknown} FilterType; private: - double dt; double ca; double cb; double cc; diff --git a/src/FDM/JSBSim/models/flight_control/FGGain.cpp b/src/FDM/JSBSim/models/flight_control/FGGain.cpp index f8f73daf3..0ecb8c645 100644 --- a/src/FDM/JSBSim/models/flight_control/FGGain.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGGain.cpp @@ -38,6 +38,12 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGGain.h" +#include "input_output/FGXMLElement.h" +#include +#include +#include + +using namespace std; namespace JSBSim { @@ -212,7 +218,10 @@ void FGGain::Debug(int from) } else { cout << " GAIN: " << Gain << endl; } - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } if (Type == "AEROSURFACE_SCALE") { cout << " In/Out Mapping:" << endl; cout << " Input MIN: " << InMin << endl; diff --git a/src/FDM/JSBSim/models/flight_control/FGGain.h b/src/FDM/JSBSim/models/flight_control/FGGain.h index faf535c69..525c4e449 100644 --- a/src/FDM/JSBSim/models/flight_control/FGGain.h +++ b/src/FDM/JSBSim/models/flight_control/FGGain.h @@ -38,11 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include -#include - -using std::string; +#include "math/FGTable.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -57,6 +53,7 @@ FORWARD DECLARATIONS namespace JSBSim { class FGFCS; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION diff --git a/src/FDM/JSBSim/models/flight_control/FGGradient.cpp b/src/FDM/JSBSim/models/flight_control/FGGradient.cpp index 15af4c5f3..2325dec1e 100644 --- a/src/FDM/JSBSim/models/flight_control/FGGradient.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGGradient.cpp @@ -38,6 +38,9 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGGradient.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/flight_control/FGGradient.h b/src/FDM/JSBSim/models/flight_control/FGGradient.h index 0d2ad21db..ce7dac4f8 100644 --- a/src/FDM/JSBSim/models/flight_control/FGGradient.h +++ b/src/FDM/JSBSim/models/flight_control/FGGradient.h @@ -38,7 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include +#include "input_output/FGXMLElement.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/flight_control/FGGyro.cpp b/src/FDM/JSBSim/models/flight_control/FGGyro.cpp index 0fcd127e8..740c01e3a 100755 --- a/src/FDM/JSBSim/models/flight_control/FGGyro.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGGyro.cpp @@ -38,6 +38,9 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGGyro.h" +#include + +using namespace std; namespace JSBSim { @@ -48,31 +51,11 @@ static const char *IdHdr = ID_GYRO; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGGyro::FGGyro(FGFCS* fcs, Element* element) : FGSensor(fcs, element) +FGGyro::FGGyro(FGFCS* fcs, Element* element) : FGSensor(fcs, element), + FGSensorOrientation(element) { Propagate = fcs->GetExec()->GetPropagate(); - Element* orient_element = element->FindElement("orientation"); - if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); - else {cerr << "No orientation given for gyro. " << endl;} - - Element* axis_element = element->FindElement("axis"); - if (axis_element) { - string sAxis = element->FindElementValue("axis"); - if (sAxis == "ROLL" || sAxis == "roll") { - axis = 1; - } else if (sAxis == "PITCH" || sAxis == "pitch") { - axis = 2; - } else if (sAxis == "YAW" || sAxis == "yaw") { - axis = 3; - } else { - cerr << " Incorrect/no axis specified for gyro; assuming Roll axis" << endl; - axis = 1; - } - } - - CalculateTransformMatrix(); - Debug(0); } @@ -94,59 +77,11 @@ bool FGGyro::Run(void ) Input = vAccel(axis); - Output = Input; // perfect gyro + ProcessSensorSignal(); - // Degrade signal as specified - - if (fail_stuck) { - Output = PreviousOutput; - return true; - } - - if (lag != 0.0) Lag(); // models gyro lag - if (noise_variance != 0.0) Noise(); // models noise - if (drift_rate != 0.0) Drift(); // models drift over time - if (bias != 0.0) Bias(); // models a finite bias - if (gain != 0.0) Gain(); // models a gain - - if (fail_low) Output = -HUGE_VAL; - if (fail_high) Output = HUGE_VAL; - - if (bits != 0) Quantize(); // models quantization degradation -// if (delay != 0.0) Delay(); // models system signal transport latencies - - Clip(); // Is it right to clip a gyro? return true; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGGyro::CalculateTransformMatrix(void) -{ - double cp,sp,cr,sr,cy,sy; - - cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch)); - cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll)); - cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw)); - - mT(1,1) = cp*cy; - mT(1,2) = cp*sy; - mT(1,3) = -sp; - - mT(2,1) = sr*sp*cy - cr*sy; - mT(2,2) = sr*sp*sy + cr*cy; - mT(2,3) = sr*cp; - - mT(3,1) = cr*sp*cy + sr*sy; - mT(3,2) = cr*sp*sy - sr*cy; - mT(3,3) = cr*cp; - - // This transform is different than for FGForce, where we want a native nozzle - // force in body frame. Here we calculate the body frame accel and want it in - // the transformed gyro frame. So, the next line is commented out. - // mT = mT.Inverse(); -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/flight_control/FGGyro.h b/src/FDM/JSBSim/models/flight_control/FGGyro.h index c486eee50..af10851bf 100755 --- a/src/FDM/JSBSim/models/flight_control/FGGyro.h +++ b/src/FDM/JSBSim/models/flight_control/FGGyro.h @@ -38,12 +38,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSensor.h" -#include +#include "input_output/FGXMLElement.h" #include "models/FGPropagate.h" #include "models/FGMassBalance.h" #include "models/FGInertial.h" #include "math/FGColumnVector3.h" #include "math/FGMatrix33.h" +#include "FGSensorOrientation.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -116,7 +117,7 @@ time. CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class FGGyro : public FGSensor +class FGGyro : public FGSensor, public FGSensorOrientation { public: FGGyro(FGFCS* fcs, Element* element); @@ -126,11 +127,8 @@ public: private: FGPropagate* Propagate; - FGColumnVector3 vOrient; FGColumnVector3 vAccel; - FGMatrix33 mT; void CalculateTransformMatrix(void); - int axis; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/flight_control/FGKinemat.cpp b/src/FDM/JSBSim/models/flight_control/FGKinemat.cpp index 5949cf710..931c1740c 100644 --- a/src/FDM/JSBSim/models/flight_control/FGKinemat.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGKinemat.cpp @@ -38,8 +38,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGKinemat.h" -#include -#include +#include "input_output/FGXMLElement.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -98,13 +101,13 @@ FGKinemat::~FGKinemat() bool FGKinemat::Run(void ) { - double dt = fcs->GetState()->Getdt(); + double dt0 = dt; Input = InputNodes[0]->getDoubleValue() * InputSigns[0]; if (DoScale) Input *= Detents[NumDetents-1]; - if (IsOutput) Output = OutputNode->getDoubleValue(); + if (IsOutput) Output = OutputNodes[0]->getDoubleValue(); if (Input < Detents[0]) Input = Detents[0]; @@ -113,7 +116,7 @@ bool FGKinemat::Run(void ) // Process all detent intervals the movement traverses until either the // final value is reached or the time interval has finished. - while ( 0.0 < dt && !EqualToRoundoff(Input, Output) ) { + while ( dt0 > 0.0 && !EqualToRoundoff(Input, Output) ) { // Find the area where Output is in int ind; @@ -137,8 +140,8 @@ bool FGKinemat::Run(void ) double ThisDt = fabs((ThisInput-Output)/Rate); // and clip to the timestep size - if (dt < ThisDt) { - ThisDt = dt; + if (dt0 < ThisDt) { + ThisDt = dt0; if (Output < Input) Output += ThisDt*Rate; else @@ -148,7 +151,7 @@ bool FGKinemat::Run(void ) // is met even in inexact arithmetics ... Output = ThisInput; - dt -= ThisDt; + dt0 -= ThisDt; } } @@ -190,7 +193,10 @@ void FGKinemat::Debug(int from) for (int i=0;igetName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } if (!DoScale) cout << " NOSCALE" << endl; } } diff --git a/src/FDM/JSBSim/models/flight_control/FGKinemat.h b/src/FDM/JSBSim/models/flight_control/FGKinemat.h index 13d2ec7d9..8dcc73bb8 100644 --- a/src/FDM/JSBSim/models/flight_control/FGKinemat.h +++ b/src/FDM/JSBSim/models/flight_control/FGKinemat.h @@ -38,12 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include #include -#include - -using std::vector; -using std::string; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -134,8 +129,8 @@ public: bool Run (void); private: - vector Detents; - vector TransitionTimes; + std::vector Detents; + std::vector TransitionTimes; int NumDetents; double OutputPct; bool DoScale; diff --git a/src/FDM/JSBSim/models/flight_control/FGMagnetometer.cpp b/src/FDM/JSBSim/models/flight_control/FGMagnetometer.cpp index 561e0dcca..368d3524e 100755 --- a/src/FDM/JSBSim/models/flight_control/FGMagnetometer.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGMagnetometer.cpp @@ -40,6 +40,10 @@ INCLUDES #include "FGMagnetometer.h" #include "simgear/magvar/coremag.hxx" #include +#include +#include + +using namespace std; namespace JSBSim { @@ -51,7 +55,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element) : FGSensor(fcs, element),\ +FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element) : FGSensor(fcs, element), + FGSensorOrientation(element), counter(0), INERTIAL_UPDATE_RATE(1000) { @@ -65,27 +70,6 @@ FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element) : FGSensor(fcs, ele vRadius = MassBalance->StructuralToBody(vLocation); - Element* orient_element = element->FindElement("orientation"); - if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); - else {cerr << "No orientation given for magnetometer. " << endl;} - - Element* axis_element = element->FindElement("axis"); - if (axis_element) { - string sAxis = element->FindElementValue("axis"); - if (sAxis == "X" || sAxis == "x") { - axis = 1; - } else if (sAxis == "Y" || sAxis == "y") { - axis = 2; - } else if (sAxis == "Z" || sAxis == "z") { - axis = 3; - } else { - cerr << " Incorrect/no axis specified for magnetometer; assuming X axis" << endl; - axis = 1; - } - } - - CalculateTransformMatrix(); - //assuming date wont significantly change over a flight to affect mag field //would be better to get the date from the sim if its simulated... time_t rawtime; @@ -114,7 +98,7 @@ FGMagnetometer::~FGMagnetometer() void FGMagnetometer::updateInertialMag(void) { counter++; - if(counter > INERTIAL_UPDATE_RATE)//dont need to update every iteration + if (counter > INERTIAL_UPDATE_RATE)//dont need to update every iteration { counter = 0; @@ -123,11 +107,11 @@ void FGMagnetometer::updateInertialMag(void) usedAlt = (Propagate->GetGeodeticAltitude()*fttom*0.001);//km //this should be done whenever the position changes significantly (in nTesla) - double magvar = calc_magvar( usedLat, - usedLon, - usedAlt, - date, - field ); + calc_magvar( usedLat, + usedLon, + usedAlt, + date, + field ); } } @@ -135,75 +119,25 @@ void FGMagnetometer::updateInertialMag(void) bool FGMagnetometer::Run(void ) { - // There is no input assumed. This is a dedicated acceleration sensor. + // There is no input assumed. This is a dedicated magnetic field sensor. vRadius = MassBalance->StructuralToBody(vLocation); - updateInertialMag(); - //Inertial magnetic field rotated to the body frame + + // Inertial magnetic field rotated to the body frame vMag = Propagate->GetTl2b() * FGColumnVector3(field[3], field[4], field[5]); - //allow for sensor orientation + // Allow for sensor orientation vMag = mT * vMag; Input = vMag(axis); - Output = Input; // perfect magnetometer + ProcessSensorSignal(); - // Degrade signal as specified - - if (fail_stuck) { - Output = PreviousOutput; - return true; - } - - if (lag != 0.0) Lag(); // models magnetometer lag - if (noise_variance != 0.0) Noise(); // models noise - if (drift_rate != 0.0) Drift(); // models drift over time - if (bias != 0.0) Bias(); // models a finite bias - if (gain != 0.0) Gain(); // models a gain - - if (fail_low) Output = -HUGE_VAL; - if (fail_high) Output = HUGE_VAL; - - if (bits != 0) Quantize(); // models quantization degradation -// if (delay != 0.0) Delay(); // models system signal transport latencies - - Clip(); // Is it right to clip an magnetometer? return true; } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGMagnetometer::CalculateTransformMatrix(void) -{ - double cp,sp,cr,sr,cy,sy; - - cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch)); - cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll)); - cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw)); - - - mT(1,1) = cp*cy; - mT(1,2) = cp*sy; - mT(1,3) = -sp; - - mT(2,1) = sr*sp*cy - cr*sy; - mT(2,2) = sr*sp*sy + cr*cy; - mT(2,3) = sr*cp; - - mT(3,1) = cr*sp*cy + sr*sy; - mT(3,2) = cr*sp*sy - sr*cy; - mT(3,3) = cr*cp; - - - // This transform is different than for FGForce, where we want a native nozzle - // force in body frame. Here we calculate the body frame accel and want it in - // the transformed magnetometer frame. So, the next line is commented out. - // mT = mT.Inverse(); -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/models/flight_control/FGMagnetometer.h b/src/FDM/JSBSim/models/flight_control/FGMagnetometer.h index 456d14d6d..e806fb622 100755 --- a/src/FDM/JSBSim/models/flight_control/FGMagnetometer.h +++ b/src/FDM/JSBSim/models/flight_control/FGMagnetometer.h @@ -38,12 +38,13 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSensor.h" -#include +#include "input_output/FGXMLElement.h" #include "models/FGPropagate.h" #include "models/FGMassBalance.h" #include "models/FGInertial.h" #include "math/FGColumnVector3.h" #include "math/FGMatrix33.h" +#include "FGSensorOrientation.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -118,7 +119,7 @@ time. CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class FGMagnetometer : public FGSensor +class FGMagnetometer : public FGSensor, public FGSensorOrientation { public: FGMagnetometer(FGFCS* fcs, Element* element); @@ -131,13 +132,9 @@ private: FGMassBalance* MassBalance; FGInertial* Inertial; FGColumnVector3 vLocation; - FGColumnVector3 vOrient; FGColumnVector3 vRadius; FGColumnVector3 vMag; - FGMatrix33 mT; - void CalculateTransformMatrix(void); void updateInertialMag(void); - int axis; double field[6]; double usedLat; double usedLon; diff --git a/src/FDM/JSBSim/models/flight_control/FGPID.cpp b/src/FDM/JSBSim/models/flight_control/FGPID.cpp index da1b4b0cd..3dda266f2 100755 --- a/src/FDM/JSBSim/models/flight_control/FGPID.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGPID.cpp @@ -36,6 +36,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGPID.h" +#include "input_output/FGXMLElement.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -49,7 +54,6 @@ CLASS IMPLEMENTATION FGPID::FGPID(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) { string kp_string, ki_string, kd_string; - dt = fcs->GetState()->Getdt(); Kp = Ki = Kd = 0.0; KpPropertyNode = 0; @@ -189,7 +193,10 @@ void FGPID::Debug(int from) else cout << " INPUT: " << InputNodes[0]->getName() << endl; - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGPID.h b/src/FDM/JSBSim/models/flight_control/FGPID.h index 5839b238a..adad3606c 100755 --- a/src/FDM/JSBSim/models/flight_control/FGPID.h +++ b/src/FDM/JSBSim/models/flight_control/FGPID.h @@ -39,8 +39,6 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -48,10 +46,6 @@ DEFINITIONS #define ID_PID "$Id$" -using std::string; - -using std::string; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -59,6 +53,7 @@ FORWARD DECLARATIONS namespace JSBSim { class FGFCS; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -105,7 +100,6 @@ public: void ResetPastStates(void) {Input_prev = Input_prev2 = Output = I_out_total = 0.0;} private: - double dt; FGPropertyManager *Trigger; double Kp, Ki, Kd; double I_out_total; diff --git a/src/FDM/JSBSim/models/flight_control/FGSensor.cpp b/src/FDM/JSBSim/models/flight_control/FGSensor.cpp index bd6a38417..1ca89b6ba 100755 --- a/src/FDM/JSBSim/models/flight_control/FGSensor.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGSensor.cpp @@ -38,6 +38,11 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSensor.h" +#include "input_output/FGXMLElement.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -52,11 +57,10 @@ CLASS IMPLEMENTATION FGSensor::FGSensor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) { double denom; - dt = fcs->GetDt(); // inputs are read from the base class constructor - bits = quantized = divisions = index = delay = 0; + bits = quantized = divisions = 0; PreviousInput = PreviousOutput = 0.0; min = max = bias = gain = noise_variance = lag = drift_rate = drift = span = 0.0; granularity = 0.0; @@ -117,11 +121,6 @@ FGSensor::FGSensor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) cerr << " defaulting to UNIFORM." << endl; } } - if ( element->FindElement("delay") ) { - delay = (unsigned int)element->FindElementValueAsNumber("delay"); - output_array.resize(delay); - for (unsigned int i=0; igetDoubleValue() * InputSigns[0]; + ProcessSensorSignal(); + + return true; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGSensor::ProcessSensorSignal(void) +{ Output = Input; // perfect sensor // Degrade signal as specified if (fail_stuck) { Output = PreviousOutput; - return true; + } else { + if (lag != 0.0) Lag(); // models sensor lag and filter + if (noise_variance != 0.0) Noise(); // models noise + if (drift_rate != 0.0) Drift(); // models drift over time + if (gain != 0.0) Gain(); // models a finite gain + if (bias != 0.0) Bias(); // models a finite bias + + if (delay != 0) Delay(); // models system signal transport latencies + + if (fail_low) Output = -HUGE_VAL; + if (fail_high) Output = HUGE_VAL; + + if (bits != 0) Quantize(); // models quantization degradation + + Clip(); } - - if (lag != 0.0) Lag(); // models sensor lag and filter - if (noise_variance != 0.0) Noise(); // models noise - if (drift_rate != 0.0) Drift(); // models drift over time - if (bias != 0.0) Bias(); // models a finite bias - if (gain != 0.0) Gain(); // models a finite gain - - if (delay != 0.0) Delay(); // models system signal transport latencies - - if (fail_low) Output = -HUGE_VAL; - if (fail_high) Output = HUGE_VAL; - - if (bits != 0) Quantize(); // models quantization degradation - - Clip(); // Is it right to clip a sensor? - return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -237,16 +243,6 @@ void FGSensor::Lag(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGSensor::Delay(void) -{ - output_array[index] = Output; - if (index == delay-1) index = 0; - else index++; - Output = output_array[index]; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - void FGSensor::bind(void) { string tmp = Name; @@ -301,8 +297,6 @@ void FGSensor::Debug(int from) else cout << " INPUT: " << InputNodes[0]->getName() << endl; } - if (delay > 0) cout <<" Frame delay: " << delay - << " frames (" << delay*dt << " sec)" << endl; if (bits != 0) { if (quant_property.empty()) cout << " Quantized output" << endl; @@ -332,7 +326,10 @@ void FGSensor::Debug(int from) cout << " Random noise is gaussian distributed." << endl; } } - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGSensor.h b/src/FDM/JSBSim/models/flight_control/FGSensor.h index 1e8701c90..136099536 100755 --- a/src/FDM/JSBSim/models/flight_control/FGSensor.h +++ b/src/FDM/JSBSim/models/flight_control/FGSensor.h @@ -38,8 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -53,8 +52,8 @@ FORWARD DECLARATIONS namespace JSBSim { -using std::vector; class FGFCS; +class Element; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -135,7 +134,6 @@ public: protected: enum eNoiseType {ePercent=0, eAbsolute} NoiseType; enum eDistributionType {eUniform=0, eGaussian} DistributionType; - double dt; double min, max; double span; double bias; @@ -153,20 +151,17 @@ protected: int bits; int quantized; int divisions; - int delay; - int index; bool fail_low; bool fail_high; bool fail_stuck; - string quant_property; - vector output_array; + std::string quant_property; + void ProcessSensorSignal(void); void Noise(void); void Bias(void); void Drift(void); void Quantize(void); void Lag(void); - void Delay(void); void Gain(void); void bind(void); diff --git a/src/FDM/JSBSim/models/flight_control/FGSensorOrientation.h b/src/FDM/JSBSim/models/flight_control/FGSensorOrientation.h new file mode 100755 index 000000000..4f6d52f3e --- /dev/null +++ b/src/FDM/JSBSim/models/flight_control/FGSensorOrientation.h @@ -0,0 +1,138 @@ +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + Header: FGSensorOrientation.h + Author: Jon Berndt + Date started: September 2009 + + ------------- Copyright (C) 2009 ------------- + + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA. + + Further information about the GNU Lesser General Public License can also be found on + the world wide web at http://www.gnu.org. + +HISTORY +-------------------------------------------------------------------------------- + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +SENTRY +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#ifndef FGSENSORORIENTATION_H +#define FGSENSORORIENTATION_H + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +INCLUDES +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#include "FGSensor.h" +#include "input_output/FGXMLElement.h" +#include "math/FGColumnVector3.h" +#include "math/FGMatrix33.h" + +#include + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +DEFINITIONS +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +#define ID_SensorOrientation "$Id$" + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +FORWARD DECLARATIONS +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +namespace JSBSim { + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS DOCUMENTATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +/** Encapsulates a SensorOrientation capability for a sensor. + +Syntax: + +@author Jon S. Berndt +@version $Revision$ +*/ + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS DECLARATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +class FGSensorOrientation : public FGJSBBase +{ +public: + FGSensorOrientation(Element* element) + { + Element* orient_element = element->FindElement("orientation"); + if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); + else { std::cerr << "No orientation given for this sensor. " << std::endl;} + + Element* axis_element = element->FindElement("axis"); + if (axis_element) { + string sAxis = element->FindElementValue("axis"); + if (sAxis == "X" || sAxis == "x") { + axis = 1; + } else if (sAxis == "Y" || sAxis == "y") { + axis = 2; + } else if (sAxis == "Z" || sAxis == "z") { + axis = 3; + } else { + std::cerr << " Incorrect/no axis specified for this sensor; assuming X axis" << std::endl; + axis = 1; + } + } + + CalculateTransformMatrix(); + } + +// ~FGSensorOrientation(); + +protected: + FGColumnVector3 vOrient; + FGMatrix33 mT; + int axis; + void CalculateTransformMatrix(void) + { + double cp,sp,cr,sr,cy,sy; + + cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch)); + cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll)); + cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw)); + + mT(1,1) = cp*cy; + mT(1,2) = cp*sy; + mT(1,3) = -sp; + + mT(2,1) = sr*sp*cy - cr*sy; + mT(2,2) = sr*sp*sy + cr*cy; + mT(2,3) = sr*cp; + + mT(3,1) = cr*sp*cy + sr*sy; + mT(3,2) = cr*sp*sy - sr*cy; + mT(3,3) = cr*cp; + + // This transform is different than for FGForce, where we want a native nozzle + // force in body frame. Here we calculate the body frame accel and want it in + // the transformed accelerometer frame. So, the next line is commented out. + // mT = mT.Inverse(); + } + +private: + void Debug(int from); +}; +} +#endif diff --git a/src/FDM/JSBSim/models/flight_control/FGSummer.cpp b/src/FDM/JSBSim/models/flight_control/FGSummer.cpp index 5071e7a2d..e77ee7208 100644 --- a/src/FDM/JSBSim/models/flight_control/FGSummer.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGSummer.cpp @@ -38,6 +38,10 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSummer.h" +#include "input_output/FGXMLElement.h" +#include + +using namespace std; namespace JSBSim { @@ -119,7 +123,10 @@ void FGSummer::Debug(int from) cout << " " << InputNodes[i]->getName() << endl; } if (Bias != 0.0) cout << " Bias: " << Bias << endl; - if (IsOutput) cout << " OUTPUT: " <getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGSummer.h b/src/FDM/JSBSim/models/flight_control/FGSummer.h index cc11352f5..e37642855 100644 --- a/src/FDM/JSBSim/models/flight_control/FGSummer.h +++ b/src/FDM/JSBSim/models/flight_control/FGSummer.h @@ -38,9 +38,6 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include -#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -48,18 +45,14 @@ DEFINITIONS #define ID_SUMMER "$Id$" -using std::vector; -using std::string; - -using std::vector; -using std::string; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ namespace JSBSim { +class Element; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/models/flight_control/FGSwitch.cpp b/src/FDM/JSBSim/models/flight_control/FGSwitch.cpp index 5ed272155..c29c72277 100644 --- a/src/FDM/JSBSim/models/flight_control/FGSwitch.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGSwitch.cpp @@ -62,6 +62,10 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGSwitch.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -261,7 +265,10 @@ void FGSwitch::Debug(int from) } cout << endl; } - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/flight_control/FGSwitch.h b/src/FDM/JSBSim/models/flight_control/FGSwitch.h index 4efec9dfb..a68c2c4a5 100644 --- a/src/FDM/JSBSim/models/flight_control/FGSwitch.h +++ b/src/FDM/JSBSim/models/flight_control/FGSwitch.h @@ -38,8 +38,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGFCSComponent.h" -#include -#include +#include "input_output/FGXMLElement.h" +#include "math/FGCondition.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/flight_control/Makefile.am b/src/FDM/JSBSim/models/flight_control/Makefile.am index ca924fdd9..2d7a1aa67 100644 --- a/src/FDM/JSBSim/models/flight_control/Makefile.am +++ b/src/FDM/JSBSim/models/flight_control/Makefile.am @@ -9,6 +9,7 @@ libFlightControl_a_SOURCES = \ noinst_HEADERS = \ FGPID.h FGDeadBand.h FGFCSComponent.h FGFilter.h \ FGGain.h FGGradient.h FGKinemat.h FGSummer.h FGSwitch.h FGFCSFunction.h\ - FGSensor.h FGActuator.h FGAccelerometer.h FGGyro.h FGMagnetometer.h + FGSensor.h FGActuator.h FGAccelerometer.h FGGyro.h FGMagnetometer.h \ + FGSensorOrientation.h INCLUDES = -I$(top_srcdir)/src/FDM/JSBSim diff --git a/src/FDM/JSBSim/models/propulsion/FGElectric.cpp b/src/FDM/JSBSim/models/propulsion/FGElectric.cpp index 32b05ea19..1ab17c7b6 100644 --- a/src/FDM/JSBSim/models/propulsion/FGElectric.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGElectric.cpp @@ -40,7 +40,14 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGElectric.h" -#include +#include "FGState.h" +#include "models/FGPropulsion.h" +#include "models/propulsion/FGThruster.h" + +#include +#include + +using namespace std; namespace JSBSim { @@ -92,24 +99,24 @@ double FGElectric::Calculate(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGElectric::GetEngineLabels(string delimeter) +string FGElectric::GetEngineLabels(const string& delimiter) { std::ostringstream buf; - buf << Name << " HP (engine " << EngineNumber << ")" << delimeter - << Thruster->GetThrusterLabels(EngineNumber, delimeter); + buf << Name << " HP (engine " << EngineNumber << ")" << delimiter + << Thruster->GetThrusterLabels(EngineNumber, delimiter); return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGElectric::GetEngineValues(string delimeter) +string FGElectric::GetEngineValues(const string& delimiter) { std::ostringstream buf; - buf << HP << delimeter - << Thruster->GetThrusterValues(EngineNumber, delimeter); + buf << HP << delimiter + << Thruster->GetThrusterValues(EngineNumber, delimiter); return buf.str(); } diff --git a/src/FDM/JSBSim/models/propulsion/FGElectric.h b/src/FDM/JSBSim/models/propulsion/FGElectric.h index ed5a93f57..da4a575bb 100644 --- a/src/FDM/JSBSim/models/propulsion/FGElectric.h +++ b/src/FDM/JSBSim/models/propulsion/FGElectric.h @@ -39,7 +39,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGEngine.h" -#include +#include "input_output/FGXMLElement.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -83,8 +83,8 @@ public: double Calculate(void); double GetPowerAvailable(void) {return PowerAvailable;} double getRPM(void) {return RPM;} - string GetEngineLabels(string delimeter); - string GetEngineValues(string delimeter); + std::string GetEngineLabels(const std::string& delimiter); + std::string GetEngineValues(const std::string& delimiter); private: diff --git a/src/FDM/JSBSim/models/propulsion/FGEngine.cpp b/src/FDM/JSBSim/models/propulsion/FGEngine.cpp index edddc11fa..4c98cd3d1 100644 --- a/src/FDM/JSBSim/models/propulsion/FGEngine.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGEngine.cpp @@ -41,9 +41,16 @@ INCLUDES #include "FGTank.h" #include "FGPropeller.h" #include "FGNozzle.h" -#include -#include +#include "FGState.h" +#include "models/FGPropulsion.h" +#include "input_output/FGXMLParse.h" +#include "math/FGColumnVector3.h" + +#include #include +#include + +using namespace std; namespace JSBSim { @@ -67,6 +74,7 @@ FGEngine::FGEngine(FGFDMExec* exec, Element* engine_element, int engine_number) SLFuelFlowMax = 0.0; MaxThrottle = 1.0; MinThrottle = 0.0; + unsigned int i; ResetToIC(); // initialize dynamic terms @@ -104,11 +112,17 @@ FGEngine::FGEngine(FGFDMExec* exec, Element* engine_element, int engine_number) cerr << "No thruster definition supplied with engine definition." << endl; } + // Build and initialize the feed tank vector. + for (i=0; i<(Propulsion->GetNumTanks()); i++) { + SourceTanks.push_back(0); + } + // Load feed tank[s] references local_element = engine_element->GetParent()->FindElement("feed"); if (local_element) { while (local_element) { - AddFeedTank((int)local_element->GetDataAsNumber()); + int tankID = (int)local_element->GetDataAsNumber(); + AddFeedTank( tankID , Propulsion->GetTank(tankID)->GetPriority()); local_element = engine_element->GetParent()->FindNextElement("feed"); } } else { @@ -165,35 +179,50 @@ void FGEngine::ConsumeFuel(void) if (TrimMode) return; unsigned int i; - double Fshortage, TanksWithFuel; + double Fshortage, FuelNeeded; FGTank* Tank; - Fshortage = TanksWithFuel = 0.0; + unsigned int TanksWithFuel = 0; + Fshortage = FuelNeeded = 0.0; + double FuelToBurn; + unsigned int CurrentPriority = 1; + vector FeedList; + Starved = false; - // count how many assigned tanks have fuel - for (i=0; iGetTank(SourceTanks[i]); - if (Tank->GetType() == FGTank::ttFUEL){ - if (Tank->GetContents() > 0.0) ++TanksWithFuel; - } else { - cerr << "No oxidizer tanks should be used for this engine type." << endl; + FuelToBurn = CalcFuelNeed(); + if (FuelToBurn == 0.0) return; + + // Count how many fuel tanks with the current priority level have fuel. + // If none, then try next lower priority. Build the feed list. + while ((TanksWithFuel == 0) && (CurrentPriority <= Propulsion->GetNumTanks())) { + for (i=0; iGetNumTanks(); i++) { + if (SourceTanks[i] != 0) { + Tank = Propulsion->GetTank(i); + if (Tank->GetType() == FGTank::ttFUEL) { + if ((Tank->GetContents() > 0.0) && ((unsigned int)Tank->GetPriority() == CurrentPriority)) { + ++TanksWithFuel; + FeedList.push_back(i); + } + } else { + cerr << "No oxidizer tanks should be used for this engine type." << endl; + } + } } + if (TanksWithFuel == 0) CurrentPriority++; } - if (TanksWithFuel==0) { + + // No fuel found at any priority! + if (TanksWithFuel == 0) { Starved = true; return; } - for (i=0; iGetTank(SourceTanks[i]); - if (Tank->GetType() == FGTank::ttFUEL) { - Fshortage += Tank->Drain(CalcFuelNeed()/TanksWithFuel); - } else { - cerr << "No oxidizer tanks should be used for this engine type." << endl; - } + // Remove equal amount of fuel from each feed tank. + FuelNeeded = FuelToBurn/TanksWithFuel; + for (i=0; iGetTank(FeedList[i]); + Tank->Drain(FuelNeeded); } - if (Fshortage < 0.00) Starved = true; - else Starved = false; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -219,9 +248,9 @@ void FGEngine::SetPlacement(FGColumnVector3& location, FGColumnVector3& orientat //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGEngine::AddFeedTank(int tkID) +void FGEngine::AddFeedTank(int tkID, int priority) { - SourceTanks.push_back(tkID); + SourceTanks[tkID] = priority; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -244,7 +273,6 @@ bool FGEngine::LoadThruster(Element *thruster_element) { string token, fullpath, localpath; string thruster_filename, thruster_fullpathname, thrType; - double P_Factor = 0, Sense = 0.0; string enginePath = FDMExec->GetEnginePath(); string aircraftPath = FDMExec->GetFullAircraftPath(); ifstream thruster_file; diff --git a/src/FDM/JSBSim/models/propulsion/FGEngine.h b/src/FDM/JSBSim/models/propulsion/FGEngine.h index 0e79e3a72..4876f571f 100644 --- a/src/FDM/JSBSim/models/propulsion/FGEngine.h +++ b/src/FDM/JSBSim/models/propulsion/FGEngine.h @@ -43,10 +43,9 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include "FGThruster.h" -#include -#include +#include "FGJSBBase.h" +#include "input_output/FGXMLFileRead.h" +#include "math/FGColumnVector3.h" #include #include @@ -56,9 +55,6 @@ DEFINITIONS #define ID_ENGINE "$Id$" -using std::string; -using std::vector; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -75,6 +71,7 @@ class FGPropulsion; class FGAuxiliary; class FGThruster; class Element; +class FGPropertyManager; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION @@ -159,7 +156,7 @@ public: virtual void SetRunning(bool bb) { Running=bb; } virtual void SetName(string name) { Name = name; } - virtual void AddFeedTank(int tkID); + virtual void AddFeedTank(int tkID, int priority); virtual void SetFuelFreeze(bool f) { FuelFreeze = f; } virtual void SetStarter(bool s) { Starter = s; } @@ -187,8 +184,8 @@ public: bool LoadThruster(Element *el); FGThruster* GetThruster(void) {return Thruster;} - virtual string GetEngineLabels(string delimeter) = 0; - virtual string GetEngineValues(string delimeter) = 0; + virtual std::string GetEngineLabels(const std::string& delimiter) = 0; + virtual std::string GetEngineValues(const std::string& delimiter) = 0; protected: /** Reduces the fuel in the active tanks by the amount required. @@ -205,7 +202,7 @@ protected: virtual double CalcFuelNeed(void); FGPropertyManager* PropertyManager; - string Name; + std::string Name; const int EngineNumber; EngineType Type; double X, Y, Z; @@ -240,20 +237,10 @@ protected: FGAuxiliary* Auxiliary; FGThruster* Thruster; - vector SourceTanks; + std::vector SourceTanks; void Debug(int from); }; } -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #endif diff --git a/src/FDM/JSBSim/models/propulsion/FGForce.cpp b/src/FDM/JSBSim/models/propulsion/FGForce.cpp index 9f39088d7..ff7532916 100644 --- a/src/FDM/JSBSim/models/propulsion/FGForce.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGForce.cpp @@ -41,11 +41,15 @@ and the cg. */ #include "FGForce.h" -#include -#include -#include -#include -#include +#include "FGFDMExec.h" +#include "models/FGAircraft.h" +#include "models/FGPropagate.h" +#include "models/FGMassBalance.h" +#include "models/FGAerodynamics.h" +#include +#include + +using namespace std; namespace JSBSim { @@ -55,8 +59,8 @@ static const char *IdHdr = ID_FORCE; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGForce::FGForce(FGFDMExec *FDMExec) : - ttype(tNone), - fdmex(FDMExec) + fdmex(FDMExec), + ttype(tNone) { mT(1,1) = 1; //identity matrix mT(2,2) = 1; @@ -112,23 +116,27 @@ FGMatrix33 FGForce::Transform(void) void FGForce::UpdateCustomTransformMatrix(void) { double cp,sp,cr,sr,cy,sy; + double srsp, crcy, crsy; cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch)); cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll)); cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw)); + srsp = sr*sp; + crcy = cr*cy; + crsy = cr*sy; + mT(1,1) = cp*cy; - mT(1,2) = cp*sy; - mT(1,3) = -sp; + mT(2,1) = cp*sy; + mT(3,1) = -sp; - mT(2,1) = sr*sp*cy - cr*sy; - mT(2,2) = sr*sp*sy + cr*cy; - mT(2,3) = sr*cp; + mT(1,2) = srsp*cy - crsy; + mT(2,2) = srsp*sy + crcy; + mT(3,2) = sr*cp; - mT(3,1) = cr*sp*cy + sr*sy; - mT(3,2) = cr*sp*sy - sr*cy; + mT(1,3) = crcy*sp + sr*sy; + mT(2,3) = crsy*sp - sr*cy; mT(3,3) = cr*cp; - mT = mT.Inverse(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/propulsion/FGForce.h b/src/FDM/JSBSim/models/propulsion/FGForce.h index 0798d00e2..eb2f59506 100644 --- a/src/FDM/JSBSim/models/propulsion/FGForce.h +++ b/src/FDM/JSBSim/models/propulsion/FGForce.h @@ -57,10 +57,10 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include -#include -#include -#include +#include "FGFDMExec.h" +#include "FGJSBBase.h" +#include "math/FGMatrix33.h" +#include "math/FGColumnVector3.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -240,6 +240,9 @@ public: virtual FGColumnVector3& GetBodyForces(void); + inline double GetBodyXForce(void) const { return vFb(eX); } + inline double GetBodyYForce(void) const { return vFb(eY); } + inline double GetBodyZForce(void) const { return vFb(eZ); } inline FGColumnVector3& GetMoments(void) { return vM; } // Normal point of application, JSBsim structural coords @@ -273,12 +276,12 @@ public: inline void SetLocation(FGColumnVector3 vv) { vXYZn = vv; SetActingLocation(vv);} inline void SetActingLocation(FGColumnVector3 vv) { vActingXYZn = vv; } - inline double GetLocationX( void ) { return vXYZn(eX);} - inline double GetLocationY( void ) { return vXYZn(eY);} - inline double GetLocationZ( void ) { return vXYZn(eZ);} - inline double GetActingLocationX( void ) { return vActingXYZn(eX);} - inline double GetActingLocationY( void ) { return vActingXYZn(eY);} - inline double GetActingLocationZ( void ) { return vActingXYZn(eZ);} + inline double GetLocationX( void ) const { return vXYZn(eX);} + inline double GetLocationY( void ) const { return vXYZn(eY);} + inline double GetLocationZ( void ) const { return vXYZn(eZ);} + inline double GetActingLocationX( void ) const { return vActingXYZn(eX);} + inline double GetActingLocationY( void ) const { return vActingXYZn(eY);} + inline double GetActingLocationZ( void ) const { return vActingXYZn(eZ);} FGColumnVector3& GetLocation(void) { return vXYZn; } FGColumnVector3& GetActingLocation(void) { return vActingXYZn; } @@ -302,10 +305,10 @@ public: double GetYaw(void) const {return vOrient(eYaw);} inline FGColumnVector3& GetAnglesToBody(void) {return vOrient;} - inline double GetAnglesToBody(int axis) {return vOrient(axis);} + inline double GetAnglesToBody(int axis) const {return vOrient(axis);} inline void SetTransformType(TransformType ii) { ttype=ii; } - inline TransformType GetTransformType(void) { return ttype; } + inline TransformType GetTransformType(void) const { return ttype; } FGMatrix33 Transform(void); diff --git a/src/FDM/JSBSim/models/propulsion/FGNozzle.cpp b/src/FDM/JSBSim/models/propulsion/FGNozzle.cpp index 78059bd2b..fdbd1533f 100644 --- a/src/FDM/JSBSim/models/propulsion/FGNozzle.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGNozzle.cpp @@ -35,10 +35,15 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include +#include #include "FGNozzle.h" -#include +#include "models/FGAtmosphere.h" +#include "input_output/FGXMLElement.h" + +using namespace std; namespace JSBSim { @@ -59,14 +64,14 @@ FGNozzle::FGNozzle(FGFDMExec* FDMExec, Element* nozzle_element, int num) cerr << "Fatal Error: Nozzle exit area must be given in nozzle config file." << endl; exit(-1); } - +/* if (nozzle_element->FindElement("pe")) PE = nozzle_element->FindElementValueAsNumberConvertTo("pe", "PSF"); else { cerr << "Fatal Error: Nozzle exit pressure must be given in nozzle config file." << endl; exit(-1); } - +*/ Thrust = 0; Type = ttNozzle; diff --git a/src/FDM/JSBSim/models/propulsion/FGNozzle.h b/src/FDM/JSBSim/models/propulsion/FGNozzle.h index 5f1d070bf..4b5dc40a5 100644 --- a/src/FDM/JSBSim/models/propulsion/FGNozzle.h +++ b/src/FDM/JSBSim/models/propulsion/FGNozzle.h @@ -95,7 +95,7 @@ public: string GetThrusterValues(int id, string delimeter); private: - double PE; +// double PE; double Area; void Debug(int from); }; diff --git a/src/FDM/JSBSim/models/propulsion/FGPiston.cpp b/src/FDM/JSBSim/models/propulsion/FGPiston.cpp index 19150d4bb..7f484e6b9 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPiston.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPiston.cpp @@ -43,8 +43,13 @@ INCLUDES #include #include "FGPiston.h" -#include +#include "FGState.h" +#include "models/FGAtmosphere.h" +#include "models/FGPropulsion.h" #include "FGPropeller.h" +#include + +using namespace std; namespace JSBSim { @@ -61,7 +66,8 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) rho_fuel(800), // estimate calorific_value_fuel(47.3e6), Cp_air(1005), // Specific heat (constant pressure) J/Kg/K - Cp_fuel(1700) + Cp_fuel(1700), + standard_pressure(101320.73) { string token; @@ -82,11 +88,14 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) MinManifoldPressure_inHg = 6.5; MaxManifoldPressure_inHg = 28.5; ISFC = -1; - volumetric_efficiency = -0.1; + volumetric_efficiency = 0.85; Bore = 5.125; Stroke = 4.375; Cylinders = 4; CompressionRatio = 8.5; + Z_airbox = -999; + Ram_Air_Factor = 1; + PeakMeanPistonSpeed_fps = 100; // These are internal program variables @@ -102,6 +111,7 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) BoostSpeed = 0; Boosted = false; BoostOverride = 0; + BoostManual = 0; bBoostOverride = false; bTakeoffBoost = false; TakeoffBoost = 0.0; // Default to no extra takeoff-boost @@ -187,10 +197,18 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN"); if (el->FindElement("cylinders")) Cylinders = el->FindElementValueAsNumber("cylinders"); + if (el->FindElement("air-intake-impedance-factor")) + Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor"); + if (el->FindElement("ram-air-factor")) + Ram_Air_Factor = el->FindElementValueAsNumber("ram-air-factor"); + if (el->FindElement("peak-piston-speed")) + PeakMeanPistonSpeed_fps = el->FindElementValueAsNumber("peak-piston-speed"); if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds"); if (el->FindElement("boostoverride")) BoostOverride = (int)el->FindElementValueAsNumber("boostoverride"); + if (el->FindElement("boostmanual")) + BoostManual = (int)el->FindElementValueAsNumber("boostmanual"); if (el->FindElement("takeoffboost")) TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI"); if (el->FindElement("ratedboost1")) @@ -221,28 +239,45 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) StarterHP = sqrt(MaxHP) * 0.4; displacement_SI = Displacement * in3tom3; + RatedMeanPistonSpeed_fps = ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS - // Create IFSC and VE to match the engine if not provided - int calculated_ve=0; - if (volumetric_efficiency < 0) { - volumetric_efficiency = MaxManifoldPressure_inHg / 29.92; - calculated_ve=1; - } + // Create IFSC to match the engine if not provided if (ISFC < 0) { - double pmep = MaxManifoldPressure_inHg > 29.92 ? 0 : 29.92 - MaxManifoldPressure_inHg; + double pmep = 29.92 - MaxManifoldPressure_inHg; pmep *= inhgtopa; - double fmep = (18400 * (2*(Stroke/12)*(MaxRPM/60)) * fttom + 46500)/2; + double fmep = (18400 * RatedMeanPistonSpeed_fps * fttom + 46500); double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371); - ISFC = ( Displacement * MaxRPM * volumetric_efficiency ) / (9411 * (MaxHP+hp_loss)); + ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss)); // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " < 29.9 ) { // Don't allow boosting with a bogus number MaxManifoldPressure_inHg = 29.9; - if (calculated_ve) volumetric_efficiency = 1.0; } minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa maxMAP = MaxManifoldPressure_inHg * inhgtopa; +// For throttle +/* + * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa + * Where: + * Pm = Manifold Pressure + * Pa = Ambient Pressre + * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed + * Zi = airbox impedance + * Zt = throttle impedance + * + * For the calculation below throttle is fully open or Zt = 0 + * + * + * + */ + + if(Z_airbox < 0.0){ + double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence + Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox + } + Z_throttle=(((MaxRPM * Stroke) / 360)/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox; // Constant for Throttle impedence + string property_name, base_property_name; base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber); property_name = base_property_name + "/power-hp"; @@ -255,6 +290,12 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) PropertyManager->Tie(property_name, &MAP); property_name = base_property_name + "/map-inhg"; PropertyManager->Tie(property_name, &ManifoldPressure_inHg); + property_name = base_property_name + "/air-intake-impedance-factor"; + PropertyManager->Tie(property_name, &Z_airbox); + property_name = base_property_name + "/ram-air-factor"; + PropertyManager->Tie(property_name, &Ram_Air_Factor); + property_name = base_property_name + "/boost-speed"; + PropertyManager->Tie(property_name, &BoostSpeed); // Set up and sanity-check the turbo/supercharging configuration based on the input values. if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true; @@ -302,6 +343,7 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number) BoostSpeed = 0; } bBoostOverride = (BoostOverride == 1 ? true : false); + bBoostManual = (BoostManual == 1 ? true : false); Debug(0); // Call Debug() routine from constructor if needed } @@ -349,6 +391,8 @@ double FGPiston::Calculate(void) // p_amb = Atmosphere->GetPressure() * psftopa; + double p = Auxiliary->GetTotalPressure() * psftopa; + p_ram = (p - p_amb) * Ram_Air_Factor + p_amb; T_amb = RankineToKelvin(Atmosphere->GetTemperature()); RPM = Thruster->GetRPM() * Thruster->GetGearRatio(); @@ -488,15 +532,20 @@ void FGPiston::doEngineStartup(void) void FGPiston::doBoostControl(void) { - if(BoostSpeed < BoostSpeeds - 1) { - // Check if we need to change to a higher boost speed - if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) { - BoostSpeed++; - } - } else if(BoostSpeed > 0) { - // Check if we need to change to a lower boost speed - if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) { - BoostSpeed--; + if(BoostManual) { + if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1; + if(BoostSpeed < 0) BoostSpeed = 0; + } else { + if(BoostSpeed < BoostSpeeds - 1) { + // Check if we need to change to a higher boost speed + if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) { + BoostSpeed++; + } + } else if(BoostSpeed > 0) { + // Check if we need to change to a lower boost speed + if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) { + BoostSpeed--; + } } } } @@ -518,15 +567,13 @@ void FGPiston::doBoostControl(void) void FGPiston::doMAP(void) { - // estimate throttle plate area. - double throttle_area = ThrottleAngle*ThrottleAngle; - // Internal Combustion Engine in Theory and Practice, Volume 2. Charles Fayette Taylor. Revised Edition, 1985 fig 6-13 - double map_coefficient = 1-((MeanPistonSpeed_fps*MeanPistonSpeed_fps)/(24978*throttle_area)); + double Zt =(1-Throttle)*(1-Throttle)*Z_throttle; // throttle impedence + double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence - if ( map_coefficient < 0.1 ) map_coefficient = 0.1; + double map_coefficient = Ze/(Ze+Z_airbox+Zt); // Add a one second lag to manifold pressure changes - double dMAP = (TMAP - p_amb * map_coefficient) * dt; + double dMAP = (TMAP - p_ram * map_coefficient) * dt; TMAP -=dMAP; // Find the mean effective pressure required to achieve this manifold pressure @@ -548,8 +595,7 @@ void FGPiston::doMAP(void) } } // Boost the manifold pressure. - double boost_factor = BoostMul[BoostSpeed] * RPM/RatedRPM[BoostSpeed]; - if (boost_factor < 1.0) boost_factor = 1.0; // boost will never reduce the MAP + double boost_factor = (( BoostMul[BoostSpeed] - 1 ) / RatedRPM[BoostSpeed] ) * RPM + 1; MAP = TMAP * boost_factor; // Now clip the manifold pressure to BCV or Wastegate setting. if (bTakeoffPos) { @@ -581,7 +627,7 @@ void FGPiston::doMAP(void) void FGPiston::doAirFlow(void) { - double gamma = 1.4; // specific heat constants + double gamma = 1.1; // specific heat constants // loss of volumentric efficiency due to difference between MAP and exhaust pressure double ve =((gamma-1)/gamma)+( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1)); @@ -806,28 +852,28 @@ void FGPiston::doOilPressure(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGPiston::GetEngineLabels(string delimeter) +string FGPiston::GetEngineLabels(const string& delimiter) { std::ostringstream buf; - buf << Name << " Power Available (engine " << EngineNumber << " in HP)" << delimeter - << Name << " HP (engine " << EngineNumber << ")" << delimeter - << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimeter - << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimeter - << Thruster->GetThrusterLabels(EngineNumber, delimeter); + buf << Name << " Power Available (engine " << EngineNumber << " in HP)" << delimiter + << Name << " HP (engine " << EngineNumber << ")" << delimiter + << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimiter + << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimiter + << Thruster->GetThrusterLabels(EngineNumber, delimiter); return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGPiston::GetEngineValues(string delimeter) +string FGPiston::GetEngineValues(const string& delimiter) { std::ostringstream buf; - buf << PowerAvailable << delimeter << HP << delimeter - << equivalence_ratio << delimeter << ManifoldPressure_inHg << delimeter - << Thruster->GetThrusterValues(EngineNumber, delimeter); + buf << PowerAvailable << delimiter << HP << delimiter + << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter + << Thruster->GetThrusterValues(EngineNumber, delimiter); return buf.str(); } @@ -872,10 +918,13 @@ void FGPiston::Debug(int from) cout << " MaxHP: " << MaxHP << endl; cout << " Cycles: " << Cycles << endl; cout << " IdleRPM: " << IdleRPM << endl; + cout << " MaxRPM: " << MaxRPM << endl; cout << " MaxThrottle: " << MaxThrottle << endl; cout << " MinThrottle: " << MinThrottle << endl; cout << " ISFC: " << ISFC << endl; - cout << " Volumentric Efficiency: " << volumetric_efficiency << endl; + cout << " Volumetric Efficiency: " << volumetric_efficiency << endl; + cout << " PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl; + cout << " Intake Impedance Factor: " << Z_airbox << endl; cout << endl; cout << " Combustion Efficiency table:" << endl; diff --git a/src/FDM/JSBSim/models/propulsion/FGPiston.h b/src/FDM/JSBSim/models/propulsion/FGPiston.h index 4c40565a4..2bfb1971a 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPiston.h +++ b/src/FDM/JSBSim/models/propulsion/FGPiston.h @@ -40,8 +40,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGEngine.h" -#include -#include +#include "math/FGTable.h" +#include "input_output/FGXMLElement.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -81,9 +81,10 @@ CLASS DOCUMENTATION {number} {number} {number} - {number} + {number} {number} {0 | 1} + {0 | 1} {number} {number} {number} @@ -97,6 +98,8 @@ CLASS DOCUMENTATION {number} {number} {number} + {number} + {number} @endcode @@ -120,6 +123,10 @@ CLASS DOCUMENTATION some way of getting the boost control cutout lever position (on or off) from FlightGear first. + - BOOSTMANUAL - whether a multispeed supercharger will manually or + automatically shift boost speeds. On manual shifting the boost speeds + is accomplished by controling propulsion/engine/boostspeed + - The next items are all appended with either 1, 2 or 3 depending on which boost speed they refer to, eg RATEDBOOST1. The rated values seems to have been a common convention at the time to express the maximum continuously @@ -188,8 +195,8 @@ public: /// Destructor ~FGPiston(); - string GetEngineLabels(string delimeter); - string GetEngineValues(string delimeter); + std::string GetEngineLabels(const std::string& delimiter); + std::string GetEngineValues(const std::string& delimiter); double Calculate(void); double GetPowerAvailable(void) {return PowerAvailable;} @@ -247,6 +254,8 @@ private: const double calorific_value_fuel; // W/Kg (approximate) const double Cp_air; // J/KgK const double Cp_fuel; // J/KgK + const double standard_pressure; //Pa + FGTable *Lookup_Combustion_Efficiency; FGTable *Mixture_Efficiency_Correlation; @@ -267,12 +276,19 @@ private: double Bore; // inches double Stroke; // inches double Cylinders; // number - double CompressionRatio; // number + double CompressionRatio; // number + double Z_airbox; // number representing intake impediance before the throttle + double Z_throttle; // number representing slope of throttle impediance + double PeakMeanPistonSpeed_fps; // ft/sec speed where intake valves begin to choke. Typically 33-50 fps + double RatedMeanPistonSpeed_fps; // ft/sec derived from MaxRPM and stroke. + double Ram_Air_Factor; // number double StarterHP; // initial horsepower of starter motor int BoostSpeeds; // Number of super/turbocharger boost speeds - zero implies no turbo/supercharging. int BoostSpeed; // The current boost-speed (zero-based). bool Boosted; // Set true for boosted engine. + int BoostManual; // The raw value read in from the config file - should be 1 or 0 - see description below. + bool bBoostManual; // Set true if pilot must manually control the boost speed. int BoostOverride; // The raw value read in from the config file - should be 1 or 0 - see description below. bool bBoostOverride; // Set true if pilot override of the boost regulator was fitted. // (Typically called 'war emergency power'). @@ -302,6 +318,7 @@ private: // Inputs (in addition to those in FGEngine). // double p_amb; // Pascals + double p_ram; // Pascals double T_amb; // degrees Kelvin double RPM; // revolutions per minute double IAS; // knots diff --git a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp index 2f5b39523..fb1be8ac1 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp @@ -35,12 +35,16 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include #include "FGPropeller.h" -#include -#include -#include +#include "models/FGPropagate.h" +#include "models/FGAtmosphere.h" +#include "models/FGAuxiliary.h" +#include "input_output/FGXMLElement.h" + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/propulsion/FGPropeller.h b/src/FDM/JSBSim/models/propulsion/FGPropeller.h index a2ddc9f41..500e67985 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPropeller.h +++ b/src/FDM/JSBSim/models/propulsion/FGPropeller.h @@ -39,7 +39,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGThruster.h" -#include +#include "math/FGTable.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS diff --git a/src/FDM/JSBSim/models/propulsion/FGRocket.cpp b/src/FDM/JSBSim/models/propulsion/FGRocket.cpp index 1f4ca5a6f..eab01be15 100644 --- a/src/FDM/JSBSim/models/propulsion/FGRocket.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGRocket.cpp @@ -38,9 +38,15 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include - #include "FGRocket.h" +#include "FGState.h" +#include "models/FGPropulsion.h" +#include "FGThruster.h" +#include "FGTank.h" + +using namespace std; namespace JSBSim { @@ -63,6 +69,7 @@ FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number) FuelFlowRate = 0.0; OxidizerFlowRate = 0.0; SLOxiFlowMax = 0.0; + BuildupTime = 0.0; It = 0.0; // Defaults @@ -71,6 +78,8 @@ FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number) if (el->FindElement("isp")) Isp = el->FindElementValueAsNumber("isp"); + if (el->FindElement("builduptime")) + BuildupTime = el->FindElementValueAsNumber("builduptime"); if (el->FindElement("maxthrottle")) MaxThrottle = el->FindElementValueAsNumber("maxthrottle"); if (el->FindElement("minthrottle")) @@ -114,21 +123,27 @@ double FGRocket::Calculate(void) PropellantFlowRate = (FuelExpended + OxidizerExpended)/dT; Throttle = FCS->GetThrottlePos(EngineNumber); - // If there is a thrust table, it is a function of propellant remaining. The + // If there is a thrust table, it is a function of propellant burned. The // engine is started when the throttle is advanced to 1.0. After that, it - // burns without regard to throttle setting. The table returns a value between - // zero and one, representing the percentage of maximum vacuum thrust being - // applied. + // burns without regard to throttle setting. if (ThrustTable != 0L) { // Thrust table given -> Solid fuel used if ((Throttle == 1 || BurnTime > 0.0 ) && !Starved) { - BurnTime += State->Getdt(); - double TotalEngineFuelAvailable=0.0; - for (int i=0; i<(int)SourceTanks.size(); i++) - TotalEngineFuelAvailable += Propulsion->GetTank(SourceTanks[i])->GetContents(); + double TotalEngineFuelBurned=0.0; + for (int i=0; i<(int)SourceTanks.size(); i++) { + FGTank* tank = Propulsion->GetTank(i); + if (SourceTanks[i] == 1) { + TotalEngineFuelBurned += tank->GetCapacity() - tank->GetContents(); + } + } - VacThrust = ThrustTable->GetValue(TotalEngineFuelAvailable); + VacThrust = ThrustTable->GetValue(TotalEngineFuelBurned); + if (BurnTime <= BuildupTime && BuildupTime > 0.0) { + VacThrust *= sin((BurnTime/BuildupTime)*M_PI/2.0); + // VacThrust *= (1-cos((BurnTime/BuildupTime)*M_PI))/2.0; // 1 - cos approach + } + BurnTime += State->Getdt(); // Increment burn time } else { VacThrust = 0.0; } @@ -143,7 +158,12 @@ double FGRocket::Calculate(void) } else { // Calculate thrust - PctPower = Throttle / MaxThrottle; // Min and MaxThrottle range from 0.0 to 1.0, normally. + // This is nonsensical. Max throttle should be assumed to be 1.0. One might + // conceivably have a throttle setting > 1.0 for some rocket engines. But, 1.0 + // should always be the default. + // PctPower = Throttle / MaxThrottle; // Min and MaxThrottle range from 0.0 to 1.0, normally. + + PctPower = Throttle; Flameout = false; VacThrust = Isp * PropellantFlowRate; @@ -248,23 +268,23 @@ double FGRocket::CalcOxidizerNeed(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGRocket::GetEngineLabels(string delimeter) +string FGRocket::GetEngineLabels(const string& delimiter) { std::ostringstream buf; - buf << Name << " Total Impulse (engine " << EngineNumber << " in psf)" << delimeter - << Thruster->GetThrusterLabels(EngineNumber, delimeter); + buf << Name << " Total Impulse (engine " << EngineNumber << " in psf)" << delimiter + << Thruster->GetThrusterLabels(EngineNumber, delimiter); return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGRocket::GetEngineValues(string delimeter) +string FGRocket::GetEngineValues(const string& delimiter) { std::ostringstream buf; - buf << It << delimeter << Thruster->GetThrusterValues(EngineNumber, delimeter); + buf << It << delimiter << Thruster->GetThrusterValues(EngineNumber, delimiter); return buf.str(); } diff --git a/src/FDM/JSBSim/models/propulsion/FGRocket.h b/src/FDM/JSBSim/models/propulsion/FGRocket.h index 4e6e8120a..b2cb76f4e 100644 --- a/src/FDM/JSBSim/models/propulsion/FGRocket.h +++ b/src/FDM/JSBSim/models/propulsion/FGRocket.h @@ -39,8 +39,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGEngine.h" -#include -#include +#include "math/FGTable.h" +#include "input_output/FGXMLElement.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -159,8 +159,8 @@ public: double GetOxiFlowRate(void) const {return OxidizerFlowRate;} - string GetEngineLabels(string delimeter); - string GetEngineValues(string delimeter); + std::string GetEngineLabels(const std::string& delimiter); + std::string GetEngineValues(const std::string& delimiter); private: /** Reduces the fuel in the active tanks by the amount required. @@ -200,6 +200,7 @@ private: double OxidizerFlowRate; double PropellantFlowRate; bool Flameout; + double BuildupTime; FGTable* ThrustTable; void Debug(int from); diff --git a/src/FDM/JSBSim/models/propulsion/FGRotor.cpp b/src/FDM/JSBSim/models/propulsion/FGRotor.cpp index 7c3de71a6..6ef33e7c0 100644 --- a/src/FDM/JSBSim/models/propulsion/FGRotor.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGRotor.cpp @@ -36,6 +36,9 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGRotor.h" +#include + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/propulsion/FGTank.cpp b/src/FDM/JSBSim/models/propulsion/FGTank.cpp index 289fbb197..dced188c5 100644 --- a/src/FDM/JSBSim/models/propulsion/FGTank.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGTank.cpp @@ -37,11 +37,14 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGTank.h" -#include +#include "FGFDMExec.h" +#include "models/FGAuxiliary.h" +#include "input_output/FGXMLElement.h" +#include "input_output/FGPropertyManager.h" +#include +#include -using std::cerr; -using std::endl; -using std::cout; +using namespace std; namespace JSBSim { @@ -59,9 +62,12 @@ FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number) Element* element; Element* element_Grain; Area = 1.0; - Temperature = -9999.0; + Density = 6.6; + InitialTemperature = Temperature = -9999.0; Ixx = Iyy = Izz = 0.0; - Radius = Capacity = Contents = Standpipe = Length = InnerRadius = 0.0; + Radius = Contents = Standpipe = Length = InnerRadius = 0.0; + Capacity = 0.00001; + Priority = InitialPriority = 1; PropertyManager = Exec->GetPropertyManager(); vXYZ.InitMatrix(); vXYZ_drain.InitMatrix(); @@ -92,15 +98,19 @@ FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number) InitialTemperature = Temperature = el->FindElementValueAsNumber("temperature"); if (el->FindElement("standpipe")) InitialStandpipe = Standpipe = el->FindElementValueAsNumberConvertTo("standpipe", "LBS"); + if (el->FindElement("priority")) + InitialPriority = Priority = el->FindElementValueAsNumber("priority"); + if (el->FindElement("density")) + Density = el->FindElementValueAsNumberConvertTo("density", "LBS/GAL"); - Selected = true; + SetPriority( InitialPriority ); // this will also set the Selected flag - if (Capacity != 0) { - PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0 - } else { - Contents = 0; - PctFull = 0; + if (Capacity == 0) { + cerr << "Tank capacity must not be zero. Reset to 0.00001 lbs!" << endl; + Capacity = 0.00001; + Contents = 0.0; } + PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0 // Check whether this is a solid propellant "tank". Initialize it if true. @@ -145,6 +155,9 @@ FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number) property_name = base_property_name + "/contents-lbs"; PropertyManager->Tie( property_name.c_str(), (FGTank*)this, &FGTank::GetContents, &FGTank::SetContents ); + property_name = base_property_name + "/priority"; + PropertyManager->Tie( property_name.c_str(), (FGTank*)this, &FGTank::GetPriority, + &FGTank::SetPriority ); if (Temperature != -9999.0) InitialTemperature = Temperature = FahrenheitToCelsius(Temperature); Area = 40.0 * pow(Capacity/1975, 0.666666667); @@ -163,11 +176,11 @@ FGTank::~FGTank() void FGTank::ResetToIC(void) { - Temperature = InitialTemperature; - Standpipe = InitialStandpipe; - Contents = InitialContents; + SetTemperature( InitialTemperature ); + SetStandpipe ( InitialStandpipe ); + SetContents ( InitialContents ); PctFull = 100.0*Contents/Capacity; - Selected = true; + SetPriority( InitialPriority ); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -199,7 +212,6 @@ double FGTank::Drain(double used) Contents = 0.0; PctFull = 0.0; - Selected = false; } if (grainType != gtUNKNOWN) CalculateInertias(); @@ -238,6 +250,14 @@ void FGTank::SetContents(double amount) } } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGTank::SetContentsGallons(double gallons) +{ + SetContents(gallons * Density); +} + + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% double FGTank::Calculate(double dt) @@ -284,6 +304,10 @@ void FGTank::CalculateInertias(void) Ixx = 0.5*Mass*Rad2/144.0; Iyy = Mass*(3.0*Rad2 + Length*Length)/(144.0*12.0); break; + case gtUNKNOWN: + cerr << "Unknown grain type found." << endl; + exit(-1); + break; } Izz = Iyy; @@ -319,6 +343,7 @@ void FGTank::Debug(int from) cout << " Tank location (X, Y, Z): " << vXYZ(eX) << ", " << vXYZ(eY) << ", " << vXYZ(eZ) << endl; cout << " Effective radius: " << Radius << " inches" << endl; cout << " Initial temperature: " << Temperature << " Fahrenheit" << endl; + cout << " Priority: " << Priority << endl; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification diff --git a/src/FDM/JSBSim/models/propulsion/FGTank.h b/src/FDM/JSBSim/models/propulsion/FGTank.h index 479fcb6c6..7f4f75457 100644 --- a/src/FDM/JSBSim/models/propulsion/FGTank.h +++ b/src/FDM/JSBSim/models/propulsion/FGTank.h @@ -44,17 +44,10 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include "FGFDMExec.h" -#include -#include -#include +#include "FGJSBBase.h" +#include "math/FGColumnVector3.h" #include -using std::string; -using std::cerr; -using std::endl; -using std::cout; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -67,6 +60,10 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; +class FGPropertyManager; +class FGFDMExec; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -127,6 +124,8 @@ CLASS DOCUMENTATION {number} {number} {number} + {integer} + {number} @endcode @@ -140,6 +139,8 @@ CLASS DOCUMENTATION - \b contents - Initial contents, defaults to pounds. - \b temperature - Initial temperature, defaults to degrees Fahrenheit. - \b standpipe - Minimum contents to which tank can dump, defaults to pounds. +- \b priority - Establishes feed sequence of tank. "1" is the highest priority. +- \b density - Density of liquid tank contents. location: - \b x - Location of tank on aircraft's x-axis, defaults to inches. @@ -160,10 +161,12 @@ be printed to the console if the location is not given - \b y - 0.0 (both full and drained CG locations) - \b z - 0.0 (both full and drained CG locations) - \b radius - 0.0 -- \b capacity - 0.0 +- \b capacity - 0.00001 (tank capacity must not be zero) - \b contents - 0.0 -- \b temperature - -9999.0 -- \b standpipe - 0.0 +- \b temperature - -9999.0 (flag which indicates no temperature is set) +- \b standpipe - 0.0 (all contents may be dumped) +- \b priority - 1 (highest feed sequence priority) +- \b density - 6.6 @author Jon Berndt, Dave Culp @see Akbar, Raza et al. "A Simple Analysis of Fuel Addition to the CWT of @@ -211,8 +214,8 @@ public: /** Resets the tank parameters to the initial conditions */ void ResetToIC(void); - /** If the tank is supplying fuel, this function returns true. - @return true if this tank is feeding an engine.*/ + /** If the tank is set to supply fuel, this function returns true. + @return true if this tank is set to a non-zero priority.*/ bool GetSelected(void) {return Selected;} /** Gets the tank fill level. @@ -223,10 +226,18 @@ public: @return the capacity of the tank in pounds. */ double GetCapacity(void) {return Capacity;} + /** Gets the capacity of the tank. + @return the capacity of the tank in gallons. */ + double GetCapacityGallons(void) {return Capacity/Density;} + /** Gets the contents of the tank. @return the contents of the tank in pounds. */ double GetContents(void) const {return Contents;} + /** Gets the contents of the tank. + @return the contents of the tank in gallons. */ + double GetContentsGallons(void) const {return Contents/Density;} + /** Gets the temperature of the fuel. The temperature of the fuel is calculated if an initial tempearture is given in the configuration file. @@ -247,13 +258,18 @@ public: double GetStandpipe(void) {return Standpipe;} + int GetPriority(void) const {return Priority;} + void SetPriority(int p) { Priority = p; Selected = p>0 ? true:false; } + const FGColumnVector3 GetXYZ(void); const double GetXYZ(int idx); double Fill(double amount); void SetContents(double amount); + void SetContentsGallons(double gallons); void SetTemperature(double temp) { Temperature = temp; } void SetStandpipe(double amount) { Standpipe = amount; } + void SetSelected(bool sel) { sel==true ? SetPriority(1):SetPriority(0); } enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER}; enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING}; @@ -262,8 +278,8 @@ private: TankType Type; GrainType grainType; int TankNumber; - string type; - string strGType; + std::string type; + std::string strGType; FGColumnVector3 vXYZ; FGColumnVector3 vXYZ_drain; double Capacity; @@ -281,6 +297,7 @@ private: double Temperature, InitialTemperature; double Standpipe, InitialStandpipe; bool Selected; + int Priority, InitialPriority; FGFDMExec* Exec; FGPropertyManager* PropertyManager; void CalculateInertias(void); diff --git a/src/FDM/JSBSim/models/propulsion/FGThruster.cpp b/src/FDM/JSBSim/models/propulsion/FGThruster.cpp index 9a5c38340..32a508ee1 100644 --- a/src/FDM/JSBSim/models/propulsion/FGThruster.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGThruster.cpp @@ -35,9 +35,13 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include #include #include "FGThruster.h" +#include "input_output/FGXMLElement.h" + +using namespace std; namespace JSBSim { diff --git a/src/FDM/JSBSim/models/propulsion/FGThruster.h b/src/FDM/JSBSim/models/propulsion/FGThruster.h index 860db5a55..886b678dc 100644 --- a/src/FDM/JSBSim/models/propulsion/FGThruster.h +++ b/src/FDM/JSBSim/models/propulsion/FGThruster.h @@ -39,9 +39,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGForce.h" -#include -#include -#include +#include "math/FGColumnVector3.h" #include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -56,6 +54,9 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; +class FGPropertyManager; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/models/propulsion/FGTurbine.cpp b/src/FDM/JSBSim/models/propulsion/FGTurbine.cpp index 6c4a7818c..b690d72f0 100644 --- a/src/FDM/JSBSim/models/propulsion/FGTurbine.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGTurbine.cpp @@ -39,10 +39,14 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include #include - #include "FGTurbine.h" +#include "FGState.h" +#include "models/FGPropulsion.h" +#include "FGThruster.h" + +using namespace std; namespace JSBSim { @@ -99,8 +103,9 @@ void FGTurbine::ResetToIC(void) Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false; Cutoff = true; phase = tpOff; - EGT_degC = 0.0; - OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0; + TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556; + EGT_degC = TAT; + OilTemp_degK = TAT + 273.0; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -112,6 +117,7 @@ double FGTurbine::Calculate(void) double thrust; TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556; + double qbar = Auxiliary->Getqbar(); dt = State->Getdt() * Propulsion->GetRate(); ThrottlePos = FCS->GetThrottlePos(EngineNumber); if (ThrottlePos > 1.0) { @@ -140,7 +146,12 @@ double FGTurbine::Calculate(void) if (!Running && Cutoff && Starter) { if (phase == tpOff) phase = tpSpinUp; } - if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart; + + // start + if ((Starter == true) || (qbar > 30.0)) { + if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart; + } + if (Cutoff && (phase != tpSpinUp)) phase = tpOff; if (dt == 0) phase = tpTrim; if (Starved) phase = tpOff; @@ -271,6 +282,7 @@ double FGTurbine::SpinUp(void) OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2); EPR = 1.0; NozzlePosition = 1.0; + if (Starter == false) phase = tpOff; return 0.0; } @@ -278,15 +290,17 @@ double FGTurbine::SpinUp(void) double FGTurbine::Start(void) { + double qbar = Auxiliary->Getqbar(); if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start Cranking = true; // provided for sound effects signal if (N2 < IdleN2) { N2 = Seek(&N2, IdleN2, 2.0, N2/2.0); N1 = Seek(&N1, IdleN1, 1.4, N1/2.0); EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3); - FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7); + FuelFlow_pph = IdleFF * N2 / IdleN2; OilPressure_psi = N2 * 0.62; ConsumeFuel(); + if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start } else { phase = tpRun; @@ -313,8 +327,10 @@ double FGTurbine::Stall(void) N1 = Seek(&N1, qbar/10.0, 0, N1/10.0); N2 = Seek(&N2, qbar/15.0, 0, N2/10.0); ConsumeFuel(); - if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle - + if (ThrottlePos < 0.01) { + phase = tpRun; // clear the stall with throttle to idle + Stalled = false; + } return 0.0; } @@ -325,7 +341,7 @@ double FGTurbine::Seize(void) double qbar = Auxiliary->Getqbar(); N2 = 0.0; N1 = Seek(&N1, qbar/20.0, 0, N1/15.0); - FuelFlow_pph = IdleFF; + FuelFlow_pph = Cutoff ? 0.0 : IdleFF; ConsumeFuel(); OilPressure_psi = 0.0; OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2); @@ -477,26 +493,26 @@ bool FGTurbine::Load(FGFDMExec* exec, Element *el) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGTurbine::GetEngineLabels(string delimeter) +string FGTurbine::GetEngineLabels(const string& delimiter) { std::ostringstream buf; - buf << Name << "_N1[" << EngineNumber << "]" << delimeter - << Name << "_N2[" << EngineNumber << "]" << delimeter - << Thruster->GetThrusterLabels(EngineNumber, delimeter); + buf << Name << "_N1[" << EngineNumber << "]" << delimiter + << Name << "_N2[" << EngineNumber << "]" << delimiter + << Thruster->GetThrusterLabels(EngineNumber, delimiter); return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGTurbine::GetEngineValues(string delimeter) +string FGTurbine::GetEngineValues(const string& delimiter) { std::ostringstream buf; - buf << N1 << delimeter - << N2 << delimeter - << Thruster->GetThrusterValues(EngineNumber, delimeter); + buf << N1 << delimiter + << N2 << delimiter + << Thruster->GetThrusterValues(EngineNumber, delimiter); return buf.str(); } @@ -514,6 +530,10 @@ void FGTurbine::bindmodel() property_name = base_property_name + "/injection_cmd"; PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this, &FGTurbine::GetInjection, &FGTurbine::SetInjection); + property_name = base_property_name + "/seized"; + PropertyManager->Tie( property_name.c_str(), &Seized); + property_name = base_property_name + "/stalled"; + PropertyManager->Tie( property_name.c_str(), &Stalled); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -522,7 +542,7 @@ int FGTurbine::InitRunning(void) { State->SuspendIntegration(); Cutoff=false; Running=true; - N2=16.0; + N2=IdleN2; Calculate(); State->ResumeIntegration(); return phase==tpRun; diff --git a/src/FDM/JSBSim/models/propulsion/FGTurbine.h b/src/FDM/JSBSim/models/propulsion/FGTurbine.h index 552c258b1..9eebc335d 100644 --- a/src/FDM/JSBSim/models/propulsion/FGTurbine.h +++ b/src/FDM/JSBSim/models/propulsion/FGTurbine.h @@ -40,10 +40,7 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include #include "FGEngine.h" -#include -#include #define ID_TURBINE "$Id$" @@ -53,6 +50,9 @@ FORWARD DECLARATIONS namespace JSBSim { +class Element; +class FGFunction; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -209,8 +209,8 @@ public: int InitRunning(void); void ResetToIC(void); - string GetEngineLabels(string delimeter); - string GetEngineValues(string delimeter); + std::string GetEngineLabels(const std::string& delimiter); + std::string GetEngineValues(const std::string& delimiter); private: diff --git a/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp b/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp index dce831412..9ebef96df 100755 --- a/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp @@ -41,11 +41,15 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include +#include #include #include "FGTurboProp.h" #include "FGPropeller.h" +#include "FGState.h" +#include "models/FGAuxiliary.h" + +using namespace std; namespace JSBSim { @@ -245,7 +249,10 @@ double FGTurboProp::Calculate(void) } //printf ("EngHP: %lf / Requi: %lf\n",Eng_HP,Prop_Required_Power); - return Thruster->Calculate((Eng_HP * hptoftlbssec)-Thruster->GetPowerRequired()); + PowerAvailable = (Eng_HP * hptoftlbssec) - Thruster->GetPowerRequired(); + + return Thruster->Calculate(PowerAvailable); + } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -438,7 +445,7 @@ double FGTurboProp::ExpSeek(double *var, double target, double accel_tau, double void FGTurboProp::SetDefaults(void) { - Name = "Not defined"; +// Name = "Not defined"; N1 = N2 = 0.0; Type = etTurboprop; MilThrust = 10000.0; @@ -468,27 +475,28 @@ void FGTurboProp::SetDefaults(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGTurboProp::GetEngineLabels(string delimeter) +string FGTurboProp::GetEngineLabels(const string& delimiter) { std::ostringstream buf; - buf << Name << "_N1[" << EngineNumber << "]" << delimeter - << Name << "_N2[" << EngineNumber << "]" << delimeter - << Name << "__PwrAvailJVK[" << EngineNumber << "]" << delimeter - << Thruster->GetThrusterLabels(EngineNumber, delimeter); + buf << Name << "_N1[" << EngineNumber << "]" << delimiter + << Name << "_N2[" << EngineNumber << "]" << delimiter + << Name << "_PwrAvail[" << EngineNumber << "]" << delimiter + << Thruster->GetThrusterLabels(EngineNumber, delimiter); return buf.str(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGTurboProp::GetEngineValues(string delimeter) +string FGTurboProp::GetEngineValues(const string& delimiter) { std::ostringstream buf; - buf << N1 << delimeter - << N2 << delimeter - << Thruster->GetThrusterValues(EngineNumber,delimeter); + buf << PowerAvailable << delimiter + << N1 << delimiter + << N2 << delimiter + << Thruster->GetThrusterValues(EngineNumber,delimiter); return buf.str(); } diff --git a/src/FDM/JSBSim/models/propulsion/FGTurboProp.h b/src/FDM/JSBSim/models/propulsion/FGTurboProp.h index 6501452b1..cb10f85b9 100755 --- a/src/FDM/JSBSim/models/propulsion/FGTurboProp.h +++ b/src/FDM/JSBSim/models/propulsion/FGTurboProp.h @@ -43,8 +43,8 @@ INCLUDES #include #include "FGEngine.h" -#include -#include +#include "input_output/FGXMLElement.h" +#include "math/FGTable.h" #define ID_TURBOPROP "$Id$" @@ -147,8 +147,8 @@ public: inline void SetGeneratorPower(bool gp) { GeneratorPower=gp; } inline void SetCondition(bool c) { Condition=c; } int InitRunning(void); - string GetEngineLabels(string delimeter); // added from Turbine 0.9.6 - string GetEngineValues(string delimeter); // added from Turbine 0.9.6 + std::string GetEngineLabels(const std::string& delimiter); + std::string GetEngineValues(const std::string& delimiter); private: @@ -167,6 +167,7 @@ private: double N2_factor; ///< factor to tie N2 and throttle double ThrottleCmd; ///< FCS-supplied throttle position double TAT; ///< total air temperature (deg C) + double PowerAvailable; bool Stalled; ///< true if engine is compressor-stalled bool Seized; ///< true if inner spool is seized bool Overtemp; ///< true if EGT exceeds limits diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 307c6cb96..2e8713a17 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -37,6 +37,7 @@ # define getcwd _getcwd # include // isatty() # define isatty _isatty +# include "Winsock2.h" // for gethostname() #endif // work around a stdc++ lib bug in some versions of linux, but doesn't