Tide function (proper use quesiton)

Related to the development libraries, released by Curt Binder

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Mon Feb 01, 2016 5:34 pm
Are there options to pass to the tide function or do you edit the header file for changes?

Right now I'm just declaring Tide, then use it as tide.isIncoming to set the dc pumps and channels. I thought I read somewhere about some values in the .h file and saw below. Was going to see if I can get a bit more alternate flow between the two pumps when they are on/off or have it change more frequently during the day.

Based on the header I'm starting to think that I'm not using it properly or there are more options (or abetter way to use tide such that I don't need to call setMode with reefCrest)?

Here is what I see in the tide.cpp file:
Tide::Tide()
{
m_WaveLength=12*SECS_PER_HOUR;
m_MaxOffset = 50;
m_MinOffset = 10;
m_Speed = 50;
m_Amp = 1;
m_CurrSpeed=m_Speed;
}

Part of my code:
if (tide.isIncoming()) {
ReefAngel.DCPump.DaylightChannel = AntiSync;
ReefAngel.DCPump.ActinicChannel = None;
}
else {
ReefAngel.DCPump.DaylightChannel = None;
ReefAngel.DCPump.ActinicChannel = Sync;
}

if (hour()>=21 || hour()<8)
{
// Sleep mode - slow things down
ReefAngel.DCPump.SetMode( ReefCrest,25,10 );
}
else
{
if (hour()>=8 && hour()<14) {
ReefAngel.DCPump.SetMode( TidalSwell,40,10 );
}
else if (hour()>=14 && hour()<18) {
ReefAngel.DCPump.SetMode( ReefCrest,30,10 );
}
else if (hour()>=18 && hour()<21) {
ReefAngel.DCPump.SetMode( NutrientTransport,40,10 ); // Nutrient Transport on sync mode
}
}
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Feb 03, 2016 6:33 am
Sorry for taking so long. I owe you a proper answer, but I need to look up the API so I can tell you properly :) should be able to respond tomorrow.

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Wed Feb 03, 2016 5:09 pm
lnevo wrote:Sorry for taking so long. I owe you a proper answer, but I need to look up the API so I can tell you properly :) should be able to respond tomorrow.


No rush. I am actually reading your RA code thread and another thread which someone is asking similar questions with the sun routines. I have my current code base and trying to see how the sun, longitude stuff, and tie works together.

I'm trying to correlate and test tide with the DCPump.DaylightChannel and DCPump.ActinicChannels to your vortec. The way I have it now just one side is on all time and not alternating so I'm doing something wrong. Yours is pretty complex with random patterns. Very cool. Your RA does everything and the dishes it seems :)

Thanks. Still reading and testing on my side. Learning is good :)
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Feb 03, 2016 9:38 pm
Based on the code you have above you set each channel to Sync or AntiSync and the other to None. You *should* be setting one to sync and the other to anti-sync and flipping them based on if tide is incoming or not. You could also set an offset so that the Sync is more powerful.

ReefAngel.DCPump.AntiSyncOffset=50; // 50% power on the Anti-Sync channel

The best ways to modify the Tide class that you've declared is with the following functions:

Tide.SetSpeed(speed); //
Tide.SetOffset(min,max);
Tide.SetWaveLength(wavelength); // Default is 12 hours

The values you showed in your original post are "private" variables, meaning you can only set them with the functions above and not directly.

What you're missing in your usage is that the Tide also calculates speed. Depending on the time of the day the tide will be stronger or weaker and at it's peak will switch direction. Also as the MoonPhase affects the tide more the speed will adjust between the min and max offsets. This is so you can control how variable this is over the month. You can see how that looks in the attached image.
graphra (1).png
graphra (1).png (17.73 KiB) Viewed 1839 times


I have found with this type of setup, you don't even need the night mode because it usually goes through 2 slower periods each day with the "late" one going overnight. All you need to do is replace the speeds you have hardcoded with the function Tide.GetSpeed();

So that pretty much takes care of the usage I think. Let me know if you have any questions. Also to know how to use things it's best to look in the .h file. This is where all the functions and variables get defined. If you want to know *what* that function does.. then look it up in the cpp file. Hope that helps with the learning.
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Feb 03, 2016 9:39 pm
You can see btw where I changed my max speed from 65 to 70 :)

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Thu Feb 04, 2016 12:53 pm
Thanks Lnevo. Very detailed and powerful code. It defineatly packages everything I'd like to use once I get it dialed in. So thanks for explaining it.

I'll fix the tide isIncoming block.

If I understand correctly I don't need the if logic at all for flow or limit after hours. I just did a quick test and removed it. However, when I tried to replace the hard coded values it didn't compile. So I'm pretty sure I'm calling it incorrectly.

ReefAngel.DCPump.SetMode( ReefCrest,30,10): works, but it isn't working if I replace the numbers with Tide.GetSpeed(), etc.
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Feb 04, 2016 1:44 pm
Tide is the classname not the variable instance of it you have declared.

Since in your code you're using tide.isIncoming, you would use the same name when retrieving the speed tide.GetSpeed();

That should take care of it.

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Thu Feb 04, 2016 2:15 pm
EDIT: Ok, I posted while off making changes - may still be applicable but this is what I had working before you replied. Sorry.

1. Needed to set variable

byte tideSpeed=tide.GetSpeed();

2. Removed older DCPump logic and added a single line

ReefAngel.DCPump.SetMode( ReefCrest, tideSpeed, 10);
// still reading on the last value does (set to 10 for now)

Compiled fine and running. Also set the AntiSyncOffset so will see how this goes for the next couple of hours. Looks good although I'm stuck at reef crest which may not be a bad thing since this is just a 40 breeder. Cool, thanks Lnevo. Just had to go through some more of your code (not programed in many many years, so forgot a lot).

Customer code now:
////// Place your custom code below here

ReefAngel.DCPump.AntiSyncOffset=50; // 50% power on the Anti-Sync channel
CheckCloud();
ReefAngel.DCPump.SetMode( ReefCrest, tideSpeed, 10);

ReefAngel.PWM.SetChannel(0,PWMChannel[0]);
ReefAngel.PWM.SetChannel(1,PWMChannel[1]);
ReefAngel.PWM.SetChannel(2,PWMChannel[2]);
ReefAngel.PWM.SetChannel(3,PWMChannel[3]);

////// Place your custom code above here

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Thu Feb 04, 2016 2:32 pm
This is also working...

ReefAngel.DCPump.SetMode( ReefCrest, tideSpeed, tide.isIncoming());

Posts: 111
Joined: Thu Jun 28, 2012 1:46 pm
PostPosted: Fri Feb 05, 2016 3:17 pm
Lnevo - one more question. How did you generate the graph you posted?

I just reconnected my wireless module since I was done uploading code and wondering how you did it.

Thanks.
Next

Return to Development Libraries

Who is online

Users browsing this forum: No registered users and 1 guest