64 if ( quantization_element) {
80 bias = element->FindElementValueAsNumber(
"bias");
83 gain = element->FindElementValueAsNumber(
"gain");
86 drift_rate = element->FindElementValueAsNumber(
"drift_rate");
89 lag = element->FindElementValueAsNumber(
"lag");
90 double denom = 2.00 + dt*lag;
92 cb = (2.00 - dt*lag) / denom;
95 noise_variance = element->FindElementValueAsNumber(
"noise");
96 string variation = element->FindElement(
"noise")->GetAttributeValue(
"variation");
97 if (variation ==
"PERCENT") {
99 }
else if (variation ==
"ABSOLUTE") {
103 cerr <<
"Unknown noise type in sensor: " <<
Name << endl;
104 cerr <<
" defaulting to PERCENT." << endl;
106 string distribution = element->
FindElement(
"noise")->GetAttributeValue(
"distribution");
107 if (distribution ==
"UNIFORM") {
109 }
else if (distribution ==
"GAUSSIAN") {
113 cerr <<
"Unknown random distribution type in sensor: " <<
Name << endl;
114 cerr <<
" defaulting to UNIFORM." << endl;
182 double random_value=0.0;
185 random_value = 2.0*(((double)rand()/(double)RAND_MAX) - 0.5);
253 if (
Name.find(
"/") == string::npos) {
256 const string tmp_low = tmp +
"/malfunction/fail_low";
257 const string tmp_high = tmp +
"/malfunction/fail_high";
258 const string tmp_stuck = tmp +
"/malfunction/fail_stuck";
268 if (node->isTied()) {
270 <<
"Property " << tmp <<
" has already been successfully bound (late)." << endl;
271 throw(
"Failed to bind the property to an existing already tied node.");
299void FGSensor::Debug(
int from)
305 if (!InputNodes.empty())
306 cout <<
" INPUT: " << InputNodes[0]->GetNameWithSign() << endl;
308 if (quant_property.empty())
309 cout <<
" Quantized output" << endl;
311 cout <<
" Quantized output (property: " << quant_property <<
")" << endl;
313 cout <<
" Bits: " << bits << endl;
314 cout <<
" Min value: " <<
min << endl;
315 cout <<
" Max value: " << max << endl;
316 cout <<
" (span: " << span <<
", granularity: " << granularity <<
")" << endl;
318 if (bias != 0.0) cout <<
" Bias: " << bias << endl;
319 if (gain != 0.0) cout <<
" Gain: " << gain << endl;
320 if (drift_rate != 0) cout <<
" Sensor drift rate: " << drift_rate << endl;
321 if (lag != 0) cout <<
" Sensor lag: " << lag << endl;
322 if (noise_variance != 0) {
323 if (NoiseType == eAbsolute) {
324 cout <<
" Noise variance (absolute): " << noise_variance << endl;
325 }
else if (NoiseType == ePercent) {
326 cout <<
" Noise variance (percent): " << noise_variance << endl;
328 cout <<
" Noise variance type is invalid" << endl;
330 if (DistributionType == eUniform) {
331 cout <<
" Random noise is uniformly distributed." << endl;
332 }
else if (DistributionType == eGaussian) {
333 cout <<
" Random noise is gaussian distributed." << endl;
336 for (
auto node: OutputNodes)
337 cout <<
" OUTPUT: " << node->getNameString() << endl;
340 if (debug_lvl & 2 ) {
341 if (from == 0) cout <<
"Instantiated: FGSensor" << endl;
342 if (from == 1) cout <<
"Destroyed: FGSensor" << endl;
344 if (debug_lvl & 4 ) {
346 if (debug_lvl & 8 ) {
348 if (debug_lvl & 16) {
350 if (debug_lvl & 64) {
double FindElementValueAsNumber(const std::string &el="")
Searches for the named element and returns the data belonging to it as a number.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindElement(const std::string &el="")
Searches for a specified element.
FGFCSComponent(FGFCS *fcs, Element *el)
Constructor.
std::vector< FGPropertyValue_ptr > InputNodes
virtual void ResetPastStates(void)
FGPropertyManager * PropertyManager
virtual void bind(Element *el)
virtual void SetOutput(void)
static double GaussianRandomNumber(void)
Class wrapper for property handling.
std::string quant_property
double GetFailLow(void) const
double cb
lag filter coefficient "a"
void bind(Element *el) override
void SetFailStuck(double val)
enum JSBSim::FGSensor::eDistributionType DistributionType
void SetFailLow(double val)
double GetFailHigh(void) const
enum JSBSim::FGSensor::eNoiseType NoiseType
double PreviousOutput
lag filter coefficient "b"
FGSensor(FGFCS *fcs, Element *element)
int GetQuantized(void) const
double GetFailStuck(void) const
void ResetPastStates(void) override
void ProcessSensorSignal(void)
void SetFailHigh(double val)