]> git.mxchange.org Git - flightgear.git/blob - src/Systems/static.cxx
TACAN: fix distance calculations and some other problems.
[flightgear.git] / src / Systems / static.cxx
1 // static.cxx - the static air system.
2 // Written by David Megginson, started 2002.
3 //
4 // Last modified by Eric van den Berg, 09 Nov 2013
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 "static.hxx"
12
13 #include <string>
14
15 #include <Main/fg_props.hxx>
16 #include <Main/util.hxx>
17 #include <simgear/constants.h>
18 #include <simgear/sg_inlines.h>
19
20
21 StaticSystem::StaticSystem ( SGPropertyNode *node )
22     :
23     _name(node->getStringValue("name", "static")),
24     _num(node->getIntValue("number", 0)),
25     _tau(node->getDoubleValue("tau", 1)),
26     _error_factor(node->getDoubleValue("error-factor", 0)),
27     _type(node->getIntValue("type", 0))
28 {
29 }
30
31 StaticSystem::~StaticSystem ()
32 {
33 }
34
35 void
36 StaticSystem::init ()
37 {
38     std::string branch = "/systems/" + _name;
39
40     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
41     _serviceable_node = node->getChild("serviceable", 0, true);
42     _pressure_in_node = fgGetNode("/environment/pressure-inhg", true);
43     _pressure_out_node = node->getChild("pressure-inhg", 0, true);
44     _beta_node = fgGetNode("/orientation/side-slip-deg", true);
45     _alpha_node = fgGetNode("/orientation/alpha-deg", true);
46     _mach_node = fgGetNode("/velocities/mach", true);
47     SG_CLAMP_RANGE(_error_factor,0.0,1.0);     // making sure the error_factor is between 0 and 1
48
49     reinit();
50 }
51
52 void
53 StaticSystem::reinit ()
54 {
55     // start with settled static pressure
56     _pressure_out_node->setDoubleValue(_pressure_in_node->getDoubleValue());
57 }
58
59 void
60 StaticSystem::bind ()
61 {
62 }
63
64 void
65 StaticSystem::unbind ()
66 {
67 }
68
69 void
70 StaticSystem::update (double dt)
71 {
72     if (_serviceable_node->getBoolValue()) {
73         double p_new = _pressure_in_node->getDoubleValue();                         //current static pressure around aircraft
74         double p = _pressure_out_node->getDoubleValue();                            //last pressure in aircraft static system
75
76         double beta;
77         double alpha;
78         double mach;
79         double trat = _tau ? dt/_tau : 100;
80
81         double proj_factor = 0;
82         double pt;
83         double qc_part;
84
85         if (_type == 1) {                                       // type 1 = static pressure dependent on side-slip only: static port on the fuselage
86             beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
87             proj_factor = sin(beta);
88         }
89
90         if (_type == 2) {                                       // type 2 = static pressure dependent on aoa and side-slip: static port on the pitot tube
91             alpha = _alpha_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
92             beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
93             proj_factor = sqrt( 1.0 - cos(beta)*cos(beta) * cos(alpha)*cos(alpha) );
94         }
95
96         if ( (_type ==1) || (_type == 2) ) {
97             mach = _mach_node->getDoubleValue();
98             pt = p_new * pow(1 + 0.2 * mach*mach*proj_factor*proj_factor, 3.5 );    //total pressure perpendicular to static port (=perpendicular to body x-axis)
99             qc_part = (pt - p_new) * _error_factor ;                            //part of impact pressure to be added to static pressure (due to sideslip)
100             p_new = p_new + qc_part;
101         }
102
103         _pressure_out_node->setDoubleValue(fgGetLowPass(p, p_new, trat));           //setting new pressure in static system
104
105     }
106 }
107
108 // end of static.cxx