]> git.mxchange.org Git - flightgear.git/blob - src/Systems/pitot.cxx
pitot adapted to /velocities/mach being the mach norm
[flightgear.git] / src / Systems / pitot.cxx
1 // pitot.cxx - the pitot air system.
2 // Written by David Megginson, started 2002.
3 //
4 // Last modified by Eric van den Berg, 24 Nov 2012
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 <simgear/constants.h>
12
13 #include <Main/fg_props.hxx>
14 #include <Main/util.hxx>
15
16 #include "pitot.hxx"
17
18
19 PitotSystem::PitotSystem ( SGPropertyNode *node )
20     :
21     _name(node->getStringValue("name", "pitot")),
22     _num(node->getIntValue("number", 0))
23 {
24 }
25
26 PitotSystem::~PitotSystem ()
27 {
28 }
29
30 void
31 PitotSystem::init ()
32 {
33     string branch;
34     branch = "/systems/" + _name;
35
36     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
37     _serviceable_node = node->getChild("serviceable", 0, true);
38     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
39     _mach_node = fgGetNode("/velocities/mach", true);
40     _alpha_deg_node = fgGetNode("/orientation/alpha-deg", true);
41     _beta_deg_node = fgGetNode("/orientation/side-slip-deg", true);
42     _total_pressure_node = node->getChild("total-pressure-inhg", 0, true);
43     _measured_total_pressure_node = node->getChild("measured-total-pressure-inhg", 0, true);
44 }
45
46 void
47 PitotSystem::bind ()
48 {
49 }
50
51 void
52 PitotSystem::unbind ()
53 {
54 }
55
56 void
57 PitotSystem::update (double dt)
58 {
59     if (_serviceable_node->getBoolValue()) {
60         double p = _pressure_node->getDoubleValue();
61         double mach = _mach_node->getDoubleValue();
62         double alpha = _alpha_deg_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
63         double beta = _beta_deg_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
64         mach = mach * fabs(cos(alpha)) * cos(beta);
65         mach = std::max( mach , 0.0 ); // we want a mach=0 if the airflow comes from behind
66         double p_t = p * pow(1 + 0.2 * mach*mach, 3.5 );    // true total pressure around aircraft
67         _total_pressure_node->setDoubleValue(p_t);
68         double p_t_meas = p_t;
69         if (mach > 1) {    
70           p_t_meas = p * pow( 1.2 * mach*mach, 3.5 ) * pow( 2.8/2.4*mach*mach - 0.4 / 2.4 , -2.5 );    // measured total pressure by pitot tube (Rayleigh formula, at Mach>1, normal shockwave in front of pitot tube)     
71         }
72         _measured_total_pressure_node->setDoubleValue(p_t_meas);
73     }
74 }
75
76 // end of pitot.cxx