From 45a446dfafe3bffa1e4fe51e8271efd97ea1bc34 Mon Sep 17 00:00:00 2001 From: jmt Date: Tue, 9 Mar 2010 11:11:07 +0000 Subject: [PATCH 1/5] Syd Adams: add ias-limit (brarber-pole) computation to airpseed-indicator expose selected DME frequency on the DME instrument --- src/Instrumentation/airspeed_indicator.cxx | 63 +++++++++++++++------- src/Instrumentation/airspeed_indicator.hxx | 8 ++- src/Instrumentation/dme.cxx | 1 + 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 0196ddbae..329d91a2e 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -20,7 +20,8 @@ AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node ) _name(node->getStringValue("name", "airspeed-indicator")), _num(node->getIntValue("number", 0)), _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")), - _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")) + _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")), + _has_barber_pole(node->getBoolValue("has-barber-pole",false)) { } @@ -40,6 +41,17 @@ AirspeedIndicator::init () _static_pressure_node = fgGetNode(_static_pressure.c_str(), true); _density_node = fgGetNode("/environment/density-slugft3", true); _speed_node = node->getChild("indicated-speed-kt", 0, true); + + // barber-pole properties + _ias_limit_node = node->getNode("ias-limit",0, true); + _mach_limit_node = node->getNode("mach-limit",0, true); + _alt_threshold_node = node->getNode("alt-threshold",0, true); + _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); + + string paSource = node->getStringValue("pressure-alt-source", + "/instrumentation/altimeter/pressure-alt-ft"); + _pressure_alt = fgGetNode(paSource.c_str(), true); + _mach = fgGetNode("/velocities/mach", true); } #ifndef FPSTOKTS @@ -53,24 +65,39 @@ AirspeedIndicator::init () void AirspeedIndicator::update (double dt) { - if (_serviceable_node->getBoolValue()) { - double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF; - double p = _static_pressure_node->getDoubleValue() * INHGTOPSF; - double r = _density_node->getDoubleValue(); - double q = ( pt - p ); // dynamic pressure - - // Now, reverse the equation (normalize dynamic pressure to - // avoid "nan" results from sqrt) - if ( q < 0 ) { q = 0.0; } - double v_fps = sqrt((2 * q) / r); - - // Publish the indicated airspeed - double last_speed_kt = _speed_node->getDoubleValue(); - double current_speed_kt = v_fps * FPSTOKTS; - _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt, - current_speed_kt, - dt * RESPONSIVENESS)); + if (!_serviceable_node->getBoolValue()) { + return; } + + double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF; + double p = _static_pressure_node->getDoubleValue() * INHGTOPSF; + double r = _density_node->getDoubleValue(); + double q = ( pt - p ); // dynamic pressure + + // Now, reverse the equation (normalize dynamic pressure to + // avoid "nan" results from sqrt) + if ( q < 0 ) { q = 0.0; } + double v_fps = sqrt((2 * q) / r); + + // Publish the indicated airspeed + double last_speed_kt = _speed_node->getDoubleValue(); + double current_speed_kt = v_fps * FPSTOKTS; + double filtered_speed = fgGetLowPass(last_speed_kt, + current_speed_kt, + dt * RESPONSIVENESS); + _speed_node->setDoubleValue(filtered_speed); + + if (!_has_barber_pole) { + return; + } + + double lmt = _ias_limit_node->getDoubleValue(); + if (_pressure_alt->getDoubleValue() > _alt_threshold_node->getDoubleValue()) { + double mmo = _mach_limit_node->getDoubleValue(); + lmt = (filtered_speed/_mach->getDoubleValue())* mmo; + } + + _airspeed_limit->setDoubleValue(lmt); } // end of airspeed_indicator.cxx diff --git a/src/Instrumentation/airspeed_indicator.hxx b/src/Instrumentation/airspeed_indicator.hxx index e4827081d..7948ed2f2 100644 --- a/src/Instrumentation/airspeed_indicator.hxx +++ b/src/Instrumentation/airspeed_indicator.hxx @@ -46,12 +46,18 @@ private: unsigned int _num; string _total_pressure; string _static_pressure; + bool _has_barber_pole; + SGPropertyNode_ptr _ias_limit_node; + SGPropertyNode_ptr _mach_limit_node; + SGPropertyNode_ptr _alt_threshold_node; SGPropertyNode_ptr _serviceable_node; SGPropertyNode_ptr _total_pressure_node; SGPropertyNode_ptr _static_pressure_node; SGPropertyNode_ptr _density_node; SGPropertyNode_ptr _speed_node; - + SGPropertyNode_ptr _airspeed_limit; + SGPropertyNode_ptr _pressure_alt; + SGPropertyNode_ptr _mach; }; #endif // __INSTRUMENTS_AIRSPEED_INDICATOR_HXX diff --git a/src/Instrumentation/dme.cxx b/src/Instrumentation/dme.cxx index 754008bd4..925681e0a 100644 --- a/src/Instrumentation/dme.cxx +++ b/src/Instrumentation/dme.cxx @@ -97,6 +97,7 @@ DME::update (double delta_time_sec) _time_before_search_sec = 0; _last_frequency_mhz = frequency_mhz; } + _frequency_node->setDoubleValue(frequency_mhz); // Get the aircraft position double longitude_rad = From 65ad38ccae11457a9603e45d99efacadad098a12 Mon Sep 17 00:00:00 2001 From: jmt Date: Thu, 11 Mar 2010 09:45:48 +0000 Subject: [PATCH 2/5] Airspeed indicator: add default values for overspeed, and rename the enable property to 'has-overspeed-indicator'. --- src/Instrumentation/airspeed_indicator.cxx | 18 +++++++++++++++--- src/Instrumentation/airspeed_indicator.hxx | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 329d91a2e..3fb9aa655 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -21,7 +21,7 @@ AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node ) _num(node->getIntValue("number", 0)), _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")), _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")), - _has_barber_pole(node->getBoolValue("has-barber-pole",false)) + _has_overspeed(node->getBoolValue("has-overspeed-indicator",false)) { } @@ -42,12 +42,24 @@ AirspeedIndicator::init () _density_node = fgGetNode("/environment/density-slugft3", true); _speed_node = node->getChild("indicated-speed-kt", 0, true); - // barber-pole properties + // overspeed-indicator properties _ias_limit_node = node->getNode("ias-limit",0, true); _mach_limit_node = node->getNode("mach-limit",0, true); _alt_threshold_node = node->getNode("alt-threshold",0, true); _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); + if (!_ias_limit_node->hasValue()) { + _ias_limit_node->setDoubleValue(250.0); + } + + if (!_mach_limit_node->hasValue()) { + _mach_limit_node->setDoubleValue(0.48); + } + + if (!_alt_threshold_node->hasValue()) { + _alt_threshold_node->setDoubleValue(13200); + } + string paSource = node->getStringValue("pressure-alt-source", "/instrumentation/altimeter/pressure-alt-ft"); _pressure_alt = fgGetNode(paSource.c_str(), true); @@ -87,7 +99,7 @@ AirspeedIndicator::update (double dt) dt * RESPONSIVENESS); _speed_node->setDoubleValue(filtered_speed); - if (!_has_barber_pole) { + if (!_has_overspeed) { return; } diff --git a/src/Instrumentation/airspeed_indicator.hxx b/src/Instrumentation/airspeed_indicator.hxx index 7948ed2f2..47eb9f43c 100644 --- a/src/Instrumentation/airspeed_indicator.hxx +++ b/src/Instrumentation/airspeed_indicator.hxx @@ -46,7 +46,7 @@ private: unsigned int _num; string _total_pressure; string _static_pressure; - bool _has_barber_pole; + bool _has_overspeed; SGPropertyNode_ptr _ias_limit_node; SGPropertyNode_ptr _mach_limit_node; SGPropertyNode_ptr _alt_threshold_node; From b1855b34c6b1c80e6163d0a2e98c555222fc36f3 Mon Sep 17 00:00:00 2001 From: jmt Date: Sat, 13 Mar 2010 12:21:51 +0000 Subject: [PATCH 3/5] Syd Adams: only define overspeed-indicator properties when enabled. --- src/Instrumentation/airspeed_indicator.cxx | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 3fb9aa655..0d59ffcf3 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -41,29 +41,31 @@ AirspeedIndicator::init () _static_pressure_node = fgGetNode(_static_pressure.c_str(), true); _density_node = fgGetNode("/environment/density-slugft3", true); _speed_node = node->getChild("indicated-speed-kt", 0, true); - + // overspeed-indicator properties - _ias_limit_node = node->getNode("ias-limit",0, true); - _mach_limit_node = node->getNode("mach-limit",0, true); - _alt_threshold_node = node->getNode("alt-threshold",0, true); - _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); - - if (!_ias_limit_node->hasValue()) { - _ias_limit_node->setDoubleValue(250.0); + if (_has_overspeed) { + _ias_limit_node = node->getNode("ias-limit",0, true); + _mach_limit_node = node->getNode("mach-limit",0, true); + _alt_threshold_node = node->getNode("alt-threshold",0, true); + _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); + + if (!_ias_limit_node->hasValue()) { + _ias_limit_node->setDoubleValue(248.0); + } + + if (!_mach_limit_node->hasValue()) { + _mach_limit_node->setDoubleValue(0.48); + } + + if (!_alt_threshold_node->hasValue()) { + _alt_threshold_node->setDoubleValue(13200); + } + + string paSource = node->getStringValue("pressure-alt-source", + "/instrumentation/altimeter/pressure-alt-ft"); + _pressure_alt = fgGetNode(paSource.c_str(), true); + _mach = fgGetNode("/velocities/mach", true); } - - if (!_mach_limit_node->hasValue()) { - _mach_limit_node->setDoubleValue(0.48); - } - - if (!_alt_threshold_node->hasValue()) { - _alt_threshold_node->setDoubleValue(13200); - } - - string paSource = node->getStringValue("pressure-alt-source", - "/instrumentation/altimeter/pressure-alt-ft"); - _pressure_alt = fgGetNode(paSource.c_str(), true); - _mach = fgGetNode("/velocities/mach", true); } #ifndef FPSTOKTS From 432da86c7babeb60aad9d84ac7b981c94e0fe0a1 Mon Sep 17 00:00:00 2001 From: jmt Date: Thu, 18 Mar 2010 00:05:26 +0000 Subject: [PATCH 4/5] Read airspeed-indicator overspeed limit values from instrument configuration, as Syd intended. --- src/Instrumentation/airspeed_indicator.cxx | 20 +++++++++++--------- src/Instrumentation/airspeed_indicator.hxx | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 0d59ffcf3..341c45edb 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -21,7 +21,11 @@ AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node ) _num(node->getIntValue("number", 0)), _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")), _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")), - _has_overspeed(node->getBoolValue("has-overspeed-indicator",false)) + _has_overspeed(node->getBoolValue("has-overspeed-indicator",false)), + _pressure_alt_source(node->getStringValue("pressure-alt-source", "/instrumentation/altimeter/pressure-alt-ft")), + _ias_limit(node->getDoubleValue("ias-limit", 248.0)), + _mach_limit(node->getDoubleValue("mach-limit", 0.48)), + _alt_threshold(node->getDoubleValue("alt-threshold", 13200)) { } @@ -47,23 +51,21 @@ AirspeedIndicator::init () _ias_limit_node = node->getNode("ias-limit",0, true); _mach_limit_node = node->getNode("mach-limit",0, true); _alt_threshold_node = node->getNode("alt-threshold",0, true); - _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); - + if (!_ias_limit_node->hasValue()) { - _ias_limit_node->setDoubleValue(248.0); + _ias_limit_node->setDoubleValue(_ias_limit); } if (!_mach_limit_node->hasValue()) { - _mach_limit_node->setDoubleValue(0.48); + _mach_limit_node->setDoubleValue(_mach_limit); } if (!_alt_threshold_node->hasValue()) { - _alt_threshold_node->setDoubleValue(13200); + _alt_threshold_node->setDoubleValue(_alt_threshold); } - string paSource = node->getStringValue("pressure-alt-source", - "/instrumentation/altimeter/pressure-alt-ft"); - _pressure_alt = fgGetNode(paSource.c_str(), true); + _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); + _pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true); _mach = fgGetNode("/velocities/mach", true); } } diff --git a/src/Instrumentation/airspeed_indicator.hxx b/src/Instrumentation/airspeed_indicator.hxx index 47eb9f43c..2248a61b6 100644 --- a/src/Instrumentation/airspeed_indicator.hxx +++ b/src/Instrumentation/airspeed_indicator.hxx @@ -47,6 +47,11 @@ private: string _total_pressure; string _static_pressure; bool _has_overspeed; + string _pressure_alt_source; + double _ias_limit; + double _mach_limit; + double _alt_threshold; + SGPropertyNode_ptr _ias_limit_node; SGPropertyNode_ptr _mach_limit_node; SGPropertyNode_ptr _alt_threshold_node; From 5695395dd58b8924fcdcbe2230687c7dd6019c68 Mon Sep 17 00:00:00 2001 From: jmt Date: Wed, 24 Mar 2010 14:57:48 +0000 Subject: [PATCH 5/5] Add Mach/TAS computation to the airspeed indicator. --- src/Instrumentation/airspeed_indicator.cxx | 39 ++++++++++++++++++++-- src/Instrumentation/airspeed_indicator.hxx | 8 ++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 341c45edb..0622f2103 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -10,6 +10,8 @@ #include "airspeed_indicator.hxx" #include
#include
+#include +#include // A higher number means more responsive. @@ -27,6 +29,7 @@ AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node ) _mach_limit(node->getDoubleValue("mach-limit", 0.48)), _alt_threshold(node->getDoubleValue("alt-threshold", 13200)) { + _environmentManager = NULL; } AirspeedIndicator::~AirspeedIndicator () @@ -45,7 +48,9 @@ AirspeedIndicator::init () _static_pressure_node = fgGetNode(_static_pressure.c_str(), true); _density_node = fgGetNode("/environment/density-slugft3", true); _speed_node = node->getChild("indicated-speed-kt", 0, true); - + _tas_node = node->getChild("true-speed-kt", 0, true); + _mach_node = node->getChild("indicated-mach", 0, true); + // overspeed-indicator properties if (_has_overspeed) { _ias_limit_node = node->getNode("ias-limit",0, true); @@ -66,8 +71,9 @@ AirspeedIndicator::init () _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); _pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true); - _mach = fgGetNode("/velocities/mach", true); } + + _environmentManager = (FGEnvironmentMgr*) globals->get_subsystem("environment"); } #ifndef FPSTOKTS @@ -102,6 +108,7 @@ AirspeedIndicator::update (double dt) current_speed_kt, dt * RESPONSIVENESS); _speed_node->setDoubleValue(filtered_speed); + computeMach(filtered_speed); if (!_has_overspeed) { return; @@ -110,10 +117,36 @@ AirspeedIndicator::update (double dt) double lmt = _ias_limit_node->getDoubleValue(); if (_pressure_alt->getDoubleValue() > _alt_threshold_node->getDoubleValue()) { double mmo = _mach_limit_node->getDoubleValue(); - lmt = (filtered_speed/_mach->getDoubleValue())* mmo; + lmt = (filtered_speed/_mach_node->getDoubleValue())* mmo; } _airspeed_limit->setDoubleValue(lmt); } +void +AirspeedIndicator::computeMach(double ias) +{ + if (!_environmentManager) { + return; + } + + FGEnvironment env(_environmentManager->getEnvironment()); + + // derived from http://williams.best.vwh.net/avform.htm#Mach + // names here are picked to be consistent with those formulae! + + double oatK = env.get_temperature_degc() + 273.15; // OAT in Kelvin + double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude + double CS_0 = 661.4786; // speed-of-sound in knots at sea-level + double P_0 = env.get_pressure_sea_level_inhg(); + double P = _static_pressure_node->getDoubleValue(); + + double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1); + double mach = pow(5 * ( pow(DP/P + 1, 2.0/7.0) -1) , 0.5); + + // publish Mach and TAS + _mach_node->setDoubleValue(mach); + _tas_node->setDoubleValue(CS * mach); +} + // end of airspeed_indicator.cxx diff --git a/src/Instrumentation/airspeed_indicator.hxx b/src/Instrumentation/airspeed_indicator.hxx index 2248a61b6..41e544c66 100644 --- a/src/Instrumentation/airspeed_indicator.hxx +++ b/src/Instrumentation/airspeed_indicator.hxx @@ -14,6 +14,8 @@ #include #include +// forward decls +class FGEnvironmentMgr; /** * Model an airspeed indicator tied to the pitot and static ports. @@ -41,6 +43,7 @@ public: virtual void update (double dt); private: + void computeMach(double ias); string _name; unsigned int _num; @@ -62,7 +65,10 @@ private: SGPropertyNode_ptr _speed_node; SGPropertyNode_ptr _airspeed_limit; SGPropertyNode_ptr _pressure_alt; - SGPropertyNode_ptr _mach; + SGPropertyNode_ptr _mach_node; + SGPropertyNode_ptr _tas_node; + + FGEnvironmentMgr* _environmentManager; }; #endif // __INSTRUMENTS_AIRSPEED_INDICATOR_HXX