]> git.mxchange.org Git - flightgear.git/blob - src/Systems/pitot.cxx
Boris Koenig:
[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     name("pitot"),
15     num(0)
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_AUTOPILOT, SG_WARN, "Error in systems config logic" );
28             if ( name.length() ) {
29                 SG_LOG( SG_AUTOPILOT, 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     _serviceable_node->setBoolValue(true);
59 }
60
61 void
62 PitotSystem::bind ()
63 {
64 }
65
66 void
67 PitotSystem::unbind ()
68 {
69 }
70
71 #ifndef INHGTOPSF
72 # define INHGTOPSF (2116.217/29.9212)
73 #endif
74
75 #ifndef PSFTOINHG
76 # define PSFTOINHG (1/INHGTOPSF)
77 #endif
78
79 #ifndef KTTOFPS
80 # define KTTOFPS 1.68781
81 #endif
82
83
84 void
85 PitotSystem::update (double dt)
86 {
87     if (_serviceable_node->getBoolValue()) {
88                                 // The pitot tube sees the forward
89                                 // velocity in the body axis.
90         double p = _pressure_node->getDoubleValue() * INHGTOPSF;
91         double r = _density_node->getDoubleValue();
92         double v = _velocity_node->getDoubleValue() * KTTOFPS;
93         double q = 0.5 * r * v * v; // dynamic
94         _total_pressure_node->setDoubleValue((p + q) * PSFTOINHG);
95     }
96 }
97
98 // end of pitot.cxx