1
0
Fork 0

Avoid a dependency on the environment-manager.

Change the ASI Mach computation (written by me) to use properties, instead of depending directly on the environment-manager.
This commit is contained in:
James Turner 2012-11-19 23:17:03 +00:00
parent 868b7b40dc
commit 93237f1b37
2 changed files with 9 additions and 18 deletions

View file

@ -14,8 +14,6 @@
#include "airspeed_indicator.hxx" #include "airspeed_indicator.hxx"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/util.hxx> #include <Main/util.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
// A higher number means more responsive. // A higher number means more responsive.
@ -33,7 +31,6 @@ AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node )
_mach_limit(node->getDoubleValue("mach-limit", 0.48)), _mach_limit(node->getDoubleValue("mach-limit", 0.48)),
_alt_threshold(node->getDoubleValue("alt-threshold", 13200)) _alt_threshold(node->getDoubleValue("alt-threshold", 13200))
{ {
_environmentManager = NULL;
} }
AirspeedIndicator::~AirspeedIndicator () AirspeedIndicator::~AirspeedIndicator ()
@ -51,6 +48,10 @@ AirspeedIndicator::init ()
_total_pressure_node = fgGetNode(_total_pressure.c_str(), true); _total_pressure_node = fgGetNode(_total_pressure.c_str(), true);
_static_pressure_node = fgGetNode(_static_pressure.c_str(), true); _static_pressure_node = fgGetNode(_static_pressure.c_str(), true);
_density_node = fgGetNode("/environment/density-slugft3", true); _density_node = fgGetNode("/environment/density-slugft3", true);
_sea_level_pressure_node = fgGetNode("/environment/pressure-sea-level-inhg", true);
_oat_celsius_node = fgGetNode("/environment/temperature-degc", true);
_speed_node = node->getChild("indicated-speed-kt", 0, true); _speed_node = node->getChild("indicated-speed-kt", 0, true);
_tas_node = node->getChild("true-speed-kt", 0, true); _tas_node = node->getChild("true-speed-kt", 0, true);
_mach_node = node->getChild("indicated-mach", 0, true); _mach_node = node->getChild("indicated-mach", 0, true);
@ -76,8 +77,6 @@ AirspeedIndicator::init ()
_airspeed_limit = node->getChild("airspeed-limit-kt", 0, true); _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true);
_pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true); _pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true);
} }
_environmentManager = (FGEnvironmentMgr*) globals->get_subsystem("environment");
} }
void void
@ -136,19 +135,14 @@ AirspeedIndicator::update (double dt)
void void
AirspeedIndicator::computeMach(double ias) AirspeedIndicator::computeMach(double ias)
{ {
if (!_environmentManager) {
return;
}
FGEnvironment env(_environmentManager->getEnvironment());
// derived from http://williams.best.vwh.net/avform.htm#Mach // derived from http://williams.best.vwh.net/avform.htm#Mach
// names here are picked to be consistent with those formulae! // names here are picked to be consistent with those formulae!
double oatK = env.get_temperature_degc() + 273.15; // OAT in Kelvin double oatK = _oat_celsius_node->getDoubleValue() + 273.15; // OAT in Kelvin
double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude 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 CS_0 = 661.4786; // speed-of-sound in knots at sea-level
double P_0 = env.get_pressure_sea_level_inhg(); double P_0 = _sea_level_pressure_node->getDoubleValue();
double P = _static_pressure_node->getDoubleValue(); double P = _static_pressure_node->getDoubleValue();
double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1); double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1);

View file

@ -14,9 +14,6 @@
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
// forward decls
class FGEnvironmentMgr;
/** /**
* Model an airspeed indicator tied to the pitot and static ports. * Model an airspeed indicator tied to the pitot and static ports.
* *
@ -68,8 +65,8 @@ private:
SGPropertyNode_ptr _pressure_alt; SGPropertyNode_ptr _pressure_alt;
SGPropertyNode_ptr _mach_node; SGPropertyNode_ptr _mach_node;
SGPropertyNode_ptr _tas_node; SGPropertyNode_ptr _tas_node;
SGPropertyNode_ptr _sea_level_pressure_node;
FGEnvironmentMgr* _environmentManager; SGPropertyNode_ptr _oat_celsius_node;
}; };
#endif // __INSTRUMENTS_AIRSPEED_INDICATOR_HXX #endif // __INSTRUMENTS_AIRSPEED_INDICATOR_HXX