FlightGear next
static.cxx
Go to the documentation of this file.
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/math/SGMisc.hxx>
19#include <simgear/math/SGLimits.hxx>
20#include <simgear/math/SGMathFwd.hxx>
21#include <simgear/sg_inlines.h>
22
23
24StaticSystem::StaticSystem ( SGPropertyNode *node )
25 :
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))
31{
32}
33
37
38void
40{
41 std::string branch = "/systems/" + _name;
42
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
51
52 reinit();
53}
54
55void
57{
58 // start with settled static pressure
59 _pressure_out_node->setDoubleValue(_pressure_in_node->getDoubleValue());
60}
61
62void
66
67void
71
72void
74{
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
78
79 double beta;
80 double alpha;
81 double mach;
82 double trat = _tau ? dt/_tau : SGLimitsd::max();
83
84 double proj_factor = 0;
85 double pt;
86 double qc_part;
87
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);
91 }
92
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) );
97 }
98
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;
104 }
105
106 _pressure_out_node->setDoubleValue(
107 _tau > .0 ? fgGetLowPass(p, p_new, trat) : p_new
108 ); //setting new pressure in static system
109
110 }
111}
112
113
114// Register the subsystem.
115#if 0
116SGSubsystemMgr::Registrant<StaticSystem> registrantStaticSystem(
117 SGSubsystemMgr::GENERAL,
118 {{"vacuum", SGSubsystemMgr::Dependency::HARD}});
119#endif
120
121// end of static.cxx
#define p(x)
virtual ~StaticSystem()
Definition static.cxx:34
void unbind() override
Definition static.cxx:68
void init() override
Definition static.cxx:39
void update(double dt) override
Definition static.cxx:73
void bind() override
Definition static.cxx:63
StaticSystem(SGPropertyNode *node)
Definition static.cxx:24
void reinit() override
Definition static.cxx:56
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27
double fgGetLowPass(double current, double target, double timeratio)
Move a value towards a target.
Definition util.cxx:46