FlightGear next
airspeed_indicator.cxx
Go to the documentation of this file.
1// airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
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.
6
7#ifdef HAVE_CONFIG_H
8# include "config.h"
9#endif
10
11#include <algorithm>
12
13#include <cmath>
14
15#include <simgear/constants.h>
16#include <simgear/math/interpolater.hxx>
17
19#include <Main/fg_props.hxx>
20#include <Main/util.hxx>
23
24
25// A higher number means more responsive.
26#define RESPONSIVENESS 50.0
27
29 :
30 _name(node->getStringValue("name", "airspeed-indicator")),
31 _num(node->getIntValue("number", 0)),
32 _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")),
33 _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
34 _has_overspeed(node->getBoolValue("has-overspeed-indicator",false)),
35 _pressure_alt_source(node->getStringValue("pressure-alt-source", "/instrumentation/altimeter/pressure-alt-ft")),
36 _ias_limit(node->getDoubleValue("ias-limit", 248.0)),
37 _mach_limit(node->getDoubleValue("mach-limit", 0.48)),
38 _alt_threshold(node->getDoubleValue("alt-threshold", 13200))
39{
40 _environmentManager = NULL;
41}
42
46
47void
49{
50 std::string branch;
51 branch = "/instrumentation/" + _name;
52
53 SGPropertyNode *node = fgGetNode(branch, _num, true );
54 _serviceable_node = node->getChild("serviceable", 0, true);
55 _total_pressure_node = fgGetNode(_total_pressure, true);
56 _static_pressure_node = fgGetNode(_static_pressure, true);
57 _density_node = fgGetNode("/environment/density-slugft3", true);
58 _speed_node = node->getChild("indicated-speed-kt", 0, true);
59 _tas_node = node->getChild("true-speed-kt", 0, true);
60 _mach_node = node->getChild("indicated-mach", 0, true);
61
62 // overspeed-indicator properties
63 if (_has_overspeed) {
64 _ias_limit_node = node->getNode("ias-limit",0, true);
65 _mach_limit_node = node->getNode("mach-limit",0, true);
66 _alt_threshold_node = node->getNode("alt-threshold",0, true);
67
68 if (!_ias_limit_node->hasValue()) {
69 _ias_limit_node->setDoubleValue(_ias_limit);
70 }
71
72 if (!_mach_limit_node->hasValue()) {
73 _mach_limit_node->setDoubleValue(_mach_limit);
74 }
75
76 if (!_alt_threshold_node->hasValue()) {
77 _alt_threshold_node->setDoubleValue(_alt_threshold);
78 }
79
80 _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true);
81 _pressure_alt = fgGetNode(_pressure_alt_source, true);
82 }
83
84 _environmentManager = globals->get_subsystem<FGEnvironmentMgr>();
85}
86
87void
89{
90 _speed_node->setDoubleValue(0.0);
91}
92
93void
95{
96 if (!_serviceable_node->getBoolValue()) {
97 return;
98 }
99
100 double pt = _total_pressure_node->getDoubleValue() ;
101 double p = _static_pressure_node->getDoubleValue() ;
102 double qc = ( pt - p ) * SG_INHG_TO_PA ; // Impact pressure in Pa, _not_ to be confused with dynamic pressure!!!
103
104 // Now, reverse the equation (normalize impact pressure to
105 // avoid "nan" results from sqrt)
106 qc = std::max( qc , 0.0 );
107 // Calibrated airspeed (using compressible aerodynamics) based on impact pressure qc in m/s
108 // Using calibrated airspeed as indicated airspeed, neglecting any airspeed indicator errors.
109 double v_cal = sqrt( 7 * SG_p0_Pa/SG_rho0_kg_p_m3 * ( pow( 1 + qc/SG_p0_Pa , 1/3.5 ) -1 ) );
110
111 // Publish the indicated airspeed
112 double last_speed_kt = _speed_node->getDoubleValue();
113 double current_speed_kt = v_cal * SG_MPS_TO_KT;
114 double filtered_speed = fgGetLowPass(last_speed_kt,
115 current_speed_kt,
116 dt * RESPONSIVENESS);
117 _speed_node->setDoubleValue(filtered_speed);
118 computeMach();
119
120 if (!_has_overspeed) {
121 return;
122 }
123
124 double lmt = _ias_limit_node->getDoubleValue();
125 if (_pressure_alt->getDoubleValue() > _alt_threshold_node->getDoubleValue()) {
126 double mmo = _mach_limit_node->getDoubleValue();
127 lmt = (filtered_speed/_mach_node->getDoubleValue())* mmo;
128 }
129
130 _airspeed_limit->setDoubleValue(lmt);
131}
132
133void
134AirspeedIndicator::computeMach()
135{
136 if (!_environmentManager) {
137 return;
138 }
139
140 const auto env = _environmentManager->getAircraftEnvironment();
141
142 double oatK = env->get_temperature_degc() + SG_T0_K - 15.0 ; // OAT in Kelvin
143 oatK = std::max( oatK , 0.001 ); // should never happen, but just in case someone flies into space...
144 double c = sqrt(SG_gamma * SG_R_m2_p_s2_p_K * oatK); // speed-of-sound in m/s at aircraft position
145 double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // total pressure in Pa
146 double p = _static_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // static pressure in Pa
147 p = std::max( p , 0.001 ); // should never happen, but just in case someone flies into space...
148 double rho = _density_node->getDoubleValue() * SG_SLUGFT3_TO_KGPM3; // air density in kg/m3
149 rho = std::max( rho , 0.001 ); // should never happen, but just in case someone flies into space...
150
151 // true airspeed in m/s
152 pt = std::max( pt , p );
153 double V_true = sqrt( 7 * p/rho * (pow( 1 + (pt-p)/p , 1/3.5 ) -1 ) );
154 // Mach number; _see notes in systems/pitot.cxx_
155 double mach = V_true / c;
156
157 // publish Mach and TAS
158 _mach_node->setDoubleValue(mach);
159 _tas_node->setDoubleValue(V_true * SG_MPS_TO_KT );
160}
161
162
163// Register the subsystem.
164#if 0
165SGSubsystemMgr::InstancedRegistrant<AirspeedIndicator> registrantAirspeedIndicator(
166 SGSubsystemMgr::FDM,
167 {{"instrumentation", SGSubsystemMgr::Dependency::HARD}});
168#endif
169
170// end of airspeed_indicator.cxx
#define p(x)
#define RESPONSIVENESS
Definition adf.cxx:31
void update(double dt) override
AirspeedIndicator(SGPropertyNode *node)
Manage environment information.
FGGlobals * globals
Definition globals.cxx:142
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27
double fgGetLowPass(double current, double target, double timeratio)
Move a value towards a target.
Definition util.cxx:46