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.19 2009/10/24 22:59:30 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"> 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 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.
109 @author Jon S. Berndt
110 @version $Revision: 1.19 $
113 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
117 class FGSensor : public FGFCSComponent
120 FGSensor(FGFCS* fcs, Element* element);
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;}
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;}
132 virtual bool Run (void);
135 enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
136 enum eDistributionType {eUniform=0, eGaussian} DistributionType;
143 double noise_variance;
146 double ca; /// lag filter coefficient "a"
147 double cb; /// lag filter coefficient "b"
148 double PreviousOutput;
149 double PreviousInput;
157 std::string quant_property;
159 void ProcessSensorSignal(void);
170 void Debug(int from);