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"
41 #include <input_output/FGXMLElement.h>
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 #define ID_SENSOR "$Id$"
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /** Encapsulates a Sensor component for the flight control system.
69 <input> property </input>
71 <noise variation="PERCENT|ABSOLUTE"> number </noise>
72 <quantization name="name">
77 <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 For noise, if the type is PERCENT, then the value supplied is understood to be a
103 percentage variance. That is, if the number given is 0.05, the the variance is
104 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
105 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
106 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
107 time. The delay element can specify a frame delay. The integer number provided is
108 the number of frames to delay the output signal.
110 @author Jon S. Berndt
114 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
118 class FGSensor : public FGFCSComponent
121 FGSensor(FGFCS* fcs, Element* element);
124 void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
125 void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
126 void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
128 double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
129 double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
130 double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
131 int GetQuantized(void) const {return quantized;}
133 virtual bool Run (void);
136 enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
137 enum eDistributionType {eUniform=0, eGaussian} DistributionType;
145 double noise_variance;
148 double ca; /// lag filter coefficient "a"
149 double cb; /// lag filter coefficient "b"
150 double PreviousOutput;
151 double PreviousInput;
161 string quant_property;
162 vector <double> output_array;
175 void Debug(int from);