1 // heading_indicator.cxx - a vacuum-powered heading indicator.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
6 #include "heading_indicator.hxx"
7 #include <Main/fg_props.hxx>
8 #include <Main/util.hxx>
11 HeadingIndicator::HeadingIndicator ()
15 HeadingIndicator::~HeadingIndicator ()
20 HeadingIndicator::init ()
23 fgGetNode("/instrumentation/heading-indicator/serviceable", true);
25 fgGetNode("/instrumentation/heading-indicator/offset-deg", true);
26 _heading_in_node = fgGetNode("/orientation/heading-deg", true);
27 _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
29 fgGetNode("/instrumentation/heading-indicator/indicated-heading-deg",
31 _last_heading_deg = (_heading_in_node->getDoubleValue() +
32 _offset_node->getDoubleValue());
36 HeadingIndicator::bind ()
41 HeadingIndicator::unbind ()
46 HeadingIndicator::update (double dt)
48 // First, calculate the bogo-spin from 0 to 1.
49 // All numbers are made up.
51 _spin -= 0.005 * dt; // spin decays every 0.5% every second.
53 // spin increases up to 25% every second
54 // if suction is available and the gauge
56 if (_serviceable_node->getBoolValue()) {
57 double suction = _suction_node->getDoubleValue();
58 double step = 0.25 * (suction / 5.0) * dt;
59 if ((_spin + step) <= (suction / 5.0))
67 // Next, calculate time-based precession
68 double offset = _offset_node->getDoubleValue();
69 offset -= dt * (0.25 / 60.0); // 360deg/day
74 _offset_node->setDoubleValue(offset);
76 // TODO: movement-induced error
78 // Next, calculate the indicated heading,
79 // introducing errors.
80 double factor = 0.01 / (_spin * _spin * _spin * _spin * _spin * _spin);
81 double heading = _heading_in_node->getDoubleValue();
82 heading = fgGetLowPass(_last_heading_deg, heading, dt/factor);
83 _last_heading_deg = heading;
91 _heading_out_node->setDoubleValue(heading);
94 // end of heading_indicator.cxx