]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/digitalfilter.cxx
Fix shared library build for metar executable
[flightgear.git] / src / Autopilot / digitalfilter.cxx
index 57bca13c86269977665dd5a0b8eee03309bbb7c7..6f83b01e1f6ea48d2b134f1748a572c1033445e2 100644 (file)
 #include "functor.hxx"
 #include <deque>
 
+using std::map;
+using std::string;
+using std::endl;
+using std::cout;
+
 namespace FGXMLAutopilot {
 
 /* --------------------------------------------------------------------------------- */
@@ -136,7 +141,7 @@ bool GainFilterImplementation::configure( const std::string & nodeName, SGProper
 
 double ReciprocalFilterImplementation::compute(  double dt, double input )
 {
-  if( input >= -SGLimitsd::min() || input <= SGLimitsd::min() )
+  if( input >= -SGLimitsd::min() && input <= SGLimitsd::min() )
     return SGLimitsd::max();
 
   return _gainInput.get_value() / input;
@@ -265,9 +270,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 +