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>
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_SENSOR "$Id$"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /** Encapsulates a Sensor component for the flight control system.
67 <input> property </input>
69 <noise variation="PERCENT|ABSOLUTE"> number </noise>
70 <quantization name="name">
75 <drift_rate> number </drift_rate>
83 <sensor name="aero/sensor/qbar">
84 <input> aero/qbar </input>
86 <noise variation="PERCENT"> 2 </noise>
87 <quantization name="aero/sensor/quantized/qbar">
96 The only required element in the sensor definition is the input element. In that
97 case, no degradation would be modeled, and the output would simply be the input.
99 For noise, if the type is PERCENT, then the value supplied is understood to be a
100 percentage variance. That is, if the number given is 0.05, the the variance is
101 understood to be +/-0.05 percent maximum variance. So, the actual value for the sensor
102 will be *anywhere* from 0.95 to 1.05 of the actual "perfect" value at any time -
103 even varying all the way from 0.95 to 1.05 in adjacent frames - whatever the delta
106 @author Jon S. Berndt
110 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
114 class FGSensor : public FGFCSComponent
117 FGSensor(FGFCS* fcs, Element* element);
120 inline void SetFailLow(double val) {if (val > 0.0) fail_low = true; else fail_low = false;}
121 inline void SetFailHigh(double val) {if (val > 0.0) fail_high = true; else fail_high = false;}
122 inline void SetFailStuck(double val) {if (val > 0.0) fail_stuck = true; else fail_stuck = false;}
124 inline double GetFailLow(void) const {if (fail_low) return 1.0; else return 0.0;}
125 inline double GetFailHigh(void) const {if (fail_high) return 1.0; else return 0.0;}
126 inline double GetFailStuck(void) const {if (fail_stuck) return 1.0; else return 0.0;}
127 inline int GetQuantized(void) const {return quantized;}
132 enum eNoiseType {ePercent=0, eAbsolute} NoiseType;
139 double noise_variance;
142 double ca; /// lag filter coefficient "a"
143 double cb; /// lag filter coefficient "b"
144 double PreviousOutput;
145 double PreviousInput;
153 string quant_property;
163 void Debug(int from);