]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSensor.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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.19 2009/10/24 22:59:30 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"> 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 For noise, if the type is PERCENT, then the value supplied is understood to be a
102 percentage variance. That is, if the number given is 0.05, the the variance is
103 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
104 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
105 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
106 time. The delay element can specify a frame delay. The integer number provided is
107 the number of frames to delay the output signal.
108
109 @author Jon S. Berndt
110 @version $Revision: 1.19 $
111 */
112
113 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 CLASS DECLARATION
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
116
117 class FGSensor  : public FGFCSComponent
118 {
119 public:
120   FGSensor(FGFCS* fcs, Element* element);
121   virtual ~FGSensor();
122
123   void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
124   void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
125   void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
126
127   double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
128   double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
129   double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
130   int    GetQuantized(void) const {return quantized;}
131
132   virtual bool Run (void);
133
134 protected:
135   enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
136   enum eDistributionType {eUniform=0, eGaussian} DistributionType;
137   double min, max;
138   double span;
139   double bias;
140   double gain;
141   double drift_rate;
142   double drift;
143   double noise_variance;
144   double lag;
145   double granularity;
146   double ca; /// lag filter coefficient "a"
147   double cb; /// lag filter coefficient "b"
148   double PreviousOutput;
149   double PreviousInput;
150   int noise_type;
151   int bits;
152   int quantized;
153   int divisions;
154   bool fail_low;
155   bool fail_high;
156   bool fail_stuck;
157   std::string quant_property;
158
159   void ProcessSensorSignal(void);
160   void Noise(void);
161   void Bias(void);
162   void Drift(void);
163   void Quantize(void);
164   void Lag(void);
165   void Gain(void);
166
167   void bind(void);
168
169 private:
170   void Debug(int from);
171 };
172 }
173 #endif