]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/flight_control/FGSensor.h
sync with JSB JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGSensor.h
index 4789996b7819374519446600aa7a3daf03b133a4..09b037696fe31cd6e9e0cf5a5d434ed6ddb62552 100755 (executable)
@@ -38,13 +38,13 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGFCSComponent.h"
-#include <input_output/FGXMLElement.h>
+#include <string>
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_SENSOR "$Id$"
+#define ID_SENSOR "$Id: FGSensor.h,v 1.21 2012/01/08 12:39:14 bcoconni Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -53,6 +53,7 @@ FORWARD DECLARATIONS
 namespace JSBSim {
 
 class FGFCS;
+class Element;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DOCUMENTATION
@@ -63,27 +64,29 @@ CLASS DOCUMENTATION
 Syntax:
 
 @code
-<sensor name=\94name\94>
+<sensor name="name">
   <input> property </input>
   <lag> number </lag>
-  <noise variation=\94PERCENT|ABSOLUTE\94> number </noise>
+  <noise [variation="PERCENT|ABSOLUTE"] [distribution="UNIFORM|GAUSSIAN"]> number </noise>
   <quantization name="name">
     <bits> number </bits>
     <min> number </min>
     <max> number </max>
   </quantization>
   <drift_rate> number </drift_rate>
+  <gain> number </gain>
   <bias> number </bias>
+  <delay> number < /delay>
 </sensor>
 @endcode
 
 Example:
 
 @code
-<sensor name=\94aero/sensor/qbar\94>
+<sensor name="aero/sensor/qbar">
   <input> aero/qbar </input>
   <lag> 0.5 </lag>
-  <noise variation=\94PERCENT\94> 2 </noise>
+  <noise variation="PERCENT"> 2 </noise>
   <quantization name="aero/sensor/quantized/qbar">
     <bits> 12 </bits>
     <min> 0 </min>
@@ -96,15 +99,32 @@ Example:
 The only required element in the sensor definition is the input element. In that
 case, no degradation would be modeled, and the output would simply be the input.
 
-For noise, if the type is PERCENT, then the value supplied is understood to be a
-percentage variance. That is, if the number given is 0.05, the the variance is
-understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
-will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
-even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
-time.
+Noise can be Gaussian or uniform, and the noise can be applied as a factor (PERCENT)
+or additively (ABSOLUTE). The noise that can be applied at each frame of the
+simulation execution is calculated as a random factor times a noise value that
+is specified in the config file. When the noise distribution type is Gaussian,
+the random number can be between roughly -3 and +3 for a span of six sigma. When
+the distribution type is UNIFORM, the random value can be between -1.0 and +1.0.
+This random value is multiplied against the specified noise to arrive at a random
+noise value for the frame. If the noise type is PERCENT, then random noise value
+is added to one, and that sum is then multiplied against the input signal for the
+sensor. In this case, the specified noise value in the config file would be
+expected to actually be a percent value, such as 0.05 (for a 5% variance). If the
+noise type is ABSOLUTE, then the random noise value specified in the config file
+is understood to be an absolute value of noise to be added to the input signal
+instead of being added to 1.0 and having that sum be multiplied against the input
+signal as in the PERCENT type. For the ABSOLUTE noise case, the noise number
+specified in the config file could be any number.
+
+If the type is ABSOLUTE, then the noise number times the random number is
+added to the input signal instead of being multiplied against it as with the
+PERCENT type of noise.
+
+The delay element can specify a frame delay. The integer number provided is
+the number of frames to delay the output signal.
 
 @author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.21 $
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -115,25 +135,26 @@ class FGSensor  : public FGFCSComponent
 {
 public:
   FGSensor(FGFCS* fcs, Element* element);
-  ~FGSensor();
+  virtual ~FGSensor();
 
-  inline void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
-  inline void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
-  inline void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
+  void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
+  void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
+  void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
 
-  inline double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
-  inline double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
-  inline double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
-  inline int    GetQuantized(void) const {return quantized;}
+  double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
+  double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
+  double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
+  int    GetQuantized(void) const {return quantized;}
 
-  bool Run (void);
+  virtual bool Run (void);
 
-private:
+protected:
   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
-  double dt;
+  enum eDistributionType {eUniform=0, eGaussian} DistributionType;
   double min, max;
   double span;
   double bias;
+  double gain;
   double drift_rate;
   double drift;
   double noise_variance;
@@ -150,16 +171,19 @@ private:
   bool fail_low;
   bool fail_high;
   bool fail_stuck;
-  string quant_property;
+  std::string quant_property;
 
+  void ProcessSensorSignal(void);
   void Noise(void);
   void Bias(void);
   void Drift(void);
   void Quantize(void);
   void Lag(void);
+  void Gain(void);
 
   void bind(void);
 
+private:
   void Debug(int from);
 };
 }