Browse Source

code optimization

atan2 replaced by fast_atan2 and pow by pow10_double
michael 1 month ago
parent
commit
c659810b18

+ 4 - 3
code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp

@@ -8,7 +8,9 @@
 #include "CTfLiteClass.h"
 #include "ClassLogFile.h"
 #include "esp_log.h"
+
 #include "../../include/defines.h"
+#include "Helper.h"
 
 static const char* TAG = "CNN";
 
@@ -671,8 +673,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) {
                 case Analogue:
                     LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Analogue");
                     {
-                        float f1, f2;
-                        f1 = 0; f2 = 0;
+                        float f1 = 0, f2 = 0;
 
                         tflite->LoadInputImageBasis(GENERAL[n]->ROI[roi]->image);        
                         tflite->Invoke();
@@ -680,7 +681,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) {
 
                         f1 = tflite->GetOutputValue(0);
                         f2 = tflite->GetOutputValue(1);
-                        float result = fmod(atan2(f1, f2) / (M_PI * 2) + 2, 1);
+                        float result = fmod(fast_atan2(f1, f2) / (M_PI * 2) + 2, 1);
                               
                         if(GENERAL[n]->ROI[roi]->CCW) {
                             GENERAL[n]->ROI[roi]->result_float = 10 - (result * 10);

+ 12 - 11
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -1,5 +1,4 @@
 #include "ClassFlowPostProcessing.h"
-#include "Helper.h"
 #include "ClassFlowTakeImage.h"
 #include "ClassLogFile.h"
 
@@ -11,7 +10,9 @@
 #include "time_sntp.h"
 
 #include "esp_log.h"
+
 #include "../../include/defines.h"
+#include "Helper.h"
 
 static const char* TAG = "POSTPROC";
 
@@ -894,8 +895,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) {
 
         if (PreValueUse && NUMBERS[j]->PreValueOkay) {
             if ((NUMBERS[j]->Nachkomma > 0) && (NUMBERS[j]->ChangeRateThreshold > 0)) {
-                double _difference1 = (NUMBERS[j]->PreValue - (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
-                double _difference2 = (NUMBERS[j]->PreValue + (NUMBERS[j]->ChangeRateThreshold / pow(10, NUMBERS[j]->Nachkomma)));
+                double _difference1 = (NUMBERS[j]->PreValue - (NUMBERS[j]->ChangeRateThreshold / pow10_double(NUMBERS[j]->Nachkomma)));
+                double _difference2 = (NUMBERS[j]->PreValue + (NUMBERS[j]->ChangeRateThreshold / pow10_double(NUMBERS[j]->Nachkomma)));
 
                 if ((NUMBERS[j]->Value >= _difference1) && (NUMBERS[j]->Value <= _difference2)) {
                     NUMBERS[j]->Value = NUMBERS[j]->PreValue;
@@ -911,7 +912,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) {
                     if (NUMBERS[j]->isExtendedResolution) {
                         LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value) 
                                                     + ", preValue=" + std::to_string(NUMBERS[j]->PreValue) 
-                                                    + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))));
+                                                    + ", preToll=" + std::to_string(NUMBERS[j]->PreValue - (2 / pow10_double(NUMBERS[j]->Nachkomma))));
                     } 
 
                     NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " "; 
@@ -1096,7 +1097,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) {
             pot = posPunkt - posN;
         }
 
-        zw =_prevalue / pow(10, pot);
+        zw =_prevalue / pow10_double(pot);
         ziffer = ((int) zw) % 10;
         input[posN] = ziffer + 48;
 
@@ -1128,27 +1129,27 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams
     pot_max = ((int) log10(input)) + 1;
 	
     while (pot <= pot_max) {
-        zw = input / pow(10, pot-1);
+        zw = input / pow10_double(pot-1);
         aktdigit_before = ((int) zw) % 10;
-        zw = _preValue / pow(10, pot-1);
+        zw = _preValue / pow10_double(pot-1);
         olddigit_before = ((int) zw) % 10;
 
-        zw = input / pow(10, pot);
+        zw = input / pow10_double(pot);
         aktdigit = ((int) zw) % 10;
-        zw = _preValue / pow(10, pot);
+        zw = _preValue / pow10_double(pot);
         olddigit = ((int) zw) % 10;
 
         no_nulldurchgang = (olddigit_before <= aktdigit_before);
 
         if (no_nulldurchgang) {
             if (aktdigit != olddigit) {
-                input = input + ((float) (olddigit - aktdigit)) * pow(10, pot);     // New Digit is replaced by old Digit;
+                input = input + ((float) (olddigit - aktdigit)) * pow10_double(pot);     // New Digit is replaced by old Digit;
             }
         }
         else {
             // despite zero crossing, digit was not incremented --> add 1
             if (aktdigit == olddigit) {
-                input = input + ((float) (1)) * pow(10, pot);   // add 1 at the point
+                input = input + ((float) (1)) * pow10_double(pot);   // add 1 at the point
             }
         }
 			

+ 4 - 2
code/components/jomjol_image_proc/CAlignAndCutImage.cpp

@@ -6,7 +6,9 @@
 #include <algorithm>
 #include <esp_log.h>
 #include "psram.h"
+
 #include "../../include/defines.h"
+#include "Helper.h"
 
 static const char* TAG = "c_align_and_cut_image";
 
@@ -69,8 +71,8 @@ bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2)
 
     float w_org, w_ist, d_winkel;
 
-    w_org = atan2(_temp2->found_y - _temp1->found_y, _temp2->found_x - _temp1->found_x);
-    w_ist = atan2(r1_y - r0_y, r1_x - r0_x);
+    w_org = fast_atan2((float)(_temp2->found_y - _temp1->found_y), (float)(_temp2->found_x - _temp1->found_x));
+    w_ist = fast_atan2((float)(r1_y - r0_y), (float)(r1_x - r0_x));
 
     d_winkel = (w_ist - w_org) * 180 / M_PI;