diff --git a/Changelog.md b/Changelog.md index b18196c7..349247e8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ - Updated built environment to `espressif32@v5.2.0` - [#1176](https://github.com/jomjol/AI-on-the-edge-device/discussions/1176) accept minor negative values (-0.2) if extended resolution is enabled +- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter AnalogDigitalTransitionStart. It can setup very early and very late digit transition starts. ### Fixed - [#1116](https://github.com/jomjol/AI-on-the-edge-device/issues/1116) precision problem at setting prevalue diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 661ce729..77e00d7c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -10,7 +10,7 @@ static const char* TAG = "flow_analog"; -bool debugdetailgeneral = false; + ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG) { @@ -28,7 +28,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy flowpostalignment = _flowalign; } -string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog) +string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog, float analogDigitalTransitionStart) { string result = ""; @@ -87,7 +87,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution { // prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev); if (_vorgaengerAnalog >= 0) - prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true); + prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true, analogDigitalTransitionStart); else prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev); result = std::to_string(prev); @@ -127,7 +127,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } -int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger) +int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger, float digitalAnalogTransitionStart) { int result; int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; @@ -147,7 +147,7 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, if (AnalogerVorgaenger) { - result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger); + result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger, digitalAnalogTransitionStart); if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - Analoger Vorgänger, Bewertung über ZeigerEvalAnalogNeu = " + std::to_string(result) + " zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); return result; @@ -201,55 +201,49 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, } -int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger) +int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart) { int result; int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10; + bool roundedUp = false; - if (ziffer_vorgaenger < 0) - { - result = (int) floor(zahl); - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - kein Vorgänger - Ergebnis = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " AnalogFehler = " + std::to_string(AnalogFehler)); - return result; - } - - if (ziffer_vorgaenger <= 3 && eval_vorgaenger<9) // Nulldurchgang hat stattgefunden (!Bewertung über Prev_value und nicht Zahl!) --> hier aufrunden (2.8 --> 3, aber auch 3.1 --> 3) - // aber Sonderfall ziffer_vorgaeger = 0.1 vor_vorgaenger 9.9 => eval_vorgaenger ist 9, damit hat Nulldurchgang nicht stattgefunden. - { - if (ergebnis_nachkomma > 5) - result = (ergebnis_vorkomma + 1) % 10; - else - result = ergebnis_vorkomma; - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang hat stattgefunden = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); - return result; - } - - // Vorlauf ziffer_vorgaenger <=9.9 und ergebnis_nachkomma >=0..1 (digits drehen nach umschalten nicht gleich weiter) - // Beispiel dig=4.0, ana=9.1 ==> dig=3 - - // Nachlauf ziffer_vorgaenger 0..2 und ergebnis_nachkomma 8..9 - // Beispiel dig=6.8, ana=2.2 ==> dig=7 - // dig=4.8, ana=5.5 => dig=4 - - // Vorlauf bei ergebnis_nachkomma >=0..1 und ziffer_vorgaenger 8..9 - if (ergebnis_nachkomma <= 1 && ziffer_vorgaenger>=8) { - result = (ergebnis_vorkomma - 1 + 10) % 10; + // Innerhalb der digitalen Unschaefe + if (ergebnis_nachkomma >= (10-DigitalUnschaerfe * 10)) { // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht + result = (int) (round(zahl) + 10) % 10; + roundedUp = true; + // vor/nachkomma neu berechnen, da wir anhand der Unschaefe die Zahl anpassen. + ergebnis_nachkomma = ((int) floor(result * 10)) % 10; + ergebnis_vorkomma = ((int) floor(result) + 10) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - digitaleUnschaerfe - Ergebnis = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger: " + std::to_string(ziffer_vorgaenger) + + " erg_vorkomma: " + std::to_string(ergebnis_vorkomma) + + " erg_nachkomma: " + std::to_string(ergebnis_nachkomma)); } else { - // Ziffer bleibt bei x.8 oder x.9 "hängen", kommt also nicht richtig auf x.0 - // muss eine Rundung erfolgen - // jedoch nicht im während der Transition (ziffer_vorgaenger>=8) - if (eval_vorgaenger<9 && ziffer_vorgaenger<8 && ergebnis_nachkomma >= 8) - result = ((int) round(zahl) + 10) % 10; - else - result = ergebnis_vorkomma; + result = (int) ((int) trunc(zahl) + 10) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - KEINE digitaleUnschaerfe - Ergebnis = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger)); } - - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - 9.0 --> noch kein Nulldurchgang = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); + + // Kein Nulldurchgang hat stattgefunden. + // Nur eval_vorgaenger verwendet, da ziffer_vorgaenger hier falsch sein könnte. + // ziffer_vorgaenger<=0.1 & eval_vorgaenger=9 entspricht analog wurde zurückgesetzt wegen vorhergehender analog, die noch nicht auf 0 sind. + if ((eval_vorgaenger>=6 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) + // digit läuft dem Analog vor. Darf aber erst passieren, wenn + // digit wirklich schnon los läuft, deshalb 9 + || (eval_vorgaenger>9 && ziffer_vorgaenger>analogDigitalTransitionStart && ergebnis_nachkomma<=1)) + + { + result = ((ergebnis_vorkomma+10) - 1) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang noch nicht stattgefunden = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + + " erg_nachkomma = " + std::to_string(ergebnis_nachkomma)); + + } + return result; + } int ClassFlowCNNGeneral::ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 055df5e3..5731c0a2 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,6 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: + bool debugdetailgeneral = true; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; @@ -28,7 +29,6 @@ protected: float DigitalUnschaerfe = 0.2; int DigitalBand = 3; float DigitalAnalogerVorgaengerUebergangsbereich = 2; - // nicht mehr benötigt float DigitalUebergangsbereichVorgaengerAnalogToDigit = 1; // war vorher 2 float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7 float DigitalUebergangsbereichVorlauf = 9.7; // Vorlauf-Nulldurchgang passiert erst ab ca. 9.7 @@ -41,8 +41,8 @@ protected: bool SaveAllFiles; int ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger); - int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger); - int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false); + int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart); + int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false, float analogDigitalTransitionStart=9.2); @@ -58,7 +58,7 @@ public: bool doFlow(string time); string getHTMLSingleStep(string host); - string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1); + string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1, float analogDigitalTransitionStart=9.2); void DrawROI(CImageBasis *_zw); diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index c296ca27..c7ebc693 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -46,6 +46,7 @@ struct NumberPost { int AnzahlDigital; int DecimalShift; int DecimalShiftInitial; + float AnalogDigitalTransitionStart; // Wann ist das digit > x.1, also wann fängt es an zu kippen int Nachkomma; bool isExtendedResolution; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index e0b900eb..d500a1ec 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -343,6 +343,29 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } } +void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) +{ + string _digit, _decpos; + int _pospunkt = _decsep.find_first_of("."); +// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); + if (_pospunkt > -1) + _digit = _decsep.substr(0, _pospunkt); + else + _digit = "default"; + + for (int j = 0; j < NUMBERS.size(); ++j) + { + float _zwdc = 9.2; + { + _zwdc = stof(_value); + } + if (_digit == "default" || NUMBERS[j]->name == _digit) // erstmal auf default setzen (falls sonst nichts gesetzt) + { + NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc; + + } + } +} void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) @@ -447,6 +470,10 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { handleDecimalSeparator(zerlegt[0], zerlegt[1]); } + if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (zerlegt.size() > 1)) + { + handleAnalogDigitalTransitionStart(zerlegt[0], zerlegt[1]); + } if ((toUpper(_param) == "MAXRATEVALUE") && (zerlegt.size() > 1)) { handleMaxRateValue(zerlegt[0], zerlegt[1]); @@ -557,6 +584,7 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->DecimalShift = 0; _number->DecimalShiftInitial = 0; _number->isExtendedResolution = false; + _number->AnalogDigitalTransitionStart=9.2; _number->FlowRateAct = 0; // m3 / min @@ -674,7 +702,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (NUMBERS[j]->digit_roi) { if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float) + NUMBERS[j]->ReturnRawValue; + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; else NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 9d63804b..dac4d4f1 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -41,7 +41,7 @@ protected: void handleMaxRateValue(string _decsep, string _value); void handleDecimalExtendedResolution(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value); - + void handleAnalogDigitalTransitionStart(string _decsep, string _value); diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp new file mode 100644 index 00000000..a118a74c --- /dev/null +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -0,0 +1,104 @@ +#include +#include + +class UnderTestCNNGeneral : public ClassFlowCNNGeneral { + public: + UnderTestCNNGeneral( ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : + ClassFlowCNNGeneral(_flowalign, _cnntype) {}; + + using ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu; + + +}; + + +/** + * @brief + * + * Transition = x.8 - x.2 hier keine Transition in den Testfaellen + * Versatz = dig=x.n, ana= n.y: kein Versatz, da beide "n" gleich + */ +void test_analogToDigit_Standard() { + + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // 4.8 ist eine "hängende" 5. Heißt sie ist nicht bis auf 5.0 umgesprungen. + // ab Transition sollte trotzdem ein "hängendes Digit" gerundet werden. + // Transition = ja + // Versatz = nein + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu(4.8, 8.0, 8, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 + // Standard: dig=9.6, ana=6.8 => erg=9 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.6, 6.8, 6, 9.2)); + + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 + // Standard: dig=4.6, ana=6.2 => erg=4 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.6, 6.2, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Hängendes digit () + // Standard: dig=6.8, ana=8.6 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Ebenfalls Hängendes digit () bei kleinem Zeiger nach 0-Durchlauf + // Standard: dig=6.8, ana=1.0 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 1.0, 1, 9.2)); + + +} + +void test_analogToDigit_Transition() { + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175 + // Standard: dig=3.9, ana=9.7 => erg=3 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(3, undertest->ZeigerEvalAnalogToDigitNeu( 3.9, 9.7, 9, 9.2)); + + // ohne Referenz + // Standard: dig=4.0, ana=9.1 => erg=4 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit ist bei analog 9.1 noch nicht losgelaufen + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.0, 9.1, 9, 9.2)); + + // ohne Referenz + // Standard: dig=9.8, ana=0.1, ana_2=9.9 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: analog wird durch vorherigen analog wieder auf 9 gesetzt + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.8, 0.1, 9, 9.2)); + + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333 + // Standard: dig=5.9, ana=9.4 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu( 5.9, 9.4, 9, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + // Standard: dig=1.8, ana=7.8 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit läuft mit Analog mit. Deshalb 1.8 (vs. 7.8) + TEST_ASSERT_EQUAL_INT(1, undertest->ZeigerEvalAnalogToDigitNeu( 1.8, 7.8, 7, 7.7)); + +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp similarity index 87% rename from code/test/components/jomjol-flowcontroll/test_flow.cpp rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 41d02a75..c37e0577 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) @@ -42,7 +42,9 @@ std::string process_doFlow(std::vector analog, std::vector digits, // run test TEST_ASSERT_TRUE(_undertestPost->doFlow(time)); - return _undertestPost->getReadout(0); + std::string result = _undertestPost->getReadout(0); + delete _undertestPost; + return result; } @@ -140,3 +142,13 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) { } } } + +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart) { + if (_analogdigitTransistionStart!=0) { + std::vector* NUMBERS = _underTestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Setting decimal shift on number: %d to %f\n", _n, _analogdigitTransistionStart); + (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; + } + } +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h similarity index 92% rename from code/test/components/jomjol-flowcontroll/test_flow.h rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h index e9f54262..6b103f25 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow.h +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h @@ -99,4 +99,12 @@ void setExtendedResolution(UnderTestPost* _UnderTestPost, bool _extendedResoluti */ void setDecimalShift(UnderTestPost* _UnderTestPost, int decimal_shift); +/** + * @brief Set the Analogdigit Transistion Start + * + * @param _underTestPost the testobject + * @param _analogdigitTransistionStart the analog to digit transition start + */ +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart); + #endif // TEST_FLOW_H diff --git a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp index 6fd55da7..0a650deb 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index da9e001d..228ff4d8 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -1,9 +1,12 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" /** + * ACHTUNG! Die Test laufen aktuell nur mit ausgeschaltetem Debug in ClassFlowCNNGeneral + * + * * @brief Testet die doFlow-Methode von ClassFlowPostprocessing * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits @@ -29,7 +32,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 * * Das Ergebnis sollte "376529.6" sein. */ @@ -40,7 +43,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 * * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true */ @@ -81,13 +84,13 @@ void test_doFlow() { digits = { 1.1, 9.0, 4.0}; analogs = { 8.1, 2.6, 6.25, 9.7}; - expected = "193.8259"; + expected = "194.8259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); digits = { 1.1, 9.0, 4.0}; analogs = { 9.1, 2.6, 6.25, 9.7}; - expected = "193.9259"; + expected = "194.9259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); @@ -346,10 +349,10 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issue-1391153343 - digits = { 1.0, 4.0, 2.0}; // 142.9269 als falsches Ergebnis + digits = { 1.0, 4.0, 2.0}; // 141.9269 als falsches Ergebnis analogs = { 9.2, 2.5, 6.8, 9.0}; - expected = "141.9269"; - expected_extended= "141.92690"; + expected = "142.9269"; + expected_extended= "142.92690"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -363,25 +366,31 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388 digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis + // letztes digit läuft mit analog zeiger mit. Hier nur lösbar mit setAnalogdigitTransistionStart=7.7 analogs = { 8.7}; expected = "170.0528"; expected_extended= "170.05287"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); - + delete undertestPost; // Fehler bei rolling post V12.0.1 // lokal watermeter1 - digits = { 0.0, 0.0, 9.0, 1.0}; //91.88174 als falsches Ergebnis + digits = { 0.0, 0.0, 9.0, 1.0}; //90.88174 als falsches Ergebnis analogs = {9.0, 8.0, 1.8, 7.4}; - expected = "90.8817"; - expected_extended= "90.88174"; + expected = "91.8817"; + expected_extended= "91.88174"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -426,9 +435,8 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + expected = "577.8649"; + expected_extended= "577.86490"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -440,12 +448,26 @@ void test_doFlow() { // Fehler V12.0.1 "TODO 00211.03480 vs 00211.03580" - // Lokal - digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis - analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + // Lokal "Hängendes Digit" + digits = { 2.0, 1.0, 1.0, 0.0, 3.0, 4.8}; // 00211.03480 als falsches Ergebnis + analogs = {8.0}; + expected = "211.0358"; + expected_extended= "211.03580"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, -3); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1281231468 + digits = { 1.0, 1.9, 6.0}; // 125.923 als falsches Ergebnis + analogs = {9.3, 2.3, 3.1}; + expected = "126.923"; + expected_extended= "126.9231"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -455,7 +477,42 @@ void test_doFlow() { result = process_doFlow(analogs, digits, Digital100, false, true, 0); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 3.0, 8.1, 5.9, 0.0, 5.0, 6.7}; // 386.05672 als richtiges Ergebnis. Letztes digit schein mit dem Analogzeiger mitzulaufen + analogs = {7.2}; + expected = "386.0567"; + expected_extended= "386.05672"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, -3); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 1.2, 7.0, 1.2, 2.0, 4.0, 1.8}; // 171.24278 als falsches Ergebnis. + // Test ist nur erfolgreich mit Veränderung des AnalogdigitTransistionStart + analogs = {7.8}; + expected = "171.2417"; + expected_extended= "171.24178"; + + // extendResolution=false + undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; + + // checkConsistency=false und extendResolution=true + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + delete undertestPost; } diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index de4343cc..f91be40c 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -1,8 +1,9 @@ #include -#include "components/jomjol-flowcontroll/test_flow.cpp" +#include "components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp" #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp" #include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp" +#include "components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp" // SD-Card //////////////////// #include "nvs_flash.h" #include "esp_vfs_fat.h" @@ -103,9 +104,12 @@ extern "C" void app_main() initGPIO(); Init_NVS_SDCard(); UNITY_BEGIN(); - - RUN_TEST(testNegative); - RUN_TEST(test_doFlow); + + RUN_TEST(testNegative); + + RUN_TEST(test_analogToDigit_Standard); + RUN_TEST(test_analogToDigit_Transition); + RUN_TEST(test_doFlow); UNITY_END(); } \ No newline at end of file diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index ee7c75fc..138e9a72 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -42,6 +42,7 @@ main.ana4 155 328 92 92 false [PostProcessing] main.DecimalShift = 0 +main.AnalogDigitalTransitionStart = 9.2 PreValueUse = true PreValueAgeStartup = 720 AllowNegativeRates = false diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index c665ba27..edc6c947 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -489,6 +489,20 @@ textarea { Shift the digit separator within the digital digits (positiv and negativ) + + + + + + + + + + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. + Only used on combination of digits and analog pointers. Default=9.2 + + + @@ -1670,6 +1684,7 @@ function UpdateInputIndividual() if (NUNBERSAkt != -1) { ReadParameter(param, "PostProcessing", "DecimalShift", true, NUNBERSAkt) + ReadParameter(param, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateType", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt) @@ -1679,6 +1694,7 @@ function UpdateInputIndividual() var sel = document.getElementById("Numbers_value1"); NUNBERSAkt = sel.selectedIndex; WriteParameter(param, category, "PostProcessing", "DecimalShift", true, NUNBERSAkt); + WriteParameter(param, category, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateType", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt); diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index afbedc5d..9e7eb8b7 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -102,6 +102,7 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "DecimalShift", 1, true); + ParamAddValue(param, catname, "AnalogDigitalTransitionStart", 1, true); ParamAddValue(param, catname, "PreValueUse"); ParamAddValue(param, catname, "PreValueAgeStartup"); ParamAddValue(param, catname, "AllowNegativeRates");