1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 9 July 2005
7 ------------- Copyright (C) 2005 -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGFCSComponent.h"
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_SENSOR "$Id: FGSensor.h,v 1.21 2012/01/08 12:39:14 bcoconni Exp $"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /** Encapsulates a Sensor component for the flight control system.
68 <input> property </input>
70 <noise [variation="PERCENT|ABSOLUTE"] [distribution="UNIFORM|GAUSSIAN"]> number </noise>
71 <quantization name="name">
76 <drift_rate> number </drift_rate>
79 <delay> number < /delay>
86 <sensor name="aero/sensor/qbar">
87 <input> aero/qbar </input>
89 <noise variation="PERCENT"> 2 </noise>
90 <quantization name="aero/sensor/quantized/qbar">
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.
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.
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.
123 The delay element can specify a frame delay. The integer number provided is
124 the number of frames to delay the output signal.
126 @author Jon S. Berndt
127 @version $Revision: 1.21 $
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
134 class FGSensor : public FGFCSComponent
137 FGSensor(FGFCS* fcs, Element* element);
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;}
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;}
149 virtual bool Run (void);
152 enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
153 enum eDistributionType {eUniform=0, eGaussian} DistributionType;
160 double noise_variance;
163 double ca; /// lag filter coefficient "a"
164 double cb; /// lag filter coefficient "b"
165 double PreviousOutput;
166 double PreviousInput;
174 std::string quant_property;
176 void ProcessSensorSignal(void);
187 void Debug(int from);