]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/heading_indicator_fg.cxx
Restore GPS compatibility with 2.10
[flightgear.git] / src / Instrumentation / heading_indicator_fg.cxx
index e35df2d63d3dd754495d9be8685d1ecca18492ac..32332a3e1a648a257cabee0e140e8eaef96909e3 100644 (file)
@@ -5,15 +5,23 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <simgear/compiler.h>
 #include <iostream>
 #include <string>
 #include <sstream>
 
-#include "heading_indicator_fg.hxx"
+#include <simgear/math/SGMath.hxx>
+
 #include <Main/fg_props.hxx>
-#include <Main/util.hxx>                           
+#include <Main/util.hxx>
+
+#include "heading_indicator_fg.hxx"
 
+using std::string;
 
 HeadingIndicatorFG::HeadingIndicatorFG ( SGPropertyNode *node )
     :
@@ -52,16 +60,30 @@ HeadingIndicatorFG::init ()
     string branch;
     branch = "/instrumentation/" + name;
     
-       _heading_in_node = fgGetNode("/orientation/heading-deg", true);
+    _heading_in_node = fgGetNode("/orientation/heading-deg", true);
+
     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
-    _offset_node = node->getChild("offset-deg", 0, true);
+    if( NULL == (_offset_node = node->getChild("offset-deg", 0, false)) ) {
+      _offset_node = node->getChild("offset-deg", 0, true);
+      _offset_node->setDoubleValue( -fgGetDouble("/environment/magnetic-variation-deg") );
+    }
     _serviceable_node = node->getChild("serviceable", 0, true);
-       _error_node = node->getChild("heading-bug-error-deg", 0, true);
-       _nav1_error_node = node->getChild("nav1-course-error-deg", 0, true);
+    _error_node = node->getChild("heading-bug-error-deg", 0, true);
+    _nav1_error_node = node->getChild("nav1-course-error-deg", 0, true);
     _heading_out_node = node->getChild("indicated-heading-deg", 0, true);
+    _off_node         = node->getChild("off-flag", 0, true);
+
+    _electrical_node = fgGetNode("/systems/electrical/outputs/DG", true);
+
+    reinit();
+}
+
+void
+HeadingIndicatorFG::reinit ()
+{
     _last_heading_deg = (_heading_in_node->getDoubleValue() +
                          _offset_node->getDoubleValue());
-       _electrical_node = fgGetNode("/systems/electrical/outputs/DG", true);
+    _gyro.reinit();
 }
 
 void
@@ -76,7 +98,6 @@ HeadingIndicatorFG::bind ()
           &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
     fgTie((branch + "/spin").c_str(),
           &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
-       
 }
 
 void
@@ -96,13 +117,18 @@ HeadingIndicatorFG::update (double dt)
 {
                                 // Get the spin from the gyro
         _gyro.set_power_norm(_electrical_node->getDoubleValue());
-
        _gyro.update(dt);
     double spin = _gyro.get_spin_norm();
 
+    if ( _electrical_node->getDoubleValue() > 0 && spin >= 0.25) {
+        _off_node->setBoolValue(false);
+    } else {
+        _off_node->setBoolValue(true);
+        return;
+    }
+
                                 // No time-based precession    for a flux gate compass
                                    // We just use offset to get the magvar
-
        double offset = _offset_node->getDoubleValue();
           
                                 // TODO: movement-induced error
@@ -115,25 +141,26 @@ HeadingIndicatorFG::update (double dt)
                                 // Now, we have to get the current
                                 // heading and the last heading into
                                 // the same range.
-    while ((heading - _last_heading_deg) > 180)
+    if ((heading - _last_heading_deg) > 180)
         _last_heading_deg += 360;
-    while ((heading - _last_heading_deg) < -180)
+    if ((heading - _last_heading_deg) < -180)
         _last_heading_deg -= 360;
 
     heading = fgGetLowPass(_last_heading_deg, heading, dt * factor);
     _last_heading_deg = heading;
 
        heading += offset;
-    while (heading < 0)
+
+    if (heading < 0)
         heading += 360;
-    while (heading > 360)
+    if (heading > 360)
         heading -= 360;
 
     _heading_out_node->setDoubleValue(heading);
 
                                     // calculate the difference between the indicated heading
                                     // and the selected heading for use with an autopilot
-       static SGPropertyNode *bnode
+       SGPropertyNode *bnode
         = fgGetNode( "/autopilot/settings/heading-bug-deg", false );
        double diff = 0;
        if ( bnode ){