mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 04:26:58 +03:00
fix analogtodigital: remove rounding
This commit is contained in:
@@ -35,7 +35,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution
|
|||||||
if (GENERAL[_analog]->ROI.size() == 0)
|
if (GENERAL[_analog]->ROI.size() == 0)
|
||||||
return result;
|
return result;
|
||||||
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::getReadout _analog=" + std::to_string(_analog) + ", _extendedResolution=" + std::to_string(_extendedResolution) + ", prev=" + std::to_string(prev));
|
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::getReadout _analog=" + std::to_string(_analog) + ", _extendedResolution=" + std::to_string(_extendedResolution) + ", prev=" + std::to_string(prev));
|
||||||
|
|
||||||
if (CNNType == Analogue || CNNType == Analogue100)
|
if (CNNType == Analogue || CNNType == Analogue100)
|
||||||
{
|
{
|
||||||
float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float;
|
float zahl = GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float;
|
||||||
@@ -147,7 +147,6 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger,
|
|||||||
|
|
||||||
if (AnalogerVorgaenger)
|
if (AnalogerVorgaenger)
|
||||||
{
|
{
|
||||||
// result = ZeigerEvalAnalogToDigitNeu(zahl, eval_vorgaenger);
|
|
||||||
result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger);
|
result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger);
|
||||||
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - Analoger Vorgänger, Bewertung über ZeigerEvalAnalogNeu = " + std::to_string(result) +
|
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));
|
" zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
|
||||||
@@ -218,12 +217,14 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor
|
|||||||
|
|
||||||
if ((ziffer_vorgaenger >= DigitalUebergangsbereichVorgaengerAnalogToDigit ) && (ziffer_vorgaenger <= (10.0 - DigitalUebergangsbereichVorgaengerAnalogToDigit)))
|
if ((ziffer_vorgaenger >= DigitalUebergangsbereichVorgaengerAnalogToDigit ) && (ziffer_vorgaenger <= (10.0 - DigitalUebergangsbereichVorgaengerAnalogToDigit)))
|
||||||
{
|
{
|
||||||
|
/* Bei DigitalUebergangsbereichVorgaengerAnalogToDigit verursacht runden weitere Fehler
|
||||||
// kein Ziffernwechsel, da Vorgänger weit genug weg ist (0+/-DigitalUebergangsbereichVorgaenger) --> zahl wird gerundet
|
// kein Ziffernwechsel, da Vorgänger weit genug weg ist (0+/-DigitalUebergangsbereichVorgaenger) --> zahl wird gerundet
|
||||||
if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
|
if ((ergebnis_nachkomma <= 2) || (ergebnis_nachkomma >= 8)) // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
|
||||||
result = ((int) round(zahl) + 10) % 10;
|
|
||||||
else
|
|
||||||
result = ((int) trunc(zahl) + 10) % 10;
|
result = ((int) trunc(zahl) + 10) % 10;
|
||||||
|
else
|
||||||
|
result = ((int) round(zahl) + 10) % 10;
|
||||||
|
*/
|
||||||
|
result = ((int) trunc(zahl) + 10) % 10;
|
||||||
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - kein Ziffernwechsel, da Vorkomma weit genug weg = " + std::to_string(result) +
|
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - kein Ziffernwechsel, da Vorkomma weit genug weg = " + std::to_string(result) +
|
||||||
" zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
|
" zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
#include <unity.h>
|
|
||||||
#include <ClassFlowCNNGeneral.h>
|
|
||||||
|
|
||||||
class UnderTestCNN : public ClassFlowCNNGeneral {
|
|
||||||
public:
|
|
||||||
using ClassFlowCNNGeneral::ZeigerEvalAnalogNeu;
|
|
||||||
using ClassFlowCNNGeneral::ZeigerEvalHybridNeu;
|
|
||||||
using ClassFlowCNNGeneral::ClassFlowCNNGeneral;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief test if all combinations of digit
|
|
||||||
* evaluation are running correctly
|
|
||||||
*/
|
|
||||||
void test_ZeigerEval()
|
|
||||||
{
|
|
||||||
UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100);
|
|
||||||
|
|
||||||
// the 5.2 is already above 5.0 and the previous digit too (3)
|
|
||||||
printf("Test 5.2, 3\n");
|
|
||||||
int result = undertest.ZeigerEvalAnalogNeu(5.2, 3);
|
|
||||||
TEST_ASSERT_EQUAL(5, result);
|
|
||||||
|
|
||||||
// the 5.2 is already above 5.0 and the previous digit not (9)
|
|
||||||
// so the current digit shoult be reduced (4.9)
|
|
||||||
printf("Test 5.2, 9\n");
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalAnalogNeu(5.2, 9));
|
|
||||||
|
|
||||||
printf("Test 4.4, 9\n");
|
|
||||||
// the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3)
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalAnalogNeu(4.4, 9));
|
|
||||||
|
|
||||||
printf("Test 4.5, 0\n");
|
|
||||||
// the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6)
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalAnalogNeu(4.5, 0));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief test if all combinations of digit
|
|
||||||
* evaluation are running correctly
|
|
||||||
*/
|
|
||||||
void test_ZeigerEvalHybrid() {
|
|
||||||
UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100);
|
|
||||||
|
|
||||||
// the 5.2 and no previous should round down
|
|
||||||
printf("ZeigerEvalHybridNeu(5.2, 0, -1)\n");
|
|
||||||
TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybridNeu(5.2, 0, -1));
|
|
||||||
|
|
||||||
// the 5.3 and no previous should trunc to 5
|
|
||||||
printf("ZeigerEvalHybridNeu(5.3, 0, -1)\n");
|
|
||||||
TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybridNeu(5.3, 0, -1));
|
|
||||||
|
|
||||||
printf("ZeigerEvalHybridNeu(5.7, 0, -1)\n");
|
|
||||||
// the 5.7 and no previous should trunc to 5
|
|
||||||
TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybridNeu(5.7, 0, -1));
|
|
||||||
|
|
||||||
// the 5.8 and no previous should round up to 6
|
|
||||||
printf("ZeigerEvalHybridNeu(5.8, 0, -1)\n");
|
|
||||||
TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybridNeu(5.8, 0, -1));
|
|
||||||
|
|
||||||
// the 5.7 with previous and the previous between 0.3-0.5 should round up to 6
|
|
||||||
TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybridNeu(5.7, 0.4, 1));
|
|
||||||
|
|
||||||
// the 5.3 with previous and the previous between 0.3-0.7 should round down to 5
|
|
||||||
TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybridNeu(5.3, 0.7, 1));
|
|
||||||
|
|
||||||
// the 5.3 with previous and the previous <=0.5 should trunc to 5
|
|
||||||
TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybridNeu(5.3, 0.1, 1));
|
|
||||||
|
|
||||||
// the 5.3 with previous and the previous >=9.5 should reduce to 4
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybridNeu(5.3, 9.6, 9));
|
|
||||||
|
|
||||||
// the 5.7 with previous and the previous >=9.5 should trunc to 5
|
|
||||||
TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybridNeu(5.7, 9.6, 9));
|
|
||||||
|
|
||||||
// the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybridNeu(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.ZeigerEvalHybridNeu(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.ZeigerEvalHybridNeu(4.5, 9.5, 9));
|
|
||||||
|
|
||||||
// 59.96889 - Pre: 58.94888
|
|
||||||
// 8.6 : 9.8 : 6.7
|
|
||||||
// the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
|
|
||||||
TEST_ASSERT_EQUAL(8, undertest.ZeigerEvalHybridNeu(8.6, 9.8, 9));
|
|
||||||
|
|
||||||
// pre = 9.9 (0.0 raw)
|
|
||||||
// zahl = 1.8
|
|
||||||
TEST_ASSERT_EQUAL(2, undertest.ZeigerEvalHybridNeu(1.8, 9.0, 9));
|
|
||||||
|
|
||||||
// if a digit have an early transition and the pointer is < 9.0
|
|
||||||
// prev (pointer) = 6.2, but on digital readout = 6.0 (prev is int parameter)
|
|
||||||
// zahl = 4.6
|
|
||||||
TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybridNeu(4.6, 6.0, 6));
|
|
||||||
|
|
||||||
|
|
||||||
// issue #879 vorgaenger is -1, zahl = 6.7
|
|
||||||
//TEST_ASSERT_EQUAL(7, undertest.ZeigerEvalHybrid(6.7, -1.0, -1));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -303,6 +303,20 @@ void test_doFlow() {
|
|||||||
result = process_doFlow(analogs, digits, Digital100, false, true, -3);
|
result = process_doFlow(analogs, digits, Digital100, false, true, -3);
|
||||||
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
||||||
|
|
||||||
|
// Fehler bei V12.0.1
|
||||||
|
// Lokal
|
||||||
|
digits = { 9.8, 9.8, 1.9, 0.9, 0.9, 9.9, 2.9, 4.8}; // 169.3493 als falsches Ergebnis
|
||||||
|
analogs = { 5.5};
|
||||||
|
expected = "211.0345";
|
||||||
|
expected_extended= "211.03455";
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,9 +402,11 @@ std::string process_doFlow(std::vector<float> analog, std::vector<float> digits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
string time;
|
string time;
|
||||||
|
|
||||||
// run test
|
// run test
|
||||||
TEST_ASSERT_TRUE(undertestPost->doFlow(time));
|
TEST_ASSERT_TRUE(undertestPost->doFlow(time));
|
||||||
|
|
||||||
|
|
||||||
return undertestPost->getReadout(0);
|
return undertestPost->getReadout(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <unity.h>
|
#include <unity.h>
|
||||||
#include "components/jomjol-flowcontroll/test_cnnflowcontroll.cpp"
|
|
||||||
#include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
|
#include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
|
||||||
// SD-Card ////////////////////
|
// SD-Card ////////////////////
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
@@ -8,6 +7,24 @@
|
|||||||
#include "driver/sdmmc_host.h"
|
#include "driver/sdmmc_host.h"
|
||||||
#include "driver/sdmmc_defs.h"
|
#include "driver/sdmmc_defs.h"
|
||||||
static const char *TAGMAIN = "main";
|
static const char *TAGMAIN = "main";
|
||||||
|
#define __SD_USE_ONE_LINE_MODE__
|
||||||
|
#include "server_GPIO.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void initGPIO()
|
||||||
|
{
|
||||||
|
gpio_config_t io_conf;
|
||||||
|
//set as output mode
|
||||||
|
io_conf.mode = gpio_mode_t::GPIO_MODE_INPUT;
|
||||||
|
//bit mask of the pins that you want to set,e.g.GPIO18/19
|
||||||
|
io_conf.pull_down_en = gpio_pulldown_t::GPIO_PULLDOWN_ENABLE;
|
||||||
|
//set pull-up mode
|
||||||
|
io_conf.pull_up_en = gpio_pullup_t::GPIO_PULLUP_DISABLE;
|
||||||
|
//configure GPIO with the given settings
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
}
|
||||||
|
|
||||||
bool Init_NVS_SDCard()
|
bool Init_NVS_SDCard()
|
||||||
{
|
{
|
||||||
@@ -80,11 +97,10 @@ bool Init_NVS_SDCard()
|
|||||||
*/
|
*/
|
||||||
extern "C" void app_main()
|
extern "C" void app_main()
|
||||||
{
|
{
|
||||||
|
initGPIO();
|
||||||
Init_NVS_SDCard();
|
Init_NVS_SDCard();
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
// RUN_TEST(test_ZeigerEval);
|
|
||||||
// RUN_TEST(test_ZeigerEvalHybrid);
|
|
||||||
RUN_TEST(test_doFlow);
|
RUN_TEST(test_doFlow);
|
||||||
|
|
||||||
UNITY_END();
|
UNITY_END();
|
||||||
|
|||||||
Reference in New Issue
Block a user