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