Page 1 of 1

Sigmoid wave form is generating a wrong value

Posted: Thu Sep 18, 2014 3:18 pm
by rimai
The sigmoid wave form is outputting the wrong value in the center of the peak.
This is what I used to generate the plot:

Code: Select all

PWMSigmoid(8,0,20,0,0,100,0)
Right in the middle, it output 50 instead of 100.
https://github.com/reefangel/Libraries/issues/194

Re: Sigmoid wave form is generating a wrong value

Posted: Thu Sep 18, 2014 5:20 pm
by AlanM
Weird. I use it every day and didn't see that. I'll check it out.

Re: Sigmoid wave form is generating a wrong value

Posted: Thu Sep 18, 2014 5:37 pm
by AlanM
Is it really exactly in the middle? The math is pretty simple, but I can maybe see a way that it would generate a different number in the center since it isn't totally continuous, when (current-start) = FWHM there doesn't seem to be a value set, since I just had done < and >, not <=, for instance. Also, FWHM is exactly in the center, so it would fit with happening at that spot.

Before I do a commit to change it, can you just add an equal sign, like this:

Code: Select all

    if ((current >= (start + FWHM)) && (current < (end - FWHM))) 
Since FWHM is at the exact halfway point, that if should be satisfied for either of them if you have an = sign in there, but it doesn't hurt to have them both. They should both give the same value.

It won't be exactly 100%, by the way, but something very close. Within 1% of 100%.

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 8:52 am
by rimai
No. that did not fix it.

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 8:56 am
by rimai
This is the code I used for testing:

Code: Select all

#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

void setup()
{
  ReefAngel.Init();  
  setSyncInterval(SECS_PER_HOUR*6000);
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
  delay(500);
  wdt_reset();
}
//ReefAngel.PWM.
void loop()
{
  while(1)
  {
    wdt_reset();
    Serial.println(PWMSigmoid(8,0,20,0,0,100,0));
    adjustTime(60);
    delay(1);
  }
  ReefAngel.ShowInterface();
}

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 9:00 am
by rimai
I think this code could even be changed up a bit to allow us to run for 24hrs and allow us to see how the pattern looks in the tank within a short span of time.
Kind of like press preview and the controller adjusts the LEDs to show how the pattern would look like. What do you think?
The only caveat is that all other functions that use time would be affected too. :(

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 9:25 am
by lnevo
That sounds cool

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 9:58 am
by lnevo
rimai wrote:The only caveat is that all other functions that use time would be affected too. :(
The only thing I would worry about that is the dosing pumps, how quick do you run through the 24 hour window? I think a simple flag to not run the dosing pumps during the preview would suffice...

Re: Sigmoid wave form is generating a wrong value

Posted: Fri Sep 19, 2014 10:58 am
by AlanM
That code is a great idea! I never thought about doing it that way.