From: curt Date: Mon, 4 Feb 2008 20:01:20 +0000 (+0000) Subject: Roy Ovesen: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=15cd4284fba912a7bb37a1aeece6cde5d08916a8;p=flightgear.git Roy Ovesen: 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. --- diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index 9ddcaf32b..8ab25c9b8 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -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(); }