Tidal Effect Simulation
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Tidal Effect Simulation
Yep. Will flow smoothly.
Re: Tidal Effect Simulation
Ok. New code put in place. Looks like it's working properly... we'll just have to see
The tidal curve is looking good. Combined with Roberto's ReefCrest function, I'm quite happy with the way my flow is changing and moving around. The PWMSlope worked great going in and out of "Night" mode.
Here's the latest version.
The tidal curve is looking good. Combined with Roberto's ReefCrest function, I'm quite happy with the way my flow is changing and moving around. The PWMSlope worked great going in and out of "Night" mode.
Here's the latest version.
- Attachments
-
- Tide.zip
- (1.46 KiB) Downloaded 533 times
- jsclownfish
- Posts: 378
- Joined: Mon Oct 24, 2011 7:52 pm
- Location: Saint Louis
Re: Tidal Effect Simulation
nice work! I've been holding off on flow control for awhile to save a few bucks, but the tidal code work and the jebo prices with the RA connection seems to good to pass up,
Tidal Effect Simulation
The gap between high and low tide doesn't seem to be as big as it should based on current MoonPhase.. I need to look into that. I'm currently seeing a difference of 11, but it should be closer to 20 since we're close to a new moon. Oops....just realized why!
Tidal Effect Simulation
Yup. The issue was the offsets need to be split in half since we only need half to affect the amplitude. But I was dividing it before I calculated the range which we need as max-min. So my range was half what it should have been. Good to know this was close to my minimum range at quarter moons. I'll post the new code later tonight.
Tidal Effect Simulation
This post has good info, which probably should have been posted here, but since the question was asked in another thread...
http://forum.reefangel.com/viewtopic.php?p=22021#p22021
http://forum.reefangel.com/viewtopic.php?p=22021#p22021
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Tidal Effect Simulation
How would us control freaks implement this without sunlocation.h? I want to define my times really
Tidal Effect Simulation
Has no dependency...it only relies on MoonPhase...
The only thing I use sun location for is to set my night mode timing...you can just as easy hard code that.
The only thing I use sun location for is to set my night mode timing...you can just as easy hard code that.
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Tidal Effect Simulation
Just had the same thought. Thanks. Keep us updated. I'm about to "find" time to test this on the tank for you.
Tidal Effect Simulation
Ok. Didn't have time to package it, so I'll just post the code..
Tide.h
Tide.cpp
Tide.h
Code: Select all
#ifndef __TIDE_H__
#define __TIDE_H__
#define PI 3.141593
class Tide
{
public:
Tide();
int CalcTide();
void CalcFlow();
void Init(int Speed, int minOffset, int maxOffset);
void SetOffset(int minOffset, int maxOffset);
void SetWaveLength(double WaveLength);
void SetSpeed(int Speed);
inline int GetSpeed() { return m_Speed; }
inline boolean isIncoming() { return m_Flood; }
inline boolean isOutgoing() { return m_Ebb; }
private:
int m_Speed;
int m_CurrSpeed;
int m_MinOffset;
int m_MaxOffset;
double m_Amp, m_PrevAmp;
double m_WaveLength;
boolean m_Ebb,m_Flood;
};
#endif // __TIDE_H__
Code: Select all
#include <stdlib.h>
#include <math.h>
#include <Time.h>
#include "Tide.h"
#include "Globals.h"
Tide::Tide()
{
m_WaveLength=12*SECS_PER_HOUR;
m_MaxOffset = 50;
m_MinOffset = 10;
m_Speed = 50;
m_Amp = 1;
m_CurrSpeed=m_Speed;
}
void Tide::Init(int Speed, int minOffset, int maxOffset)
{
SetSpeed(Speed);
SetOffset(minOffset,maxOffset);
}
void Tide::SetSpeed(int Speed)
{
m_Speed = Speed;
}
void Tide::SetWaveLength(double WaveLength)
{
m_WaveLength = WaveLength;
}
void Tide::SetOffset(int minOffset, int maxOffset)
{
// We want these in half since they will be multiplied by amplitude (+1/-1)
m_MinOffset = minOffset/2;
m_MaxOffset = maxOffset/2;
}
/*
Spring tides occur during the full moon and the new moon.
At these times, the high tides are very high and the low tides are very low.
Neap tides occur during quarter moons.
The result is a smaller difference between high and low tides
MoonPhase 0-25 = Spring
MoonPhase 26-74 = Neap
MoonPhase 75-100 = Spring
So, the effect of the Moon will be a cosine wave.
*/
int Tide::CalcTide() {
double moonOffset; // gap between high and low
double amplitude; // tide curve
// Calculate the gap between high and low tide based on MoonPhase()
moonOffset=cos(((2*PI)/100)*MoonPhase());
moonOffset=((moonOffset+1)/2)*100; // Comvert to percentage
moonOffset=map(moonOffset,0,100,m_MinOffset,m_MaxOffset);
// Find out the current tidal height
amplitude=sin(((2*PI)/m_WaveLength)*now());
amplitude=amplitude*moonOffset;
// Update Ebb/Flood
m_PrevAmp=m_Amp;
m_Amp=amplitude;
CalcFlow();
// Adjust the calculate speed to be in our adjusted range
m_CurrSpeed=constrain(m_Speed+amplitude,0,100);
return m_CurrSpeed;
}
void Tide::CalcFlow() {
if (m_Amp>m_PrevAmp) {
m_Flood=true;
m_Ebb=false;
} else if (m_Amp<m_PrevAmp) {
m_Flood=false;
m_Ebb=true;
}
}
Tidal Effect Simulation
Hmmm...maybe I did want the range cut in half...probably...not sure now...oh well, play with it later
Edit: reverted the change in the code above...after re-looking at the math...
Edit: reverted the change in the code above...after re-looking at the math...
Re: Tidal Effect Simulation
I think I can use the map() function to shift the range... this way I can stop banging my head and questioning myself...
- DrewPalmer04
- Posts: 818
- Joined: Tue May 29, 2012 2:12 pm
- Location: Christopher, IL
Re: Tidal Effect Simulation
HATE when that happenslnevo wrote:I think I can use the map() function to shift the range... this way I can stop banging my head and questioning myself...
Re: Tidal Effect Simulation
Modified the above code with the map function which looks to be working good in my test executable. Should be good. We'll see how test goes.
Tidal Effect Simulation
Doing the constrain badly...need to reload later tonight. Thank god for graphs!
Re: Tidal Effect Simulation
Yep... was actually doing the constrain twice and amplitude starts out -1 to 1. So... didn't need it.
Code modified in http://forum.reefangel.com/viewtopic.php?p=22049#p22049
Code modified in http://forum.reefangel.com/viewtopic.php?p=22049#p22049
Tidal Effect Simulation
I think the map function is not working as written. Hard to tell since based on current MoonPhase we should be close to minimum which I am, but I've seen no change... In any event, I plan on doing some debug tonight to confirm the values Im getting.
Re: Tidal Effect Simulation
Yeah, map did not like a number between 0 and 1. I multiplied by 100 and then used that in the map function
Re: Tidal Effect Simulation
So, I wanted to post some charts of that show the usage of the simulation.
Here is the graph of the default curve coming out of CalcTide() function. You can see that the high/low marks before Mar 25 are just slightly less than today's. This will continue to grow till we hit full moon.
Here you can see the change of incoming/outgoing tide. I use the following code to address either channel 0 or channel 1 of my vortech pumps. I do the slower pump first so that RFS shows the higher value
Here's the speed that my tide class is set to. You can see my transition to night mode around the 9pm and 10am marks.
And finally, the moment we've been building up to. This is the end result of the speed my vortech's are being set to. This is with the ReefCrest function applied to it. You could use whichever mode you wanted and feed the result similarly. The anti-sync output is applied to the second pump. That is the second graph.
Currently the anti-sync pump is running at 70% of the main pump. The pumps switch roles during the switch from high toward low tide and vice-versa.
Here is the graph of the default curve coming out of CalcTide() function. You can see that the high/low marks before Mar 25 are just slightly less than today's. This will continue to grow till we hit full moon.
Here you can see the change of incoming/outgoing tide. I use the following code to address either channel 0 or channel 1 of my vortech pumps. I do the slower pump first so that RFS shows the higher value
Code: Select all
ReefAngel.RF.SetMode(Custom,rcSpeedAS,tide.isOutgoing());
ReefAngel.RF.SetMode(Custom,rcSpeed,tide.isIncoming());
Here's the speed that my tide class is set to. You can see my transition to night mode around the 9pm and 10am marks.
Code: Select all
tide.SetSpeed(PWMSlope-1(sl.GetRiseHour(),sl.GetRiseMinute(),
sl.GetSetHour(),sl.GetSetMinute(),vtNightSpeed,vtSpeed,120,vtNightSpeed));
And finally, the moment we've been building up to. This is the end result of the speed my vortech's are being set to. This is with the ReefCrest function applied to it. You could use whichever mode you wanted and feed the result similarly. The anti-sync output is applied to the second pump. That is the second graph.
Code: Select all
int rcSpeed=ReefCrestMode(tide.CalcTide(),vtDuration,true);
Currently the anti-sync pump is running at 70% of the main pump. The pumps switch roles during the switch from high toward low tide and vice-versa.
Code: Select all
int rcSpeedAS=ReefCrestMode(tide.CalcTide(),vtDuration,false)*pumpOffset;
Re: Tidal Effect Simulation
Just as a reference, my base speed is 45 and my night speed is 25.. So you don't see so much change in the graphs above. I do have 2 mp-40 on a 65g tank... so I try to avoid going above 65 (my Smart_NTM setting)
Re: Tidal Effect Simulation
oh, and I don't have good long term graphs because I keep playing with them... but at some point
Re: Tidal Effect Simulation
Has this code been working well for you? I'm going to be tinkering and setting up my RA in the next few weeks and so far I'm really liking this option. I still need to get the RF module but I will have 4 MP10's and 2 Wp40's on my tank and was wondering if this would be sufficient for that many pumps?
Still really new to RA but I need some randomized flow and the WP's are gonna prob be running max 50-70% so I would just have to alter the speeds and implement this code? Or would I have to have different options installed as I'm running the WP's off PWM and the MP's on the RF? Maybe I should just run the MP's on this and do a seperate code for the WP's?
Sorry if I sidetracked the thread a little but I def would like to try this out and have something that is really not a recurring/looping current.. Thanks in advance for the time put into the code.
Still really new to RA but I need some randomized flow and the WP's are gonna prob be running max 50-70% so I would just have to alter the speeds and implement this code? Or would I have to have different options installed as I'm running the WP's off PWM and the MP's on the RF? Maybe I should just run the MP's on this and do a seperate code for the WP's?
Sorry if I sidetracked the thread a little but I def would like to try this out and have something that is really not a recurring/looping current.. Thanks in advance for the time put into the code.
My other hobby has 450rwhp and eats tires instead of mysis!
Tidal Effect Simulation
This code is more about how you use it. There is a tide mode function now in the library or you could use the class posted. The difference being that the class tracks ebb and flow of the tide effect. Using the value by itself, you would get a constant speed that varied from a max speed to a min speed with two "high tides" and two "low tides" a day. The gap between the max and min is adjusted based on MoonPhase. I use this value returned and feed it to the RA ReefCrestMode and get that effect on top of it. I'm using the custom rf function so I can control each mp40 separately so I basically flip the primary pump when the tide changes. So far I've been happy. I'm going to go back Ectotech mode for a little while just to see if there's any difference.dapg8gt wrote:Has this code been working well for you? I'm going to be tinkering and setting up my RA in the next few weeks and so far I'm really liking this option. I still need to get the RF module but I will have 4 MP10's and 2 Wp40's on my tank and was wondering if this would be sufficient for that many pumps?
Still really new to RA but I need some randomized flow and the WP's are gonna prob be running max 50-70% so I would just have to alter the speeds and implement this code? Or would I have to have different options installed as I'm running the WP's off PWM and the MP's on the RF? Maybe I should just run the MP's on this and do a seperate code for the WP's?
Sorry if I sidetracked the thread a little but I def would like to try this out and have something that is really not a recurring/looping current.. Thanks in advance for the time put into the code.
Re: Tidal Effect Simulation
Thanks for responding. I am gonna have 2 wp40's along with the four MP10's . I think if I use the ecotechs with a tidal swell mode I can have the random chaotic flow delivered by my wp's.. just brainstorming and trying to gauge all my options as I will have a good chance that the MP's will not overpower the larger tank and can have them follow this code 24/7 while the wp adds the main flow and add night mode to them.. I may just run them all on alternating reef crest, lagoon and long pulse at various speeds antisynched between the two brands. Still unsure. Thanks for the info
My other hobby has 450rwhp and eats tires instead of mysis!
Re: Tidal Effect Simulation
Latest version and 1.1.0 compatible
- Attachments
-
- Tide.zip
- (1.52 KiB) Downloaded 683 times
-
- Posts: 32
- Joined: Fri Aug 30, 2013 3:50 pm
Re: Tidal Effect Simulation
is their an easy way to incorporate this code into my file? looking at this coding is like trying to count the number of branches on a birds nest.
I only have to WP40's with the max output at 80%.
I know this is asking alot, but can someone put the tidal effect simulation into my ino file?
I only have to WP40's with the max output at 80%.
I know this is asking alot, but can someone put the tidal effect simulation into my ino file?
- Attachments
-
- sketch_oct04a.ino
- (4.51 KiB) Downloaded 618 times
Re: Tidal Effect Simulation
The question I always ask when someone wants this is what do you want it to do?
The class is pretty easy to use and overall pretty easy to add, but you need to do something with the data it gives you... Right now the output looks like a wave going from the min speed to the max speed 2 times a day (2 high tides and 2 low todes per 24 hours). The speed needs to get passed back to something like the other wave functions, otherwise it's just a constant speed.
The class is pretty easy to use and overall pretty easy to add, but you need to do something with the data it gives you... Right now the output looks like a wave going from the min speed to the max speed 2 times a day (2 high tides and 2 low todes per 24 hours). The speed needs to get passed back to something like the other wave functions, otherwise it's just a constant speed.
-
- Posts: 32
- Joined: Fri Aug 30, 2013 3:50 pm
Re: Tidal Effect Simulation
lnevo wrote:The question I always ask when someone wants this is what do you want it to do?
The class is pretty easy to use and overall pretty easy to add, but you need to do something with the data it gives you... Right now the output looks like a wave going from the min speed to the max speed 2 times a day (2 high tides and 2 low todes per 24 hours). The speed needs to get passed back to something like the other wave functions, otherwise it's just a constant speed.
is that pig latin? LOL
ok, what data are you refering too? are you talking about the graphs... ummm, i don't need it
can it go back to reefcrest mode or lagoon or nutrient export mode?
Re: Tidal Effect Simulation
lnevo
I've tried to add this to my nighttime mode but am getting some errors....here is the error msg:
My_RA_Version2_1.cpp: In function 'void loop()':
My_RA_Version2_1:253: error: expected primary-expression before '.' token
My_RA_Version2_1:253: error: '2' cannot be used as a function
And this is the code in the loop:
// Jebao Code
// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,ReefCrestMode(50,20,true)*2.55);
ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.LowATOChannel = Sync ; // Jebo connected to AtoPINLow
// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;
// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Lagoon, ReefCrest, TidalSwell, Sine, Gyre, NutrientTransport, Else };
if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}
// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
if (now()-feeding<900) {
// First 15 minutes after feeding mode stops. Smart_NTM
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()-feeding<2250) { // 15 minutes plus 1 hour
// Continue NTM for the next 60 minutes (75 minutes total)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<27000 || now()%SECS_PER_DAY>=67500) { // 8:30am / 10:30pm
// Night mode (go to 30%)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=(Custom,ReefCrest(Tide.CalcSpeed()),-1Tide.isIncoming());
//ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
// Custom Mode and nothing else going on
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
if (modes[rmode]==Else) {
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=Constant;
ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),25,true ); // ElseMode on sync mode, Portal Speed Setting +/- 25%
} else {
ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode
ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
}
} else {
ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
I've tried to add this to my nighttime mode but am getting some errors....here is the error msg:
My_RA_Version2_1.cpp: In function 'void loop()':
My_RA_Version2_1:253: error: expected primary-expression before '.' token
My_RA_Version2_1:253: error: '2' cannot be used as a function
And this is the code in the loop:
// Jebao Code
// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
pinMode(lowATOPin,OUTPUT);
analogWrite(lowATOPin,ReefCrestMode(50,20,true)*2.55);
ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.LowATOChannel = Sync ; // Jebo connected to AtoPINLow
// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;
// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Lagoon, ReefCrest, TidalSwell, Sine, Gyre, NutrientTransport, Else };
if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}
// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
if (now()-feeding<900) {
// First 15 minutes after feeding mode stops. Smart_NTM
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()-feeding<2250) { // 15 minutes plus 1 hour
// Continue NTM for the next 60 minutes (75 minutes total)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<27000 || now()%SECS_PER_DAY>=67500) { // 8:30am / 10:30pm
// Night mode (go to 30%)
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=(Custom,ReefCrest(Tide.CalcSpeed()),-1Tide.isIncoming());
//ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) {
// Custom Mode and nothing else going on
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
if (modes[rmode]==Else) {
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.Mode=Constant;
ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),25,true ); // ElseMode on sync mode, Portal Speed Setting +/- 25%
} else {
ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode
ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
}
} else {
ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}