From: ThorstenB Date: Sun, 7 Oct 2012 18:47:50 +0000 (+0200) Subject: Improve gyro heading indicator failure simulation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ccb890447ae2f950b8032649ca8b8190bdafaf90;p=flightgear.git Improve gyro heading indicator failure simulation Error/offset induced by precession and yaw also depend on spin (no spin => no additional error/offset). Error/offset induced by changing a/c orientation while gyro spin is low (<<1) should apply to the "offset" (instead of "error") property. --- diff --git a/src/Instrumentation/heading_indicator_dg.cxx b/src/Instrumentation/heading_indicator_dg.cxx index efca5713b..8966c0f3d 100644 --- a/src/Instrumentation/heading_indicator_dg.cxx +++ b/src/Instrumentation/heading_indicator_dg.cxx @@ -47,10 +47,6 @@ HeadingIndicatorDG::HeadingIndicatorDG ( SGPropertyNode *node ) : } } -HeadingIndicatorDG::HeadingIndicatorDG () -{ -} - HeadingIndicatorDG::~HeadingIndicatorDG () { } @@ -113,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(); } @@ -126,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 @@ -141,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 = POW6(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); diff --git a/src/Instrumentation/heading_indicator_dg.hxx b/src/Instrumentation/heading_indicator_dg.hxx index d4f2fb759..5efa505f7 100644 --- a/src/Instrumentation/heading_indicator_dg.hxx +++ b/src/Instrumentation/heading_indicator_dg.hxx @@ -48,7 +48,7 @@ public: private: Gyro _gyro; - double _last_heading_deg; + double _last_heading_deg, _last_indicated_heading_dg; std::string name; int num;