AlexanderTonn / SolarPowerhouse

Solar balkony power plant, which includes control logic for switching between micro inverter and battery depending on the state of charge. The repository containing any drawings and manuals.
Apache License 2.0
0 stars 0 forks source link

[BUG] Bool variable returning "183" or "76" #1

Closed AlexanderTonn closed 11 months ago

AlexanderTonn commented 11 months ago

:bug: Describe the bug

 :bangbang: To Reproduce**

Steps to reproduce the behavior:

:interrobang: Expected behavior

:camera: Screenshots

Serial monitor

Bildschirmfoto 2023-07-23 um 15 17 32

:computer: Desktop (please complete the following information):**

 :iphone: Smartphone (please complete the following information):**

Additional context

AlexanderTonn commented 11 months ago

I'm not clearly sure what the issue was, but i suppose that I did something wrong with the declaration and the including of the template function in "Util.h" and "util.ino".

AlexanderTonn commented 9 months ago

I had the same issue again with following Terminal Output:

  bool xTrigBatteryFull = edgeDetection(fBatteryVoltage, 
                                  fTrigBatteryFullPrevious, 
                                  edgeType::RISING_EDGE, 
                                  fTargetVoltageInverter);    // Battery is full after reaching 100%
  bool xTrigBatteryEmpty = edgeDetection(fBatteryVoltage, fTrigBatteryEmptyPrevious, edgeType::FALLING_EDGE, fTargetVoltageMppt); // Battery should charged if dropped down to 50%

  Serial.print("xTrigBatteryFull: ");
Serial.println(xTrigBatteryFull);
Serial.print("xTrigBatteryEmpty: ");
Serial.println(xTrigBatteryEmpty);
xTrigBatteryFull: 0
xTrigBatteryEmpty: 0

Reason for the issue

template<typename T1, typename T2, typename T3 >
auto edgeDetection (T1 TinputSignal, T2 &TpreviousSignal, edgeType Type, T3 Ttrigger ) -> bool {
  // RISING EDGE detection
  switch(Type)
  {
    case edgeType::RISING_EDGE :
    if (TinputSignal >= Ttrigger && TpreviousSignal < Ttrigger ) {
      TpreviousSignal = TinputSignal;
      return true;
    }
    // Resetting the signal if Ttrigger was reached
    else if ((TinputSignal >= Ttrigger && TpreviousSignal >= Ttrigger) 
          || (TinputSignal < Ttrigger && TpreviousSignal >= Ttrigger)) {
      TpreviousSignal = TinputSignal;
      return false;
    }
+ else 
+      return false; 
    break;