Merge branch 'syd/ias-limit'
This commit is contained in:
commit
103114fd66
3 changed files with 112 additions and 18 deletions
|
@ -10,6 +10,8 @@
|
|||
#include "airspeed_indicator.hxx"
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/util.hxx>
|
||||
#include <Environment/environment_mgr.hxx>
|
||||
#include <Environment/environment.hxx>
|
||||
|
||||
|
||||
// A higher number means more responsive.
|
||||
|
@ -20,8 +22,14 @@ 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_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))
|
||||
{
|
||||
_environmentManager = NULL;
|
||||
}
|
||||
|
||||
AirspeedIndicator::~AirspeedIndicator ()
|
||||
|
@ -40,6 +48,32 @@ 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);
|
||||
_mach_limit_node = node->getNode("mach-limit",0, true);
|
||||
_alt_threshold_node = node->getNode("alt-threshold",0, true);
|
||||
|
||||
if (!_ias_limit_node->hasValue()) {
|
||||
_ias_limit_node->setDoubleValue(_ias_limit);
|
||||
}
|
||||
|
||||
if (!_mach_limit_node->hasValue()) {
|
||||
_mach_limit_node->setDoubleValue(_mach_limit);
|
||||
}
|
||||
|
||||
if (!_alt_threshold_node->hasValue()) {
|
||||
_alt_threshold_node->setDoubleValue(_alt_threshold);
|
||||
}
|
||||
|
||||
_airspeed_limit = node->getChild("airspeed-limit-kt", 0, true);
|
||||
_pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true);
|
||||
}
|
||||
|
||||
_environmentManager = (FGEnvironmentMgr*) globals->get_subsystem("environment");
|
||||
}
|
||||
|
||||
#ifndef FPSTOKTS
|
||||
|
@ -53,24 +87,66 @@ 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);
|
||||
computeMach(filtered_speed);
|
||||
|
||||
if (!_has_overspeed) {
|
||||
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_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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
|
||||
// forward decls
|
||||
class FGEnvironmentMgr;
|
||||
|
||||
/**
|
||||
* Model an airspeed indicator tied to the pitot and static ports.
|
||||
|
@ -41,17 +43,32 @@ public:
|
|||
virtual void update (double dt);
|
||||
|
||||
private:
|
||||
void computeMach(double ias);
|
||||
|
||||
string _name;
|
||||
unsigned int _num;
|
||||
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;
|
||||
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_node;
|
||||
SGPropertyNode_ptr _tas_node;
|
||||
|
||||
FGEnvironmentMgr* _environmentManager;
|
||||
};
|
||||
|
||||
#endif // __INSTRUMENTS_AIRSPEED_INDICATOR_HXX
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue