1
1
// airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
2
2
// Written by David Megginson, started 2002.
3
// Last modified by Eric van den Berg, 09 Dec 2012
4
5
// This file is in the Public Domain and comes with no warranty.
13
#include <simgear/constants.h>
12
14
#include <simgear/math/interpolater.hxx>
14
16
#include "airspeed_indicator.hxx"
15
17
#include <Main/fg_props.hxx>
16
18
#include <Main/util.hxx>
19
#include <Environment/environment_mgr.hxx>
20
#include <Environment/environment.hxx>
19
23
// A higher number means more responsive.
31
35
_mach_limit(node->getDoubleValue("mach-limit", 0.48)),
32
36
_alt_threshold(node->getDoubleValue("alt-threshold", 13200))
38
_environmentManager = NULL;
36
41
AirspeedIndicator::~AirspeedIndicator ()
48
53
_total_pressure_node = fgGetNode(_total_pressure.c_str(), true);
49
54
_static_pressure_node = fgGetNode(_static_pressure.c_str(), true);
50
55
_density_node = fgGetNode("/environment/density-slugft3", true);
52
_sea_level_pressure_node = fgGetNode("/environment/pressure-sea-level-inhg", true);
53
_oat_celsius_node = fgGetNode("/environment/temperature-degc", true);
55
56
_speed_node = node->getChild("indicated-speed-kt", 0, true);
56
57
_tas_node = node->getChild("true-speed-kt", 0, true);
57
58
_mach_node = node->getChild("indicated-mach", 0, true);
77
78
_airspeed_limit = node->getChild("airspeed-limit-kt", 0, true);
78
79
_pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true);
82
_environmentManager = (FGEnvironmentMgr*) globals->get_subsystem("environment");
103
double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
104
double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
105
double r = _density_node->getDoubleValue();
106
double q = ( pt - p ); // dynamic pressure
98
double pt = _total_pressure_node->getDoubleValue() ;
99
double p = _static_pressure_node->getDoubleValue() ;
100
double qc = ( pt - p ) * SG_INHG_TO_PA ; // Impact pressure in Pa, _not_ to be confused with dynamic pressure!!!
108
// Now, reverse the equation (normalize dynamic pressure to
102
// Now, reverse the equation (normalize impact pressure to
109
103
// avoid "nan" results from sqrt)
110
if ( q < 0 ) { q = 0.0; }
111
double v_fps = sqrt((2 * q) / r);
104
qc = std::max( qc , 0.0 );
105
// Calibrated airspeed (using compressible aerodynamics) based on impact pressure qc in m/s
106
// Using calibrated airspeed as indicated airspeed, neglecting any airspeed indicator errors.
107
double v_cal = sqrt( 7 * SG_p0_Pa/SG_rho0_kg_p_m3 * ( pow( 1 + qc/SG_p0_Pa , 1/3.5 ) -1 ) );
113
109
// Publish the indicated airspeed
114
110
double last_speed_kt = _speed_node->getDoubleValue();
115
double current_speed_kt = v_fps * FPSTOKTS;
111
double current_speed_kt = v_cal * SG_MPS_TO_KT;
116
112
double filtered_speed = fgGetLowPass(last_speed_kt,
117
113
current_speed_kt,
118
114
dt * RESPONSIVENESS);
119
115
_speed_node->setDoubleValue(filtered_speed);
120
computeMach(filtered_speed);
122
118
if (!_has_overspeed) {
136
AirspeedIndicator::computeMach(double ias)
132
AirspeedIndicator::computeMach()
139
// derived from http://williams.best.vwh.net/avform.htm#Mach
140
// names here are picked to be consistent with those formulae!
142
double oatK = _oat_celsius_node->getDoubleValue() + 273.15; // OAT in Kelvin
143
double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude
144
double CS_0 = 661.4786; // speed-of-sound in knots at sea-level
145
double P_0 = _sea_level_pressure_node->getDoubleValue();
146
double P = _static_pressure_node->getDoubleValue();
148
double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1);
149
double mach = pow(5 * ( pow(DP/P + 1, 2.0/7.0) -1) , 0.5);
134
if (!_environmentManager) {
138
FGEnvironment env(_environmentManager->getEnvironment());
140
double oatK = env.get_temperature_degc() + SG_T0_K - 15.0 ; // OAT in Kelvin
141
oatK = std::max( oatK , 0.001 ); // should never happen, but just in case someone flies into space...
142
double c = sqrt(SG_gamma * SG_R_m2_p_s2_p_K * oatK); // speed-of-sound in m/s at aircraft position
143
double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // total pressure in Pa
144
double p = _static_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // static pressure in Pa
145
p = std::max( p , 0.001 ); // should never happen, but just in case someone flies into space...
146
double rho = _density_node->getDoubleValue() * SG_SLUGFT3_TO_KGPM3; // air density in kg/m3
147
rho = std::max( rho , 0.001 ); // should never happen, but just in case someone flies into space...
149
// true airspeed in m/s
150
pt = std::max( pt , p );
151
double V_true = sqrt( 7 * p/rho * (pow( 1 + (pt-p)/p , 1/3.5 ) -1 ) );
152
// Mach number; _see notes in systems/pitot.cxx_
153
double mach = V_true / c;
151
155
// publish Mach and TAS
152
156
_mach_node->setDoubleValue(mach);
153
_tas_node->setDoubleValue(CS * mach);
157
_tas_node->setDoubleValue(V_true * SG_MPS_TO_KT );
156
160
// end of airspeed_indicator.cxx