diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 7c67db53..ddf65819 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -105,7 +105,13 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution { if (GENERAL[_analog]->ROI[i]->result_float >= 0) { - prev = ZeigerEvalHybrid(GENERAL[_analog]->ROI[i]->result_float, GENERAL[_analog]->ROI[i+1]->result_float, prev); + // Digital Modelle haben nur x.0 und benötigen eine andere Prüfung bei Nullübergang + if (CNNType != Digital){ + prev = ZeigerEvalDigital(GENERAL[_analog]->ROI[i]->result_float, GENERAL[_analog]->ROI[i+1]->result_float, prev); + + } else { + prev = ZeigerEvalHybrid(GENERAL[_analog]->ROI[i]->result_float, GENERAL[_analog]->ROI[i+1]->result_float, prev); + } result = std::to_string(prev) + result; } @@ -169,6 +175,46 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } +int ClassFlowCNNGeneral::ZeigerEvalDigital(float zahl, float zahl_vorgaenger, int eval_vorgaenger) +{ + int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; + + if (zahl_vorgaenger < 0) // keine Vorzahl vorhanden !!! --> Runde die Zahl + { + if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht + return ((int) round(zahl) + 10) % 10; + else + return ((int) trunc(zahl) + 10) % 10; + } + + if (zahl_vorgaenger > 9.2) // Ziffernwechsel beginnt + { + if (eval_vorgaenger == 0) // Wechsel hat schon stattgefunden + { + return ((int) round(zahl) + 10) % 10; // Annahme, dass die neue Zahl schon in der Nähe des Ziels ist + } + else + { + if (zahl_vorgaenger <= 9.5) // Wechsel startet gerade, aber beginnt erst + { + if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht + return ((int) round(zahl) + 10) % 10; + else + return ((int) trunc(zahl) + 10) % 10; + } + else + { + return ((int) trunc(zahl) + 10) % 10; // Wechsel schon weiter fortgeschritten, d.h. über 2 als Nachkomma + } + } + } + + if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht + return ((int) round(zahl) + 10) % 10; + + return ((int) trunc(zahl) + 10) % 10; +} + int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int eval_vorgaenger) { int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 66aa56d5..9d5b0a2c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -36,6 +36,7 @@ protected: int ZeigerEval(float zahl, int ziffer_vorgaenger); int ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int eval_vorgaenger); + int ZeigerEvalDigital(float zahl, float zahl_vorgaenger, int eval_vorgaenger); bool doNeuralNetwork(string time); diff --git a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp index 18129ada..5fec93d9 100644 --- a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp +++ b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp @@ -5,6 +5,7 @@ class UnderTest : public ClassFlowCNNGeneral { public: using ClassFlowCNNGeneral::ZeigerEval; using ClassFlowCNNGeneral::ZeigerEvalHybrid; + using ClassFlowCNNGeneral::ZeigerEvalDigital; using ClassFlowCNNGeneral::ClassFlowCNNGeneral; }; @@ -44,6 +45,12 @@ void test_ZeigerEval() // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6) TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.5, 0)); + // the 5.5 (digital100) is not above 6 and the previous digit (analog) not over Zero (9.7) + TEST_ASSERT_EQUAL(5, undertest.ZeigerEval(5.5, 9)); + + // the 5.0 (digital100) and the previous digit (analog) not over Zero (9.5). The transition is not completed + TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(5.0, 9)); + } /** @@ -84,9 +91,24 @@ void test_ZeigerEvalHybrid() { TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 0)); // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6) - TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 9)); + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 9)); + + // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.5, 9)); + //56.95797 // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) - TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.5, 9)); + TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.5, 9.7, 9)); + + // the 5.0 (digital100) and the previous digit (analog) not over Zero (9.5). The transition is not completed + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(5.0, 9.7, 9)); } + +void test_ZeigerEvalDigital() { + UnderTest undertest = UnderTest(nullptr, Digital); + + // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) + TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalDigital(5.0, 9.7, 9)); + +} diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index 48b2993e..be611a88 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -11,6 +11,7 @@ extern "C" void app_main() RUN_TEST(test_ZeigerEval); RUN_TEST(test_ZeigerEvalHybrid); + RUN_TEST(test_ZeigerEvalDigital); UNITY_END(); } \ No newline at end of file