SGPropertyNode * n;
if( (n = node->getChild("condition")) != NULL ) {
- _condition = sgReadCondition(node, n);
+ _condition = sgReadCondition(fgGetNode("/"), n);
}
if( (n = node->getChild( "scale" )) != NULL ) {
debug = child->getBoolValue();
} else if ( cname == "enable" ) {
if( (prop = child->getChild("condition")) != NULL ) {
- _condition = sgReadCondition(child, prop);
+ _condition = sgReadCondition(fgGetNode("/"), prop);
} else {
if ( (prop = child->getChild( "prop" )) != NULL ) {
enable_prop = fgGetNode( prop->getStringValue(), true );
}
}
+FGXMLAutopilotGroup::FGXMLAutopilotGroup()
+{
+}
-FGXMLAutopilot::FGXMLAutopilot() {
+void FGXMLAutopilotGroup::reinit()
+{
+ for( vector<string>::size_type i = 0; i < _autopilotNames.size(); i++ ) {
+ FGXMLAutopilot * ap = (FGXMLAutopilot*)get_subsystem( _autopilotNames[i] );
+ if( ap == NULL ) continue; // ?
+ remove_subsystem( _autopilotNames[i] );
+ delete ap;
+ }
+ _autopilotNames.clear();
+ init();
}
+void FGXMLAutopilotGroup::init()
+{
+ vector<SGPropertyNode_ptr> autopilotNodes = fgGetNode( "/sim/systems", true )->getChildren("autopilot");
+ if( autopilotNodes.size() == 0 ) {
+ SG_LOG( SG_ALL, SG_WARN, "No autopilot configuration specified for this model!");
+ return;
+ }
-FGXMLAutopilot::~FGXMLAutopilot() {
-}
+ for( vector<SGPropertyNode_ptr>::size_type i = 0; i < autopilotNodes.size(); i++ ) {
+ SGPropertyNode_ptr pathNode = autopilotNodes[i]->getNode( "path" );
+ if( pathNode == NULL ) {
+ SG_LOG( SG_ALL, SG_WARN, "No autopilot configuration file specified for this autopilot!");
+ continue;
+ }
-
-void FGXMLAutopilot::init() {
- config_props = fgGetNode( "/autopilot/new-config", true );
+ string apName;
+ SGPropertyNode_ptr nameNode = autopilotNodes[i]->getNode( "name" );
+ if( nameNode != NULL ) {
+ apName = nameNode->getStringValue();
+ } else {
+ std::ostringstream buf;
+ buf << "unnamed_autopilot_" << i;
+ apName = buf.str();
+ }
- SGPropertyNode *path_n = fgGetNode("/sim/systems/autopilot/path");
+ if( get_subsystem( apName.c_str() ) != NULL ) {
+ SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot configuration name " << apName << " ignored" );
+ continue;
+ }
- if ( path_n ) {
SGPath config( globals->get_fg_root() );
- config.append( path_n->getStringValue() );
+ config.append( pathNode->getStringValue() );
- SG_LOG( SG_ALL, SG_INFO, "Reading autopilot configuration from "
- << config.str() );
+ SG_LOG( SG_ALL, SG_INFO, "Reading autopilot configuration from " << config.str() );
+ // FGXMLAutopilot
+ FGXMLAutopilot * ap = new FGXMLAutopilot;
try {
- readProperties( config.str(), config_props );
+ SGPropertyNode_ptr root = new SGPropertyNode();
+ readProperties( config.str(), root );
- if ( ! build() ) {
- SG_LOG( SG_ALL, SG_ALERT,
- "Detected an internal inconsistency in the autopilot");
- SG_LOG( SG_ALL, SG_ALERT,
- " configuration. See earlier errors for" );
+
+ if ( ! ap->build( root ) ) {
SG_LOG( SG_ALL, SG_ALERT,
- " details.");
- exit(-1);
+ "Detected an internal inconsistency in the autopilot configuration." << endl << " See earlier errors for details." );
+ delete ap;
+ continue;
}
} catch (const sg_exception& e) {
SG_LOG( SG_ALL, SG_ALERT, "Failed to load autopilot configuration: "
<< config.str() << ":" << e.getMessage() );
+ delete ap;
+ continue;
}
- } else {
- SG_LOG( SG_ALL, SG_WARN,
- "No autopilot configuration specified for this model!");
+ SG_LOG( SG_ALL, SG_INFO, "adding autopilot subsystem " << apName );
+ set_subsystem( apName, ap );
+ _autopilotNames.push_back( apName );
}
+
+ SGSubsystemGroup::init();
+}
+
+FGXMLAutopilot::FGXMLAutopilot() {
+}
+
+
+FGXMLAutopilot::~FGXMLAutopilot() {
+}
+
+
+/* read all /sim/systems/autopilot[n]/path properties, try to read the file specified therein
+ * and configure/add the digital filters specified in that file
+ */
+void FGXMLAutopilot::init()
+{
}
void FGXMLAutopilot::unbind() {
}
-bool FGXMLAutopilot::build() {
+bool FGXMLAutopilot::build( SGPropertyNode_ptr config_props ) {
SGPropertyNode *node;
int i;
node = config_props->getChild(i);
string name = node->getName();
// cout << name << endl;
+ SG_LOG( SG_ALL, SG_INFO, "adding autopilot component " << name );
if ( name == "pid-controller" ) {
components.push_back( new FGPIDController( node ) );
} else if ( name == "pi-simple-controller" ) {