]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
GPS: enable switching to OBS/DTO mode with no valid scratch - use active waypoint.
[flightgear.git] / src / Instrumentation / airspeed_indicator.cxx
1 // airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <math.h>
7
8 #include <simgear/math/interpolater.hxx>
9
10 #include "airspeed_indicator.hxx"
11 #include <Main/fg_props.hxx>
12 #include <Main/util.hxx>
13
14
15 // A higher number means more responsive.
16 #define RESPONSIVENESS 50.0
17
18 AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node )
19     :
20     _name(node->getStringValue("name", "airspeed-indicator")),
21     _num(node->getIntValue("number", 0)),
22     _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")),
23     _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg"))
24 {
25 }
26
27 AirspeedIndicator::~AirspeedIndicator ()
28 {
29 }
30
31 void
32 AirspeedIndicator::init ()
33 {
34     string branch;
35     branch = "/instrumentation/" + _name;
36
37     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
38     _serviceable_node = node->getChild("serviceable", 0, true);
39     _total_pressure_node = fgGetNode(_total_pressure.c_str(), true);
40     _static_pressure_node = fgGetNode(_static_pressure.c_str(), true);
41     _density_node = fgGetNode("/environment/density-slugft3", true);
42     _speed_node = node->getChild("indicated-speed-kt", 0, true);
43 }
44
45 #ifndef FPSTOKTS
46 # define FPSTOKTS 0.592484
47 #endif
48
49 #ifndef INHGTOPSF
50 # define INHGTOPSF (2116.217/29.9212)
51 #endif
52
53 void
54 AirspeedIndicator::update (double dt)
55 {
56     if (_serviceable_node->getBoolValue()) {
57         double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
58         double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
59         double r = _density_node->getDoubleValue();
60         double q = ( pt - p );  // dynamic pressure
61
62         // Now, reverse the equation (normalize dynamic pressure to
63         // avoid "nan" results from sqrt)
64         if ( q < 0 ) { q = 0.0; }
65         double v_fps = sqrt((2 * q) / r);
66
67                                 // Publish the indicated airspeed
68         double last_speed_kt = _speed_node->getDoubleValue();
69         double current_speed_kt = v_fps * FPSTOKTS;
70         _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
71                                                  current_speed_kt,
72                                                  dt * RESPONSIVENESS));
73     }
74 }
75
76 // end of airspeed_indicator.cxx