]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/digitalfilter.cxx
Fix bug 191, uninitialised HUD color.
[flightgear.git] / src / Autopilot / digitalfilter.cxx
index 57bca13c86269977665dd5a0b8eee03309bbb7c7..45087a79a29352b2eabea4b056cc231f3d9ec724 100644 (file)
@@ -265,9 +265,14 @@ void ExponentialFilterImplementation::initialize( double output )
 double ExponentialFilterImplementation::compute(  double dt, double input )
 {
   input = GainFilterImplementation::compute( dt, input );
+  double tf = _TfInput.get_value();
 
   double output_0;
-  double alpha = 1 / ((_TfInput.get_value()/dt) + 1);
+
+  // avoid negative filter times 
+  // and div by zero if -tf == dt
+
+  double alpha = tf > 0.0 ? 1 / ((tf/dt) + 1) : 1.0;
  
   if(_isSecondOrder) {
     output_0 = alpha * alpha * input +