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/offset-deg", true);
24 _heading_in_node = fgGetNode("/orientation/heading-deg", true);
25 _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
27 fgGetNode("/instrumentation/heading-indicator/indicated-heading-deg",
29 _last_heading_deg = (_heading_in_node->getDoubleValue() +
30 _offset_node->getDoubleValue());
34 HeadingIndicator::bind ()
36 fgTie("/instrumentation/heading-indicator/serviceable",
37 &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
38 fgTie("/instrumentation/heading-indicator/spin",
39 &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
43 HeadingIndicator::unbind ()
45 fgUntie("/instrumentation/heading-indicator/serviceable");
46 fgUntie("/instrumentation/heading-indicator/spin");
50 HeadingIndicator::update (double dt)
52 // Get the spin from the gyro
53 _gyro.set_power_norm(_suction_node->getDoubleValue()/5.0);
55 double spin = _gyro.get_spin_norm();
57 // Next, calculate time-based precession
58 double offset = _offset_node->getDoubleValue();
59 offset -= dt * (0.25 / 60.0); // 360deg/day
64 _offset_node->setDoubleValue(offset);
66 // TODO: movement-induced error
68 // Next, calculate the indicated heading,
69 // introducing errors.
70 double factor = 0.01 / (spin * spin * spin * spin * spin * spin);
71 double heading = _heading_in_node->getDoubleValue();
73 // Now, we have to get the current
74 // heading and the last heading into
76 while ((heading - _last_heading_deg) > 180)
77 _last_heading_deg += 360;
78 while ((heading - _last_heading_deg) < -180)
79 _last_heading_deg -= 360;
81 heading = fgGetLowPass(_last_heading_deg, heading, dt/factor);
82 _last_heading_deg = heading;
90 _heading_out_node->setDoubleValue(heading);
93 // end of heading_indicator.cxx