]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
Sync. w. 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 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 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 <sensor name=\94name\94 rate_group=\94name\94>
66   <input> property </input>
67   <lag> number </lag>
68   <noise variation=\94PERCENT|ABSOLUTE\94> number </noise>
69   <quantization name="name">
70     <bits> number </bits>
71     <min> number </min>
72     <max> number </max>
73   </quantization>
74   <drift_rate> number </drift_rate>
75   <bias> number </bias>
76 </sensor>
77
78 Example:
79
80 <sensor name=\94aero/sensor/qbar\94 rate_group=\94HFCS\94>
81   <input> aero/qbar </input>
82   <lag> 0.5 </lag>
83   <noise variation=\94PERCENT\94> 2 </noise>
84   <quantization name="aero/sensor/quantized/qbar">
85     <bits> 12 </bits>
86     <min> 0 </min>
87     <max> 400 </max>
88   </quantization>
89   <bias> 0.5 </bias>
90 </sensor>
91
92 The only required element in the sensor definition is the input element. In that
93 case, no degradation would be modeled, and the output would simply be the input.
94
95 For noise, if the type is PERCENT, then the value supplied is understood to be a
96 percentage variance. That is, if the number given is 0.05, the the variance is
97 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
98 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
99 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
100 time.
101
102 @author Jon S. Berndt
103 @version $Revision$
104   */
105
106 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 CLASS DECLARATION
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109
110 class FGSensor  : public FGFCSComponent
111 {
112 public:
113   FGSensor(FGFCS* fcs, Element* element);
114   ~FGSensor();
115
116   inline void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
117   inline void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
118   inline void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
119
120   inline double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
121   inline double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
122   inline double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
123
124   bool Run (void);
125
126 private:
127   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
128   double dt;
129   double min, max;
130   double span;
131   double bias;
132   double drift_rate;
133   double drift;
134   double noise_variance;
135   double lag;
136   double granularity;
137   double ca; /// lag filter coefficient "a"
138   double cb; /// lag filter coefficient "b"
139   double PreviousOutput;
140   double PreviousInput;
141   int noise_type;
142   int bits;
143   int quantized;
144   int divisions;
145   bool fail_low;
146   bool fail_high;
147   bool fail_stuck;
148
149   void Noise(void);
150   void Bias(void);
151   void Drift(void);
152   void Quantize(void);
153   void Lag(void);
154
155   void bind(void);
156
157   void Debug(int from);
158 };
159 }
160 #endif