2003-02-12 18:35:04 +00:00
|
|
|
// airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
|
2002-09-28 20:48:53 +00:00
|
|
|
// Written by David Megginson, started 2002.
|
|
|
|
//
|
|
|
|
// This file is in the Public Domain and comes with no warranty.
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <simgear/math/interpolater.hxx>
|
|
|
|
|
|
|
|
#include "airspeed_indicator.hxx"
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Main/util.hxx>
|
|
|
|
|
|
|
|
|
2003-02-12 18:35:04 +00:00
|
|
|
// A higher number means more responsive.
|
|
|
|
#define RESPONSIVENESS 50.0
|
|
|
|
|
2004-10-16 12:37:39 +00:00
|
|
|
AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node )
|
|
|
|
:
|
2006-10-26 17:46:05 +00:00
|
|
|
name(node->getStringValue("name", "airspeed-indicator")),
|
|
|
|
num(node->getIntValue("number", 0)),
|
|
|
|
pitot_port(node->getStringValue("pitot-port", "/systems/pitot")),
|
|
|
|
static_port(node->getStringValue("static-port", "/systems/static"))
|
2004-10-16 12:37:39 +00:00
|
|
|
{
|
2002-09-28 20:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AirspeedIndicator::~AirspeedIndicator ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AirspeedIndicator::init ()
|
|
|
|
{
|
2004-10-16 12:37:39 +00:00
|
|
|
string branch;
|
|
|
|
branch = "/instrumentation/" + name;
|
|
|
|
pitot_port += "/total-pressure-inhg";
|
|
|
|
static_port += "/pressure-inhg";
|
|
|
|
|
|
|
|
SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
|
|
|
|
_serviceable_node = node->getChild("serviceable", 0, true);
|
|
|
|
_total_pressure_node = fgGetNode(pitot_port.c_str(), true);
|
|
|
|
_static_pressure_node = fgGetNode(static_port.c_str(), true);
|
2003-03-12 20:28:54 +00:00
|
|
|
_density_node = fgGetNode("/environment/density-slugft3", true);
|
2004-10-16 12:37:39 +00:00
|
|
|
_speed_node = node->getChild("indicated-speed-kt", 0, true);
|
2002-09-28 20:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef FPSTOKTS
|
|
|
|
# define FPSTOKTS 0.592484
|
|
|
|
#endif
|
|
|
|
|
2002-10-10 18:15:22 +00:00
|
|
|
#ifndef INHGTOPSF
|
|
|
|
# define INHGTOPSF (2116.217/29.9212)
|
|
|
|
#endif
|
|
|
|
|
2002-09-28 20:48:53 +00:00
|
|
|
void
|
|
|
|
AirspeedIndicator::update (double dt)
|
|
|
|
{
|
|
|
|
if (_serviceable_node->getBoolValue()) {
|
2003-03-12 20:28:54 +00:00
|
|
|
double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
|
|
|
|
double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
|
|
|
|
double r = _density_node->getDoubleValue();
|
|
|
|
double q = ( pt - p ); // dynamic pressure
|
2002-09-28 20:48:53 +00:00
|
|
|
|
2003-02-16 20:47:40 +00:00
|
|
|
// Now, reverse the equation (normalize dynamic pressure to
|
|
|
|
// avoid "nan" results from sqrt)
|
|
|
|
if ( q < 0 ) { q = 0.0; }
|
2003-03-12 20:28:54 +00:00
|
|
|
double v_fps = sqrt((2 * q) / r);
|
2002-09-28 20:48:53 +00:00
|
|
|
|
2003-02-12 18:35:04 +00:00
|
|
|
// Publish the indicated airspeed
|
|
|
|
double last_speed_kt = _speed_node->getDoubleValue();
|
|
|
|
double current_speed_kt = v_fps * FPSTOKTS;
|
|
|
|
_speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
|
|
|
|
current_speed_kt,
|
|
|
|
dt * RESPONSIVENESS));
|
2002-09-28 20:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of airspeed_indicator.cxx
|