]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
87fd3d5182378a18f4aade3aa4371e9f456b1d26
[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
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_SENSOR "$Id$"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 class FGFCS;
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 /** Encapsulates a Sensor component for the flight control system.
62
63 Syntax:
64
65 @code
66 <sensor name="name">
67   <input> property </input>
68   <lag> number </lag>
69   <noise variation="PERCENT|ABSOLUTE"> number </noise>
70   <quantization name="name">
71     <bits> number </bits>
72     <min> number </min>
73     <max> number </max>
74   </quantization>
75   <drift_rate> number </drift_rate>
76   <bias> number </bias>
77 </sensor>
78 @endcode
79
80 Example:
81
82 @code
83 <sensor name="aero/sensor/qbar">
84   <input> aero/qbar </input>
85   <lag> 0.5 </lag>
86   <noise variation="PERCENT"> 2 </noise>
87   <quantization name="aero/sensor/quantized/qbar">
88     <bits> 12 </bits>
89     <min> 0 </min>
90     <max> 400 </max>
91   </quantization>
92   <bias> 0.5 </bias>
93 </sensor>
94 @endcode
95
96 The only required element in the sensor definition is the input element. In that
97 case, no degradation would be modeled, and the output would simply be the input.
98
99 For noise, if the type is PERCENT, then the value supplied is understood to be a
100 percentage variance. That is, if the number given is 0.05, the the variance is
101 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
102 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
103 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
104 time.
105
106 @author Jon S. Berndt
107 @version $Revision$
108 */
109
110 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 CLASS DECLARATION
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
113
114 class FGSensor  : public FGFCSComponent
115 {
116 public:
117   FGSensor(FGFCS* fcs, Element* element);
118   ~FGSensor();
119
120   void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
121   void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
122   void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
123
124   double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
125   double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
126   double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
127   int    GetQuantized(void) const {return quantized;}
128
129   virtual bool Run (void);
130
131 protected:
132   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
133   double dt;
134   double min, max;
135   double span;
136   double bias;
137   double drift_rate;
138   double drift;
139   double noise_variance;
140   double lag;
141   double granularity;
142   double ca; /// lag filter coefficient "a"
143   double cb; /// lag filter coefficient "b"
144   double PreviousOutput;
145   double PreviousInput;
146   int noise_type;
147   int bits;
148   int quantized;
149   int divisions;
150   bool fail_low;
151   bool fail_high;
152   bool fail_stuck;
153   string quant_property;
154
155   void Noise(void);
156   void Bias(void);
157   void Drift(void);
158   void Quantize(void);
159   void Lag(void);
160
161   void bind(void);
162
163 private:
164   void Debug(int from);
165 };
166 }
167 #endif