2002-09-27 18:27:58 +00:00
|
|
|
// static.cxx - the static air system.
|
|
|
|
// Written by David Megginson, started 2002.
|
|
|
|
//
|
2013-11-16 22:15:11 +00:00
|
|
|
// Last modified by Eric van den Berg, 09 Nov 2013
|
2002-09-27 18:27:58 +00:00
|
|
|
// This file is in the Public Domain and comes with no warranty.
|
|
|
|
|
2011-11-14 07:38:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 18:27:58 +00:00
|
|
|
#include "static.hxx"
|
2011-10-17 16:41:59 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2002-09-27 18:27:58 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2002-09-27 22:04:21 +00:00
|
|
|
#include <Main/util.hxx>
|
2013-11-16 22:15:11 +00:00
|
|
|
#include <simgear/constants.h>
|
2014-09-10 19:07:57 +00:00
|
|
|
#include <simgear/math/SGMisc.hxx>
|
|
|
|
#include <simgear/math/SGLimits.hxx>
|
|
|
|
#include <simgear/math/SGMathFwd.hxx>
|
2013-11-16 22:15:11 +00:00
|
|
|
#include <simgear/sg_inlines.h>
|
2002-09-27 18:27:58 +00:00
|
|
|
|
|
|
|
|
2004-10-16 12:37:39 +00:00
|
|
|
StaticSystem::StaticSystem ( SGPropertyNode *node )
|
|
|
|
:
|
2006-12-06 22:11:43 +00:00
|
|
|
_name(node->getStringValue("name", "static")),
|
2007-03-31 09:36:19 +00:00
|
|
|
_num(node->getIntValue("number", 0)),
|
2014-09-10 19:07:57 +00:00
|
|
|
_tau(SGMiscd::max(.0,node->getDoubleValue("tau", 1))),
|
2013-11-16 22:15:11 +00:00
|
|
|
_error_factor(node->getDoubleValue("error-factor", 0)),
|
|
|
|
_type(node->getIntValue("type", 0))
|
2002-09-27 18:27:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StaticSystem::~StaticSystem ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticSystem::init ()
|
|
|
|
{
|
2011-10-17 16:41:59 +00:00
|
|
|
std::string branch = "/systems/" + _name;
|
2004-10-16 12:37:39 +00:00
|
|
|
|
2006-12-06 22:11:43 +00:00
|
|
|
SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
|
2004-10-16 12:37:39 +00:00
|
|
|
_serviceable_node = node->getChild("serviceable", 0, true);
|
2002-09-27 18:27:58 +00:00
|
|
|
_pressure_in_node = fgGetNode("/environment/pressure-inhg", true);
|
2004-10-16 12:37:39 +00:00
|
|
|
_pressure_out_node = node->getChild("pressure-inhg", 0, true);
|
2013-11-16 22:15:11 +00:00
|
|
|
_beta_node = fgGetNode("/orientation/side-slip-deg", true);
|
|
|
|
_alpha_node = fgGetNode("/orientation/alpha-deg", true);
|
|
|
|
_mach_node = fgGetNode("/velocities/mach", true);
|
|
|
|
SG_CLAMP_RANGE(_error_factor,0.0,1.0); // making sure the error_factor is between 0 and 1
|
2012-09-16 22:12:29 +00:00
|
|
|
|
|
|
|
reinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticSystem::reinit ()
|
|
|
|
{
|
|
|
|
// start with settled static pressure
|
|
|
|
_pressure_out_node->setDoubleValue(_pressure_in_node->getDoubleValue());
|
2002-09-27 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticSystem::bind ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticSystem::unbind ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StaticSystem::update (double dt)
|
|
|
|
{
|
|
|
|
if (_serviceable_node->getBoolValue()) {
|
2013-11-16 22:15:11 +00:00
|
|
|
double p_new = _pressure_in_node->getDoubleValue(); //current static pressure around aircraft
|
|
|
|
double p = _pressure_out_node->getDoubleValue(); //last pressure in aircraft static system
|
|
|
|
|
|
|
|
double beta;
|
|
|
|
double alpha;
|
|
|
|
double mach;
|
2014-09-10 19:07:57 +00:00
|
|
|
double trat = _tau ? dt/_tau : SGLimitsd::max();
|
2013-11-16 22:15:11 +00:00
|
|
|
|
|
|
|
double proj_factor = 0;
|
|
|
|
double pt;
|
|
|
|
double qc_part;
|
|
|
|
|
|
|
|
if (_type == 1) { // type 1 = static pressure dependent on side-slip only: static port on the fuselage
|
|
|
|
beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
|
|
|
|
proj_factor = sin(beta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_type == 2) { // type 2 = static pressure dependent on aoa and side-slip: static port on the pitot tube
|
|
|
|
alpha = _alpha_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
|
|
|
|
beta = _beta_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
|
|
|
|
proj_factor = sqrt( 1.0 - cos(beta)*cos(beta) * cos(alpha)*cos(alpha) );
|
|
|
|
}
|
|
|
|
|
2013-11-17 16:26:56 +00:00
|
|
|
if ( (_type ==1) || (_type == 2) ) {
|
2013-11-16 22:15:11 +00:00
|
|
|
mach = _mach_node->getDoubleValue();
|
|
|
|
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)
|
|
|
|
qc_part = (pt - p_new) * _error_factor ; //part of impact pressure to be added to static pressure (due to sideslip)
|
|
|
|
p_new = p_new + qc_part;
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:07:57 +00:00
|
|
|
_pressure_out_node->setDoubleValue(
|
|
|
|
_tau > .0 ? fgGetLowPass(p, p_new, trat) : p_new
|
|
|
|
); //setting new pressure in static system
|
2013-11-16 22:15:11 +00:00
|
|
|
|
2002-09-27 18:27:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of static.cxx
|