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.20 2011/08/18 12:42:17 jberndt 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>
78 <delay> number < /delay>
85 <sensor name="aero/sensor/qbar">
86 <input> aero/qbar </input>
88 <noise variation="PERCENT"> 2 </noise>
89 <quantization name="aero/sensor/quantized/qbar">
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.
101 Noise can be Gaussian or uniform, and the noise can be applied as a factor (PERCENT)
102 or additively (ABSOLUTE). The noise that can be applied at each frame of the
103 simulation execution is calculated as a random factor times a noise value that
104 is specified in the config file. When the noise distribution type is Gaussian,
105 the random number can be between roughly -3 and +3 for a span of six sigma. When
106 the distribution type is UNIFORM, the random value can be between -1.0 and +1.0.
107 This random value is multiplied against the specified noise to arrive at a random
108 noise value for the frame. If the noise type is PERCENT, then random noise value
109 is added to one, and that sum is then multiplied against the input signal for the
110 sensor. In this case, the specified noise value in the config file would be
111 expected to actually be a percent value, such as 0.05 (for a 5% variance). If the
112 noise type is ABSOLUTE, then the random noise value specified in the config file
113 is understood to be an absolute value of noise to be added to the input signal
114 instead of being added to 1.0 and having that sum be multiplied against the input
115 signal as in the PERCENT type. For the ABSOLUTE noise case, the noise number
116 specified in the config file could be any number.
118 If the type is ABSOLUTE, then the noise number times the random number is
119 added to the input signal instead of being multiplied against it as with the
120 PERCENT type of noise.
122 The delay element can specify a frame delay. The integer number provided is
123 the number of frames to delay the output signal.
125 @author Jon S. Berndt
126 @version $Revision: 1.20 $
129 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
133 class FGSensor : public FGFCSComponent
136 FGSensor(FGFCS* fcs, Element* element);
139 void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
140 void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
141 void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
143 double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
144 double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
145 double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
146 int GetQuantized(void) const {return quantized;}
148 virtual bool Run (void);
151 enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
152 enum eDistributionType {eUniform=0, eGaussian} DistributionType;
159 double noise_variance;
162 double ca; /// lag filter coefficient "a"
163 double cb; /// lag filter coefficient "b"
164 double PreviousOutput;
165 double PreviousInput;
173 std::string quant_property;
175 void ProcessSensorSignal(void);
186 void Debug(int from);