]> git.mxchange.org Git - flightgear.git/commitdiff
Roy Ovesen:
authorcurt <curt>
Mon, 4 Feb 2008 20:01:20 +0000 (20:01 +0000)
committercurt <curt>
Mon, 4 Feb 2008 20:01:20 +0000 (20:01 +0000)
Please find attatched a new version of xmlauto.cxx.

Remove the call to build() in reinit(). This prevents build() from being
called twice when Reload Autopilot is selected from the Debug menu.

I've also added the ability to define an enabled property for the filters.
It's used like the PID controllers. If there is no enabled tag then the
filter defaults to enabled so that nothing should get broken by this change.

This ability can be used to create a filter between the output of a PID
controller and the property that it controls (a control surface). By putting
a noise spike filter between the output of a controller and the control
surface that it controls, we can simulate the limited movement rate that is
inherent in autopilot servos.

src/Autopilot/xmlauto.cxx

index 9ddcaf32b426885e1d4463b0669b4717f23a8b3f..8ab25c9b82e0d5bcecd760f162848bf3c94f3d5d 100644 (file)
@@ -640,6 +640,19 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node)
             name = cval;
         } else if ( cname == "debug" ) {
             debug = child->getBoolValue();
+        } else if ( cname == "enable" ) {
+            SGPropertyNode *prop = child->getChild( "prop" );
+            if ( prop != NULL ) {
+                enable_prop = fgGetNode( prop->getStringValue(), true );
+            }
+            SGPropertyNode *val = child->getChild( "value" );
+            if ( val != NULL ) {
+                enable_value = val->getStringValue();
+            }
+            SGPropertyNode *pass = child->getChild( "honor-passive" );
+            if ( pass != NULL ) {
+                honor_passive = pass->getBoolValue();
+            }
         } else if ( cname == "type" ) {
             if ( cval == "exponential" ) {
                 filterType = exponential;
@@ -670,10 +683,23 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node)
 
 void FGDigitalFilter::update(double dt)
 {
-    if ( input_prop != NULL ) {
+    if ( input_prop != NULL && 
+         enable_prop != NULL && 
+         enable_prop->getStringValue() == enable_value) {
+        input.push_front(input_prop->getDoubleValue());
+        input.resize(samples + 1, 0.0);
+        if ( !enabled ) {
+            // first time being enabled, initialize output to the
+            // value of the output property to avoid bumping.
+            output.push_front(output_list[0]->getDoubleValue());
+            output.resize(1);
+        }
+
+        enabled = true;
+    } else if (enable_prop == NULL &&
+               input_prop != NULL) {
         input.push_front(input_prop->getDoubleValue());
         input.resize(samples + 1, 0.0);
-        // no sense if there isn't an input :-)
         enabled = true;
     } else {
         enabled = false;
@@ -798,7 +824,6 @@ void FGXMLAutopilot::init() {
 void FGXMLAutopilot::reinit() {
     components.clear();
     init();
-    build();
 }