]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/xmlauto.hxx
working on the termination of the last hardcoded dialogs in Autopilot/auto_gui.cxx:
[flightgear.git] / src / Autopilot / xmlauto.hxx
index 92735d6a8721448955bd6043f9c02360573f0ec0..d87dc6a65fd7f0b464bada80d151e7570742b378 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started January 2004.
 //
-// Copyright (C) 2004  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 
 #include STL_STRING
 #include <vector>
+#include <deque>
 
 SG_USING_STD(string);
 SG_USING_STD(vector);
+SG_USING_STD(deque);
 
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
@@ -76,9 +78,9 @@ public:
 
     virtual ~FGXMLAutoComponent() {}
 
-    virtual void update (double dt) {}
+    virtual void update (double dt)=0;
     
-    inline string get_name() { return name; }
+    inline const string& get_name() { return name; }
 };
 
 
@@ -96,6 +98,10 @@ private:
     // Input values
     double y_n;                 // measured process value
     double r_n;                 // reference (set point) value
+    double y_scale;             // scale process input from property system
+    double r_scale;             // scale reference input from property system
+    double y_offset;
+    double r_offset;
 
     // Configuration values
     double Kp;                  // proportional gain
@@ -119,6 +125,8 @@ private:
     double edf_n_1;             // edf[n-1] (derivative error)
     double edf_n_2;             // edf[n-2] (derivative error)
     double u_n_1;               // u[n-1]   (output)
+    double desiredTs;            // desired sampling interval (sec)
+    double elapsedTime;          // elapsed time (sec)
     
     
     
@@ -137,19 +145,19 @@ public:
  * A simplistic P [ + I ] PID controller
  */
 
-class FGSimplePIController : public FGXMLAutoComponent {
+class FGPISimpleController : public FGXMLAutoComponent {
 
 private:
 
     // proportional component data
     bool proportional;
-    double factor;
+    double Kp;
     SGPropertyNode *offset_prop;
     double offset_value;
 
     // integral component data
     bool integral;
-    double gain;
+    double Ki;
     double int_sum;
 
     // post functions for output
@@ -161,6 +169,8 @@ private:
     // Input values
     double y_n;                 // measured process value
     double r_n;                 // reference (set point) value
+    double y_scale;             // scale process input from property system
+    double r_scale;             // scale reference input from property system
 
     double u_min;               // Minimum output clamp
     double u_max;               // Maximum output clamp
@@ -168,13 +178,74 @@ private:
     
 public:
 
-    FGSimplePIController( SGPropertyNode *node );
-    ~FGSimplePIController() {}
+    FGPISimpleController( SGPropertyNode *node );
+    ~FGPISimpleController() {}
 
     void update( double dt );
 };
 
 
+/**
+ * Predictor - calculates value in x seconds future.
+ */
+
+class FGPredictor : public FGXMLAutoComponent {
+
+private:
+
+    // proportional component data
+    double last_value;
+    double average;
+    double seconds;
+    double filter_gain;
+
+    // debug flag
+    bool debug;
+
+    // Input values
+    double ivalue;                 // input value
+    
+public:
+
+    FGPredictor( SGPropertyNode *node );
+    ~FGPredictor() {}
+
+    void update( double dt );
+};
+
+
+/**
+ * FGDigitalFilter - a selection of digital filters
+ *
+ * Exponential filter
+ * Double exponential filter
+ * Moving average filter
+ * Noise spike filter
+ *
+ * All these filters are low-pass filters.
+ *
+ */
+
+class FGDigitalFilter : public FGXMLAutoComponent
+{
+private:
+    double Tf;            // Filter time [s]
+    unsigned int samples; // Number of input samples to average
+    double rateOfChange;  // The maximum allowable rate of change [1/s]
+    deque <double> output;
+    deque <double> input;
+    enum filterTypes { exponential, doubleExponential, movingAverage, noiseSpike };
+    filterTypes filterType;
+
+    bool debug;
+
+public:
+    FGDigitalFilter(SGPropertyNode *node);
+    ~FGDigitalFilter() {}
+
+    void update(double dt);
+};
+
 /**
  * Model an autopilot system.
  *