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/spin", true);
27 fgGetNode("/instrumentation/heading-indicator/offset-deg", true);
28 _heading_in_node = fgGetNode("/orientation/heading-deg", true);
29 _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
31 fgGetNode("/instrumentation/heading-indicator/indicated-heading-deg",
33 _last_heading_deg = (_heading_in_node->getDoubleValue() +
34 _offset_node->getDoubleValue());
38 HeadingIndicator::bind ()
43 HeadingIndicator::unbind ()
48 HeadingIndicator::update (double dt)
50 // First, calculate the bogo-spin from 0 to 1.
51 // All numbers are made up.
53 double spin = _spin_node->getDoubleValue();
54 spin -= 0.005 * dt; // spin decays every 0.5% every second.
56 // spin increases up to 25% every second
57 // if suction is available and the gauge
59 if (_serviceable_node->getBoolValue()) {
60 double suction = _suction_node->getDoubleValue();
61 double step = 0.25 * (suction / 5.0) * dt;
62 if ((spin + step) <= (suction / 5.0))
69 _spin_node->setDoubleValue(spin);
71 // Next, calculate time-based precession
72 double offset = _offset_node->getDoubleValue();
73 offset -= dt * (0.25 / 60.0); // 360deg/day
78 _offset_node->setDoubleValue(offset);
80 // TODO: movement-induced error
82 // Next, calculate the indicated heading,
83 // introducing errors.
84 double factor = 0.01 / (spin * spin * spin * spin * spin * spin);
85 double heading = _heading_in_node->getDoubleValue();
87 // Now, we have to get the current
88 // heading and the last heading into
90 while ((heading - _last_heading_deg) > 180)
91 _last_heading_deg += 360;
92 while ((heading - _last_heading_deg) < -180)
93 _last_heading_deg -= 360;
95 heading = fgGetLowPass(_last_heading_deg, heading, dt/factor);
96 _last_heading_deg = heading;
101 while (heading > 360)
104 _heading_out_node->setDoubleValue(heading);
107 // end of heading_indicator.cxx