]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
sync with JSB JSBSim CVS
[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.21 2012/01/08 12:39:14 bcoconni 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   <gain> number </gain>
78   <bias> number </bias>
79   <delay> number < /delay>
80 </sensor>
81 @endcode
82
83 Example:
84
85 @code
86 <sensor name="aero/sensor/qbar">
87   <input> aero/qbar </input>
88   <lag> 0.5 </lag>
89   <noise variation="PERCENT"> 2 </noise>
90   <quantization name="aero/sensor/quantized/qbar">
91     <bits> 12 </bits>
92     <min> 0 </min>
93     <max> 400 </max>
94   </quantization>
95   <bias> 0.5 </bias>
96 </sensor>
97 @endcode
98
99 The only required element in the sensor definition is the input element. In that
100 case, no degradation would be modeled, and the output would simply be the input.
101
102 Noise can be Gaussian or uniform, and the noise can be applied as a factor (PERCENT)
103 or additively (ABSOLUTE). The noise that can be applied at each frame of the
104 simulation execution is calculated as a random factor times a noise value that
105 is specified in the config file. When the noise distribution type is Gaussian,
106 the random number can be between roughly -3 and +3 for a span of six sigma. When
107 the distribution type is UNIFORM, the random value can be between -1.0 and +1.0.
108 This random value is multiplied against the specified noise to arrive at a random
109 noise value for the frame. If the noise type is PERCENT, then random noise value
110 is added to one, and that sum is then multiplied against the input signal for the
111 sensor. In this case, the specified noise value in the config file would be
112 expected to actually be a percent value, such as 0.05 (for a 5% variance). If the
113 noise type is ABSOLUTE, then the random noise value specified in the config file
114 is understood to be an absolute value of noise to be added to the input signal
115 instead of being added to 1.0 and having that sum be multiplied against the input
116 signal as in the PERCENT type. For the ABSOLUTE noise case, the noise number
117 specified in the config file could be any number.
118
119 If the type is ABSOLUTE, then the noise number times the random number is
120 added to the input signal instead of being multiplied against it as with the
121 PERCENT type of noise.
122
123 The delay element can specify a frame delay. The integer number provided is
124 the number of frames to delay the output signal.
125
126 @author Jon S. Berndt
127 @version $Revision: 1.21 $
128 */
129
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 CLASS DECLARATION
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
133
134 class FGSensor  : public FGFCSComponent
135 {
136 public:
137   FGSensor(FGFCS* fcs, Element* element);
138   virtual ~FGSensor();
139
140   void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
141   void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
142   void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
143
144   double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
145   double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
146   double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
147   int    GetQuantized(void) const {return quantized;}
148
149   virtual bool Run (void);
150
151 protected:
152   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
153   enum eDistributionType {eUniform=0, eGaussian} DistributionType;
154   double min, max;
155   double span;
156   double bias;
157   double gain;
158   double drift_rate;
159   double drift;
160   double noise_variance;
161   double lag;
162   double granularity;
163   double ca; /// lag filter coefficient "a"
164   double cb; /// lag filter coefficient "b"
165   double PreviousOutput;
166   double PreviousInput;
167   int noise_type;
168   int bits;
169   int quantized;
170   int divisions;
171   bool fail_low;
172   bool fail_high;
173   bool fail_stuck;
174   std::string quant_property;
175
176   void ProcessSensorSignal(void);
177   void Noise(void);
178   void Bias(void);
179   void Drift(void);
180   void Quantize(void);
181   void Lag(void);
182   void Gain(void);
183
184   void bind(void);
185
186 private:
187   void Debug(int from);
188 };
189 }
190 #endif