add <initialize-to> to components
The tag <initialize-to> can be used to control the value of the output when the component is first enabled. This controls initialization of the output property and the current value for internal computation Valid values are <initialize-to>input</initialize-to> set the output-property to the input value <initialize-to>output</initialize-to> set the output-property to the output value <initialize-to>none</initialize-to> ignore input and output value
This commit is contained in:
parent
545969054c
commit
c56aaa8771
2 changed files with 39 additions and 3 deletions
|
@ -303,7 +303,8 @@ bool ExponentialFilterImplementation::configure( const std::string & nodeName, S
|
||||||
/* --------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
DigitalFilter::DigitalFilter() :
|
DigitalFilter::DigitalFilter() :
|
||||||
AnalogComponent()
|
AnalogComponent(),
|
||||||
|
_initializeTo(INITIALIZE_INPUT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,6 +336,20 @@ bool DigitalFilter::configure(const string& nodeName, SGPropertyNode_ptr configN
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( nodeName == "initialize-to" ) {
|
||||||
|
string s( configNode->getStringValue() );
|
||||||
|
if( s == "input" ) {
|
||||||
|
_initializeTo = INITIALIZE_INPUT;
|
||||||
|
} else if( s == "output" ) {
|
||||||
|
_initializeTo = INITIALIZE_OUTPUT;
|
||||||
|
} else if( s == "none" ) {
|
||||||
|
_initializeTo = INITIALIZE_NONE;
|
||||||
|
} else {
|
||||||
|
SG_LOG( SG_AUTOPILOT, SG_WARN, "unhandled initialize-to value '" << s << "' ignored" );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
SG_LOG( SG_AUTOPILOT, SG_BULK, "DigitalFilter::configure(" << nodeName << ") [unhandled]" << endl );
|
SG_LOG( SG_AUTOPILOT, SG_BULK, "DigitalFilter::configure(" << nodeName << ") [unhandled]" << endl );
|
||||||
return false; // not handled by us, let the base class try
|
return false; // not handled by us, let the base class try
|
||||||
}
|
}
|
||||||
|
@ -344,8 +359,22 @@ void DigitalFilter::update( bool firstTime, double dt)
|
||||||
if( _implementation == NULL ) return;
|
if( _implementation == NULL ) return;
|
||||||
|
|
||||||
if( firstTime ) {
|
if( firstTime ) {
|
||||||
|
switch( _initializeTo ) {
|
||||||
|
|
||||||
|
case INITIALIZE_INPUT:
|
||||||
SG_LOG(SG_AUTOPILOT,SG_DEBUG, "First time initialization of " << get_name() << " to " << _valueInput.get_value() );
|
SG_LOG(SG_AUTOPILOT,SG_DEBUG, "First time initialization of " << get_name() << " to " << _valueInput.get_value() );
|
||||||
_implementation->initialize( _valueInput.get_value() );
|
_implementation->initialize( _valueInput.get_value() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INITIALIZE_OUTPUT:
|
||||||
|
SG_LOG(SG_AUTOPILOT,SG_DEBUG, "First time initialization of " << get_name() << " to " << get_output_value() );
|
||||||
|
_implementation->initialize( get_output_value() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SG_LOG(SG_AUTOPILOT,SG_DEBUG, "First time initialization of " << get_name() << " to (uninitialized)" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double input = _valueInput.get_value() - _referenceInput.get_value();
|
double input = _valueInput.get_value() - _referenceInput.get_value();
|
||||||
|
|
|
@ -53,6 +53,12 @@ class DigitalFilter : public AnalogComponent
|
||||||
private:
|
private:
|
||||||
SGSharedPtr<DigitalFilterImplementation> _implementation;
|
SGSharedPtr<DigitalFilterImplementation> _implementation;
|
||||||
|
|
||||||
|
enum InitializeTo {
|
||||||
|
INITIALIZE_OUTPUT,
|
||||||
|
INITIALIZE_INPUT,
|
||||||
|
INITIALIZE_NONE
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode);
|
bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode);
|
||||||
void update( bool firstTime, double dt);
|
void update( bool firstTime, double dt);
|
||||||
|
@ -61,6 +67,7 @@ protected:
|
||||||
InputValueList _samples;
|
InputValueList _samples;
|
||||||
InputValueList _rateOfChange;
|
InputValueList _rateOfChange;
|
||||||
InputValueList _gain;
|
InputValueList _gain;
|
||||||
|
InitializeTo _initializeTo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DigitalFilter();
|
DigitalFilter();
|
||||||
|
|
Loading…
Reference in a new issue