]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/xmlauto.cxx
Merge branch 'ehofman/sound'
[flightgear.git] / src / Autopilot / xmlauto.cxx
index e8f7ab0eee4ecebb8386dab348527e345349bc00..6d542855787ee720bc80f7a92336bdac8d13e37a 100644 (file)
 using std::cout;
 using std::endl;
 
-/* 
-parse element with
-  <node>
-    <value>1</value>
-    <prop>/some/property</prop>
-  </node>
-or
-  <node>123</node>
-or
-  <node>/some/property</node>
-*/
+FGXMLAutoInput::FGXMLAutoInput( SGPropertyNode_ptr node, double value, double offset, double scale) :
+  value(0.0),
+  abs(false),
+  property(NULL),
+  offset(NULL),
+  scale(NULL),
+  min(NULL),
+  max(NULL),
+  _condition(NULL) 
+{
+  parse( node, value, offset, scale );
+}
+
 
 void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffset, double aScale )
 {
-    delete property;
-    property = NULL;
     value = aValue;
-    offset = aOffset;
-    scale = aScale;
+    property = NULL; 
+    offset = NULL;
+    scale = NULL;
+    min = NULL;
+    max = NULL;
 
     if( node == NULL )
         return;
 
     SGPropertyNode * n;
 
-    if( (n = node->getChild( "scale" )) != NULL )
-        scale = n->getDoubleValue();
+    if( (n = node->getChild("condition")) != NULL ) {
+        _condition = sgReadCondition(node, n);
+    }
 
-    if( (n = node->getChild( "offset" )) != NULL )
-        offset = n->getDoubleValue();
+    if( (n = node->getChild( "scale" )) != NULL ) {
+        scale = new FGXMLAutoInput( n, aScale );
+    }
+
+    if( (n = node->getChild( "offset" )) != NULL ) {
+        offset = new FGXMLAutoInput( n, aOffset );
+    }
+
+    if( (n = node->getChild( "max" )) != NULL ) {
+        max = new FGXMLAutoInput( n );
+    }
+
+    if( (n = node->getChild( "min" )) != NULL ) {
+        min = new FGXMLAutoInput( n );
+    }
+
+    if( (n = node->getChild( "abs" )) != NULL ) {
+      abs = n->getBoolValue();
+    }
 
     SGPropertyNode *valueNode = node->getChild( "value" );
     if ( valueNode != NULL ) {
@@ -87,8 +108,9 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
         if ( valueNode != NULL ) {
             // initialize property with given value 
             // if both <prop> and <value> exist
-            if( scale != 0 )
-              property->setDoubleValue( (value - offset)/scale );
+            double s = get_scale();
+            if( s != 0 )
+              property->setDoubleValue( (value - get_offset())/s );
             else
               property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
         }
@@ -108,91 +130,52 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
     }
 }
 
-FGXMLAutoComponent::FGXMLAutoComponent( SGPropertyNode * node ) :
-      debug(false),
-      name(""),
-      enable_prop( NULL ),
-      passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) ),
-      enable_value( NULL ),
-      honor_passive( false ),
-      enabled( false ),
-      clamp( false ),
-      _condition( NULL )
+void FGXMLAutoInput::set_value( double aValue ) 
 {
-    int i;
-    SGPropertyNode *prop; 
-
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "name" ) {
-            name = cval;
-
-        } else if ( cname == "debug" ) {
-            debug = child->getBoolValue();
-
-        } else if ( cname == "enable" ) {
-            if( (prop = child->getChild("condition")) != NULL ) {
-              _condition = sgReadCondition(child, prop);
-            } else {
-               if ( (prop = child->getChild( "prop" )) != NULL ) {
-                   enable_prop = fgGetNode( prop->getStringValue(), true );
-               }
-
-               if ( (prop = child->getChild( "value" )) != NULL ) {
-                   delete enable_value;
-                   enable_value = new string(prop->getStringValue());
-               }
-            }
-            if ( (prop = child->getChild( "honor-passive" )) != NULL ) {
-                honor_passive = prop->getBoolValue();
-            }
-
-        } else if ( cname == "input" ) {
+    double s = get_scale();
+    if( s != 0 )
+        property->setDoubleValue( (aValue - get_offset())/s );
+    else
+        property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
+}
 
-              valueInput.parse( child );
+double FGXMLAutoInput::get_value() 
+{
+    if( property != NULL ) 
+        value = property->getDoubleValue();
 
-        } else if ( cname == "reference" ) {
+    if( scale ) 
+        value *= scale->get_value();
 
-            referenceInput.parse( child );
+    if( offset ) 
+        value += offset->get_value();
 
-        } else if ( cname == "output" ) {
-            // grab all <prop> and <property> childs
-            int found = 0;
-            // backwards compatibility: allow <prop> elements
-            for( int i = 0; (prop = child->getChild("prop", i)) != NULL; i++ ) { 
-                SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
-                output_list.push_back( tmp );
-                found++;
-            }
-            for( int i = 0; (prop = child->getChild("property", i)) != NULL; i++ ) { 
-                SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
-                output_list.push_back( tmp );
-                found++;
-            }
+    if( min ) {
+        double m = min->get_value();
+        if( value < m )
+            value = m;
+    }
 
-            // no <prop> elements, text node of <output> is property name
-            if( found == 0 )
-                output_list.push_back( fgGetNode(child->getStringValue(), true ) );
+    if( max ) {
+        double m = max->get_value();
+        if( value > m )
+            value = m;
+    }
+    
+    return abs ? fabs(value) : value;
+}
 
-        } else if ( cname == "config" ) {
-            if( (prop = child->getChild("u_min")) != NULL ) {
-              uminInput.parse( prop );
-              clamp = true;
-            }
-            if( (prop = child->getChild("u_max")) != NULL ) {
-              umaxInput.parse( prop );
-              clamp = true;
-            }
-        } else if ( cname == "u_min" ) {
-            uminInput.parse( child );
-            clamp = true;
-        } else if ( cname == "u_max" ) {
-            umaxInput.parse( child );
-            clamp = true;
-        } 
-    }   
+FGXMLAutoComponent::FGXMLAutoComponent() :
+      _condition( NULL ),
+      enable_prop( NULL ),
+      enable_value( NULL ),
+      passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) ),
+      honor_passive( false ),
+      name(""),
+      feedback_if_disabled( false ),
+      debug(false),
+      enabled( false )
+{
 }
 
 FGXMLAutoComponent::~FGXMLAutoComponent() 
@@ -200,6 +183,111 @@ FGXMLAutoComponent::~FGXMLAutoComponent()
     delete enable_value;
 }
 
+void FGXMLAutoComponent::parseNode(SGPropertyNode* aNode)
+{
+  SGPropertyNode *prop; 
+  for (int i = 0; i < aNode->nChildren(); ++i ) {
+    SGPropertyNode *child = aNode->getChild(i);
+    string cname(child->getName());
+    
+    if (parseNodeHook(cname, child)) {
+      // derived class handled it, fine
+    } else if ( cname == "name" ) {
+      name = child->getStringValue();
+    } else if ( cname == "feedback-if-disabled" ) {
+      feedback_if_disabled = child->getBoolValue();
+    } else if ( cname == "debug" ) {
+      debug = child->getBoolValue();
+    } else if ( cname == "enable" ) {
+      if( (prop = child->getChild("condition")) != NULL ) {
+        _condition = sgReadCondition(child, prop);
+      } else {
+         if ( (prop = child->getChild( "prop" )) != NULL ) {
+             enable_prop = fgGetNode( prop->getStringValue(), true );
+         }
+
+         if ( (prop = child->getChild( "value" )) != NULL ) {
+             delete enable_value;
+             enable_value = new string(prop->getStringValue());
+         }
+      }
+      if ( (prop = child->getChild( "honor-passive" )) != NULL ) {
+          honor_passive = prop->getBoolValue();
+      }
+    } else if ( cname == "input" ) {
+      valueInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "reference" ) {
+      referenceInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "output" ) {
+      // grab all <prop> and <property> childs
+      int found = 0;
+      // backwards compatibility: allow <prop> elements
+      for( int i = 0; (prop = child->getChild("prop", i)) != NULL; i++ ) { 
+          SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
+          output_list.push_back( tmp );
+          found++;
+      }
+      for( int i = 0; (prop = child->getChild("property", i)) != NULL; i++ ) { 
+          SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
+          output_list.push_back( tmp );
+          found++;
+      }
+
+      // no <prop> elements, text node of <output> is property name
+      if( found == 0 )
+          output_list.push_back( fgGetNode(child->getStringValue(), true ) );
+    } else if ( cname == "config" ) {
+      parseConfig(child);
+    } else if ( cname == "min" ) {
+        uminInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "u_min" ) {
+        uminInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "max" ) {
+        umaxInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "u_max" ) {
+        umaxInput.push_back( new FGXMLAutoInput( child ) );
+    } else {
+      SG_LOG(SG_AUTOPILOT, SG_ALERT, "malformed autopilot definition - unrecognized node:" 
+        << cname << " in section " << name);
+      throw sg_io_exception("XMLAuto: unrecognized component node:" + cname, "Section=" + name);
+    }
+  } // of top-level iteration
+}
+
+void FGXMLAutoComponent::parseConfig(SGPropertyNode* aConfig)
+{
+  for (int i = 0; i < aConfig->nChildren(); ++i ) {
+    SGPropertyNode *child = aConfig->getChild(i);
+    string cname(child->getName());
+    
+    if (parseConfigHook(cname, child)) {
+      // derived class handled it, fine
+    } else if ( cname == "min" ) {
+        uminInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "u_min" ) {
+        uminInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "max" ) {
+        umaxInput.push_back( new FGXMLAutoInput( child ) );
+    } else if ( cname == "u_max" ) {
+        umaxInput.push_back( new FGXMLAutoInput( child ) );
+    } else {
+      SG_LOG(SG_AUTOPILOT, SG_ALERT, "malformed autopilot definition - unrecognized config node:" 
+        << cname << " in section " << name);
+      throw sg_io_exception("XMLAuto: unrecognized config node:" + cname, "Section=" + name);
+    }
+  } // of config iteration
+}
+
+bool FGXMLAutoComponent::parseNodeHook(const string& aName, SGPropertyNode* aNode)
+{
+  return false;
+}
+
+bool FGXMLAutoComponent::parseConfigHook(const string& aName, SGPropertyNode* aNode)
+{
+  return false;
+}
+
 bool FGXMLAutoComponent::isPropertyEnabled()
 {
     if( _condition )
@@ -215,8 +303,29 @@ bool FGXMLAutoComponent::isPropertyEnabled()
     return true;
 }
 
+void FGXMLAutoComponent::do_feedback_if_disabled()
+{
+    if( output_list.size() > 0 ) {    
+        FGXMLAutoInput * input = valueInput.get_active();
+        if( input != NULL )
+            input->set_value( output_list[0]->getDoubleValue() );
+    }
+}
+
+double FGXMLAutoComponent::clamp( double value )
+{
+    // clamp, if either min or max is defined
+    if( uminInput.size() + umaxInput.size() > 0 ) {
+        double d = umaxInput.get_value( 0.0 );
+        if( value > d ) value = d;
+        d = uminInput.get_value( 0.0 );
+        if( value < d ) value = d;
+    }
+    return value;
+}
+
 FGPIDController::FGPIDController( SGPropertyNode *node ):
-    FGXMLAutoComponent( node ),
+    FGXMLAutoComponent(),
     alpha( 0.1 ),
     beta( 1.0 ),
     gamma( 0.0 ),
@@ -227,46 +336,32 @@ FGPIDController::FGPIDController( SGPropertyNode *node ):
     desiredTs( 0.0 ),
     elapsedTime( 0.0 )
 {
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "config" ) {
-            SGPropertyNode *config;
-
-            if ( (config = child->getChild( "Ts" )) != NULL ) {
-                desiredTs = config->getDoubleValue();
-            }
-           
-            Kp.parse( child->getChild( "Kp" ) );
-            Ti.parse( child->getChild( "Ti" ) );
-            Td.parse( child->getChild( "Td" ) );
-
-            config = child->getChild( "beta" );
-            if ( config != NULL ) {
-                beta = config->getDoubleValue();
-            }
-
-            config = child->getChild( "alpha" );
-            if ( config != NULL ) {
-                alpha = config->getDoubleValue();
-            }
-
-            config = child->getChild( "gamma" );
-            if ( config != NULL ) {
-                gamma = config->getDoubleValue();
-            }
-
-        } else {
-            SG_LOG( SG_AUTOPILOT, SG_WARN, "Error in autopilot config logic" );
-            if ( get_name().length() ) {
-                SG_LOG( SG_AUTOPILOT, SG_WARN, "Section = " << get_name() );
-            }
-        }
-    }   
+  parseNode(node);
 }
 
+bool FGPIDController::parseConfigHook(const string& aName, SGPropertyNode* aNode)
+{
+  if (aName == "Ts") {
+    desiredTs = aNode->getDoubleValue();
+  } else if (aName == "Kp") {
+    Kp.push_back( new FGXMLAutoInput(aNode) );
+  } else if (aName == "Ti") {
+    Ti.push_back( new FGXMLAutoInput(aNode) );
+  } else if (aName == "Td") {
+    Td.push_back( new FGXMLAutoInput(aNode) );
+  } else if (aName == "beta") {
+    beta = aNode->getDoubleValue();
+  } else if (aName == "alpha") {
+    alpha = aNode->getDoubleValue();
+  } else if (aName == "gamma") {
+    gamma = aNode->getDoubleValue();
+  } else {
+    // unhandled by us, let the base class try it
+    return false;
+  }
+
+  return true;
+}
 
 /*
  * Roy Vegard Ovesen:
@@ -329,8 +424,8 @@ void FGPIDController::update( double dt ) {
     double u_n = 0.0;       // absolute output
     double Ts;              // sampling interval (sec)
 
-    double u_min = uminInput.getValue();
-    double u_max = umaxInput.getValue();
+    double u_min = uminInput.get_value();
+    double u_max = umaxInput.get_value();
 
     elapsedTime += dt;
     if ( elapsedTime <= desiredTs ) {
@@ -345,20 +440,21 @@ void FGPIDController::update( double dt ) {
         if ( !enabled ) {
             // first time being enabled, seed u_n with current
             // property tree value
-            u_n = getOutputValue();
+            u_n = get_output_value();
             u_n_1 = u_n;
         }
         enabled = true;
     } else {
         enabled = false;
+        do_feedback();
     }
 
     if ( enabled && Ts > 0.0) {
         if ( debug ) cout << "Updating " << get_name()
                           << " Ts " << Ts << endl;
 
-        double y_n = valueInput.getValue();
-        double r_n = referenceInput.getValue();
+        double y_n = valueInput.get_value();
+        double r_n = referenceInput.get_value();
                       
         if ( debug ) cout << "  input = " << y_n << " ref = " << r_n << endl;
 
@@ -375,7 +471,7 @@ void FGPIDController::update( double dt ) {
         ed_n = gamma * r_n - y_n;
         if ( debug ) cout << " ed_n = " << ed_n;
 
-        double td = Td.getValue();
+        double td = Td.get_value();
         if ( td > 0.0 ) {
             // Calculates filter time:
             Tf = alpha * td;
@@ -390,18 +486,18 @@ void FGPIDController::update( double dt ) {
         }
 
         // Calculates the incremental output:
-        double ti = Ti.getValue();
+        double ti = Ti.get_value();
         if ( ti > 0.0 ) {
-            delta_u_n = Kp.getValue() * ( (ep_n - ep_n_1)
+            delta_u_n = Kp.get_value() * ( (ep_n - ep_n_1)
                                + ((Ts/ti) * e_n)
                                + ((td/Ts) * (edf_n - 2*edf_n_1 + edf_n_2)) );
         }
 
         if ( debug ) {
             cout << " delta_u_n = " << delta_u_n << endl;
-            cout << "P:" << Kp.getValue() * (ep_n - ep_n_1)
-                 << " I:" << Kp.getValue() * ((Ts/ti) * e_n)
-                 << " D:" << Kp.getValue() * ((td/Ts) * (edf_n - 2*edf_n_1 + edf_n_2))
+            cout << "P:" << Kp.get_value() * (ep_n - ep_n_1)
+                 << " I:" << Kp.get_value() * ((Ts/ti) * e_n)
+                 << " D:" << Kp.get_value() * ((td/Ts) * (edf_n - 2*edf_n_1 + edf_n_2))
                  << endl;
         }
 
@@ -424,7 +520,7 @@ void FGPIDController::update( double dt ) {
         edf_n_2 = edf_n_1;
         edf_n_1 = edf_n;
 
-        setOutputValue( u_n );
+        set_output_value( u_n );
     } else if ( !enabled ) {
         ep_n  = 0.0;
         edf_n = 0.0;
@@ -438,26 +534,25 @@ void FGPIDController::update( double dt ) {
 
 
 FGPISimpleController::FGPISimpleController( SGPropertyNode *node ):
-    FGXMLAutoComponent( node ),
+    FGXMLAutoComponent(),
     int_sum( 0.0 )
 {
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "config" ) {
-            Kp.parse( child->getChild( "Kp" ) );
-            Ki.parse( child->getChild( "Ki" ) );
-        } else {
-            SG_LOG( SG_AUTOPILOT, SG_WARN, "Error in autopilot config logic" );
-            if ( get_name().length() ) {
-                SG_LOG( SG_AUTOPILOT, SG_WARN, "Section = " << get_name() );
-            }
-        }
-    }   
+  parseNode(node);
 }
 
+bool FGPISimpleController::parseConfigHook(const string& aName, SGPropertyNode* aNode)
+{
+  if (aName == "Kp") {
+    Kp.push_back( new FGXMLAutoInput(aNode) );
+  } else if (aName == "Ki") {
+    Ki.push_back( new FGXMLAutoInput(aNode) );
+  } else {
+    // unhandled by us, let the base class try it
+    return false;
+  }
+
+  return true;
+}
 
 void FGPISimpleController::update( double dt ) {
 
@@ -469,12 +564,13 @@ void FGPISimpleController::update( double dt ) {
         enabled = true;
     } else {
         enabled = false;
+        do_feedback();
     }
 
     if ( enabled ) {
         if ( debug ) cout << "Updating " << get_name() << endl;
-        double y_n = valueInput.getValue();
-        double r_n = referenceInput.getValue();
+        double y_n = valueInput.get_value();
+        double r_n = referenceInput.get_value();
                       
         double error = r_n - y_n;
         if ( debug ) cout << "input = " << y_n
@@ -482,39 +578,39 @@ void FGPISimpleController::update( double dt ) {
                           << " error = " << error
                           << endl;
 
-        double prop_comp = error * Kp.getValue();
-        int_sum += error * Ki.getValue() * dt;
+        double prop_comp = error * Kp.get_value();
+        int_sum += error * Ki.get_value() * dt;
 
 
         if ( debug ) cout << "prop_comp = " << prop_comp
                           << " int_sum = " << int_sum << endl;
 
         double output = prop_comp + int_sum;
-        output = Clamp( output );
-        setOutputValue( output );
+        output = clamp( output );
+        set_output_value( output );
         if ( debug ) cout << "output = " << output << endl;
     }
 }
 
 
 FGPredictor::FGPredictor ( SGPropertyNode *node ):
-    FGXMLAutoComponent( node ),
-    average ( 0.0 ),
-    seconds( 0.0 ),
-    filter_gain( 0.0 ),
-    ivalue( 0.0 )
+    FGXMLAutoComponent(),
+    average(0.0)
 {
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "seconds" ) {
-            seconds = child->getDoubleValue();
-        } else if ( cname == "filter-gain" ) {
-            filter_gain = child->getDoubleValue();
-        }
-    }   
+  parseNode(node);
+}
+
+bool FGPredictor::parseNodeHook(const string& aName, SGPropertyNode* aNode)
+{
+  if (aName == "seconds") {
+    seconds.push_back( new FGXMLAutoInput( aNode, 0 ) );
+  } else if (aName == "filter-gain") {
+    filter_gain.push_back( new FGXMLAutoInput( aNode, 0 ) );
+  } else {
+    return false;
+  }
+  
+  return true;
 }
 
 void FGPredictor::update( double dt ) {
@@ -531,7 +627,7 @@ void FGPredictor::update( double dt ) {
 
     */
 
-    ivalue = valueInput.getValue();
+    double ivalue = valueInput.get_value();
 
     if ( isPropertyEnabled() ) {
         if ( !enabled ) {
@@ -541,22 +637,21 @@ void FGPredictor::update( double dt ) {
         enabled = true;
     } else {
         enabled = false;
+        do_feedback();
     }
 
     if ( enabled ) {
 
         if ( dt > 0.0 ) {
             double current = (ivalue - last_value)/dt; // calculate current error change (per second)
-            if ( dt < 1.0 ) {
-                average = (1.0 - dt) * average + current * dt;
-            } else {
-                average = current;
-            }
+            average = dt < 1.0 ? ((1.0 - dt) * average + current * dt) : current;
 
             // calculate output with filter gain adjustment
-            double output = ivalue + (1.0 - filter_gain) * (average * seconds) + filter_gain * (current * seconds);
-            output = Clamp( output );
-            setOutputValue( output );
+            double output = ivalue + 
+               (1.0 - filter_gain.get_value()) * (average * seconds.get_value()) + 
+                       filter_gain.get_value() * (current * seconds.get_value());
+            output = clamp( output );
+            set_output_value( output );
         }
         last_value = ivalue;
     }
@@ -564,58 +659,69 @@ void FGPredictor::update( double dt ) {
 
 
 FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node):
-    FGXMLAutoComponent( node )
+    FGXMLAutoComponent(),
+    filterType(none)
 {
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "type" ) {
-            if ( cval == "exponential" ) {
-                filterType = exponential;
-            } else if (cval == "double-exponential") {
-                filterType = doubleExponential;
-            } else if (cval == "moving-average") {
-                filterType = movingAverage;
-            } else if (cval == "noise-spike") {
-                filterType = noiseSpike;
-            } else if (cval == "gain") {
-                filterType = gain;
-            } else if (cval == "reciprocal") {
-                filterType = reciprocal;
-            }
-        } else if ( cname == "filter-time" ) {
-            TfInput.parse( child, 1.0 );
-        } else if ( cname == "samples" ) {
-            samplesInput.parse( child, 1 );
-        } else if ( cname == "max-rate-of-change" ) {
-            rateOfChangeInput.parse( child, 1.0 );
-        } else if ( cname == "gain" ) {
-            gainInput.parse( child );
-        }
-    }
+    parseNode(node);
 
     output.resize(2, 0.0);
-    input.resize(samplesInput.getValue() + 1, 0.0);
+    input.resize(samplesInput.get_value() + 1, 0.0);
+}
+
+
+bool FGDigitalFilter::parseNodeHook(const string& aName, SGPropertyNode* aNode)
+{
+  if (aName == "type" ) {
+    string val(aNode->getStringValue());
+    if ( val == "exponential" ) {
+      filterType = exponential;
+    } else if (val == "double-exponential") {
+      filterType = doubleExponential;
+    } else if (val == "moving-average") {
+      filterType = movingAverage;
+    } else if (val == "noise-spike") {
+      filterType = noiseSpike;
+    } else if (val == "gain") {
+      filterType = gain;
+    } else if (val == "reciprocal") {
+      filterType = reciprocal;
+    }
+  } else if (aName == "filter-time" ) {
+    TfInput.push_back( new FGXMLAutoInput( aNode, 1.0 ) );
+    if( filterType == none ) filterType = exponential;
+  } else if (aName == "samples" ) {
+    samplesInput.push_back( new FGXMLAutoInput( aNode, 1 ) );
+    if( filterType == none ) filterType = movingAverage;
+  } else if (aName == "max-rate-of-change" ) {
+    rateOfChangeInput.push_back( new FGXMLAutoInput( aNode, 1 ) );
+    if( filterType == none ) filterType = noiseSpike;
+  } else if (aName == "gain" ) {
+    gainInput.push_back( new FGXMLAutoInput( aNode, 1 ) );
+    if( filterType == none ) filterType = gain;
+  } else {
+    return false; // not handled by us, let the base class try
+  }
+  
+  return true;
 }
 
 void FGDigitalFilter::update(double dt)
 {
     if ( isPropertyEnabled() ) {
 
-        input.push_front(valueInput.getValue());
-        input.resize(samplesInput.getValue() + 1, 0.0);
+        input.push_front(valueInput.get_value());
+        input.resize(samplesInput.get_value() + 1, 0.0);
 
         if ( !enabled ) {
             // first time being enabled, initialize output to the
             // value of the output property to avoid bumping.
-            output.push_front(getOutputValue());
+            output.push_front(get_output_value());
         }
 
         enabled = true;
     } else {
         enabled = false;
+        do_feedback();
     }
 
     if ( enabled && dt > 0.0 ) {
@@ -630,13 +736,13 @@ void FGDigitalFilter::update(double dt)
 
         if (filterType == exponential)
         {
-            double alpha = 1 / ((TfInput.getValue()/dt) + 1);
+            double alpha = 1 / ((TfInput.get_value()/dt) + 1);
             output.push_front(alpha * input[0] + 
                               (1 - alpha) * output[0]);
         } 
         else if (filterType == doubleExponential)
         {
-            double alpha = 1 / ((TfInput.getValue()/dt) + 1);
+            double alpha = 1 / ((TfInput.get_value()/dt) + 1);
             output.push_front(alpha * alpha * input[0] + 
                               2 * (1 - alpha) * output[0] -
                               (1 - alpha) * (1 - alpha) * output[1]);
@@ -644,11 +750,11 @@ void FGDigitalFilter::update(double dt)
         else if (filterType == movingAverage)
         {
             output.push_front(output[0] + 
-                              (input[0] - input.back()) / samplesInput.getValue());
+                              (input[0] - input.back()) / samplesInput.get_value());
         }
         else if (filterType == noiseSpike)
         {
-            double maxChange = rateOfChangeInput.getValue() * dt;
+            double maxChange = rateOfChangeInput.get_value() * dt;
 
             if ((output[0] - input[0]) > maxChange)
             {
@@ -665,17 +771,17 @@ void FGDigitalFilter::update(double dt)
         }
         else if (filterType == gain)
         {
-            output[0] = gainInput.getValue() * input[0];
+            output[0] = gainInput.get_value() * input[0];
         }
         else if (filterType == reciprocal)
         {
             if (input[0] != 0.0) {
-                output[0] = gainInput.getValue() / input[0];
+                output[0] = gainInput.get_value() / input[0];
             }
         }
 
-        output[0] = Clamp(output[0]) ;
-        setOutputValue( output[0] );
+        output[0] = clamp(output[0]) ;
+        set_output_value( output[0] );
 
         output.resize(2);
 
@@ -719,9 +825,9 @@ void FGXMLAutopilot::init() {
                         " details.");
                 exit(-1);
             }        
-        } catch (const sg_exception& exc) {
+        } catch (const sg_exception& e) {
             SG_LOG( SG_ALL, SG_ALERT, "Failed to load autopilot configuration: "
-                    << config.str() );
+                    << config.str() << ":" << e.getMessage() );
         }
 
     } else {