1 // pitot.cxx - the pitot air system.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
6 #include <simgear/constants.h>
8 #include <Main/fg_props.hxx>
9 #include <Main/util.hxx>
14 PitotSystem::PitotSystem ( SGPropertyNode *node )
20 for ( i = 0; i < node->nChildren(); ++i ) {
21 SGPropertyNode *child = node->getChild(i);
22 string cname = child->getName();
23 string cval = child->getStringValue();
24 if ( cname == "name" ) {
26 } else if ( cname == "number" ) {
27 num = child->getIntValue();
29 SG_LOG( SG_SYSTEMS, SG_WARN, "Error in systems config logic" );
30 if ( name.length() ) {
31 SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name );
37 PitotSystem::PitotSystem ( int i )
43 PitotSystem::~PitotSystem ()
51 branch = "/systems/" + name;
53 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
54 _serviceable_node = node->getChild("serviceable", 0, true);
55 _pressure_node = fgGetNode("/environment/pressure-inhg", true);
56 _density_node = fgGetNode("/environment/density-slugft3", true);
57 _velocity_node = fgGetNode("/velocities/airspeed-kt", true);
58 _slip_angle = fgGetNode("/orientation/side-slip-rad", true);
59 _total_pressure_node = node->getChild("total-pressure-inhg", 0, true);
68 PitotSystem::unbind ()
73 # define INHGTOPSF (2116.217/29.9212)
77 # define PSFTOINHG (1/INHGTOPSF)
82 PitotSystem::update (double dt)
84 if (_serviceable_node->getBoolValue()) {
85 // The pitot tube sees the forward
86 // velocity in the body axis.
87 double p = _pressure_node->getDoubleValue() * INHGTOPSF;
88 double r = _density_node->getDoubleValue();
89 double v = _velocity_node->getDoubleValue() * SG_KT_TO_FPS;
90 v *= cos(_slip_angle->getDoubleValue());
93 double q = 0.5 * r * v * v; // dynamic
94 _total_pressure_node->setDoubleValue((p + q) * PSFTOINHG);