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:
parent
f3b750fbc9
commit
3f0e9b0161
2 changed files with 42 additions and 25 deletions
|
@ -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,6 +79,8 @@ 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" ) {
|
||||||
|
_condition = getCondition( child );
|
||||||
|
if( _condition == NULL ) {
|
||||||
// cout << "parsing enable" << endl;
|
// cout << "parsing enable" << endl;
|
||||||
SGPropertyNode *prop = child->getChild( "prop" );
|
SGPropertyNode *prop = child->getChild( "prop" );
|
||||||
if ( prop != NULL ) {
|
if ( prop != NULL ) {
|
||||||
|
@ -85,6 +93,7 @@ FGPIDController::FGPIDController( SGPropertyNode *node ):
|
||||||
if ( val != NULL ) {
|
if ( val != NULL ) {
|
||||||
enable_value = val->getStringValue();
|
enable_value = val->getStringValue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SGPropertyNode *pass = child->getChild( "honor-passive" );
|
SGPropertyNode *pass = child->getChild( "honor-passive" );
|
||||||
if ( pass != NULL ) {
|
if ( pass != NULL ) {
|
||||||
honor_passive = pass->getBoolValue();
|
honor_passive = pass->getBoolValue();
|
||||||
|
@ -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,6 +517,8 @@ 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" ) {
|
||||||
|
_condition = getCondition( child );
|
||||||
|
if( _condition == NULL ) {
|
||||||
// cout << "parsing enable" << endl;
|
// cout << "parsing enable" << endl;
|
||||||
SGPropertyNode *prop = child->getChild( "prop" );
|
SGPropertyNode *prop = child->getChild( "prop" );
|
||||||
if ( prop != NULL ) {
|
if ( prop != NULL ) {
|
||||||
|
@ -519,6 +531,7 @@ FGPISimpleController::FGPISimpleController( SGPropertyNode *node ):
|
||||||
if ( val != NULL ) {
|
if ( val != NULL ) {
|
||||||
enable_value = val->getStringValue();
|
enable_value = val->getStringValue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if ( cname == "input" ) {
|
} else if ( cname == "input" ) {
|
||||||
SGPropertyNode *prop = child->getChild( "prop" );
|
SGPropertyNode *prop = child->getChild( "prop" );
|
||||||
if ( prop != NULL ) {
|
if ( prop != NULL ) {
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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() {}
|
||||||
|
|
Loading…
Reference in a new issue