X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fheading_indicator_dg.cxx;h=0c5fdf879c9217543f43cfd90ee6a61fc8611629;hb=68c71d5787f2a0309e35c3e05939950113618cb7;hp=52fe89834e6dd27d2a68ff32939251f785d60235;hpb=002cada172fb80fffe351758870e921d8945b5d5;p=flightgear.git diff --git a/src/Instrumentation/heading_indicator_dg.cxx b/src/Instrumentation/heading_indicator_dg.cxx index 52fe89834..0c5fdf879 100644 --- a/src/Instrumentation/heading_indicator_dg.cxx +++ b/src/Instrumentation/heading_indicator_dg.cxx @@ -22,6 +22,8 @@ #include "heading_indicator_dg.hxx" +/** Macro calculating x^6 (faster than super-slow math/pow). */ +#define POW6(x) (x*x*x*x*x*x) HeadingIndicatorDG::HeadingIndicatorDG ( SGPropertyNode *node ) : name("heading-indicator-dg"), @@ -45,10 +47,6 @@ HeadingIndicatorDG::HeadingIndicatorDG ( SGPropertyNode *node ) : } } -HeadingIndicatorDG::HeadingIndicatorDG () -{ -} - HeadingIndicatorDG::~HeadingIndicatorDG () { } @@ -111,8 +109,8 @@ HeadingIndicatorDG::reinit (void) _error_node->setDoubleValue(0.0); _offset_node->setDoubleValue(0.0); - _last_heading_deg = (_heading_in_node->getDoubleValue() + - _offset_node->getDoubleValue() + _align_node->getDoubleValue()); + _last_heading_deg = _heading_in_node->getDoubleValue(); + _last_indicated_heading_dg = _last_heading_deg; _gyro.reinit(); } @@ -124,12 +122,33 @@ HeadingIndicatorDG::update (double dt) _gyro.set_power_norm(_electrical_node->getDoubleValue()); _gyro.update(dt); - double spin = _gyro.get_spin_norm(); - // Next, calculate time-based precession + // read inputs + double spin = _gyro.get_spin_norm(); + double heading = _heading_in_node->getDoubleValue(); double offset = _offset_node->getDoubleValue(); - offset -= dt * (0.25 / 60.0); // 360deg/day - offset = SGMiscd::normalizePeriodic(-360.0,360.0,offset); + + // calculate scaling factor + double factor = POW6(spin); + + // calculate time-based precession (scaled by spin factor, since + // there is no precession when the gyro is stuck). + offset -= dt * (0.25 / 60.0) * factor; // 360deg/day + + // indication should get more and more stuck at low gyro spins + if (spin < 0.9) + { + // when gyro spin is low, then any heading change results in + // increasing the offset + double diff = SGMiscd::normalizePeriodic(-180.0, 180.0, _last_heading_deg - heading); + // scaled by 1-factor, so indication is fully stuck at spin==0 (offset compensates + // any heading change) + offset += diff * (1.0-factor); + } + _last_heading_deg = heading; + + // normalize offset + offset = SGMiscd::normalizePeriodic(-180.0,180.0,offset); _offset_node->setDoubleValue(offset); // No magvar - set the alignment manually @@ -139,36 +158,24 @@ HeadingIndicatorDG::update (double dt) double yaw_rate = _yaw_rate_node->getDoubleValue(); double error = _error_node->getDoubleValue(); double g = _g_node->getDoubleValue(); - if ( fabs ( yaw_rate ) > 5 ) { - error += 0.033 * -yaw_rate * dt ; + error += 0.033 * -yaw_rate * dt * factor; } if ( g > 1.5 || g < -0.5){ - error += 0.033 * g * dt; - } - - // Next, calculate the indicated heading, - // introducing errors. - double factor = spin * spin * spin * spin * spin * spin; - double heading = _heading_in_node->getDoubleValue(); - if (spin < 0.9) - { - // when gyro spin is low, then any heading change results in - // increasing the error (spin=0 => indicator is stuck) - error += (_last_heading_deg - heading)*(1-factor); + error += 0.033 * g * dt * factor; } _error_node->setDoubleValue(error); // Now, we have to get the current // heading and the last heading into // the same range. - while ((heading - _last_heading_deg) > 180) - _last_heading_deg += 360; - while ((heading - _last_heading_deg) < -180) - _last_heading_deg -= 360; - heading = fgGetLowPass(_last_heading_deg, heading, dt * factor * 100); - _last_heading_deg = heading; + while ((heading - _last_indicated_heading_dg) > 180) + _last_indicated_heading_dg += 360; + while ((heading - _last_indicated_heading_dg) < -180) + _last_indicated_heading_dg -= 360; + heading = fgGetLowPass(_last_indicated_heading_dg, heading, dt * 100); + _last_indicated_heading_dg = heading; heading += offset + align + error; heading = SGMiscd::normalizePeriodic(0.0,360.0,heading); @@ -177,7 +184,7 @@ HeadingIndicatorDG::update (double dt) // 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 ); if ( bnode ) { double diff = bnode->getDoubleValue() - heading;