Skip to content

Commit 780453c

Browse files
V1.6.60 - Updates
- Fixed a bug in the Go Home function that did not reset the RA target value. - Added support for setting backlash steps in the CAL menu.
1 parent 742bb55 commit 780453c

File tree

4 files changed

+147
-50
lines changed

4 files changed

+147
-50
lines changed

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ void Mount::readPersistentData()
9292
{
9393
// Read the magic marker byte and state
9494
int marker = EEPROM.read(4) + EEPROM.read(5) * 256;
95-
#ifdef DEBUG_MODE
96-
logv("EEPROM: Marker is %d", marker);
97-
#endif
9895
if ((marker & 0xFF01) == 0xBE01) {
9996
_stepsPerRADegree = EEPROM.read(6) + EEPROM.read(7) * 256;
10097
#ifdef DEBUG_MODE
@@ -121,7 +118,7 @@ void Mount::readPersistentData()
121118
if ((marker & 0xFF08) == 0xBE08) {
122119
_backlashCorrectionSteps = EEPROM.read(10) + EEPROM.read(11) * 256;
123120
#ifdef DEBUG_MODE
124-
logv("EEPROM: Backash Steps Marker OK! Backlash correction is %d", _backlashCorrectionSteps);
121+
logv("EEPROM: Backlash Steps Marker OK! Backlash correction is %d", _backlashCorrectionSteps);
125122
#endif
126123
}
127124

@@ -301,8 +298,8 @@ int Mount::getBacklashCorrection()
301298
// The EEPROM storage location 5 is set to 0xBE if this value has ever been written. The storage location 4
302299
// contains a bitfield indicating which values have been stored. Currently bit 0 is used for RA and bit 1 for DEC.
303300
void Mount::setBacklashCorrection(int steps) {
304-
writePersistentData(BACKLASH_CORRECTION, steps);
305301
_backlashCorrectionSteps = steps;
302+
writePersistentData(BACKLASH_CORRECTION, steps);
306303
}
307304

308305
/////////////////////////////////
@@ -403,7 +400,11 @@ const DayTime Mount::currentRA() const {
403400
logv("CurrentRA: ZeroPos : %s", _zeroPosRA.ToString());
404401
logv("CurrentRA: POS (+zp) : %s", DayTime(hourPos).ToString());
405402
#endif
406-
if (_stepperDEC->currentPosition() < 0)
403+
404+
bool flipRA = NORTHERN_HEMISPHERE ?
405+
_stepperDEC->currentPosition() < 0
406+
: _stepperDEC->currentPosition() > 0;
407+
if (flipRA)
407408
{
408409
hourPos += 12;
409410
if (hourPos > 24) hourPos -= 24;
@@ -427,11 +428,23 @@ const DayTime Mount::currentRA() const {
427428
const DegreeTime Mount::currentDEC() const {
428429

429430
float degreePos = 1.0 * _stepperDEC->currentPosition() / _stepsPerDECDegree;
431+
#ifdef DEBUG_MODE
432+
logv("CurrentDEC: Steps/deg : %d", _stepsPerDECDegree);
433+
logv("CurrentDEC: DEC Steps : %d", _stepperDEC->currentPosition());
434+
logv("CurrentDEC: POS : %s", String(degreePos).c_str());
435+
#endif
436+
430437
if (degreePos > 0)
431438
{
432439
degreePos = -degreePos;
440+
#ifdef DEBUG_MODE
441+
logv("CurrentDEC: Greater Zero, flipping.");
442+
#endif
433443
}
434444

445+
#ifdef DEBUG_MODE
446+
logv("CurrentDEC: POS : %s", DegreeTime(degreePos).ToString());
447+
#endif
435448
return degreePos;
436449
}
437450

@@ -666,6 +679,7 @@ void Mount::goHome()
666679
stopGuiding();
667680
setTargetToHome();
668681
startSlewingToTarget();
682+
_slewingToHome = true;
669683
}
670684

671685
/////////////////////////////////
@@ -1090,6 +1104,7 @@ void Mount::loop() {
10901104
#endif
10911105
_stepperRA->setCurrentPosition(0);
10921106
_stepperTRK->setCurrentPosition(0);
1107+
_targetRA = currentRA();
10931108
if (isParking()) {
10941109
#ifdef DEBUG_MODE
10951110
logv("Loop: Was parking, so no tracking.");
@@ -1124,14 +1139,23 @@ void Mount::loop() {
11241139
//
11251140
/////////////////////////////////
11261141
void Mount::setHome() {
1142+
#ifdef DEBUG_MODE
1143+
logv("Mount::setHomePre: currentRA is %s", currentRA().ToString());
1144+
logv("Mount::setHomePre: zeroPos is %s", _zeroPosRA.ToString());
1145+
logv("Mount::setHomePre: targetRA is %s", targetRA().ToString());
1146+
#endif
11271147
_zeroPosRA = currentRA();
11281148

11291149
_stepperRA->setCurrentPosition(0);
11301150
_stepperDEC->setCurrentPosition(0);
11311151
_stepperTRK->setCurrentPosition(0);
11321152

1153+
_targetRA = currentRA();
1154+
11331155
#ifdef DEBUG_MODE
1134-
logv("Mount::setHome: ZeroPosRA set to %s", _zeroPosRA.ToString());
1156+
logv("Mount::setHomePost: currentRA is %s", currentRA().ToString());
1157+
logv("Mount::setHomePost: zeroPos is %s", _zeroPosRA.ToString());
1158+
logv("Mount::setHomePost: targetRA is %s", targetRA().ToString());
11351159
#endif
11361160
}
11371161

@@ -1148,9 +1172,10 @@ void Mount::setTargetToHome() {
11481172
// offset HATime by elapsed time since last HA set and also
11491173
// adjust RA by the elapsed time and set it to zero.
11501174
#ifdef DEBUG_MODE
1151-
logv("Mount::setTargetToHome: Pre-ZeroPosRA is %s", _zeroPosRA.ToString());
1152-
logv("Mount::setTargetToHome: TrackedSeconds is %f, TRK Stepper: %l", trackedSeconds, _stepperTRK->currentPosition());
1153-
logv("Mount::setTargetToHome: Pre-LST is %s", _LST.ToString());
1175+
logv("Mount::setTargetToHomePre: currentRA is %s", currentRA().ToString());
1176+
logv("Mount::setTargetToHomePre: ZeroPosRA is %s", _zeroPosRA.ToString());
1177+
logv("Mount::setTargetToHomePre: TrackedSeconds is %f, TRK Stepper: %l", trackedSeconds, _stepperTRK->currentPosition());
1178+
logv("Mount::setTargetToHomePre: LST is %s", _LST.ToString());
11541179
#endif
11551180
DayTime lst(_LST);
11561181
lst.addSeconds(trackedSeconds);
@@ -1159,9 +1184,10 @@ void Mount::setTargetToHome() {
11591184
_targetRA.addSeconds(trackedSeconds);
11601185

11611186
#ifdef DEBUG_MODE
1162-
logv("Mount::setTargetToHome: Post-ZeroPosRA is %s", _zeroPosRA.ToString());
1163-
logv("Mount::setTargetToHome: Post-LST is %s", _LST.ToString());
1164-
logv("Mount::setTargetToHome: Post-TargetRA is %s", _targetRA.ToString());
1187+
logv("Mount::setTargetToHomePost: currentRA is %s", currentRA().ToString());
1188+
logv("Mount::setTargetToHomePost: ZeroPosRA is %s", _zeroPosRA.ToString());
1189+
logv("Mount::setTargetToHomePost: LST is %s", _LST.ToString());
1190+
logv("Mount::setTargetToHomePost: TargetRA is %s", _targetRA.ToString());
11651191
#endif
11661192

11671193
// Set DEC to pole
@@ -1199,23 +1225,24 @@ float Mount::getSpeed(int direction) {
11991225
/////////////////////////////////
12001226
void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12011227
#ifdef DEBUG_MODE
1202-
logv("Mount::CalcSteppers: Target RA: %s, Target DEC: %s", _targetRA.ToString(), _targetDEC.ToString());
1203-
logv("Mount::CalcSteppers: ZeroRA: %s", _zeroPosRA.ToString());
1204-
logv("Mount::CalcSteppers: Steppers: RA: %l, DEC: %l, TRK: %l", _stepperRA->currentPosition(), _stepperDEC->currentPosition(), _stepperTRK->currentPosition());
1228+
logv("Mount::CalcSteppersPre: Current: RA: %s, DEC: %s", currentRA().ToString(), currentDEC().ToString());
1229+
logv("Mount::CalcSteppersPre: Target : RA: %s, DEC: %s", _targetRA.ToString(), _targetDEC.ToString());
1230+
logv("Mount::CalcSteppersPre: ZeroRA : %s", _zeroPosRA.ToString());
1231+
logv("Mount::CalcSteppersPre: Stepper: RA: %l, DEC: %l, TRK: %l", _stepperRA->currentPosition(), _stepperDEC->currentPosition(), _stepperTRK->currentPosition());
12051232
#endif
12061233
DayTime raTarget = _targetRA;
12071234

12081235
raTarget.subtractTime(_zeroPosRA);
12091236
#ifdef DEBUG_MODE
1210-
logv("Mount::CalcSteppers: Adjust RA by Zeropos. New Target RA: %s, DEC: %s", raTarget.ToString(), _targetDEC.ToString());
1237+
logv("Mount::CalcSteppersIn: Adjust RA by Zeropos. New Target RA: %s, DEC: %s", raTarget.ToString(), _targetDEC.ToString());
12111238
#endif
12121239

12131240
float hourPos = raTarget.getTotalHours();
12141241
// Map [0 to 24] range to [-12 to +12] range
12151242
if (hourPos > 12) {
12161243
hourPos = hourPos - 24;
12171244
#ifdef DEBUG_MODE
1218-
logv("Mount::CalcSteppers: RA>12 so -24. New Target RA: %s, DEC: %s", DayTime(hourPos).ToString(), _targetDEC.ToString());
1245+
logv("Mount::CalcSteppersIn: RA>12 so -24. New Target RA: %s, DEC: %s", DayTime(hourPos).ToString(), _targetDEC.ToString());
12191246
#endif
12201247
}
12211248

@@ -1230,8 +1257,8 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12301257
float moveDEC = -_targetDEC.getTotalDegrees() * _stepsPerDECDegree;
12311258

12321259
#ifdef DEBUG_MODE
1233-
logv("Mount::CalcSteppers: RA Steps/deg: %d Steps/srhour: %f", _stepsPerRADegree, stepsPerSiderealHour);
1234-
logv("Mount::CalcSteppers: Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
1260+
logv("Mount::CalcSteppersIn: RA Steps/deg: %d Steps/srhour: %f", _stepsPerRADegree, stepsPerSiderealHour);
1261+
logv("Mount::CalcSteppersIn: Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
12351262
#endif
12361263

12371264
// We can move 6 hours in either direction. Outside of that we need to flip directions.
@@ -1240,31 +1267,34 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12401267
// If we reach the limit in the positive direction ...
12411268
if (moveRA > RALimit) {
12421269
#ifdef DEBUG_MODE
1243-
logv("Mount::CalcSteppers: RA is past +limit: %f, DEC: %f", RALimit);
1270+
logv("Mount::CalcSteppersIn: RA is past +limit: %f, DEC: %f", RALimit);
12441271
#endif
12451272

12461273
// ... turn both RA and DEC axis around
12471274
float oldRA = moveRA;
12481275
moveRA -= long(12.0f * stepsPerSiderealHour / 2);
12491276
moveDEC = -moveDEC;
12501277
#ifdef DEBUG_MODE
1251-
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
1278+
logv("Mount::CalcSteppersIn: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
12521279
#endif
12531280
}
12541281
// If we reach the limit in the negative direction...
12551282
else if (moveRA < -RALimit) {
12561283
#ifdef DEBUG_MODE
1257-
logv("Mount::CalcSteppers: RA is past -limit: %f, DEC: %f", -RALimit);
1284+
logv("Mount::CalcSteppersIn: RA is past -limit: %f, DEC: %f", -RALimit);
12581285
#endif
12591286
// ... turn both RA and DEC axis around
12601287
float oldRA = moveRA;
12611288
moveRA += long(12.0f * stepsPerSiderealHour / 2);
12621289
moveDEC = -moveDEC;
12631290
#ifdef DEBUG_MODE
1264-
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
1291+
logv("Mount::CalcSteppersPost: Adjusted Target. Moved RA, inverted DEC");
12651292
#endif
12661293
}
12671294

1295+
#ifdef DEBUG_MODE
1296+
logv("Mount::CalcSteppersPost: Target Steps RA: %f, DEC: %f", moveRA, moveDEC);
1297+
#endif
12681298
// float targetRA = clamp(-moveRA, -RAStepperLimit, RAStepperLimit);
12691299
// float targetDEC = clamp(moveDEC, DECStepperUpLimit, DECStepperDownLimit);
12701300
targetRA = -moveRA;
@@ -1280,11 +1310,13 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
12801310
// Serial.println("Moving DEC from " + String(stepperDEC.currentPosition()) + " to " + targetDEC);
12811311
// }
12821312
}
1313+
12831314
void Mount::moveSteppersTo(float targetRA, float targetDEC) {
12841315
// Show time: tell the steppers where to go!
12851316
_correctForBacklash = false;
12861317
#ifdef DEBUG_MODE
1287-
logv("Mount::MoveSteppersTo: RA Cur: %l, Trg: %f", _stepperRA->currentPosition(), targetRA);
1318+
logv("Mount::MoveSteppersTo: RA From: %l To: %f", _stepperRA->currentPosition(), targetRA);
1319+
logv("Mount::MoveSteppersTo: DEC From: %l To: %f", _stepperDEC->currentPosition(), targetDEC);
12881320
#endif
12891321

12901322
if ((_stepperRA->currentPosition() - targetRA) > 0) {
@@ -1383,12 +1415,24 @@ void Mount::displayStepperPositionThrottled() {
13831415
String Mount::DECString(byte type, byte active) {
13841416
DegreeTime dec;
13851417
if ((type & TARGET_STRING) == TARGET_STRING) {
1418+
#ifdef DEBUG_MODE
1419+
logv("DECString: TARGET!");
1420+
#endif
13861421
dec = DegreeTime(_targetDEC);
13871422
}
13881423
else {
1424+
#ifdef DEBUG_MODE
1425+
logv("DECString: CURRENT!");
1426+
#endif
13891427
dec = DegreeTime(currentDEC());
13901428
}
1429+
#ifdef DEBUG_MODE
1430+
logv("DECString: Precheck : %s", dec.ToString());
1431+
#endif
13911432
dec.checkHours();
1433+
#ifdef DEBUG_MODE
1434+
logv("DECString: Postcheck : %s", dec.ToString());
1435+
#endif
13921436

13931437
sprintf(scratchBuffer, formatStringsDEC[type & FORMAT_STRING_MASK], dec.getPrintDegrees() > 0 ? '+' : '-', int(fabs(dec.getPrintDegrees())), dec.getMinutes(), dec.getSeconds());
13941438
if ((type & FORMAT_STRING_MASK) == LCDMENU_STRING) {

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "Globals.h"
1818

19-
String version = "V1.6.59";
19+
String version = "V1.6.60";
2020

2121
///////////////////////////////////////////////////////////////////////////
2222
// Please see the Globals.h file for configuration of the firmware.

Software/Arduino code/OpenAstroTracker/c72_menuHA.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bool processHAKeys() {
3434
EEPROM.update(2, mount.HA().getMinutes());
3535
lcdMenu.printMenu("Stored.");
3636
mount.delay(500);
37+
mount.setHome();
3738

3839
#ifdef SUPPORT_GUIDED_STARTUP
3940
if (startupState == StartupWaitForHACompletion) {

0 commit comments

Comments
 (0)