Skip to content

Commit fb2f672

Browse files
V1.5.20 - Updates
- Fixed a bug in time handling (affected HA loading) - Home menu now takes travelled tracker distance into account and adjusts HA time accordingly. - Removed Polaris menu and added Polaris as the first Point of Interest. - Added new INFO menu to show stepper motor positions, version number and any other info that seems needed. - Removed some of the magic numbers in the stepper calculations that seemed unnecessary. - Renamed some variables to better describe their meaning. - Added general comments as well as comments explaining the math behind calculating the RA and DEC steps. - Changed the RASteps value substantially (from 330 to 300) in accordance with the math of the hardware setup. Hopefully this will make speed calibration superfluous. It works on my - Changed speed calibration to be a factor instead of an addition. - Improved the display while moving (now displays during stopping and displays final coordinate) - Serial fix: RA setter was not correcting the passed RA correctly. - Serial fix: Quit command only stops motors for extended command (:Qq#). Regular Quit leaves the motors as they are. - Serial fix: Added HA set command (:SH)
1 parent c356b34 commit fb2f672

17 files changed

+272
-226
lines changed

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@
1414
1515
=======================================================================================================================================
1616
*/
17-
String version = "V1.5.11";
17+
String version = "V1.5.20";
1818

1919
boolean north = true; // change this to 'false' if youre in the southern hemisphere
2020

2121
float speed = 1.000; // Use this value to slightly increase or decrese tracking speed. The values from the "CAL" menu will be added to this.
2222

23-
24-
// Belt moves 40mm for one rev (2mm pitch, 20 teeth).
25-
// RA wheel is 2 x Pi x 180mm circumference which is 1130.97mm
26-
// One RA revolution needs 28.27 (1131mm/40mm) stepper revolutions
27-
// which means 115814 steps (28.27 x 4096) moves 360 degrees
28-
// So 321.7 steps/ degree (115814 / 360)
29-
int RAStepsPerDegree = 330; // adjust this value to calibrate RA movement
30-
31-
// Belt moves 40mm for one rev (2mm pitch, 20 teeth).
32-
// DEC wheel is 2 x Pi x 90mm circumference which is 565.5mm
33-
// So 14.13 stepper revs (14.13 x 4096 = 57906 steps) moves 360degrees
34-
// So 160.85 steps/ degree (57906/360)
35-
int DECStepsPerDegree = 163; // Number of steps needed to move DEC motor 1 degree.
23+
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
24+
// RA wheel is 2 x PI x 168.24mm circumference = 1057.1mm
25+
// One RA revolution needs 26.43 (1057.1mm / 40mm) stepper revolutions
26+
// Which means 108245 steps (26.43 x 4096) moves 360 degrees
27+
// So there are 300.1 steps/degree (108245 / 360)
28+
int RAStepsPerDegree = 300; // adjust this value to calibrate RA movement
29+
30+
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
31+
// DEC wheel is 2 x PI x 90mm circumference which is 565.5mm
32+
// One DEC revolution needs 14.13 (565.5mm/40mm) stepper revolutions
33+
// Which means 57907 steps (14.14 x 4096) moves 360 degrees
34+
// So there are 160.85 steps/degree (57907/360)
35+
int DECStepsPerDegree = 161; // Number of steps needed to move DEC motor 1 degree.
3636

3737
// This is how many steps your 28BYJ-48 stepper needs for a full rotation. It is almost always 4096.
3838
// This code drives the steppers in halfstep mode

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,113 +36,113 @@ LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
3636
#define RA_Menu 0
3737
#define DEC_Menu 1
3838
#define HA_Menu 2
39-
#define Polaris_Menu 3
4039
#define Heat_Menu 4
4140
#define Calibration_Menu 5
4241
#define Control_Menu 6
4342
#define Home_Menu 7
4443
#define POI_Menu 8
44+
#define Status_Menu 9
4545

4646
// Stepper control for RA and DEV.
4747
// TRK is used for live tracking and runs in parallel with RA.
4848
// GUIDE is used for Stellarium control
4949
AccelStepper stepperRA(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
5050
AccelStepper stepperDEC(HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
51-
AccelStepper stepperTRK(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); //yes, this is the same motor as stepperRA, dont ask why
52-
AccelStepper stepperGUIDE(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
5351

54-
int lcd_key = 0; // The current key state
55-
int adc_key_in = 0; // The analog value of the keys
52+
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
53+
AccelStepper stepperTRK(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
54+
55+
// Use another AccelStepper to run the RA motor as well for use with Stellarium... hmmmm....
56+
AccelStepper stepperGUIDE(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
5657

5758
String inString = "";
5859

59-
bool inStartup = true; // Start with a guided startup
60+
bool inStartup = true; // Start with a guided startup
6061

62+
// Serial control variables
6163
bool inSerialControl = false; // When the serial port is in control
6264
bool serialIsSlewing = false; // When the serial port is slewing the tracker
65+
bool quitSerialOnNextButtonRelease = false; // Used to detect SELECT button to quit Serial mode.
66+
String logString;
67+
boolean isPulseGuiding = true;
6368

69+
// Display related variables
70+
int displayLoopsToSkip = 400; // Update the LCD every 400 iterations (perf issue)
71+
int displaySkipsLeft = 0; // How many loop cycles left before updating the display
72+
float totalDECMove = 0; // The number of DEC steps we asked for
73+
float totalRAMove = 0;
74+
int leftArrow = 3; // LCD special chars
75+
int rightArrow = 4; // LCD special chars
6476

65-
int calDelay = 150; // The current delay when changing calibration value. The longer a button is depressed, the samller this gets.
66-
67-
bool waitForButtonRelease = false; // When a button is pressed should we wait for its release before another loop?
77+
// Calibration variables
78+
float inputcal; // calibration variable set form as integer. Added to speed after dividing by 10000
79+
float speedCalibration; // speed calibration factor
80+
int calDelay = 150; // The current delay in ms when changing calibration value. The longer a button is depressed, the smaller this gets.
6881

6982
// Variables for use in the CONTROL menu
83+
bool inControlMode = false; // Is manual control enabled
7084
int StateMaskDEC = 0x0011; // Is the DEC stepper running?
7185
int StateMaskUp = 0x0001; // Is the DEC stepper moving upwards?
7286
int StateMaskDown = 0x0010; // Is the DEC stepper moving downwards?
7387
int StateMaskRA = 0x1100; // Is the RA stepper running?
7488
int StateMaskLeft = 0x0100; // Is the RA stepper moving left (CW)?
7589
int StateMaskRight = 0x1000; // Is the RA stepper moving right (CCW)?
76-
7790
int controlState = 0x0000; // The current state of the steppers (combination of above values)
78-
int controlDisplay = 0; // How many loop cycles left before updating the display
79-
bool inControlMode = false; // Is manual control enabled
8091

92+
// Main loop variables
93+
int lcd_key = 0; // The current key state
94+
int adc_key_in = 0; // The analog value of the keys
95+
bool waitForButtonRelease = false; // When a button is pressed should we wait for its release before another loop?
8196
int lastKey = btnNONE; // The key state when we last came through the loop
8297

83-
float totalDECMove = 0; // The number of DEC steps we asked for
84-
float totalRAMove = 0;
98+
// Global variables
8599
bool isUnreachable = false;
86100

87-
//String inCmd;
88-
//String inputString = "";
89-
//String commandString = "";
90-
//boolean isConnected = false;
91-
92-
String logString;
93-
//boolean stringComplete = false;
94-
//unsigned long timeWait;
95-
boolean isPulseGuiding = true;
96-
97101
unsigned long Zeit;
98-
float stepsPerHour;
99102

103+
// Stepper motor variables
104+
float stepsPerHour; // How many steps does the RA stepper need to make to move 15 degrees (1 hour of earths rotation)
105+
float trackingSpeed; // At what speed does the RA stepper need to run to match earths rotation (steps/sec)
106+
int tracking = 1; // Are we tracking earths rotation?
107+
108+
// PC Control variables.
100109
boolean pcControl = false;
101-
int currentSecs;
102-
int currentMins;
103-
float inputcal;
104-
float speedcalibration;
110+
105111
int direction_old = 1;
106112
int direction_new;
107113

108-
int hPolarisPosition;
109-
int mPolarisPosition;
110-
111-
int tracking = 1;
112-
float trackingspeed;
113114

114-
// RA stuff
115+
// RA variables
115116
float moveRA;
116117
int RAselect;
117118

118-
//DEC stuff
119+
// DEC variables
119120
int degreeDEC;
120121
int minDEC;
121122
int secDEC;
122123
float moveDEC;
123124
int DECselect;
124125
int printdegDEC;
125126

126-
//Hour stuff
127+
// HA variables
127128
int HAselect;
129+
unsigned long lastHAset = 0;
128130

129-
// HEAT menu settings
131+
// HEAT menu variables
130132
int heatselect; // Which stepper are we changing?
131133
int RAheat = 0; // Are we heating the RA stepper?
132134
int DECheat = 0; // Are we heating the DEC stepper?
133135

134-
//Stellarium
136+
// Stellarium variables
135137
char current_RA[10];
136138
char current_DEC[12];
137139
int HAh_save;
138140
int HAm_save;
139141
float slew_RA;
140142
float slew_DEC;
141143

142-
// LCD special chars
143-
int leftArrow = 3;
144-
int rightArrow = 4;
145144

145+
// LCD Character bitmaps
146146
byte DegreesBitmap[8] = {
147147
B01100,
148148
B10010,

Software/Arduino code/OpenAstroTracker/b2_daytime.ino

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DayTime {
1919
secs = other.secs;
2020
}
2121

22-
DayTime(int m, int h, int s) {
22+
DayTime(int h, int m, int s) {
2323
hours = h;
2424
mins = m;
2525
secs = s;
@@ -92,7 +92,7 @@ class DayTime {
9292
}
9393

9494
// Add seconds, wrapping minutes and hours if needed
95-
void addSeconds(int deltaSecs) {
95+
void addSeconds(long deltaSecs) {
9696
secs += deltaSecs;
9797
while (secs > 59) {
9898
secs -= 60;
@@ -120,6 +120,14 @@ class DayTime {
120120
addHours(other.getHours());
121121
}
122122

123+
// Subtract another time, wrapping seconds, minutes and hours if needed
124+
void subtractTime(const DayTime& other)
125+
{
126+
addSeconds(-other.getSeconds());
127+
addMinutes(-other.getMinutes());
128+
addHours(-other.getHours());
129+
}
130+
123131
// Convert to a standard string (like 14:45:06)
124132
String ToString()
125133
{

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LcdMenu lcdMenu(&lcd, 16);
66
DayTime RATime;
77
DayTime RADisplayTime;
88
DayTime HATime;
9+
DayTime HACorrection;
910

1011
void setup() {
1112

@@ -43,32 +44,36 @@ void setup() {
4344

4445
// Read persisted values
4546
inputcal = EEPROM.read(0);
46-
speedcalibration = speed + inputcal / 10000;
47+
speedCalibration = speed + inputcal / 10000;
4748
HATime = DayTime(EEPROM.read(1), EEPROM.read(2), 0);
48-
49+
HACorrection.set(HATime);
50+
HACorrection.addTime(-h, -m, -s);
51+
lastHAset = millis();
52+
4953
#ifdef DEBUG_MODE
5054
logv("HATime = %s", HATime.ToString().c_str());
5155
#endif
5256

5357
// Create the menu items
54-
lcdMenu.addItem("RAs", RA_Menu);
58+
lcdMenu.addItem("RA", RA_Menu);
5559
lcdMenu.addItem("DEC", DEC_Menu);
5660
lcdMenu.addItem("POI", POI_Menu);
5761
lcdMenu.addItem("HOME", Home_Menu);
5862
lcdMenu.addItem("HA", HA_Menu);
59-
if (north) {
60-
lcdMenu.addItem("POL", Polaris_Menu);
61-
}
6263
#ifdef SUPPORT_HEATING
63-
lcdMenu.addItem("HEAT", Heat_Menu);
64+
lcdMenu.addItem("HEA", Heat_Menu);
6465
#endif
6566
lcdMenu.addItem("CTRL", Control_Menu);
6667
lcdMenu.addItem("CAL", Calibration_Menu);
68+
lcdMenu.addItem("INFO", Status_Menu);
6769

6870
// Show a splash screen
6971
lcd.setCursor(0, 0);
7072
lcd.print("OpenAstroTracker");
7173
lcd.setCursor(0, 1);
7274
lcd.print(" " + version);
7375
delay(1750);
76+
77+
doCalculations();
78+
stepperTRK.setSpeed(trackingSpeed);
7479
}

Software/Arduino code/OpenAstroTracker/c5_calcStepperPos.ino

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/////////////////////////////////////////////
12
// This code tells the steppers to what location to move to, given the select right ascension and declination
23
void handleDECandRACalculations()
34
{
@@ -8,14 +9,16 @@ void handleDECandRACalculations()
89
}
910

1011
// How many steps moves the RA ring one hour along (15degrees?) No idea what 288 is?
11-
stepsPerHour = (float(RAStepsPerDegree) / 288.0) * StepsPerRevolution;
12+
// stepsPerHour = (float(RAStepsPerDegree) / 288.0) * StepsPerRevolution;
13+
stepsPerHour = RAStepsPerDegree * 15.0;
1214

1315
// Where do we want to move RA to? Why divided by 2?
1416
float moveRA = hourPos * stepsPerHour / 2;
1517

1618
// Where do we want to move DEC to?
1719
// the variable degreeDEC is 0deg for the celestial pole (90deg), and goes negative only.
18-
moveDEC = (degreeDEC * float(DECStepsPerDegree) + minDEC * (float(DECStepsPerDegree) / 60.0f) + secDEC * (float(DECStepsPerDegree) / 3600.0f));
20+
moveDEC = degreeDEC + ( minDEC / 60.0f) + (secDEC / 3600.0f); // Convert to double
21+
moveDEC *= DECStepsPerDegree; // How many steps represent that position?
1922

2023
// We can move 6 hours in either direction. Outside of that we need to flip directions.
2124
float RALimit = (6.0f * stepsPerHour / 2);
@@ -50,19 +53,28 @@ void handleDECandRACalculations()
5053
stepperDEC.moveTo(targetDEC);
5154
}
5255

56+
/////////////////////////////////////////////
57+
// Runs the tracker stepper to compensate for earths rotation.
5358
void runTracker()
5459
{
5560
if (tracking == 1) {
5661
stepperTRK.runSpeed();
5762
}
5863
}
5964

60-
void doCalculations() {
61-
currentSecs = millis() / 1000;
65+
/////////////////////////////////////////////
66+
// Calculate tracking speed, RA and DEC display.
67+
void doCalculations() {
68+
69+
// Run speed for steppers is steps/second
70+
// What are these magic numbers??? 335.14? 288? 3590?
71+
//trackingSpeed = ((((335.1417 / 288.0) * StepsPerRevolution) / 3590)) - 1 + float(speedCalibration);
72+
73+
// The tracker simply needs to rotate at 15degrees/hour
74+
trackingSpeed = speedCalibration * RAStepsPerDegree * 15.0f / 3600.0f;
75+
stepperTRK.setSpeed(trackingSpeed);
6276

6377
RADisplayTime.set(RATime);
64-
DayTime HACorrection(HATime);
65-
HACorrection.addTime(-h, -m, -s);
6678
RADisplayTime.addTime(HACorrection);
6779

6880
if (!north) {

Software/Arduino code/OpenAstroTracker/c65_startup.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//////////////////////////////////////////////////////////////
2+
// This file contains the Starup 'wizard' that guides you through initial setup
3+
14
#define StartupIsPointedAtPole 1
25
#define StartupSetHATime 4
36
#define StartupWaitForHACompletion 6
@@ -13,7 +16,6 @@
1316
int startupState = StartupIsPointedAtPole;
1417
int isAtPole = NO;
1518

16-
1719
void startupIsCompleted() {
1820
startupState = StartupCompleted;
1921
inStartup = false;

0 commit comments

Comments
 (0)