Skip to content

Commit 86df8d2

Browse files
Merge pull request #44 from MichelDequick/develop
TinyGPSPlus based LST calculator
2 parents faabbfd + a71deba commit 86df8d2

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Software/Arduino code/Sidereal.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "Sidereal.hpp"
2+
3+
// Constants for sidereal calculation
4+
// Source: http://www.stargazing.net/kepler/altaz.html
5+
#define C1 100.46
6+
#define C2 0.985647
7+
#define C3 15.0
8+
#define C4 -0.5125
9+
#define J2000 2000
10+
11+
static DayTime Sidereal::calculateByGPS(TinyGPSPlus* gps){
12+
DayTime timeUTC = DayTime(gps->time.hour(), gps->time.minute(), gps->time.second());
13+
int deltaJd = calculateDeltaJd(gps->date.year(), gps->date.month(), gps->date.day());
14+
double deltaJ = deltaJd + ((timeUTC.getTotalHours()) / 24.0);
15+
return DayTime((float)(calculateTheta(deltaJ, gps->location.lng(), timeUTC.getTotalHours()) / 15.0));
16+
}
17+
18+
static const double Sidereal::calculateTheta(double deltaJ, double longitude, float timeUTC){
19+
double theta = C1;
20+
theta += C2 * deltaJ;
21+
theta += C3 * timeUTC;
22+
theta += C4;
23+
theta += longitude;
24+
return fmod(theta, 360.0);
25+
}
26+
27+
static const int Sidereal::calculateDeltaJd(int year, int month, int day){
28+
const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
29+
30+
// Calculating days without leapdays
31+
long int deltaJd = (year - J2000) * 365 + day;
32+
for (int i=0; i < month - 1; i++){
33+
deltaJd += daysInMonth[i];
34+
}
35+
36+
// Add leapdays
37+
if (month <= 2){
38+
// Not counting current year if we have not passed february yet
39+
year--;
40+
}
41+
deltaJd += year / 4 - year / 100 + year / 400;
42+
deltaJd -= J2000 / 4 - J2000 / 100 + J2000 / 400;
43+
return deltaJd;
44+
}

Software/Arduino code/Sidereal.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <math.h>
4+
#include <TinyGPS++.h>
5+
6+
#include "DayTime.hpp"
7+
8+
9+
class Sidereal
10+
{
11+
public:
12+
static DayTime calculateByGPS(TinyGPSPlus* gps);
13+
14+
private:
15+
static const double calculateTheta(double deltaJ, double longitude, float timeUTC);
16+
static const int calculateDeltaJd(int year, int month, int day);
17+
};

0 commit comments

Comments
 (0)