Skip to content

Commit b9fb580

Browse files
committed
TinyGPSPlus based LST calculator
1 parent 49a16f6 commit b9fb580

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Software/Arduino code/Sidereal.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "Sidereal.hpp"
2+
3+
static DayTime Sidereal::calculateByGPS(TinyGPSPlus* gps){
4+
DayTime timeUTC = DayTime(gps->time.hour(), gps->time.minute(), gps->time.second());
5+
int deltaJd = calculateDeltaJd(gps->date.year(), gps->date.month(), gps->date.day());
6+
float deltaJ = (float) deltaJd + ((timeUTC.getTotalHours()) / 24.0);
7+
return DayTime((float) (calculateTheta(deltaJ, (float) gps->location.lng(), timeUTC.getTotalHours()) / 15.0));
8+
}
9+
10+
static const float Sidereal::calculateTheta(float deltaJ, float longitude, float timeUTC){
11+
float theta = C1;
12+
theta += C2 * deltaJ;
13+
theta += C3 * timeUTC;
14+
theta += longitude;
15+
return fmod(theta, 360.0);
16+
}
17+
18+
static const int Sidereal::calculateDeltaJd(int year, int month, int day){
19+
const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
20+
21+
// Calculating days without leapdays
22+
long int deltaJd = (year - REFERENCE_JEAR) * 365 + day;
23+
for (int i=0; i < month - 1; i++){deltaJd += daysInMonth[i];}
24+
25+
// Add leapdays
26+
if (month <= 2){year--;}
27+
deltaJd += (year / 4 - year / 100 + year / 400);
28+
deltaJd -= (REFERENCE_JEAR / 4 - REFERENCE_JEAR / 100 + REFERENCE_JEAR / 400);
29+
return deltaJd;
30+
}

Software/Arduino code/Sidereal.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <math.h>
4+
#include <TinyGPS++.h>
5+
6+
#include "DayTime.hpp"
7+
8+
// Constants for sidereal calculation
9+
// Source: http://www.stargazing.net/kepler/altaz.html
10+
#define C1 100.46
11+
#define C2 0.985647
12+
#define C3 15
13+
#define REFERENCE_JEAR 2000
14+
15+
16+
class Sidereal
17+
{
18+
public:
19+
static DayTime calculateByGPS(TinyGPSPlus* gps);
20+
21+
private:
22+
static const float calculateTheta(float deltaJ, float longitude, float timeUTC);
23+
static const int calculateDeltaJd(int year, int month, int day);
24+
};

0 commit comments

Comments
 (0)