From fca7a477281ed2ff154d8329443da981eaf2c768 Mon Sep 17 00:00:00 2001 From: Ulrich Meine Date: Sat, 17 May 2025 12:18:21 +0200 Subject: [PATCH] smoothing factor adjustments --- lib/obp60task/BoatDataCalibration.cpp | 26 +++++++++++++++++--------- lib/obp60task/config.json | 6 +++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/obp60task/BoatDataCalibration.cpp b/lib/obp60task/BoatDataCalibration.cpp index 80c3aa7..cb2c853 100644 --- a/lib/obp60task/BoatDataCalibration.cpp +++ b/lib/obp60task/BoatDataCalibration.cpp @@ -84,15 +84,23 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger) slope *= 9.0 / 5.0; // Convert °F to K } } - if (smooth < 0) { + + // transform smoothing factor from {0.01..10} to {0.3..0.95} and invert for exponential smoothing formula + if (smooth <= 0) { smooth = 0; - } else if (smooth > 9) { - smooth = 9; + } else { + if (smooth > 10) { + smooth = 10; + } + // calibrationData.list[i].smooth = 1 - (smooth / 10.0); // smooth factor is between 0 and 1 + smooth = 0.3 + ((smooth - 0.01) * (0.95 - 0.3) / (10 - 0.01)); } + smooth = 1 - smooth; + calibrationData.list[i].instance = instance; calibrationData.list[i].offset = offset; calibrationData.list[i].slope = slope; - calibrationData.list[i].smooth = 1 - (smooth / 10.0); // smooth factor is between 0 and 1 + calibrationData.list[i].smooth = smooth; calibrationData.list[i].isCalibrated = false; LOG_DEBUG(GwLog::LOG, "stored calibration data: %s, offset: %f, slope: %f, smoothing: %f", calibrationData.list[i].instance.c_str(), calibrationData.list[i].offset, calibrationData.list[i].slope, calibrationData.list[i].smooth); @@ -132,7 +140,7 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b int listNo = getInstanceListNo(instance); if (listNo < 0) { - LOG_DEBUG(GwLog::LOG, "BoatDataCalibration: %s not found in calibration data list", instance.c_str()); + LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s not found in calibration data list", instance.c_str()); return; } else { offset = calibrationData.list[listNo].offset; @@ -142,7 +150,7 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b return; } else { dataValue = boatDataValue->value; - LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: name: %s: value: %f format: %s", boatDataValue->getName().c_str(), boatDataValue->value, boatDataValue->getFormat().c_str()); + LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: value: %f, format: %s", boatDataValue->getName().c_str(), boatDataValue->value, boatDataValue->getFormat().c_str()); if (boatDataValue->getFormat() == "formatWind") { // instance is of type angle dataValue = (dataValue * slope) + offset; @@ -168,12 +176,12 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b calibrationData.list[listNo].value = dataValue; calibrationData.list[listNo].isCalibrated = true; boatDataValue->value = dataValue; - LOG_DEBUG(GwLog::LOG, "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, double& dataValue, GwLog* logger) // Method to smoothen the boat data value { // array for last values of smoothed boat data values @@ -189,7 +197,7 @@ void CalibrationDataList::smoothInstance(String instance, double &dataValue, GwL } lastValue[instance.c_str()] = dataValue; // store the new value for next cycle; first time, store only the current value and return - LOG_DEBUG(GwLog::LOG, "BoatDataCalibration: %s: Smoothed value: %f", instance.c_str(), dataValue); + LOG_DEBUG(GwLog::DEBUG, "BoatDataCalibration: %s: Smoothing factor: %f, Smoothed value: %f", instance.c_str(), smoothFactor, dataValue); } #endif \ No newline at end of file diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index ebce2df..c1801af 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -740,7 +740,7 @@ "default": "0", "check": "checkMinMax", "min": 0, - "max": 9, + "max": 10, "description": "Smoothing factor for data instance 1", "category": "OBP60 Calibrations", "capabilities": { @@ -801,7 +801,7 @@ "default": "0", "check": "checkMinMax", "min": 0, - "max": 9, + "max": 10, "description": "Smoothing factor for data instance 2", "category": "OBP60 Calibrations", "capabilities": { @@ -862,7 +862,7 @@ "default": "0", "check": "checkMinMax", "min": 0, - "max": 9, + "max": 10, "description": "Smoothing factor for data instance 3", "category": "OBP60 Calibrations", "capabilities": {