Skip to content

Commit 756ffaf

Browse files
V1.6.10 - Updates
- Placed all Serial output, except Meade Protocol implementation inside a DEBUG_MODE define - Removed a bunch of logging/commented out code. - Correctly implement current RA and DEC retrieval.
1 parent e04835c commit 756ffaf

File tree

7 files changed

+64
-38
lines changed

7 files changed

+64
-38
lines changed

Software/Arduino code/OpenAstroTracker/DayTime.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ void DayTime::addHours(int deltaHours) {
9090
}
9191

9292
void DayTime::checkHours() {
93-
Serial.println("DtIn: "+String(hours));
9493
while (hours >= hourWrap) {
9594
hours -= hourWrap;
9695
}
9796
while (hours < 0) {
9897
hours += hourWrap;
9998
}
100-
Serial.println("DtOut: "+String(hours));
10199
}
102100

103101
// Add minutes, wrapping hours if needed
@@ -208,10 +206,8 @@ float DegreeTime::getTotalDegrees() {
208206

209207
void DegreeTime::checkHours() {
210208
if (NORTHERN_HEMISPHERE) {
211-
Serial.println("DgIn: "+String(hours));
212209
if (hours > 0) hours = 0;
213210
if (hours < -180) hours = -180;
214-
Serial.println("DgOut: "+String(hours));
215211
} else {
216212
if (hours > 180) hours = 180;
217213
if (hours < 0) hours = 0;

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,29 @@ DegreeTime& Mount::targetDEC() {
164164
/////////////////////////////////
165165
// Get current RA value.
166166
const DayTime Mount::currentRA() const {
167-
// there are twice as many steps since this motor is being half-stepped.
168-
// It's negative because the motor coordinates increase CCW
169-
float raPosDegrees = -2.0 * _stepperRA->currentPosition() / _stepsPerRADegree;
170-
float raPos = raPosDegrees / siderealDegreesInHour;
171-
return raPos;
167+
if (!isSlewingRA() || (_mountStatus & STATUS_SLEWING_TO_TARGET) == 0) return _currentRA;
168+
169+
// How many steps are needed between current and target
170+
long deltaSteps = _stepperRA->targetPosition() - _currentRAStepperPosition;
171+
172+
// Calculate how far along (0..1) we are
173+
float alongPathNormalized = 1.0 * (_stepperRA->currentPosition() - _currentRAStepperPosition) / deltaSteps;
174+
175+
float raT = _targetRA.getTotalHours();
176+
float raC = _currentRA.getTotalHours();
177+
float deltaT = raT - raC;
178+
179+
// If we're rolling over, take the short route. i.e. if the motor direction indicates
180+
// the other direction than the math, move the target beyond current in the right direction
181+
if ( (raT < raC && (deltaSteps < 0)) || (raT > raC && (deltaSteps > 0))) {
182+
raT += (deltaSteps < 0) ? 24 : -24;
183+
deltaT = raT - raC;
184+
}
185+
186+
// Move the RA along by wher we are, fractionally
187+
raC += deltaT * alongPathNormalized;
188+
189+
return raC;
172190
}
173191

174192
/////////////////////////////////
@@ -178,9 +196,19 @@ const DayTime Mount::currentRA() const {
178196
/////////////////////////////////
179197
// Get current DEC value.
180198
const DegreeTime Mount::currentDEC() const {
181-
float decPosDegrees = 1.0 * _stepperDEC->currentPosition() / _stepsPerDECDegree;
182-
// return NORTHERN_HEMISPHERE ? 90 - decPosDegrees : 90 + decPosDegrees ;
183-
return decPosDegrees;
199+
if (!isSlewingDEC() || (_mountStatus & STATUS_SLEWING_TO_TARGET) == 0) return _currentDEC;
200+
201+
// How many steps are needed between current and target
202+
long deltaSteps = _stepperDEC->targetPosition() - _currentDECStepperPosition;
203+
204+
// Calculate how far along (0..1) we are
205+
float alongPathNormalized = 1.0 * (_stepperDEC->currentPosition() - _currentDECStepperPosition) / deltaSteps;
206+
207+
float decT = _targetDEC.getTotalDegrees();
208+
float decC = _currentDEC.getTotalDegrees();
209+
float deltaT = decT - decC;
210+
decC += deltaT * alongPathNormalized;
211+
return decC;
184212
}
185213

186214
/////////////////////////////////
@@ -193,11 +221,14 @@ const DegreeTime Mount::currentDEC() const {
193221
void Mount::startSlewingToTarget() {
194222
//Serial.println("StSlew2Trgt!");
195223
// Calculate new RA stepper target (and DEC)
224+
_currentDECStepperPosition = _stepperDEC->currentPosition();
225+
_currentRAStepperPosition = _stepperRA->currentPosition();
226+
196227
calculateRAandDECSteppers();
228+
197229
_mountStatus |= STATUS_SLEWING | STATUS_SLEWING_TO_TARGET;
198230
_totalDECMove = 1.0f * _stepperDEC->distanceToGo();
199231
_totalRAMove = 1.0f * _stepperRA->distanceToGo();
200-
// Serial.println("StSlew2Trgt: M " + String(_mountStatus) + " Totals: R" + String(_totalRAMove) + "D" + String(_totalDECMove));
201232
}
202233

203234
/////////////////////////////////
@@ -462,6 +493,12 @@ void Mount::loop() {
462493
_mountStatus &= ~(STATUS_SLEWING | STATUS_SLEWING_TO_TARGET);
463494

464495
if (_stepperWasRunning) {
496+
// Mount is at Target!
497+
_currentRA = _targetRA;
498+
_currentDEC = _targetDEC;
499+
_currentDECStepperPosition = _stepperDEC->currentPosition();
500+
_currentRAStepperPosition = _stepperRA->currentPosition();
501+
465502
// Make sure we do one last update when the steppers have stopped.
466503
displayStepperPosition();
467504
_lcdMenu->updateDisplay();

Software/Arduino code/OpenAstroTracker/Mount.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,15 @@ class Mount {
128128
int _stepsPerDECDegree;
129129
long _lastHASet;
130130
DayTime _HAAdjust;
131+
131132
DayTime _targetRA;
133+
DayTime _currentRA;
134+
long _currentRAStepperPosition;
135+
132136
DegreeTime _targetDEC;
137+
DegreeTime _currentDEC;
138+
long _currentDECStepperPosition;
139+
133140
float _totalDECMove;
134141
float _totalRAMove;
135142

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

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

1919
// See NORTHERN_HEMISPHERE in Globals.h if you not in the northern hemisphere
2020

@@ -70,16 +70,11 @@ int s = 25;
7070
// The same could be done for the DEC coordinates but they dont change significantly for the next 5 years
7171

7272
// Comment this out to save some code space
73-
#define DEBUG_MODE
73+
// #define DEBUG_MODE
7474

7575
// Uncomment this to support the heating menu
7676
// NOTE: Heating is currently not supported!
7777
// #define SUPPORT_HEATING
7878

7979
// Uncomment to run a key diagnostic
8080
// #define LCD_BUTTON_TEST
81-
82-
83-
// Started at 25672 and 1312 -- with f_serial
84-
// finished at 23830 and 1111 -- without f_serial.
85-
// finished at 23740 and 1117 -- Keyboard class, bug fixes, without f_serial.

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ void setup() {
1616
Serial.begin(57600);
1717
//BT.begin(9600);
1818

19+
#ifdef DEBUG_MODE
1920
Serial.println("Hello");
21+
#endif
2022

2123
// Show a splash screen
2224
lcdMenu.setCursor(0, 0);
@@ -42,10 +44,13 @@ void setup() {
4244
// Read persisted values adn set in mount
4345
inputcal = EEPROM.read(0);
4446
DayTime haTime = DayTime(EEPROM.read(1), EEPROM.read(2), 0);
45-
Serial.println("InputCal: " + String(inputcal));
4647
mount.setSpeedCalibration(speed + inputcal / 10000);
48+
#ifdef DEBUG_MODE
49+
Serial.println("InputCal: " + String(inputcal));
4750
Serial.println("SpeedCal: " + String(mount.getSpeedCalibration(), 5));
4851
Serial.println("TRKSpeed: " + String(mount.getSpeed(TRACKING), 5));
52+
#endif
53+
4954
mount.setHA(haTime);
5055

5156
// Start the tracker.
@@ -67,5 +72,8 @@ void setup() {
6772
while (millis() - now < 750) {
6873
mount.loop();
6974
}
75+
#ifdef DEBUG_MODE
7076
Serial.println("SetupDone");
77+
#endif
78+
7179
}

Software/Arduino code/OpenAstroTracker/c75_menuCTRL.ino

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,51 +46,38 @@ bool processControlKeys() {
4646
}
4747

4848
if (lcdButtons.keyChanged(key)) {
49-
//Serial.print("KEY CHANGE!");
5049
switch (key) {
5150
case btnUP: {
52-
//Serial.print("KEY UP:");
5351
if (!mount.isSlewingDEC()) {
54-
//Serial.println(" Go N");
5552
mount.startSlewing(NORTH);
5653
} else {
57-
//Serial.println(" Stop NS");
5854
mount.stopSlewing(NORTH | SOUTH);
5955
}
6056
}
6157
break;
6258

6359
case btnDOWN: {
64-
//Serial.print("KEY DN:");
6560
if (!mount.isSlewingDEC()) {
66-
//Serial.println(" Go S");
6761
mount.startSlewing(SOUTH);
6862
} else {
69-
//Serial.println(" Stop NS");
7063
mount.stopSlewing(NORTH | SOUTH);
7164
}
7265
}
7366
break;
7467

7568
case btnLEFT: {
76-
//Serial.print("KEY LF:");
7769
if (!mount.isSlewingRA()) {
78-
//Serial.println(" Go W");
7970
mount.startSlewing(WEST);
8071
} else {
81-
//Serial.println(" Stop EW");
8272
mount.stopSlewing(EAST | WEST);
8373
}
8474
}
8575
break;
8676

8777
case btnRIGHT: {
88-
//Serial.print("KEY RT:");
8978
if (!mount.isSlewingRA()) {
90-
//Serial.println(" Go E");
9179
mount.startSlewing(EAST);
9280
} else {
93-
//Serial.println(" Stop EW");
9481
mount.stopSlewing(EAST | WEST);
9582
}
9683
}

Software/Arduino code/OpenAstroTracker/c_buttons.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,9 @@ void loop() {
100100
}
101101

102102
if (waitForButtonRelease) {
103-
//Serial.print("Wait:");
104103
if (lcdButtons.currentKey() != btnNONE) {
105-
//Serial.println("KeyNotNone:");
106104
do {
107105
if (lcdButtons.currentKey() == btnNONE) {
108-
//Serial.println("KeyIsNone:");
109106
break;
110107
}
111108

@@ -114,7 +111,6 @@ void loop() {
114111
}
115112
while (true);
116113
}
117-
//Serial.println("WaitOver:");
118114
}
119115

120116
// Input handled, do output

0 commit comments

Comments
 (0)