#ifndef _XMLAUTO_HXX
#define _XMLAUTO_HXX 1
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <simgear/compiler.h>
#include <string>
#include <vector>
#include <deque>
-using std::string;
-using std::vector;
-using std::deque;
-
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/props/condition.hxx>
-#include <Main/fg_props.hxx>
+typedef SGSharedPtr<class FGXMLAutoInput> FGXMLAutoInput_ptr;
+typedef SGSharedPtr<class FGPeriodicalValue> FGPeriodicalValue_ptr;
+class FGPeriodicalValue : public SGReferenced {
+private:
+ FGXMLAutoInput_ptr minPeriod; // The minimum value of the period
+ FGXMLAutoInput_ptr maxPeriod; // The maximum value of the period
+public:
+ FGPeriodicalValue( SGPropertyNode_ptr node );
+ double normalize( double value );
+};
class FGXMLAutoInput : public SGReferenced {
private:
double value; // The value as a constant or initializer for the property
bool abs; // return absolute value
SGPropertyNode_ptr property; // The name of the property containing the value
- SGSharedPtr<FGXMLAutoInput> offset; // A fixed offset, defaults to zero
- SGSharedPtr<FGXMLAutoInput> scale; // A constant scaling factor defaults to one
- SGSharedPtr<FGXMLAutoInput> min; // A minimum clip defaults to no clipping
- SGSharedPtr<FGXMLAutoInput> max; // A maximum clip defaults to no clipping
+ FGXMLAutoInput_ptr offset; // A fixed offset, defaults to zero
+ FGXMLAutoInput_ptr scale; // A constant scaling factor defaults to one
+ FGXMLAutoInput_ptr min; // A minimum clip defaults to no clipping
+ FGXMLAutoInput_ptr max; // A maximum clip defaults to no clipping
+ FGPeriodicalValue_ptr periodical; //
SGSharedPtr<const SGCondition> _condition;
public:
- FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 ) :
- property(NULL),
- value(0.0),
- abs(false),
- offset(NULL),
- scale(NULL),
- min(NULL),
- max(NULL),
- _condition(NULL) {
- parse( node, value, offset, scale );
- }
-
+ FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 );
+
void parse( SGPropertyNode_ptr, double value = 0.0, double offset = 0.0, double scale = 1.0 );
/* get the value of this input, apply scale and offset and clipping */
};
-class FGXMLAutoInputList : public vector<SGSharedPtr<FGXMLAutoInput> > {
+class FGXMLAutoInputList : public std::vector<FGXMLAutoInput_ptr> {
public:
- FGXMLAutoInput * get_active() {
+ FGXMLAutoInput_ptr get_active() {
for (iterator it = begin(); it != end(); ++it) {
if( (*it)->is_enabled() )
return *it;
}
double get_value( double def = 0.0 ) {
- FGXMLAutoInput * input = get_active();
+ FGXMLAutoInput_ptr input = get_active();
return input == NULL ? def : input->get_value();
}
class FGXMLAutoComponent : public SGReferenced {
private:
- vector <SGPropertyNode_ptr> output_list;
+ std::vector <SGPropertyNode_ptr> output_list;
SGSharedPtr<const SGCondition> _condition;
SGPropertyNode_ptr enable_prop;
- string * enable_value;
+ std::string * enable_value;
SGPropertyNode_ptr passive_mode;
bool honor_passive;
- string name;
+ std::string name;
/* Feed back output property to input property if
this filter is disabled. This is for multi-stage
void do_feedback_if_disabled();
protected:
+ FGXMLAutoComponent();
+
+ /*
+ * Parse a component specification read from a property-list.
+ * Calls the hook methods below to allow derived classes to
+ * specialise parsing bevaiour.
+ */
+ void parseNode(SGPropertyNode* aNode);
+
+ /**
+ * Helper to parse the config section
+ */
+ void parseConfig(SGPropertyNode* aConfig);
+
+ /*
+ * Over-rideable hook method to allow derived classes to refine top-level
+ * node parsing. Return true if the node was handled, false otherwise.
+ */
+ virtual bool parseNodeHook(const std::string& aName, SGPropertyNode* aNode);
+
+ /**
+ * Over-rideable hook method to allow derived classes to refine config
+ * node parsing. Return true if the node was handled, false otherwise.
+ */
+ virtual bool parseConfigHook(const std::string& aName, SGPropertyNode* aNode);
FGXMLAutoInputList valueInput;
FGXMLAutoInputList referenceInput;
FGXMLAutoInputList uminInput;
FGXMLAutoInputList umaxInput;
+ FGPeriodicalValue_ptr periodical;
// debug flag
bool debug;
bool enabled;
}
public:
-
- FGXMLAutoComponent( SGPropertyNode *node);
+
virtual ~FGXMLAutoComponent();
virtual void update (double dt)=0;
- inline const string& get_name() { return name; }
+ inline const std::string& get_name() { return name; }
double clamp( double value );
// helpful for things like flight directors which position
// their vbars from the autopilot computations.
if ( honor_passive && passive_mode->getBoolValue() ) return;
- for( vector <SGPropertyNode_ptr>::iterator it = output_list.begin(); it != output_list.end(); ++it)
+ for( std::vector <SGPropertyNode_ptr>::iterator it = output_list.begin(); it != output_list.end(); ++it)
(*it)->setDoubleValue( clamp( value ) );
}
bool isPropertyEnabled();
};
+typedef SGSharedPtr<FGXMLAutoComponent> FGXMLAutoComponent_ptr;
+
/**
* Roy Ovesen's PID controller
double desiredTs; // desired sampling interval (sec)
double elapsedTime; // elapsed time (sec)
-
+
+protected:
+ bool parseConfigHook(const std::string& aName, SGPropertyNode* aNode);
public:
FGXMLAutoInputList Ki;
double int_sum;
+protected:
+ bool parseConfigHook(const std::string& aName, SGPropertyNode* aNode);
public:
private:
double last_value;
+ double average;
FGXMLAutoInputList seconds;
FGXMLAutoInputList filter_gain;
+protected:
+ bool parseNodeHook(const std::string& aName, SGPropertyNode* aNode);
+
public:
FGPredictor( SGPropertyNode *node );
~FGPredictor() {}
FGXMLAutoInputList gainInput; //
FGXMLAutoInputList TfInput; // Filter time [s]
- deque <double> output;
- deque <double> input;
+ std::deque <double> output;
+ std::deque <double> input;
enum filterTypes { exponential, doubleExponential, movingAverage,
- noiseSpike, gain, reciprocal, none };
+ noiseSpike, gain, reciprocal, differential, none };
filterTypes filterType;
+protected:
+ bool parseNodeHook(const std::string& aName, SGPropertyNode* aNode);
+
public:
FGDigitalFilter(SGPropertyNode *node);
~FGDigitalFilter() {}
*
*/
+class FGXMLAutopilotGroup : public SGSubsystemGroup
+{
+public:
+ FGXMLAutopilotGroup();
+ void init();
+ void reinit();
+ void update( double dt );
+private:
+ std::vector<std::string> _autopilotNames;
+
+ double average;
+ double v_last;
+ double last_static_pressure;
+
+ SGPropertyNode_ptr vel;
+ SGPropertyNode_ptr lookahead5;
+ SGPropertyNode_ptr lookahead10;
+ SGPropertyNode_ptr bug;
+ SGPropertyNode_ptr mag_hdg;
+ SGPropertyNode_ptr bug_error;
+ SGPropertyNode_ptr fdm_bug_error;
+ SGPropertyNode_ptr target_true;
+ SGPropertyNode_ptr true_hdg;
+ SGPropertyNode_ptr true_error;
+ SGPropertyNode_ptr target_nav1;
+ SGPropertyNode_ptr true_nav1;
+ SGPropertyNode_ptr true_track_nav1;
+ SGPropertyNode_ptr nav1_course_error;
+ SGPropertyNode_ptr nav1_selected_course;
+ SGPropertyNode_ptr vs_fps;
+ SGPropertyNode_ptr vs_fpm;
+ SGPropertyNode_ptr static_pressure;
+ SGPropertyNode_ptr pressure_rate;
+ SGPropertyNode_ptr track;
+};
+
class FGXMLAutopilot : public SGSubsystem
{
void unbind();
void update( double dt );
- bool build();
+ bool build( SGPropertyNode_ptr );
protected:
-
- typedef vector<SGSharedPtr<FGXMLAutoComponent> > comp_list;
+ typedef std::vector<FGXMLAutoComponent_ptr> comp_list;
private:
-
bool serviceable;
- SGPropertyNode_ptr config_props;
comp_list components;
+
};