Basis working
This commit is contained in:
parent
6dbbd13ead
commit
10951d7f13
|
@ -3,6 +3,7 @@
|
||||||
#include "BoatDataCalibration.h"
|
#include "BoatDataCalibration.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
CalibrationDataList calibrationData;
|
CalibrationDataList calibrationData;
|
||||||
|
|
||||||
|
@ -13,10 +14,12 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger)
|
||||||
String instance;
|
String instance;
|
||||||
double offset;
|
double offset;
|
||||||
double slope;
|
double slope;
|
||||||
|
double smooth;
|
||||||
|
|
||||||
String calInstance = "";
|
String calInstance = "";
|
||||||
String calOffset = "";
|
String calOffset = "";
|
||||||
String calSlope = "";
|
String calSlope = "";
|
||||||
|
String calSmooth = "";
|
||||||
|
|
||||||
// Load user format configuration values
|
// Load user format configuration values
|
||||||
String lengthFormat = config->getString(config->lengthFormat); // [m|ft]
|
String lengthFormat = config->getString(config->lengthFormat); // [m|ft]
|
||||||
|
@ -30,7 +33,8 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger)
|
||||||
calInstance = "calInstance" + String(i + 1);
|
calInstance = "calInstance" + String(i + 1);
|
||||||
calOffset = "calOffset" + String(i + 1);
|
calOffset = "calOffset" + String(i + 1);
|
||||||
calSlope = "calSlope" + String(i + 1);
|
calSlope = "calSlope" + String(i + 1);
|
||||||
calibrationData.list[i] = { "---", 0.0f, 1.0f, 0.0f, false };
|
calSmooth = "calSmooth" + String(i + 1);
|
||||||
|
calibrationData.list[i] = { "---", 0.0f, 1.0f, 1, 0.0f, false };
|
||||||
|
|
||||||
instance = config->getString(calInstance, "---");
|
instance = config->getString(calInstance, "---");
|
||||||
if (instance == "---") {
|
if (instance == "---") {
|
||||||
|
@ -39,6 +43,7 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger)
|
||||||
}
|
}
|
||||||
offset = (config->getString(calOffset, "")).toFloat();
|
offset = (config->getString(calOffset, "")).toFloat();
|
||||||
slope = (config->getString(calSlope, "")).toFloat();
|
slope = (config->getString(calSlope, "")).toFloat();
|
||||||
|
smooth = (config->getString(calSmooth, "")).toInt();
|
||||||
|
|
||||||
// Convert calibration values to internal standard formats
|
// Convert calibration values to internal standard formats
|
||||||
if (instance == "AWS" || instance == "TWS") {
|
if (instance == "AWS" || instance == "TWS") {
|
||||||
|
@ -52,8 +57,7 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger)
|
||||||
offset *= 0.5; // Convert Bft to m/s (approx) -> to be improved
|
offset *= 0.5; // Convert Bft to m/s (approx) -> to be improved
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (instance == "AWA" || instance == "TWA" ||instance == "TWD" || instance == "HDM" ||
|
} else if (instance == "AWA" || instance == "TWA" || instance == "TWD" || instance == "HDM" || instance == "PRPOS" || instance == "RPOS") {
|
||||||
instance == "PRPOS" || instance == "RPOS") {
|
|
||||||
offset *= M_PI / 180; // Convert deg to rad
|
offset *= M_PI / 180; // Convert deg to rad
|
||||||
|
|
||||||
} else if (instance == "DBT") {
|
} else if (instance == "DBT") {
|
||||||
|
@ -80,11 +84,18 @@ void CalibrationDataList::readConfig(GwConfigHandler* config, GwLog* logger)
|
||||||
slope *= 9.0 / 5.0; // Convert °F to K
|
slope *= 9.0 / 5.0; // Convert °F to K
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (smooth < 0) {
|
||||||
|
smooth = 0;
|
||||||
|
} else if (smooth > 9) {
|
||||||
|
smooth = 9;
|
||||||
|
}
|
||||||
calibrationData.list[i].instance = instance;
|
calibrationData.list[i].instance = instance;
|
||||||
calibrationData.list[i].offset = offset;
|
calibrationData.list[i].offset = offset;
|
||||||
calibrationData.list[i].slope = slope;
|
calibrationData.list[i].slope = slope;
|
||||||
|
calibrationData.list[i].smooth = 1 - (smooth / 10.0); // smooth factor is between 0 and 1
|
||||||
calibrationData.list[i].isCalibrated = false;
|
calibrationData.list[i].isCalibrated = false;
|
||||||
LOG_DEBUG(GwLog::LOG, "stored calibration data: %s, offset: %f, slope: %f", calibrationData.list[i].instance.c_str(), calibrationData.list[i].offset, calibrationData.list[i].slope);
|
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);
|
||||||
}
|
}
|
||||||
LOG_DEBUG(GwLog::LOG, "all calibration data read");
|
LOG_DEBUG(GwLog::LOG, "all calibration data read");
|
||||||
}
|
}
|
||||||
|
@ -153,6 +164,7 @@ 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].value = dataValue;
|
||||||
calibrationData.list[listNo].isCalibrated = true;
|
calibrationData.list[listNo].isCalibrated = true;
|
||||||
boatDataValue->value = dataValue;
|
boatDataValue->value = dataValue;
|
||||||
|
@ -161,4 +173,23 @@ void CalibrationDataList::calibrateInstance(String instance, GwApi::BoatValue* b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
static std::unordered_map<std::string, double> lastValue;
|
||||||
|
|
||||||
|
double oldValue = 0;
|
||||||
|
double smoothFactor = calibrationData.list[getInstanceListNo(instance)].smooth;
|
||||||
|
|
||||||
|
if (lastValue.find(instance.c_str()) != lastValue.end()) {
|
||||||
|
oldValue = lastValue[instance.c_str()];
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
LOG_DEBUG(GwLog::LOG, "BoatDataCalibration: %s: Smoothed value: %f", instance.c_str(), dataValue);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -10,6 +10,7 @@ typedef struct {
|
||||||
String instance; // data type/instance to be calibrated
|
String instance; // data type/instance to be calibrated
|
||||||
double offset; // calibration offset
|
double offset; // calibration offset
|
||||||
double slope; // calibration slope
|
double slope; // calibration slope
|
||||||
|
double smooth; // smoothing factor
|
||||||
double value; // calibrated data value
|
double value; // calibrated data value
|
||||||
bool isCalibrated; // is data instance value calibrated?
|
bool isCalibrated; // is data instance value calibrated?
|
||||||
} CalibData;
|
} CalibData;
|
||||||
|
@ -23,6 +24,7 @@ public:
|
||||||
static void readConfig(GwConfigHandler* config, GwLog* logger);
|
static void readConfig(GwConfigHandler* config, GwLog* logger);
|
||||||
static int getInstanceListNo(String instance);
|
static int getInstanceListNo(String instance);
|
||||||
static void calibrateInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger);
|
static void calibrateInstance(String instance, GwApi::BoatValue* boatDataValue, GwLog* logger);
|
||||||
|
void smoothInstance(String instance, double &dataValue, GwLog* logger);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -713,7 +713,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calOffset1",
|
"name": "calOffset1",
|
||||||
"label": "Calibration Data Instance 1 Offset",
|
"label": "Data Instance 1 Calibration Offset",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "0.00",
|
"default": "0.00",
|
||||||
"description": "Offset for data instance 1",
|
"description": "Offset for data instance 1",
|
||||||
|
@ -724,7 +724,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calSlope1",
|
"name": "calSlope1",
|
||||||
"label": "Calibration Data Instance 1 Slope",
|
"label": "Data Instance 1 Calibration Slope",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "1.00",
|
"default": "1.00",
|
||||||
"description": "Slope for data instance 1",
|
"description": "Slope for data instance 1",
|
||||||
|
@ -733,6 +733,20 @@
|
||||||
"obp60":"true"
|
"obp60":"true"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "calSmooth1",
|
||||||
|
"label": "Data Instance 1 Smoothing",
|
||||||
|
"type": "number",
|
||||||
|
"default": "0",
|
||||||
|
"check": "checkMinMax",
|
||||||
|
"min": 0,
|
||||||
|
"max": 9,
|
||||||
|
"description": "Smoothing factor for data instance 1",
|
||||||
|
"category": "OBP60 Calibrations",
|
||||||
|
"capabilities": {
|
||||||
|
"obp60":"true"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "calInstance2",
|
"name": "calInstance2",
|
||||||
"label": "Calibration Data Instance 2",
|
"label": "Calibration Data Instance 2",
|
||||||
|
@ -760,7 +774,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calOffset2",
|
"name": "calOffset2",
|
||||||
"label": "Calibration Data Instance 2 Offset",
|
"label": "Data Instance 2 Calibration Offset",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "0.00",
|
"default": "0.00",
|
||||||
"description": "Offset for data instance 2",
|
"description": "Offset for data instance 2",
|
||||||
|
@ -771,7 +785,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calSlope2",
|
"name": "calSlope2",
|
||||||
"label": "Calibration Data Instance 2 Slope",
|
"label": "Data Instance 2 Calibration Slope",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "1.00",
|
"default": "1.00",
|
||||||
"description": "Slope for data instance 2",
|
"description": "Slope for data instance 2",
|
||||||
|
@ -780,6 +794,20 @@
|
||||||
"obp60":"true"
|
"obp60":"true"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "calSmooth2",
|
||||||
|
"label": "Data Instance 2 Smoothing",
|
||||||
|
"type": "number",
|
||||||
|
"default": "0",
|
||||||
|
"check": "checkMinMax",
|
||||||
|
"min": 0,
|
||||||
|
"max": 9,
|
||||||
|
"description": "Smoothing factor for data instance 2",
|
||||||
|
"category": "OBP60 Calibrations",
|
||||||
|
"capabilities": {
|
||||||
|
"obp60":"true"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "calInstance3",
|
"name": "calInstance3",
|
||||||
"label": "Calibration Data Instance 3",
|
"label": "Calibration Data Instance 3",
|
||||||
|
@ -807,7 +835,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calOffset3",
|
"name": "calOffset3",
|
||||||
"label": "Calibration Data Instance 3 Offset",
|
"label": "Data Instance 3 Calibration Offset",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "0.00",
|
"default": "0.00",
|
||||||
"description": "Offset for data instance 3",
|
"description": "Offset for data instance 3",
|
||||||
|
@ -818,7 +846,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calSlope3",
|
"name": "calSlope3",
|
||||||
"label": "Calibration Data Instance 3 Slope",
|
"label": "Data Instance 3 Calibration Slope",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": "1.00",
|
"default": "1.00",
|
||||||
"description": "Slope for data instance 3",
|
"description": "Slope for data instance 3",
|
||||||
|
@ -827,6 +855,20 @@
|
||||||
"obp60":"true"
|
"obp60":"true"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "calSmooth3",
|
||||||
|
"label": "Data Instance 3 Smoothing",
|
||||||
|
"type": "number",
|
||||||
|
"default": "0",
|
||||||
|
"check": "checkMinMax",
|
||||||
|
"min": 0,
|
||||||
|
"max": 9,
|
||||||
|
"description": "Smoothing factor for data instance 3",
|
||||||
|
"category": "OBP60 Calibrations",
|
||||||
|
"capabilities": {
|
||||||
|
"obp60":"true"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "display",
|
"name": "display",
|
||||||
"label": "Display Mode",
|
"label": "Display Mode",
|
||||||
|
|
Loading…
Reference in New Issue