]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGJSBBase.h
Sync. w. JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / FGJSBBase.h
index 8ec8e828bee9eb744f1b9892c47e41d1d7588ae3..c4d0542460c2b4637dd6b7fcd255fe2ebe75b550 100644 (file)
@@ -41,6 +41,7 @@ INCLUDES
 #include <float.h>
 #include <queue>
 #include <string>
+#include <sstream>
 #include <cmath>
 
 using std::fabs;
@@ -102,6 +103,27 @@ public:
     double dVal;
   };
 
+  /// First order, (low pass / lag) filter
+  class Filter {
+    double prev_in;
+    double prev_out;
+    double ca;
+    double cb;
+    public: Filter(void) {}
+    public: Filter(double coeff, double dt) {
+      prev_in = prev_out = 0.0;
+      double denom = 2.0 + coeff*dt;
+      ca = coeff*dt/denom;
+      cb = (2.0 - coeff*dt)/denom;
+    }
+    public: double execute(double in) {
+      double out = (in + prev_in)*ca + prev_out*cb;
+      prev_in = in;
+      prev_out = out;
+      return out;
+    }
+  };
+
   ///@name JSBSim console output highlighting terms.
   //@{
   /// highlights text
@@ -303,6 +325,15 @@ protected:
   static const string needed_cfg_version;
   static const string JSBSim_version;
 
+  static string CreateIndexedPropertyName(string Property, int index)
+  {
+    std::stringstream str;
+    str << index;
+    string tmp;
+    str >> tmp;
+    return Property + "[" + tmp + "]";
+  }
+
 public:
 /// Moments L, M, N
 enum {eL     = 1, eM,     eN    };