]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
Added two missing files from JSBSim.org that were missing in the last sync.
[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 <input_output/FGXMLElement.h>
42 #include <vector>
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #define ID_SENSOR "$Id$"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FORWARD DECLARATIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 namespace JSBSim {
55
56 using std::vector;
57 class FGFCS;
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS DOCUMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
63 /** Encapsulates a Sensor component for the flight control system.
64
65 Syntax:
66
67 @code
68 <sensor name="name">
69   <input> property </input>
70   <lag> number </lag>
71   <noise variation="PERCENT|ABSOLUTE"> number </noise>
72   <quantization name="name">
73     <bits> number </bits>
74     <min> number </min>
75     <max> number </max>
76   </quantization>
77   <drift_rate> number </drift_rate>
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 For noise, if the type is PERCENT, then the value supplied is understood to be a
103 percentage variance. That is, if the number given is 0.05, the the variance is
104 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
105 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
106 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
107 time. The delay element can specify a frame delay. The integer number provided is
108 the number of frames to delay the output signal.
109
110 @author Jon S. Berndt
111 @version $Revision$
112 */
113
114 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 CLASS DECLARATION
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
117
118 class FGSensor  : public FGFCSComponent
119 {
120 public:
121   FGSensor(FGFCS* fcs, Element* element);
122   virtual ~FGSensor();
123
124   void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
125   void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
126   void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
127
128   double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
129   double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
130   double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
131   int    GetQuantized(void) const {return quantized;}
132
133   virtual bool Run (void);
134
135 protected:
136   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
137   enum eDistributionType {eUniform=0, eGaussian} DistributionType;
138   double dt;
139   double min, max;
140   double span;
141   double bias;
142   double gain;
143   double drift_rate;
144   double drift;
145   double noise_variance;
146   double lag;
147   double granularity;
148   double ca; /// lag filter coefficient "a"
149   double cb; /// lag filter coefficient "b"
150   double PreviousOutput;
151   double PreviousInput;
152   int noise_type;
153   int bits;
154   int quantized;
155   int divisions;
156   int delay;
157   int index;
158   bool fail_low;
159   bool fail_high;
160   bool fail_stuck;
161   string quant_property;
162   vector <double> output_array;
163
164   void Noise(void);
165   void Bias(void);
166   void Drift(void);
167   void Quantize(void);
168   void Lag(void);
169   void Delay(void);
170   void Gain(void);
171
172   void bind(void);
173
174 private:
175   void Debug(int from);
176 };
177 }
178 #endif