]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
New version of JSBSim, a big rewrite.
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGSensor.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGSensor.h
4  Author:       Jon Berndt
5  Date started: 9 July 2005
6
7  ------------- Copyright (C) 2005 -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33 #ifndef FGSENSOR_H
34 #define FGSENSOR_H
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCSComponent.h"
41 #include <string>
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_SENSOR "$Id: FGSensor.h,v 1.20 2011/08/18 12:42:17 jberndt Exp $"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 class FGFCS;
56 class Element;
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS DOCUMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 /** Encapsulates a Sensor component for the flight control system.
63
64 Syntax:
65
66 @code
67 <sensor name="name">
68   <input> property </input>
69   <lag> number </lag>
70   <noise [variation="PERCENT|ABSOLUTE"] [distribution="UNIFORM|GAUSSIAN"]> number </noise>
71   <quantization name="name">
72     <bits> number </bits>
73     <min> number </min>
74     <max> number </max>
75   </quantization>
76   <drift_rate> number </drift_rate>
77   <bias> number </bias>
78   <delay> number < /delay>
79 </sensor>
80 @endcode
81
82 Example:
83
84 @code
85 <sensor name="aero/sensor/qbar">
86   <input> aero/qbar </input>
87   <lag> 0.5 </lag>
88   <noise variation="PERCENT"> 2 </noise>
89   <quantization name="aero/sensor/quantized/qbar">
90     <bits> 12 </bits>
91     <min> 0 </min>
92     <max> 400 </max>
93   </quantization>
94   <bias> 0.5 </bias>
95 </sensor>
96 @endcode
97
98 The only required element in the sensor definition is the input element. In that
99 case, no degradation would be modeled, and the output would simply be the input.
100
101 Noise can be Gaussian or uniform, and the noise can be applied as a factor (PERCENT)
102 or additively (ABSOLUTE). The noise that can be applied at each frame of the
103 simulation execution is calculated as a random factor times a noise value that
104 is specified in the config file. When the noise distribution type is Gaussian,
105 the random number can be between roughly -3 and +3 for a span of six sigma. When
106 the distribution type is UNIFORM, the random value can be between -1.0 and +1.0.
107 This random value is multiplied against the specified noise to arrive at a random
108 noise value for the frame. If the noise type is PERCENT, then random noise value
109 is added to one, and that sum is then multiplied against the input signal for the
110 sensor. In this case, the specified noise value in the config file would be
111 expected to actually be a percent value, such as 0.05 (for a 5% variance). If the
112 noise type is ABSOLUTE, then the random noise value specified in the config file
113 is understood to be an absolute value of noise to be added to the input signal
114 instead of being added to 1.0 and having that sum be multiplied against the input
115 signal as in the PERCENT type. For the ABSOLUTE noise case, the noise number
116 specified in the config file could be any number.
117
118 If the type is ABSOLUTE, then the noise number times the random number is
119 added to the input signal instead of being multiplied against it as with the
120 PERCENT type of noise.
121
122 The delay element can specify a frame delay. The integer number provided is
123 the number of frames to delay the output signal.
124
125 @author Jon S. Berndt
126 @version $Revision: 1.20 $
127 */
128
129 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 CLASS DECLARATION
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132
133 class FGSensor  : public FGFCSComponent
134 {
135 public:
136   FGSensor(FGFCS* fcs, Element* element);
137   virtual ~FGSensor();
138
139   void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
140   void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
141   void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
142
143   double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
144   double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
145   double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
146   int    GetQuantized(void) const {return quantized;}
147
148   virtual bool Run (void);
149
150 protected:
151   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
152   enum eDistributionType {eUniform=0, eGaussian} DistributionType;
153   double min, max;
154   double span;
155   double bias;
156   double gain;
157   double drift_rate;
158   double drift;
159   double noise_variance;
160   double lag;
161   double granularity;
162   double ca; /// lag filter coefficient "a"
163   double cb; /// lag filter coefficient "b"
164   double PreviousOutput;
165   double PreviousInput;
166   int noise_type;
167   int bits;
168   int quantized;
169   int divisions;
170   bool fail_low;
171   bool fail_high;
172   bool fail_stuck;
173   std::string quant_property;
174
175   void ProcessSensorSignal(void);
176   void Noise(void);
177   void Bias(void);
178   void Drift(void);
179   void Quantize(void);
180   void Lag(void);
181   void Gain(void);
182
183   void bind(void);
184
185 private:
186   void Debug(int from);
187 };
188 }
189 #endif