No smoothing when boatDataValue is invalid
This commit is contained in:
parent
4e6d52d197
commit
0c4fce0e25
|
@ -169,22 +169,30 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b
|
||||||
dataValue = (dataValue * slope) + offset;
|
dataValue = (dataValue * slope) + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
calibrationData.smoothInstance(instance, dataValue, logger); // smooth the boat data value
|
|
||||||
calibrationData.list[listNo].value = dataValue;
|
|
||||||
calibrationData.list[listNo].isCalibrated = true;
|
calibrationData.list[listNo].isCalibrated = true;
|
||||||
boatDataValue->value = dataValue;
|
boatDataValue->value = dataValue;
|
||||||
|
|
||||||
|
calibrationData.smoothInstance(instance, boatDataValue, logger); // smooth the boat data value
|
||||||
|
calibrationData.list[listNo].value = boatDataValue->value; // store the calibrated + smoothed value in the list
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: Offset: %f, Slope: %f, Result: %f", instance.c_str(), offset, slope, boatDataValue->value);
|
LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: Offset: %f, Slope: %f, Result: %f", instance.c_str(), offset, slope, boatDataValue->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalibrationDataList::smoothInstance(String instance, double& dataValue, GwLog* logger)
|
void CalibrationDataList::smoothInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger)
|
||||||
// Method to smoothen the boat data value
|
// Method to smoothen the boat data value
|
||||||
{
|
{
|
||||||
// array for last values of smoothed boat data values
|
// array for last values of smoothed boat data values
|
||||||
static std::unordered_map<std::string, double> lastValue;
|
static std::unordered_map<std::string, double> lastValue;
|
||||||
|
|
||||||
double oldValue = 0;
|
double oldValue = 0;
|
||||||
|
double dataValue = boatDataValue->value;
|
||||||
|
|
||||||
|
if (!boatDataValue->valid) { // no valid boat data value, so we don't want to smoothen value
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
|
||||||
double smoothFactor = calibrationData.list[getInstanceListNo(instance)].smooth;
|
double smoothFactor = calibrationData.list[getInstanceListNo(instance)].smooth;
|
||||||
|
|
||||||
if (lastValue.find(instance.c_str()) != lastValue.end()) {
|
if (lastValue.find(instance.c_str()) != lastValue.end()) {
|
||||||
|
@ -193,8 +201,10 @@ void CalibrationDataList::smoothInstance(String instance, double& dataValue, GwL
|
||||||
dataValue = oldValue + (smoothFactor * (dataValue - oldValue)); // exponential smoothing algorithm
|
dataValue = oldValue + (smoothFactor * (dataValue - oldValue)); // exponential smoothing algorithm
|
||||||
}
|
}
|
||||||
lastValue[instance.c_str()] = dataValue; // store the new value for next cycle; first time, store only the current value and return
|
lastValue[instance.c_str()] = dataValue; // store the new value for next cycle; first time, store only the current value and return
|
||||||
|
boatDataValue->value = dataValue; // set the smoothed value to the boat data value
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: Smoothing factor: %f, Smoothed value: %f", instance.c_str(), smoothFactor, dataValue);
|
LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: Smoothing factor: %f, Smoothed value: %f", instance.c_str(), smoothFactor, dataValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -24,7 +24,8 @@ public:
|
||||||
void readConfig(GwConfigHandler* config, GwLog* logger);
|
void readConfig(GwConfigHandler* config, GwLog* logger);
|
||||||
int getInstanceListNo(String instance);
|
int getInstanceListNo(String instance);
|
||||||
void calibrateInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger);
|
void calibrateInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger);
|
||||||
void smoothInstance(String instance, double &dataValue, GwLog* logger);
|
// void smoothInstance(String instance, double &dataValue, GwLog* logger);
|
||||||
|
void smoothInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue