X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2Fflight_control%2FFGSensor.cpp;h=d2f9243d92a49147fc03524deba9a2391d233af3;hb=0f0f25512d4b5a4c1b56de2ad975abc7285c9bf5;hp=bd6a384179a172b913a4835db9513bfaa9508d51;hpb=a6db6d89ff41a619569e6433409e8bf62ff98499;p=flightgear.git diff --git a/src/FDM/JSBSim/models/flight_control/FGSensor.cpp b/src/FDM/JSBSim/models/flight_control/FGSensor.cpp index bd6a38417..d2f9243d9 100755 --- a/src/FDM/JSBSim/models/flight_control/FGSensor.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGSensor.cpp @@ -52,11 +52,10 @@ CLASS IMPLEMENTATION FGSensor::FGSensor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) { double denom; - dt = fcs->GetDt(); // inputs are read from the base class constructor - bits = quantized = divisions = index = delay = 0; + bits = quantized = divisions = 0; PreviousInput = PreviousOutput = 0.0; min = max = bias = gain = noise_variance = lag = drift_rate = drift = span = 0.0; granularity = 0.0; @@ -117,11 +116,6 @@ FGSensor::FGSensor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) cerr << " defaulting to UNIFORM." << endl; } } - if ( element->FindElement("delay") ) { - delay = (unsigned int)element->FindElementValueAsNumber("delay"); - output_array.resize(delay); - for (unsigned int i=0; igetDoubleValue() * InputSigns[0]; + ProcessSensorSignal(); + + return true; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGSensor::ProcessSensorSignal(void) +{ Output = Input; // perfect sensor // Degrade signal as specified if (fail_stuck) { Output = PreviousOutput; - return true; - } - - if (lag != 0.0) Lag(); // models sensor lag and filter - if (noise_variance != 0.0) Noise(); // models noise - if (drift_rate != 0.0) Drift(); // models drift over time - if (bias != 0.0) Bias(); // models a finite bias - if (gain != 0.0) Gain(); // models a finite gain + } else { + if (lag != 0.0) Lag(); // models sensor lag and filter + if (noise_variance != 0.0) Noise(); // models noise + if (drift_rate != 0.0) Drift(); // models drift over time + if (gain != 0.0) Gain(); // models a finite gain + if (bias != 0.0) Bias(); // models a finite bias - if (delay != 0.0) Delay(); // models system signal transport latencies + if (delay != 0) Delay(); // models system signal transport latencies - if (fail_low) Output = -HUGE_VAL; - if (fail_high) Output = HUGE_VAL; + if (fail_low) Output = -HUGE_VAL; + if (fail_high) Output = HUGE_VAL; - if (bits != 0) Quantize(); // models quantization degradation + if (bits != 0) Quantize(); // models quantization degradation - Clip(); // Is it right to clip a sensor? - return true; + Clip(); + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -237,16 +238,6 @@ void FGSensor::Lag(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGSensor::Delay(void) -{ - output_array[index] = Output; - if (index == delay-1) index = 0; - else index++; - Output = output_array[index]; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - void FGSensor::bind(void) { string tmp = Name; @@ -301,8 +292,6 @@ void FGSensor::Debug(int from) else cout << " INPUT: " << InputNodes[0]->getName() << endl; } - if (delay > 0) cout <<" Frame delay: " << delay - << " frames (" << delay*dt << " sec)" << endl; if (bits != 0) { if (quant_property.empty()) cout << " Quantized output" << endl; @@ -332,7 +321,10 @@ void FGSensor::Debug(int from) cout << " Random noise is gaussian distributed." << endl; } } - if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl; + if (IsOutput) { + for (unsigned int i=0; igetName() << endl; + } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification