1
0
Fork 0

Added support for <condition> elements under <enable> elements.

The old <prop> and <value> elements are still supported but ignored, if a <condition> element exists.
This commit is contained in:
torsten 2009-02-28 16:16:13 +00:00 committed by Tim Moore
parent f3b750fbc9
commit 3f0e9b0161
2 changed files with 42 additions and 25 deletions

View file

@ -40,6 +40,12 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
static SGCondition * getCondition( SGPropertyNode * node )
{
const SGPropertyNode* conditionNode = node->getChild("condition");
return conditionNode ? sgReadCondition(node, conditionNode) : NULL;
}
FGPIDController::FGPIDController( SGPropertyNode *node ): FGPIDController::FGPIDController( SGPropertyNode *node ):
debug( false ), debug( false ),
y_n( 0.0 ), y_n( 0.0 ),
@ -73,17 +79,20 @@ FGPIDController::FGPIDController( SGPropertyNode *node ):
} else if ( cname == "debug" ) { } else if ( cname == "debug" ) {
debug = child->getBoolValue(); debug = child->getBoolValue();
} else if ( cname == "enable" ) { } else if ( cname == "enable" ) {
// cout << "parsing enable" << endl; _condition = getCondition( child );
SGPropertyNode *prop = child->getChild( "prop" ); if( _condition == NULL ) {
if ( prop != NULL ) { // cout << "parsing enable" << endl;
// cout << "prop = " << prop->getStringValue() << endl; SGPropertyNode *prop = child->getChild( "prop" );
enable_prop = fgGetNode( prop->getStringValue(), true ); if ( prop != NULL ) {
} else { // cout << "prop = " << prop->getStringValue() << endl;
// cout << "no prop child" << endl; enable_prop = fgGetNode( prop->getStringValue(), true );
} } else {
SGPropertyNode *val = child->getChild( "value" ); // cout << "no prop child" << endl;
if ( val != NULL ) { }
enable_value = val->getStringValue(); SGPropertyNode *val = child->getChild( "value" );
if ( val != NULL ) {
enable_value = val->getStringValue();
}
} }
SGPropertyNode *pass = child->getChild( "honor-passive" ); SGPropertyNode *pass = child->getChild( "honor-passive" );
if ( pass != NULL ) { if ( pass != NULL ) {
@ -359,7 +368,8 @@ void FGPIDController::update( double dt ) {
Ts = elapsedTime; Ts = elapsedTime;
elapsedTime = 0.0; elapsedTime = 0.0;
if (enable_prop != NULL && enable_prop->getStringValue() == enable_value) { if (( _condition && _condition->test() ) ||
(enable_prop != NULL && enable_prop->getStringValue() == enable_value)) {
if ( !enabled ) { if ( !enabled ) {
// first time being enabled, seed u_n with current // first time being enabled, seed u_n with current
// property tree value // property tree value
@ -507,17 +517,20 @@ FGPISimpleController::FGPISimpleController( SGPropertyNode *node ):
} else if ( cname == "debug" ) { } else if ( cname == "debug" ) {
debug = child->getBoolValue(); debug = child->getBoolValue();
} else if ( cname == "enable" ) { } else if ( cname == "enable" ) {
// cout << "parsing enable" << endl; _condition = getCondition( child );
SGPropertyNode *prop = child->getChild( "prop" ); if( _condition == NULL ) {
if ( prop != NULL ) { // cout << "parsing enable" << endl;
// cout << "prop = " << prop->getStringValue() << endl; SGPropertyNode *prop = child->getChild( "prop" );
enable_prop = fgGetNode( prop->getStringValue(), true ); if ( prop != NULL ) {
} else { // cout << "prop = " << prop->getStringValue() << endl;
// cout << "no prop child" << endl; enable_prop = fgGetNode( prop->getStringValue(), true );
} } else {
SGPropertyNode *val = child->getChild( "value" ); // cout << "no prop child" << endl;
if ( val != NULL ) { }
enable_value = val->getStringValue(); SGPropertyNode *val = child->getChild( "value" );
if ( val != NULL ) {
enable_value = val->getStringValue();
}
} }
} else if ( cname == "input" ) { } else if ( cname == "input" ) {
SGPropertyNode *prop = child->getChild( "prop" ); SGPropertyNode *prop = child->getChild( "prop" );
@ -642,7 +655,8 @@ void FGPISimpleController::update( double dt ) {
if (umax_prop != NULL)u_max = umax_prop->getDoubleValue(); if (umax_prop != NULL)u_max = umax_prop->getDoubleValue();
if (Kp_prop != NULL)Kp = Kp_prop->getDoubleValue(); if (Kp_prop != NULL)Kp = Kp_prop->getDoubleValue();
if (enable_prop != NULL && enable_prop->getStringValue() == enable_value) { if (( _condition && _condition->test() ) ||
(enable_prop != NULL && enable_prop->getStringValue() == enable_value)) {
if ( !enabled ) { if ( !enabled ) {
// we have just been enabled, zero out int_sum // we have just been enabled, zero out int_sum
int_sum = 0.0; int_sum = 0.0;

View file

@ -44,6 +44,7 @@ using std::deque;
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/props/condition.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -68,6 +69,7 @@ protected:
SGPropertyNode_ptr r_n_prop; SGPropertyNode_ptr r_n_prop;
double r_n_value; double r_n_value;
vector <SGPropertyNode_ptr> output_list; vector <SGPropertyNode_ptr> output_list;
SGSharedPtr<const SGCondition> _condition;
public: public:
@ -79,7 +81,8 @@ public:
enabled( false ), enabled( false ),
input_prop( NULL ), input_prop( NULL ),
r_n_prop( NULL ), r_n_prop( NULL ),
r_n_value( 0.0 ) r_n_value( 0.0 ),
_condition( NULL )
{ } { }
virtual ~FGXMLAutoComponent() {} virtual ~FGXMLAutoComponent() {}