1 // static.cxx - the static air system.
2 // Written by David Megginson, started 2002.
4 // Last modified by Eric van den Berg, 09 Nov 2013
5 // This file is in the Public Domain and comes with no warranty.
15 #include <Main/fg_props.hxx>
16 #include <Main/util.hxx>
17 #include <simgear/constants.h>
18 #include <simgear/math/SGMisc.hxx>
19 #include <simgear/math/SGLimits.hxx>
20 #include <simgear/math/SGMathFwd.hxx>
21 #include <simgear/sg_inlines.h>
24 StaticSystem::StaticSystem ( SGPropertyNode *node )
26 _name(node->getStringValue("name", "static")),
27 _num(node->getIntValue("number", 0)),
28 _tau(SGMiscd::max(.0,node->getDoubleValue("tau", 1))),
29 _error_factor(node->getDoubleValue("error-factor", 0)),
30 _type(node->getIntValue("type", 0))
34 StaticSystem::~StaticSystem ()
41 std::string branch = "/systems/" + _name;
43 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
44 _serviceable_node = node->getChild("serviceable", 0, true);
45 _pressure_in_node = fgGetNode("/environment/pressure-inhg", true);
46 _pressure_out_node = node->getChild("pressure-inhg", 0, true);
47 _beta_node = fgGetNode("/orientation/side-slip-deg", true);
48 _alpha_node = fgGetNode("/orientation/alpha-deg", true);
49 _mach_node = fgGetNode("/velocities/mach", true);
50 SG_CLAMP_RANGE(_error_factor,0.0,1.0); // making sure the error_factor is between 0 and 1
56 StaticSystem::reinit ()
58 // start with settled static pressure
59 _pressure_out_node->setDoubleValue(_pressure_in_node->getDoubleValue());
68 StaticSystem::unbind ()
73 StaticSystem::update (double dt)
75 if (_serviceable_node->getBoolValue()) {
76 double p_new = _pressure_in_node->getDoubleValue(); //current static pressure around aircraft
77 double p = _pressure_out_node->getDoubleValue(); //last pressure in aircraft static system
82 double trat = _tau ? dt/_tau : SGLimitsd::max();
84 double proj_factor = 0;
88 if (_type == 1) { // type 1 = static pressure dependent on side-slip only: static port on the fuselage
89 beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
90 proj_factor = sin(beta);
93 if (_type == 2) { // type 2 = static pressure dependent on aoa and side-slip: static port on the pitot tube
94 alpha = _alpha_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
95 beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
96 proj_factor = sqrt( 1.0 - cos(beta)*cos(beta) * cos(alpha)*cos(alpha) );
99 if ( (_type ==1) || (_type == 2) ) {
100 mach = _mach_node->getDoubleValue();
101 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)
102 qc_part = (pt - p_new) * _error_factor ; //part of impact pressure to be added to static pressure (due to sideslip)
103 p_new = p_new + qc_part;
106 _pressure_out_node->setDoubleValue(
107 _tau > .0 ? fgGetLowPass(p, p_new, trat) : p_new
108 ); //setting new pressure in static system