]> git.mxchange.org Git - flightgear.git/blob - src/Systems/pitot.cxx
warning--
[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 "pitot.hxx"
7 #include <Main/fg_props.hxx>
8 #include <Main/util.hxx>
9
10
11
12 PitotSystem::PitotSystem ( SGPropertyNode *node )
13     :
14     num(0),
15     name("pitot")
16 {
17     int i;
18     for ( i = 0; i < node->nChildren(); ++i ) {
19         SGPropertyNode *child = node->getChild(i);
20         string cname = child->getName();
21         string cval = child->getStringValue();
22         if ( cname == "name" ) {
23             name = cval;
24         } else if ( cname == "number" ) {
25             num = child->getIntValue();
26         } else {
27             SG_LOG( SG_SYSTEMS, SG_WARN, "Error in systems config logic" );
28             if ( name.length() ) {
29                 SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name );
30             }
31         }
32     }
33 }
34
35 PitotSystem::PitotSystem ( int i )
36 {
37     num = i;
38     name = "pitot";
39 }
40
41 PitotSystem::~PitotSystem ()
42 {
43 }
44
45 void
46 PitotSystem::init ()
47 {
48     string branch;
49     branch = "/systems/" + name;
50
51     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
52     _serviceable_node = node->getChild("serviceable", 0, true);
53     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
54     _density_node = fgGetNode("/environment/density-slugft3", true);
55     _velocity_node = fgGetNode("/velocities/airspeed-kt", true);
56     _total_pressure_node = node->getChild("total-pressure-inhg", 0, true);
57 }
58
59 void
60 PitotSystem::bind ()
61 {
62 }
63
64 void
65 PitotSystem::unbind ()
66 {
67 }
68
69 #ifndef INHGTOPSF
70 # define INHGTOPSF (2116.217/29.9212)
71 #endif
72
73 #ifndef PSFTOINHG
74 # define PSFTOINHG (1/INHGTOPSF)
75 #endif
76
77 #ifndef KTTOFPS
78 # define KTTOFPS 1.68781
79 #endif
80
81
82 void
83 PitotSystem::update (double dt)
84 {
85     if (_serviceable_node->getBoolValue()) {
86                                 // The pitot tube sees the forward
87                                 // velocity in the body axis.
88         double p = _pressure_node->getDoubleValue() * INHGTOPSF;
89         double r = _density_node->getDoubleValue();
90         double v = _velocity_node->getDoubleValue() * KTTOFPS;
91         double q = 0.5 * r * v * v; // dynamic
92         _total_pressure_node->setDoubleValue((p + q) * PSFTOINHG);
93     }
94 }
95
96 // end of pitot.cxx