kh monitor + variable dosing

Requests for new functions or software apps
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Dec 26, 2018 8:39 am
I wasn't getting the values expected. I suspect because of string to integer conversions, I'm not sure at all. I just know I wasn't getting odd numbers even when explicitly writing the same value to three files. I saw we have a read32 function, that didn't help me much as I wasn't sure if my write was even working properly. I have to look for my mini sd conversion thing so I can actually look at the files that were created and see what they hold.
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Dec 26, 2018 3:18 pm
Ok, so today I have devised how I will affect the variable dosing.

Since I'm dosing by volume currently, what I've decided I will do is if the ALK is over or under the threshold that I'll make a micro adjustment to the dosing time.

So let's say the target alk is 155ppm (byte set in Memory Mem_B_AlkTarget) which converts to 868 by the PHE meter. If the ALK reading is 20 above this (so 888 or 159ppm) then I will reduce the dosing by X amount. Other people using other controllers are simply putting in a if ALK > N don't dose anything which I would worry would cause more of a swing.
Conversely, if the ALK is 20 below the threshold (.20dkH) then I will increase the dosing by X amount.

X in these cases will only be a few ml. Basically for my tank, i need 10ml to increase .2dKH (the +/- threshold I mentioned earlier). So let's say we start with the example above and my alk measures 890. I'm currently dosing 18ml a day which comes to .75ml per hour. My function will add 1/24th of a dose to each hour until the alk drops back in the range. If I set the adjustment value (Mem_B_AlkAdjVol) to 4ml, it would add .16ml to the dosage for those hours, but it won't be able to ever dose more than +/-4ml extra per day.

Next, need to add monitoring for the adjustments and maybe some more checks

Code: Select all
    // If any of these are on
    if (ReefAngel.Relay.Status(VO_Calibrate) || ReefAngel.DisplayedMenu==FEEDING_MODE || ReefAngel.DisplayedMenu==WATERCHANGE_MODE) {
       // Do nothing
    } else {
      // Only apply to pumps 0 and 1 when Adjustment value is between 1-9ml and PHExp value is not in Error (500)
      if (InternalMemory.read(Mem_B_AlkAdjVol)>0 && InternalMemory.read(Mem_B_AlkAdjVol)<10 && i<2 && ReefAngel.Params.PHExp>600) {
        if (ReefAngel.Params.PHExp < (InternalMemory.read(Mem_B_AlkTarget) / .1786) - 20) { // Convert AlkTarget PPM to DKH and subtract our threshold
          // Increase dosage time if we're under our threshold
          doseTime[i]+=(InternalMemory.read(Mem_B_AlkAdjVol)/rate)/(1440/dpRepeat);
        }
        if (ReefAngel.Params.PHExp > (InternalMemory.read(Mem_B_AlkTarget) / .1786)  + 20) { // Convert AlkTarget PPM to DKH and add our threshold.
          // Decrease dosage time if we're over our threshold
          doseTime[i]-=(InternalMemory.read(Mem_B_AlkAdjVol)/rate)/(1440/dpRepeat);
        }
      }
      ReefAngel.DosingPumpRepeat(pump[i], i*5, dpRepeat, doseTime[i]);
    }
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Dec 27, 2018 12:20 am
I think the nice thing about the approach is that it should smooth the natural curve of alk consumption on an adaptive basis. I would just have to tune the amount of adjustment I allow to compensate for the natural plus/minus that occurs. Also seeing how long an adjustment is in effect for can help me determine how often I will need to test. I've currently increased it from every 4 hours back to the 2 hour default in order to get more data and not miss any trends.

I just need to figure out how I will track the adjustments made. *scratch* that... I think I just figured that out :) So I currently report my dosing log in the actual amount based on seconds the pump has run. I record that in a CustomVar so I can see throughout the day how much has been dosed. I can then use another CustomVariable to store what should have been dosed without adjustment. That would allow me to overlay the two in a graph nicely and see the affect. I can also set an alarm to trigger at the end of the day if we've hit the limit of the threshold that's been set. So basically if I'm increasing every dosage, then it's time to increase the baseline setting on the dosers.

And thus an alert is born:
Code: Select all
      if (i=0 && abs(ReefAngel.CustomVar[1]-ReefAngel.CustomVar[7])>=InternalMemory.read(Mem_B_AlkAdjVol)) {
        alkAlert.Send("Alk+usage+alert.");
      }
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Jan 06, 2019 11:29 am
So I've had some instability with the readings, but after installing the lab grade ph probe they sell for it, it's working much better. In the meantime I have a shipment on the way for a new reaction chamber which has an upgraded level sensor, float switch, and motor for the magnetic stirrer which are all supposed to really help with consistency and accuracy. As of now I still get some outliers around 30% of the time. The challenge now will be how to compensate...

Roberto, may need to revisit logging to a file and reading the results :)

01/04 08 52 09 W.145 %0 KH 7.47 / 133 ppm
01/04 12 39 14 W.150 %0 KH 7.44 / 132 ppm
01/04 16 16 38 W.147 %2 KH 7.07 / 126 ppm
01/04 16 41 29 W.146 %0 KH 7.45 / 133 ppm
01/04 17 25 12 W.145 %0 KH 7.06 / 126 ppm
01/04 18 30 47 W.151 %0 KH 7.44 / 132 ppm
01/04 19 16 06 W.151 %0 KH 7.16 / 127 ppm
01/04 19 32 28 W.152 %0 KH 7.48 / 133 ppm
01/04 19 44 25 W.148 %0 KH 7.85 / 140 ppm
01/04 20 08 06 W.149 %0 KH 7.89 / 140 ppm
01/04 22 03 11 W.148 %0 KH 7.49 / 133 ppm
01/04 23 31 48 W.147 %1 KH 7.48 / 133 ppm
01/05 00 02 37 W.149 %0 KH 7.62 / 136 ppm
01/05 00 46 52 W.150 %0 KH 7.59 / 135 ppm
01/05 01 08 02 W.150 %0 KH 7.58 / 135 ppm
01/05 02 40 06 W.150 %0 KH 7.59 / 135 ppm
01/05 04 39 15 W.153 %0 KH 7.19 / 128 ppm
01/05 06 47 15 W.150 %1 KH 7.48 / 133 ppm
01/05 08 46 40 W.152 %0 KH 7.32 / 130 ppm
01/05 12 39 56 W.151 %0 KH 7.57 / 135 ppm
01/05 14 39 49 W.150 %1 KH 7.59 / 135 ppm
01/05 16 46 45 W.147 %0 KH 7.58 / 135 ppm
01/05 18 46 47 W.151 %1 KH 7.60 / 135 ppm
01/05 20 46 41 W.151 %1 KH 7.60 / 135 ppm
01/05 22 39 51 W.155 %0 KH 7.58 / 135 ppm
01/06 00 46 41 W.156 %1 KH 7.59 / 135 ppm
01/06 02 46 15 W.150 %0 KH 7.16 / 127 ppm
01/06 04 39 30 W.147 %0 KH 7.61 / 135 ppm
01/06 06 39 38 W.146 %0 KH 7.59 / 135 ppm
01/06 08 46 50 W.147 %0 KH 7.90 / 141 ppm

Posts: 12391
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon Jan 07, 2019 12:40 am
What is that you are trying to log?
Roberto.
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Feb 11, 2019 10:51 pm
That's the log of alk tests. Since then I've been working with the inventor and scouring the facebook group. I've managed to improve the accuracy and number of outliers quite significantly, plus I"m logging more frequency. Previously if the guardian got a bad value it would re-run the test. Since I've gotten it down, it hasn't re-run any of the tests and the largest outlier was .33dKH off, but typically it's .01-.05dKH between tests, which I'm doing every 90 minutes right now, so that's pretty significant.

I'm going to revise my approach a little bit. I want to gently nudge the alk so I'm planning right now to test with an external script before making the RA autonomous. I'm going to adjust by 1ppm when the value exceeds +/-2ppm. The last column in my report shows when I would have dosed and if it were to reduce or increase the supplement. The column before that is a running net total of addition or subtraction. The goal is to stay as net neutral as possible to stick with what I've set the doser to do.

Here's the last 5 days of testing. You can see how tight the values have been.

02/07/19 17:34:58 7.76 / 138 0
02/07/19 17:44:53 7.76 / 138 0
02/07/19 18:09:43 7.72 / 137 0
02/07/19 21:10:35 7.67 / 136 0
02/07/19 21:27:20 7.62 / 136 0
02/07/19 21:44:54 7.59 / 135 0
02/07/19 22:02:54 7.62 / 136 0
02/07/19 22:20:32 7.61 / 135 0
02/07/19 22:40:11 7.57 / 135 0
02/07/19 22:58:33 7.59 / 136 0
02/08/19 01:08:24 7.59 / 136 0
02/08/19 01:15:04 7.58 / 135 0
02/08/19 01:50:56 7.75 / 138 0
02/08/19 04:08:07 7.58 / 135 0
02/08/19 06:25:47 7.68 / 137 0
02/08/19 09:14:39 7.68 / 137 0
02/08/19 11:32:00 7.71 / 138 0
02/08/19 13:48:10 7.73 / 138 0
02/08/19 16:05:20 7.73 / 138 0
02/08/19 19:40:45 7.71 / 138 0
02/08/19 21:57:30 7.58 / 135 0
02/09/19 00:07:49 7.62 / 136 0
02/09/19 02:22:19 7.61 / 136 0
02/09/19 04:09:20 7.75 / 138 0
02/09/19 05:56:41 7.72 / 138 0
02/09/19 09:24:20 7.82 / 140 -1 Dose -1
02/09/19 11:04:41 7.77 / 139 -1
02/09/19 12:45:13 7.71 / 138 -1
02/09/19 14:25:21 7.72 / 138 -1
02/09/19 16:12:09 7.72 / 138 -1
02/09/19 17:52:18 7.73 / 138 -1
02/09/19 19:32:28 7.72 / 138 -1
02/09/19 21:19:04 7.67 / 137 -1
02/09/19 22:57:43 7.62 / 136 -1
02/10/19 00:37:56 7.57 / 135 -1
02/10/19 02:18:13 7.59 / 136 -1
02/10/19 04:05:06 7.59 / 136 -1
02/10/19 05:52:07 7.57 / 135 -1
02/10/19 07:32:25 7.90 / 141 -2 Dose -1
02/10/19 08:56:53 7.76 / 139 -2
02/10/19 10:36:59 7.77 / 139 -2
02/10/19 12:17:04 7.71 / 138 -2
02/10/19 13:57:10 7.71 / 138 -2
02/10/19 15:44:10 7.72 / 138 -2
02/10/19 17:24:18 7.72 / 138 -2
02/10/19 19:04:28 7.71 / 138 -2
02/10/19 20:50:46 7.63 / 136 -2
02/10/19 22:30:54 7.53 / 134 -1 Dose + 1
02/11/19 01:37:52 7.46 / 133 0 Dose + 1
02/11/19 03:24:53 7.58 / 135 0
02/11/19 05:03:32 7.53 / 134 1 Dose + 1
02/11/19 06:43:48 7.58 / 135 1
02/11/19 08:30:50 7.57 / 135 1
02/11/19 10:17:49 7.59 / 136 1
02/11/19 12:04:50 7.62 / 136 1
02/11/19 13:45:00 7.68 / 137 1
02/11/19 15:25:08 7.73 / 138 1
02/11/19 17:05:17 7.73 / 138 1
02/11/19 18:45:29 7.71 / 138 1
02/11/19 20:32:02 7.67 / 137 1
02/11/19 22:19:00 7.67 / 137 1
02/12/19 00:06:14 7.67 / 137 1
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Feb 13, 2019 11:02 am
So, I implemented this in two parts. Right now I have a script running externally that queries the guardian and if it’s reading after a new test. If it’s +/-2ppm it will set a cvar to either my target + 1 or - 1. If it’s over my target, this tells the RA that it should reduce or slip the dose. If it’s above then the RA should increase the dose.

On the RA side, I start by looking at the PHE reading. It also has to be +/-2ppm and the cvar has to be set appropriately to match. I also keep track of a “delta” and track the number of times we add or reduce the supplement. So if we max out the increases, the RA will not increase until we have a reduction in order to prevent constantly adding or reducing.
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Feb 14, 2019 5:03 pm
So some success and some failures, although the failures are quite minor. First failure was the RA did not reset the CustomVar after the pumped turned off. That means any action that was due to do something was going to repeat it every hour, unless I override (or automate overriding...) Anyway that was an easy fix. I was doing my test wrong it seems.

Second failure that happened was pretty basic. I've been having ATO problems lately. My gravity feed ATO depends on a siphon I guess and it's been stopping about halfway, I guess air is getting in there. I need to come up with something better and more permanent for that. I did not get an alarm when my pump shut off and so my return pump was off the whole day. The guardian continued to do tests and the alk was climbing, and I couldn't figure it out because the code I was using pretty much was supposed to stop the dosing when it reached the high point. I'm assuming because the return was down the alk wasn't being consumed. In any case, I now have some other alarms set to capture that.

So after that whole debacle, my alk has been super stable :) My last 14 tests were all within .01dkh! As I was looking to raise my alk anyway, I changed my target alk to match where I hit, and now my RA has dosed some extra as the alk has started dropping.

02/13/19 19:22:46 7.73 dKH / 138 ppm
02/13/19 21:02:57 7.72 dKH / 138 ppm
02/13/19 22:43:06 7.72 dKH / 138 ppm
02/14/19 00:23:12 7.72 dKH / 138 ppm
02/14/19 02:10:20 7.72 dKH / 138 ppm
02/14/19 03:57:21 7.73 dKH / 138 ppm
02/14/19 05:37:31 7.72 dKH / 138 ppm
02/14/19 07:24:50 7.73 dKH / 138 ppm
02/14/19 09:12:02 7.73 dKH / 138 ppm
02/14/19 10:52:14 7.72 dKH / 138 ppm
02/14/19 12:32:26 7.72 dKH / 138 ppm
02/14/19 14:12:36 7.73 dKH / 138 ppm
02/14/19 14:24:56 7.72 dKH / 138 ppm
02/14/19 16:05:07 7.72 dKH / 138 ppm
02/14/19 17:51:44 7.67 dKH / 137 ppm +

I can see in the graph that my alk did dose more this hour. The value reset properly and the delta was updated in memory. So we're off. My only concern is that my threshold is too wide now based on the accuracy of this thing, but obviously want to go gently. Let's see how this is for a bit and I can tighten up the controls once I'm happy with it.
User avatar
Posts: 5390
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Feb 14, 2019 5:09 pm
For the record, I like having the external factor in addition to the RA doing it's own thing. Since this is such a vital factor, if for some reason the monitor stopped doing tests, the RA might do something that doesn't match. The script I run externally keeps track of the time of the last test and it will only submit if no errors detected and if it were a new test. So pretty happy with the overall interaction.

The other nice thing now is that my Calcium is now raised alongside my alk keeping everything in proportion.
Previous

Return to Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron