Tidal Effect Simulation

Share you PDE file with our community
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Tue Mar 12, 2013 9:37 am
Yep. Will flow smoothly.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Mar 12, 2013 3:21 pm
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.
Attachments
Tide.zip
(1.46 KiB) Downloaded 107 times
User avatar
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis
PostPosted: Tue Mar 12, 2013 4:31 pm
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,
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Mar 13, 2013 5:41 pm
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! :)
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Mar 13, 2013 6:03 pm
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.
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Mar 13, 2013 6:03 pm
This post has good info, which probably should have been posted here, but since the question was asked in another thread...

viewtopic.php?p=22021#p22021
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Wed Mar 13, 2013 7:12 pm
How would us control freaks implement this without sunlocation.h? I want to define my times really :)
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Mar 13, 2013 7:32 pm
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.
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Wed Mar 13, 2013 7:35 pm
Just had the same thought. Thanks. Keep us updated. I'm about to "find" time to test this on the tank for you.
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
Posts: 5420
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Thu Mar 14, 2013 5:21 am
Ok. Didn't have time to package it, so I'll just post the code..

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__


Tide.cpp
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;
  }
}
PreviousNext

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 0 guests

cron