]> git.mxchange.org Git - flightgear.git/blob - src/Systems/pitot.cxx
Use some more logging class variety.
[flightgear.git] / src / Systems / pitot.cxx
1 // pitot.cxx - the pitot air system.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <simgear/constants.h>
7
8 #include <Main/fg_props.hxx>
9 #include <Main/util.hxx>
10
11 #include "pitot.hxx"
12
13
14 PitotSystem::PitotSystem ( SGPropertyNode *node )
15     :
16     _name(node->getStringValue("name", "pitot")),
17     _num(node->getIntValue("number", 0))
18 {
19 }
20
21 PitotSystem::~PitotSystem ()
22 {
23 }
24
25 void
26 PitotSystem::init ()
27 {
28     string branch;
29     branch = "/systems/" + _name;
30
31     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
32     _serviceable_node = node->getChild("serviceable", 0, true);
33     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
34     _density_node = fgGetNode("/environment/density-slugft3", true);
35     _velocity_node = fgGetNode("/velocities/airspeed-kt", true);
36     _slip_angle = fgGetNode("/orientation/side-slip-rad", true);
37     _total_pressure_node = node->getChild("total-pressure-inhg", 0, true);
38 }
39
40 void
41 PitotSystem::bind ()
42 {
43 }
44
45 void
46 PitotSystem::unbind ()
47 {
48 }
49
50 #ifndef INHGTOPSF
51 # define INHGTOPSF (2116.217/29.9212)
52 #endif
53
54 #ifndef PSFTOINHG
55 # define PSFTOINHG (1/INHGTOPSF)
56 #endif
57
58
59 void
60 PitotSystem::update (double dt)
61 {
62     if (_serviceable_node->getBoolValue()) {
63                                 // The pitot tube sees the forward
64                                 // velocity in the body axis.
65         double p = _pressure_node->getDoubleValue() * INHGTOPSF;
66         double r = _density_node->getDoubleValue();
67         double v = _velocity_node->getDoubleValue() * SG_KT_TO_FPS;
68         v *= cos(_slip_angle->getDoubleValue());
69         if (v < 0.0)
70             v = 0.0;
71         double q = 0.5 * r * v * v; // dynamic
72         _total_pressure_node->setDoubleValue((p + q) * PSFTOINHG);
73     }
74 }
75
76 // end of pitot.cxx