No smoothing when boatDataValue is invalid

This commit is contained in:
Ulrich Meine 2025-05-24 00:40:10 +02:00
parent 4e6d52d197
commit 0c4fce0e25
2 changed files with 28 additions and 17 deletions

View File

@ -169,22 +169,30 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b
dataValue = (dataValue * slope) + offset;
}
calibrationData.smoothInstance(instance, dataValue, logger); // smooth the boat data value
calibrationData.list[listNo].value = dataValue;
calibrationData.list[listNo].isCalibrated = true;
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);
}
}
}
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
{
// array for last values of smoothed boat data values
static std::unordered_map<std::string, double> lastValue;
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;
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
}
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);
}
}
#endif

View File

@ -24,7 +24,8 @@ public:
void readConfig(GwConfigHandler* config, GwLog* logger);
int getInstanceListNo(String instance);
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:
};