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/sg_inlines.h>
21 StaticSystem::StaticSystem ( SGPropertyNode *node )
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))
31 StaticSystem::~StaticSystem ()
38 std::string branch = "/systems/" + _name;
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
53 StaticSystem::reinit ()
55 // start with settled static pressure
56 _pressure_out_node->setDoubleValue(_pressure_in_node->getDoubleValue());
65 StaticSystem::unbind ()
70 StaticSystem::update (double dt)
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
79 double trat = _tau ? dt/_tau : 100;
81 double proj_factor = 0;
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);
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) );
96 if ( (_type ==1) or (_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;
103 _pressure_out_node->setDoubleValue(fgGetLowPass(p, p_new, trat)); //setting new pressure in static system