Turn on relay when WL is at 100% or >?

Do you have a question on how to do something.
Ask in here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Right now. I'm testing an issue I had with the multi WL dropping faster then it actually is. Roberto wanted me swap my single with my multi and see if it moves with the swap or it it stays.
I put that off while working on the dev libraries with you guys.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

No problem. Have to figure out the best way to solve the wrap around...constrain/negative number/something else...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Thanks
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

So there is a function to get the raw value.

ReefAngel.WaterLevel.Read() and ReefAngel.WaterLevel.Read(byte Channel)

I took a quick look at the code and it's first doing a map and then a constrain, so I think the wrapping is happening first int the map function, because the constrain is from 0 to 200. So if it were less than 0 then it would be 0..
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

OK. You're speaking greek to me Lee, but it sounds like you can do something about it.
Again nothing major. When you can get to it.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

I dont have a solution yet. Although maybe I have an idea...just as I wrote that..

But for now you can do the read function above and compare it to the InternalMemory.WaterLevelMin_read() function to see if the raw uncalculated value is less than "0".
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Ok, I figured out the issue!!!

Roberto, in the WaterLevel::Convert function... why is t an "unsigned" long. Here's the issue. First we do a map of the value read from the sensor to the min/max calibrated values. We assign this to t (which is unsigned...) So, if the value read is less than 0 we will get a negative number. Since t is unsigned, this causes the number to wrap around and thus we get an extremely large number instead of a negative. Then when we do the constrain so that the number gets held within the 0-200 range it gets set to 200.

So the solution is to either convert the unsigned long t to just long t or we have to wrap the first map with the constrain so that it's constrained to a positive number before assigning it to t. If we do that, then t could really just be a byte instead of an unsigned long.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Ok, I know why t is an unsigned long, because your using t to also de-bounce the sensor and taking 20 readings in a row. Therefore to not change this behavior and not introduce any other unexpected behavior, I recommend we do:

t=constrain(map(t, WLmin,WLmax,0,100),0,200);

That should prevent having the negative wrap during the assignment to t since t will always be constrained. Also I would propose changing the range to 0-255 just because we can :) and in code would look better because level[x] is a byte. So the constrain rather than be an arbitrary range is ensuring we stay within the confines of our destination variable.

If you agree, I'll create a pull request tonight.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Turn on relay when WL is at 100% or >?

Post by rimai »

0-255 range is fine :)
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Sounds good. I'll patch it up tonight! Anyone able to help test it? My reservoir is still half full and I don't feel like siphoning all the water out... :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

I just filled mine yesterday, but I would think if I pull the pipe out of the reservoir that is the same as emptying the reservoir.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Yeah Steve, that'd work. I have no way to get to mine the way it's mounted. If you can test it that way, it would definitely help. I plan to load my controller with this too, but it will be a few days before I'm at that point to know it's working. It's an annoying bug because I have to manually put water in until it's back to 0 so my refill function will work :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

I'll be glad to test it when I get home tonight.
Let me know when the code is up.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Has the code been put up?
Is it in your branch Lee or has it been merged into the dev code?

Let me know and I'll test it.
It's a simple test should know right away if it works or not.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Just finished getting things cleaned up. Man I hate git still sometimes :)

Anyway, my branch is here: https://github.com/lnevo/Libraries/tree/waterlevelfix

And I made a pull request to Roberto. Needed to make sure the branch had all the fixes I made so far...
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Ok. Just finishing dinner.
I'll download it a bit.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Works great.
I really didn't even need to lift up my WL1 pipe to test it.
The other 3 WL sensors on the multi level sensor were all reading 0 before I even got back to my tank to pull the WL 1 pipe out of the sump.

I did it anyway as a double check and it's perfect. :D
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

Sweet!!! I'm pretty pleased with this one :) as soon as my 16mo old goes to bed.. :)
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

Putting a 16 month old to bed at 9:50? :o
I just put my 10 year old to bed at 9:30. :-)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Turn on relay when WL is at 100% or >?

Post by lnevo »

He's insane. Hates his crib. Should have stuck with one ;) lol
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Turn on relay when WL is at 100% or >?

Post by Sacohen »

LOL. He wants to be with Daddy.
Post Reply