From 296bca469c15d9bb3385fad8c3059cb5d9e84d8e Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 2 Dec 2022 00:37:15 -0800 Subject: [PATCH 01/14] WIP - Move hemisphere to variable --- Configuration.hpp | 5 --- src/Declination.cpp | 28 +++++++++-------- src/MeadeCommandProcessor.cpp | 58 +++++++++++++++++++++++++++++++---- src/Mount.cpp | 31 ++++++++++--------- src/b_setup.hpp | 1 + src/c76_menuCAL.hpp | 4 +-- src/inc/Globals.cpp | 1 + src/inc/Globals.hpp | 1 + 8 files changed, 89 insertions(+), 40 deletions(-) diff --git a/Configuration.hpp b/Configuration.hpp index 13a60e94..91e96742 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -47,11 +47,6 @@ #error You have to specify the board #endif -// Set to 1 for the northern hemisphere, 0 otherwise -#ifndef NORTHERN_HEMISPHERE - #define NORTHERN_HEMISPHERE 1 -#endif - /** * @brief Display & keypad configuration. * See Constants.hpp for supported DISPLAY_TYPE options. diff --git a/src/Declination.cpp b/src/Declination.cpp index 9f8eef2b..884bb3dc 100644 --- a/src/Declination.cpp +++ b/src/Declination.cpp @@ -1,4 +1,5 @@ -#include "../Configuration.hpp" // For NORTHERN_HEMISPHERE only +#include "./inc/Globals.hpp" +#include "../Configuration.hpp" #include "Utility.hpp" #include "Declination.hpp" @@ -11,13 +12,13 @@ // Parses the RA or DEC from a string that has an optional sign, a two digit degree, a seperator, a two digit minute, a seperator and a two digit second. // For example: -45*32:11 or 23:44:22 -// In the northern hemisphere, 0 is north pole, 180 and -180 is south pole +// In the NORTHERN hemisphere, 0 is north pole, 180 and -180 is south pole //------------------ S---------------------------------------- N ---------------------------------- S // Celestial -90 -60 -30 0 30 60 90 60 30 0 -30 -60 -90 // Celestial = 90 - abs(Declination) // Declination -180 -150 -120 -90 -60 -30 0 30 60 90 120 150 180 -// In the southern hemisphere, 0 is south pole, 180 and -180 is north pole +// In the SOUTHERN hemisphere, 0 is south pole, 180 and -180 is north pole //------------------ N---------------------------------------- S ---------------------------------- N // Celestial 90 60 30 0 -30 -60 -90 -60 -30 0 30 60 90 // Celestial = -90 + abs(Declination) @@ -87,7 +88,7 @@ const char *Declination::ToString() const *p++ = ' '; *p++ = '('; - strcpy(p, String(NORTHERN_HEMISPHERE ? 90 - fabsf(getTotalHours()) : -90 + fabsf(getTotalHours()), 4).c_str()); + strcpy(p, String(inNorthernHemisphere ? 90 - fabsf(getTotalHours()) : -90 + fabsf(getTotalHours()), 4).c_str()); strcat(p, ")"); return achBufDeg; @@ -96,15 +97,16 @@ const char *Declination::ToString() const Declination Declination::ParseFromMeade(String const &s) { Declination result; - LOG(DEBUG_GENERAL, "[DECLINATION]: Declination.Parse(%s)", s.c_str()); + LOG(DEBUG_GENERAL, "[DECLINATION]: Declination.Parse(%s) for %s Hemi", s.c_str(), inNorthernHemisphere ? "N" : "S"); // Use the DayTime code to parse it... DayTime dt = DayTime::ParseFromMeade(s); + LOG(DEBUG_GENERAL, "[DECLINATION]: Declination DayTime is %l secs", dt.getTotalSeconds()); // ...and then correct for hemisphere - result.totalSeconds = NORTHERN_HEMISPHERE ? (arcSecondsPerHemisphere / 2) - dt.getTotalSeconds() - : -(arcSecondsPerHemisphere / 2) + dt.getTotalSeconds(); - LOG(DEBUG_GENERAL, "[DECLINATION]: Declination.Parse(%s) -> %s (%l)", s.c_str(), result.ToString(), result.totalSeconds); + result.totalSeconds = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - dt.getTotalSeconds() + : -(arcSecondsPerHemisphere / 2) + dt.getTotalSeconds(); + LOG(DEBUG_GENERAL, "[DECLINATION]: Adjust for hemisphere. %s -> %s (%l secs)", s.c_str(), result.ToString(), result.totalSeconds); return result; } @@ -112,16 +114,16 @@ Declination Declination::FromSeconds(long seconds) { const auto secondsFloat = static_cast(seconds); const auto arcSecondsPerHemisphereFloat = static_cast(arcSecondsPerHemisphere); -#if NORTHERN_HEMISPHERE == 1 - return Declination(((arcSecondsPerHemisphereFloat / 2.0f) - secondsFloat) / 3600.0f); -#else + if (inNorthernHemisphere) + { + return Declination(((arcSecondsPerHemisphereFloat / 2.0f) - secondsFloat) / 3600.0f); + } return Declination(((-arcSecondsPerHemisphereFloat / 2.0f) + secondsFloat) / 3600.0f); -#endif } const char *Declination::formatString(char *targetBuffer, const char *format, long *) const { long secs - = NORTHERN_HEMISPHERE ? (arcSecondsPerHemisphere / 2) - labs(totalSeconds) : -(arcSecondsPerHemisphere / 2) + labs(totalSeconds); + = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - labs(totalSeconds) : -(arcSecondsPerHemisphere / 2) + labs(totalSeconds); return DayTime::formatString(targetBuffer, format, &secs); } diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 2bd8bde5..b6cae919 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -616,7 +616,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // "1#" // // :XDnnn# -// Description: +// Description:S // Run drift alignment // Information: // This runs a drift alignment procedure where the mounts slews east, pauses, slews west and pauses. @@ -775,6 +775,15 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Returns: // "n#" - the number of steps from the center of the hall sensor trigger range to the home position. // +// :XGHS# +// Description: +// Get Hemisphere +// Information: +// Get the hemisphere that the OAT currently assumes it is operating in. +// Returns: +// "N#" - for northern hemisphere +// "S#" - for southern hemisphere +// // :XGM# // Description: // Get Mount configuration settings @@ -834,6 +843,17 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Returns: // nothing // +// :XSHSx# +// Description: +// Set hemisphere +// Information: +// Set the hemisphere in which the OAT should be set to work in +// Parameters: +// "x" is either "N" or "S", depending on whether the OAT is in the northern or southern hemisphere +// Returns: +// "0" if the hemisphere was not set (x was not N or S) +// "1" if the hemisphere was set +// // :XSHRnnn# // Description: // Set homing offset for RA ring from Hall sensor center @@ -1676,9 +1696,16 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) } else if (inCmd[1] == 'H') // :XGH# { - if (inCmd.length() > 2 && inCmd[2] == 'R') // :XGHR# + if (inCmd.length() > 2) { - return String(_mount->getHomingOffset(StepperAxis::RA_STEPS)) + "#"; + if (inCmd[2] == 'R') // :XGHR# + { + return String(_mount->getHomingOffset(StepperAxis::RA_STEPS)) + "#"; + } + else if (inCmd[2] == 'S') // :XGHS# + { + return String(inNorthernHemisphere ? "N#" : "S#") + } } else { @@ -1785,12 +1812,31 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) { _mount->setBacklashCorrection(inCmd.substring(2).toInt()); } - else if (inCmd[1] == 'H') // :XSH { - if (inCmd.length() > 2 && inCmd[2] == 'R') // :XSHR + if (inCmd.length() > 2) { - _mount->setHomingOffset(StepperAxis::RA_STEPS, inCmd.substring(3).toInt()); + if (inCmd[2] == 'R') // :XSHR + { + _mount->setHomingOffset(StepperAxis::RA_STEPS, inCmd.substring(3).toInt()); + } + else if (inCmd[2] == 'S') // :XSHSx + { + if (inCmd.length() > 3) + { + if (inCmd[3] == 'S') // :XSHSS + { + inNorthernHemisphere = false; + return "1"; + } + else if (inCmd[3] == 'N') // :XSHSN + { + inNorthernHemisphere = true; + return "1"; + } + } + return "0"; + } } } } diff --git a/src/Mount.cpp b/src/Mount.cpp index a68dc694..cf891df9 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -98,6 +98,13 @@ Mount::Mount(LcdMenu *lcdMenu) void Mount::initializeVariables() { +// If we have defined the hemisphere, transfer it to the variable. This is +// for older local config files, the define is only needed for southern +// hemisphere and can now be switched by a Meade command. +#ifdef NORTHERN_HEMISPHERE + inNorthernHemisphere = NORTHERN_HEMISPHERE == 1; +#endif + _stepsPerRADegree = RA_STEPS_PER_DEGREE; // u-steps per degree when slewing _stepsPerDECDegree = DEC_STEPS_PER_DEGREE; // u-steps per degree when slewing @@ -245,8 +252,8 @@ void Mount::configureRAStepper(byte pin1, byte pin2, int maxSpeed, int maxAccele _stepperTRK->setMaxSpeed(2000); _stepperTRK->setAcceleration(15000); - _stepperRA->setPinsInverted(NORTHERN_HEMISPHERE == RA_INVERT_DIR, false, false); - _stepperTRK->setPinsInverted(NORTHERN_HEMISPHERE == RA_INVERT_DIR, false, false); + _stepperRA->setPinsInverted(inNorthernHemisphere == RA_INVERT_DIR, false, false); + _stepperTRK->setPinsInverted(inNorthernHemisphere == RA_INVERT_DIR, false, false); } ///////////////////////////////// @@ -1035,9 +1042,10 @@ String Mount::getMountHardwareInfo() #if (USE_RA_END_SWITCH == 1) ret += F("_RA"); #endif - #if || (USE_DEC_END_SWITCH == 1) + #if (USE_DEC_END_SWITCH == 1) ret += F("_DEC"); #endif + ret += F(","); #else ret += F("NO_ENDSW,"); #endif @@ -1196,7 +1204,7 @@ const DayTime Mount::currentRA() const hourPos += _zeroPosRA.getTotalHours(); const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; - if (NORTHERN_HEMISPHERE ? degreePos < 0 : degreePos > 0) + if (inNorthernHemisphere ? degreePos < 0 : degreePos > 0) { hourPos += 12; if (hourPos > 24) @@ -2148,7 +2156,7 @@ void Mount::startSlewing(int direction) else { // Start slewing - int sign = NORTHERN_HEMISPHERE ? 1 : -1; + int sign = inNorthernHemisphere ? 1 : -1; // Set move rate to last commanded slew rate setSlewRate(_moveRate); @@ -3231,7 +3239,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, // Where do we want to move RA to? float moveRA = raTarget.getTotalHours(); - if (!NORTHERN_HEMISPHERE) + if (!inNorthernHemisphere) { moveRA += 12; } @@ -3281,13 +3289,8 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, * sections around the home position of RA. The tracking time will still be limited to around 2h in * worst case if the target is located right before the 5h mark during slewing. */ -#if NORTHERN_HEMISPHERE == 1 - float const RALimitL = -RA_LIMIT_LEFT; - float const RALimitR = RA_LIMIT_RIGHT; -#else - float const RALimitL = -RA_LIMIT_RIGHT; - float const RALimitR = RA_LIMIT_LEFT; -#endif + float const RALimitL = inNorthernHemisphere ? -RA_LIMIT_LEFT : -RA_LIMIT_RIGHT; + float const RALimitR = inNorthernHemisphere ? RA_LIMIT_RIGHT : RA_LIMIT_LEFT; LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Limits are : %f to %f", RALimitL, RALimitR); if (pSolutions != nullptr) @@ -3854,7 +3857,7 @@ void Mount::checkRALimit() const float RALimit = RA_TRACKING_LIMIT; const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; float hourPos = currentRA().getTotalHours(); - if (NORTHERN_HEMISPHERE ? degreePos < 0 : degreePos > 0) + if (inNorthernHemisphere ? degreePos < 0 : degreePos > 0) { hourPos -= 12; if (hourPos < 0) diff --git a/src/b_setup.hpp b/src/b_setup.hpp index 77f2c71a..997b5720 100644 --- a/src/b_setup.hpp +++ b/src/b_setup.hpp @@ -106,6 +106,7 @@ void setup() #endif LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT %s!", VERSION); + LOG(DEBUG_ANY, "[SYSTEM]: Located in %s hemisphere.", inNorthernHemisphere ? "northern" : "southern"); #if USE_GPS == 1 GPS_SERIAL_PORT.begin(GPS_BAUD_RATE); diff --git a/src/c76_menuCAL.hpp b/src/c76_menuCAL.hpp index 6d5c8e8b..9936670a 100644 --- a/src/c76_menuCAL.hpp +++ b/src/c76_menuCAL.hpp @@ -697,7 +697,7 @@ bool processCalibrationKeys() // Set DEC to move the same distance past Polaris as // it is from the Celestial Pole. That equates to 88deg 42' 11.2". - mount.targetDEC() = Declination(88 - (NORTHERN_HEMISPHERE ? 90 : -90), 42, 11); + mount.targetDEC() = Declination(88 - (inNorthernHemisphere ? 90 : -90), 42, 11); mount.startSlewingToTarget(); okToUpdateMenu = false; } @@ -717,7 +717,7 @@ bool processCalibrationKeys() mount.delay(750); // Sync the mount to Polaris, since that's where it's pointing - mount.syncPosition(mount.currentRA(), Declination(89 - (NORTHERN_HEMISPHERE ? 90 : -90), 21, 6)); + mount.syncPosition(mount.currentRA(), Declination(89 - (inNorthernHemisphere ? 90 : -90), 21, 6)); // Go home from here mount.startSlewingToHome(); diff --git a/src/inc/Globals.cpp b/src/inc/Globals.cpp index 54a3d63a..6ce75167 100644 --- a/src/inc/Globals.cpp +++ b/src/inc/Globals.cpp @@ -2,3 +2,4 @@ // TODO: Should move this somewhere else... bool inSerialControl = false; // True when the serial port is in control +bool inNorthernHemisphere = true; // Default to northern hemisphere \ No newline at end of file diff --git a/src/inc/Globals.hpp b/src/inc/Globals.hpp index 54713563..a324372a 100644 --- a/src/inc/Globals.hpp +++ b/src/inc/Globals.hpp @@ -17,3 +17,4 @@ PUSH_NO_WARNINGS POP_NO_WARNINGS extern bool inSerialControl; // True when the serial port is in control +extern bool inNorthernHemisphere; \ No newline at end of file From 73754aa11fe82094bc04e739b213c2553c0e0590 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 2 Dec 2022 14:37:32 -0800 Subject: [PATCH 02/14] WIP --- src/MeadeCommandProcessor.cpp | 2 +- src/Mount.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index b6cae919..ce11261e 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -1704,7 +1704,7 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) } else if (inCmd[2] == 'S') // :XGHS# { - return String(inNorthernHemisphere ? "N#" : "S#") + return String(inNorthernHemisphere ? "N#" : "S#"); } } else diff --git a/src/Mount.cpp b/src/Mount.cpp index 74a23569..aa3517fb 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -1204,7 +1204,7 @@ const DayTime Mount::currentRA() const hourPos += _zeroPosRA.getTotalHours(); const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; - if (inNorthernHemisphere ? degreePos < 0 : degreePos > 0) + if (degreePos < 0) { hourPos += 12; if (hourPos > 24) @@ -1271,6 +1271,12 @@ void Mount::syncPosition(DayTime ra, Declination dec) { decAdjust = -decAdjust; } + + // if (!inNorthernHemisphere) + // { + // decAdjust += 180; + // } + _zeroPosDEC += decAdjust; LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zerPosDEC adjusted by: %f", decAdjust); LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zerPosDEC: %f", _zeroPosDEC); @@ -3277,6 +3283,10 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, // Where do we want to move DEC to? float moveDEC = decTarget.getTotalDegrees(); + // if (!inNorthernHemisphere) + // { + // moveDEC += 180; + // } LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Target hrs pos RA: %f (regRA: %f), DEC: %f", homeTargetDeltaRA, moveRA, moveDEC); @@ -3769,6 +3779,14 @@ DayTime Mount::calculateLst() DayTime timeUTC = getUtcTime(); LocalDate localDate = getLocalDate(); DayTime lst = Sidereal::calculateByDateAndTime(longitude().getTotalHours(), localDate.year, localDate.month, localDate.day, &timeUTC); + LOG(DEBUG_INFO, + "[MOUNT]: Calculating LST. UTC time: %s. Date: %d-%d-%d. Longitude: %s", + timeUTC.ToString(), + localDate.year, + localDate.month, + localDate.day, + longitude().ToString()); + LOG(DEBUG_INFO, "[MOUNT]: LST is: %s", lst.ToString()); return lst; } @@ -3780,7 +3798,10 @@ DayTime Mount::calculateLst() DayTime Mount::calculateHa() { DayTime lst = calculateLst(); - return Sidereal::calculateHa(lst.getTotalHours()); + LOG(DEBUG_INFO, "[MOUNT]: Calculating HA from LST: %s", lst.ToString()); + DayTime ha = Sidereal::calculateHa(lst.getTotalHours()); + LOG(DEBUG_INFO, "[MOUNT]: HA is: %s", ha.ToString()); + return ha; } ///////////////////////////////// From 3fcbc629219291fcd32b97a6a23dccd3e4bced08 Mon Sep 17 00:00:00 2001 From: Lutz Date: Mon, 5 Dec 2022 01:19:30 -0800 Subject: [PATCH 03/14] WIP - Southern hemisphere fixes --- src/Declination.cpp | 8 ++++--- src/Mount.cpp | 51 ++++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Declination.cpp b/src/Declination.cpp index 884bb3dc..f4a77b48 100644 --- a/src/Declination.cpp +++ b/src/Declination.cpp @@ -89,6 +89,8 @@ const char *Declination::ToString() const *p++ = ' '; *p++ = '('; strcpy(p, String(inNorthernHemisphere ? 90 - fabsf(getTotalHours()) : -90 + fabsf(getTotalHours()), 4).c_str()); + strcat(p,", "); + strcat(p,String(getTotalHours(),4).c_str()); strcat(p, ")"); return achBufDeg; @@ -104,8 +106,8 @@ Declination Declination::ParseFromMeade(String const &s) LOG(DEBUG_GENERAL, "[DECLINATION]: Declination DayTime is %l secs", dt.getTotalSeconds()); // ...and then correct for hemisphere - result.totalSeconds = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - dt.getTotalSeconds() - : -(arcSecondsPerHemisphere / 2) + dt.getTotalSeconds(); + result.totalSeconds = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - labs(dt.getTotalSeconds()) + : -(arcSecondsPerHemisphere / 2) + labs(dt.getTotalSeconds()); LOG(DEBUG_GENERAL, "[DECLINATION]: Adjust for hemisphere. %s -> %s (%l secs)", s.c_str(), result.ToString(), result.totalSeconds); return result; } @@ -118,7 +120,7 @@ Declination Declination::FromSeconds(long seconds) { return Declination(((arcSecondsPerHemisphereFloat / 2.0f) - secondsFloat) / 3600.0f); } - return Declination(((-arcSecondsPerHemisphereFloat / 2.0f) + secondsFloat) / 3600.0f); + return Declination(((arcSecondsPerHemisphereFloat / 2.0f) + secondsFloat) / 3600.0f); } const char *Declination::formatString(char *targetBuffer, const char *format, long *) const diff --git a/src/Mount.cpp b/src/Mount.cpp index 75bc316d..744eb154 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -229,8 +229,12 @@ void Mount::configureRAStepper(byte pin1, byte pin2, int maxSpeed, int maxAccele _stepperTRK->setMaxSpeed(2000); _stepperTRK->setAcceleration(15000); - _stepperRA->setPinsInverted(inNorthernHemisphere == RA_INVERT_DIR, false, false); - _stepperTRK->setPinsInverted(inNorthernHemisphere == RA_INVERT_DIR, false, false); + // _stepperRA->setPinsInverted(inNorthernHemisphere == (RA_INVERT_DIR == 1), false, false); + // _stepperTRK->setPinsInverted(inNorthernHemisphere == (RA_INVERT_DIR == 1), false, false); +#if RA_INVERT_DIR == 1 + _stepperRA->setPinsInverted(true, false, false); + _stepperTRK->setPinsInverted(true, false, false); +#endif } ///////////////////////////////// @@ -3094,6 +3098,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, DayTime raTarget = _targetRA; Declination decTarget = _targetDEC; + // Calculate how far from the home position this new target is. raTarget.subtractTime(_zeroPosRA); LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Adjust RA by ZeroPosRA. New Target RA: %s, DEC: %s", @@ -3102,10 +3107,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, // Where do we want to move RA to? float moveRA = raTarget.getTotalHours(); - if (!inNorthernHemisphere) - { - moveRA += 12; - } + LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: moveRA (target) is %f", moveRA); // Total hours of tracking-to-date float trackedHours = (_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F; // steps / steps/s / 3600 = hours @@ -3113,9 +3115,14 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, // The current RA of the home position, taking tracking-to-date into account float homeRA = _zeroPosRA.getTotalHours() + trackedHours; + LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: homeRA adjusted by elasped tracking actually represents %f h", homeRA); // Delta between target RA and home position with a normalized range of -12 hr to 12 hr float homeTargetDeltaRA = _targetRA.getTotalHours() - homeRA; + LOG(DEBUG_COORD_CALC, + "[MOUNT]: CalcSteppersIn: Delta of home to targetRA (%f) is %f (will use to check limits) ", + _targetRA.getTotalHours(), + homeTargetDeltaRA); while (homeTargetDeltaRA > 12) { homeTargetDeltaRA = homeTargetDeltaRA - 24; @@ -3140,14 +3147,20 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, // Where do we want to move DEC to? float moveDEC = decTarget.getTotalDegrees(); - // if (!inNorthernHemisphere) - // { - // moveDEC += 180; - // } + if (!inNorthernHemisphere) + { + LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: moveDEC inverted for southern Hemisphere => %f", moveDEC); + moveDEC = -moveDEC; + } - LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Target hrs pos RA: %f (regRA: %f), DEC: %f", homeTargetDeltaRA, moveRA, moveDEC); + LOG(DEBUG_COORD_CALC, + "[MOUNT]: CalcSteppersIn: Target hrs pos RA: Delta:%f (moveRA: %f), DEC: %s (moveDEC: %f)", + homeTargetDeltaRA, + moveRA, + decTarget.ToString(), + moveDEC); -/* + /* * Current RA wheel has a rotation limit of around 7 hours in each direction from home position. * Since tracking does not trigger the meridian flip, we try to extend the possible tracking time * without reaching the RA ring end by executing the meridian flip before slewing to the target. @@ -3178,7 +3191,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, if (homeTargetDeltaRA > RALimitR) { LOG(DEBUG_COORD_CALC, - "[MOUNT]: CalcSteppersIn: targetRA %f (RA:%f) is past max limit %f (solution 2)", + "[MOUNT]: CalcSteppersIn: Using Solution 2, since hometargetDeltaRA %f (RA:%f) is past max limit %f, inverting both axes", homeTargetDeltaRA, moveRA, RALimitR); @@ -3192,7 +3205,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, else if (homeTargetDeltaRA < RALimitL) { LOG(DEBUG_COORD_CALC, - "[MOUNT]: CalcSteppersIn: targetRA %f (RA:%f) is past min limit: %f, (solution 3)", + "[MOUNT]: CalcSteppersIn: Using solution 3 since homeTargetDeltaRA %f (RA:%f) is past min limit: %f, inverting both axes", homeTargetDeltaRA, moveRA, RALimitL); @@ -3205,19 +3218,19 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, else { LOG(DEBUG_COORD_CALC, - "[MOUNT]: CalcSteppersIn: targetRA %f is in range. RA: %f, DEC: %f (solution 1)", + "[MOUNT]: CalcSteppersIn: Using solution 1 since targetRA %f is in range. RA: %f, DEC: %f", homeTargetDeltaRA, moveRA, moveDEC); } - moveDEC -= _zeroPosDEC; // deg - LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: _zeroPosDEC: %f", _zeroPosDEC); - LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Adjusted moveDEC: %f", moveDEC); + moveDEC + -= _zeroPosDEC; // in degs. zeroPosDEC will be zero unless one or more Sync commands have moved it, in which case it is the accumulated offset from zero (home). + LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: adjusted DEC by _zeroPosDEC: %f => DEC: %f", _zeroPosDEC, moveDEC); targetRASteps = -moveRA * stepsPerSiderealHour; targetDECSteps = moveDEC * _stepsPerDECDegree; - LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersPost: Target Steps RA: %l, DEC: %l", targetRASteps, targetDECSteps); + LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersPost: ResultTarget Steps RA: %l, DEC: %l", targetRASteps, targetDECSteps); } ///////////////////////////////// From aac71533ac864a566e40af876246e5379cd516ec Mon Sep 17 00:00:00 2001 From: Lutz Date: Sun, 8 Jan 2023 15:03:05 -0800 Subject: [PATCH 04/14] V1.12.5 - Updates - Binding interrupt stepper library to 0.0.1 --- Version.h | 2 +- platformio.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Version.h b/Version.h index a3989c17..966851c6 100644 --- a/Version.h +++ b/Version.h @@ -3,4 +3,4 @@ // Also, numbers are interpreted as simple numbers. _ __ _ // So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/ -#define VERSION "V1.12.4" +#define VERSION "V1.12.5" diff --git a/platformio.ini b/platformio.ini index 6d5e5e45..158abc5e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -92,7 +92,7 @@ debug_build_flags = lib_deps = ${common.lib_deps} jdolinay/avr-debugger @ 1.2 - https://github.com/andre-stefanov/avr-interrupt-stepper + https://github.com/andre-stefanov/avr-interrupt-stepper@0.0.1 [env:mksgenlv21] extends = env:ramps From 78e6e29fdded65113cddf9383e992d96a5ca1d50 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sun, 8 Jan 2023 15:03:54 -0800 Subject: [PATCH 05/14] V1.12.5 - Updates Update changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index d8e923b5..46327780 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +**V1.12.5 - Updates** +- Bound interrupt stepper library to version 0.0.1. + **V1.12.4 - Updates** - Fixed a bug that incorrectly stopped the RA motor after issuing a DEC move. From 40563991ec3256119a4c67e51046ce30cee04228 Mon Sep 17 00:00:00 2001 From: Lutz Date: Mon, 9 Jan 2023 00:52:30 -0800 Subject: [PATCH 06/14] V1.12.6 - Updates - Added support for DIR inversion to interrupt stepper library. - Firmware now determines hemisphere automatically from the given Latitude, switching at the equator. - Fixed the logic in Sync call to account for both hemispheres. --- Changelog.md | 5 +++ Version.h | 2 +- src/InterruptAccelStepper.h | 2 +- src/MeadeCommandProcessor.cpp | 30 +--------------- src/Mount.cpp | 66 ++++++++++++++++++++++++----------- src/Mount.hpp | 2 ++ src/StepperConfiguration.hpp | 8 ++--- 7 files changed, 59 insertions(+), 56 deletions(-) diff --git a/Changelog.md b/Changelog.md index 46327780..c60ff00f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +**V1.12.6 - Updates** +- Added support for DIR inversion to interrupt stepper library. +- Firmware now determines hemisphere automatically from the given Latitude, switching at the equator. +- Fixed the logic in Sync call to account for both hemispheres. + **V1.12.5 - Updates** - Bound interrupt stepper library to version 0.0.1. diff --git a/Version.h b/Version.h index 966851c6..608d9088 100644 --- a/Version.h +++ b/Version.h @@ -3,4 +3,4 @@ // Also, numbers are interpreted as simple numbers. _ __ _ // So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/ -#define VERSION "V1.12.5" +#define VERSION "V1.12.6" diff --git a/src/InterruptAccelStepper.h b/src/InterruptAccelStepper.h index 40d83fe1..31d93f73 100644 --- a/src/InterruptAccelStepper.h +++ b/src/InterruptAccelStepper.h @@ -136,7 +136,7 @@ template class InterruptAccelStepper void setPinsInverted(bool directionInvert = false, bool stepInvert = false, bool enableInvert = false) { - // STUB + STEPPER::setInverted(directionInvert); } bool isRunning() diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 4c8eedd4..8788cd04 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -800,7 +800,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Description: // Get Hemisphere // Information: -// Get the hemisphere that the OAT currently assumes it is operating in. +// Get the hemisphere that the OAT currently assumes it is operating in. This is set via setting Latitude (see ":St" command) // Returns: // "N#" - for northern hemisphere // "S#" - for southern hemisphere @@ -864,17 +864,6 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Returns: // nothing // -// :XSHSx# -// Description: -// Set hemisphere -// Information: -// Set the hemisphere in which the OAT should be set to work in -// Parameters: -// "x" is either "N" or "S", depending on whether the OAT is in the northern or southern hemisphere -// Returns: -// "0" if the hemisphere was not set (x was not N or S) -// "1" if the hemisphere was set -// // :XSHRnnn# // Description: // Set homing offset for RA ring from Hall sensor center @@ -1875,23 +1864,6 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) { _mount->setHomingOffset(StepperAxis::RA_STEPS, inCmd.substring(3).toInt()); } - else if (inCmd[2] == 'S') // :XSHSx - { - if (inCmd.length() > 3) - { - if (inCmd[3] == 'S') // :XSHSS - { - inNorthernHemisphere = false; - return "1"; - } - else if (inCmd[3] == 'N') // :XSHSN - { - inNorthernHemisphere = true; - return "1"; - } - } - return "0"; - } } else if (inCmd.length() > 2 && inCmd[2] == 'D') // :XSHD { diff --git a/src/Mount.cpp b/src/Mount.cpp index 43c429cb..089dadfd 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -86,12 +86,10 @@ Mount::Mount(LcdMenu *lcdMenu) void Mount::initializeVariables() { -// If we have defined the hemisphere, transfer it to the variable. This is -// for older local config files, the define is only needed for southern -// hemisphere and can now be switched by a Meade command. -#ifdef NORTHERN_HEMISPHERE - inNorthernHemisphere = NORTHERN_HEMISPHERE == 1; -#endif + // If we have defined the hemisphere, transfer it to the variable. This is + // for older local config files, the define is only needed for southern + // hemisphere and can now be switched by a Meade command. + inNorthernHemisphere = true; // Since we set latitude to +45 below. _stepsPerRADegree = RA_STEPS_PER_DEGREE; // u-steps per degree when slewing _stepsPerDECDegree = DEC_STEPS_PER_DEGREE; // u-steps per degree when slewing @@ -213,6 +211,23 @@ void Mount::readPersistentData() LOG(DEBUG_INFO, "[MOUNT]: EEPROM: DEC limits read as %l -> %l", _decLowerLimit, _decUpperLimit); } +///////////////////////////////// +// +// configureHemisphere +// +///////////////////////////////// +void Mount::configureHemisphere(bool inNorthern) +{ + inNorthernHemisphere = inNorthern; + bool invertDir = inNorthernHemisphere ? (RA_INVERT_DIR == 1) : (RA_INVERT_DIR != 1); + LOG(DEBUG_ANY, + "[SYSTEM]: Configured steppers for %s hemisphere. Invert is %d", + inNorthernHemisphere ? "northern" : "southern", + invertDir); + _stepperRA->setPinsInverted(invertDir, false, false); + _stepperTRK->setPinsInverted(invertDir, false, false); +} + ///////////////////////////////// // // configureRAStepper @@ -232,12 +247,7 @@ void Mount::configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t _stepperTRK->setMaxSpeed(2000); _stepperTRK->setAcceleration(15000); - // _stepperRA->setPinsInverted(inNorthernHemisphere == (RA_INVERT_DIR == 1), false, false); - // _stepperTRK->setPinsInverted(inNorthernHemisphere == (RA_INVERT_DIR == 1), false, false); -#if RA_INVERT_DIR == 1 - _stepperRA->setPinsInverted(true, false, false); - _stepperTRK->setPinsInverted(true, false, false); -#endif + configureHemisphere(inNorthernHemisphere); } ///////////////////////////////// @@ -1129,6 +1139,7 @@ void Mount::setLST(const DayTime &lst) void Mount::setLatitude(Latitude latitude) { _latitude = latitude; + configureHemisphere(_latitude.getTotalHours() > 0); EEPROMStore::storeLatitude(_latitude); } @@ -1244,7 +1255,15 @@ void Mount::syncPosition(DayTime ra, Declination dec) long solutions[6]; _targetDEC = dec; _targetRA = ra; - LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition( RA: %s and DEC: %s )", _targetRA.ToString(), _targetDEC.ToString()); + LOG(DEBUG_COORD_CALC, + "[MOUNT]: syncPosition: Target Sync is RA: %f and DEC: %f", + _targetRA.getTotalHours(), + _targetDEC.getTotalDegrees()); + LOG(DEBUG_COORD_CALC, + "[MOUNT]: syncPosition: Current Pos is RA: %f and DEC: %f )", + currentRA().getTotalHours(), + currentDEC().getTotalDegrees()); + LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: ZeroPos values RA: %f and DEC: %f)", _zeroPosRA.getTotalHours(), _zeroPosDEC); // Adjust the home RA position by the delta sync position. float raAdjust = ra.getTotalHours() - currentRA().getTotalHours(); @@ -1263,20 +1282,25 @@ void Mount::syncPosition(DayTime ra, Declination dec) // Adjust the home DEC position by the delta between the sync'd target and current position. const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; // u-steps / u-steps/deg = deg - float decAdjust = dec.getTotalDegrees() - fabsf(currentDEC().getTotalDegrees()); + LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: DEC degreePos is: %f", degreePos); + + // Dec totalhours can be plus or minus the distance from the pole (because it keeps track of whether we are upwards or downwards from the pole) + // So we use the abs of both values to find their difference + float decAdjust = fabsf(dec.getTotalDegrees()) - fabsf(currentDEC().getTotalDegrees()); + LOG(DEBUG_COORD_CALC, + "[MOUNT]: syncPosition: DecAdjust is: %f ( |%f| - |%f| )", + decAdjust, + dec.getTotalDegrees(), + currentDEC().getTotalDegrees()); if (degreePos < 0) { + LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: Inverted DecAdjust to: %f (below home pos)", decAdjust); decAdjust = -decAdjust; } - // if (!inNorthernHemisphere) - // { - // decAdjust += 180; - // } - _zeroPosDEC += decAdjust; - LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zerPosDEC adjusted by: %f", decAdjust); - LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zerPosDEC: %f", _zeroPosDEC); + LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zeroPosDEC adjusted by: %f", decAdjust); + LOG(DEBUG_COORD_CALC, "[MOUNT]: syncPosition: _zeroPosDEC: %f", _zeroPosDEC); long targetRAPosition, targetDECPosition; calculateRAandDECSteppers(targetRAPosition, targetDECPosition, solutions); diff --git a/src/Mount.hpp b/src/Mount.hpp index e2a27254..ddf889e9 100644 --- a/src/Mount.hpp +++ b/src/Mount.hpp @@ -129,6 +129,8 @@ class Mount // Configure the RA stepper motor. This also sets up the TRK stepper on the same pins. void configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration); + void configureHemisphere(bool isNorthern); + // Configure the DEC stepper motor. void configureDECStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration); diff --git a/src/StepperConfiguration.hpp b/src/StepperConfiguration.hpp index 6e16bc1f..105c119e 100644 --- a/src/StepperConfiguration.hpp +++ b/src/StepperConfiguration.hpp @@ -32,7 +32,7 @@ struct Ra { using pin_dir = Pin; using interrupt = IntervalInterrupt; - using driver = Driver; + using driver = Driver; using ramp_slew = AccelerationRamp<256, interrupt::FREQ, UINT32(SPEED_SLEW), UINT32(ACCEL_SLEW)>; using ramp_trk = ConstantRamp; @@ -64,7 +64,7 @@ struct Dec { using pin_dir = Pin; using interrupt = IntervalInterrupt; - using driver = Driver; + using driver = Driver; using ramp_slew = AccelerationRamp<256, interrupt::FREQ, UINT32(SPEED_SLEW), UINT32(ACCEL_SLEW)>; using ramp_trk = ConstantRamp; @@ -84,7 +84,7 @@ struct Az { using pin_dir = Pin; using interrupt = IntervalInterrupt; - using driver = Driver; + using driver = Driver; using ramp_slew = AccelerationRamp<64, interrupt::FREQ, UINT32(SPEED_SLEW), UINT32(ACCEL_SLEW)>; @@ -103,7 +103,7 @@ struct Alt { using pin_dir = Pin; using interrupt = IntervalInterrupt; - using driver = Driver; + using driver = Driver; using ramp_slew = AccelerationRamp<64, interrupt::FREQ, UINT32(SPEED_SLEW), UINT32(ACCEL_SLEW)>; From 3d2fbad4a8ec370989bc85e3e6e6c850d6ca1f43 Mon Sep 17 00:00:00 2001 From: Lutz Date: Mon, 9 Jan 2023 01:02:49 -0800 Subject: [PATCH 07/14] V1.12.6 - Updates - Cosmetic code updates --- src/MeadeCommandProcessor.cpp | 2 +- src/Mount.cpp | 7 +++---- src/b_setup.hpp | 1 - src/inc/Globals.cpp | 2 +- src/inc/Globals.hpp | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 8788cd04..af73f0b2 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -637,7 +637,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // "1#" // // :XDnnn# -// Description:S +// Description: // Run drift alignment // Information: // This runs a drift alignment procedure where the mounts slews east, pauses, slews west and pauses. diff --git a/src/Mount.cpp b/src/Mount.cpp index 089dadfd..3c821cd9 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -86,9 +86,8 @@ Mount::Mount(LcdMenu *lcdMenu) void Mount::initializeVariables() { - // If we have defined the hemisphere, transfer it to the variable. This is - // for older local config files, the define is only needed for southern - // hemisphere and can now be switched by a Meade command. + // We are now defaulting to northern hemisphere at 45deg. Switching is now supported + // at runtime when the Latitude is received via Meade command. inNorthernHemisphere = true; // Since we set latitude to +45 below. _stepsPerRADegree = RA_STEPS_PER_DEGREE; // u-steps per degree when slewing @@ -221,7 +220,7 @@ void Mount::configureHemisphere(bool inNorthern) inNorthernHemisphere = inNorthern; bool invertDir = inNorthernHemisphere ? (RA_INVERT_DIR == 1) : (RA_INVERT_DIR != 1); LOG(DEBUG_ANY, - "[SYSTEM]: Configured steppers for %s hemisphere. Invert is %d", + "[SYSTEM]: Configured RA steppers for %s hemisphere. DIR Invert is %d", inNorthernHemisphere ? "northern" : "southern", invertDir); _stepperRA->setPinsInverted(invertDir, false, false); diff --git a/src/b_setup.hpp b/src/b_setup.hpp index e3a5cd39..75c6db14 100644 --- a/src/b_setup.hpp +++ b/src/b_setup.hpp @@ -93,7 +93,6 @@ void setup() #endif LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT %s!", VERSION); - LOG(DEBUG_ANY, "[SYSTEM]: Located in %s hemisphere.", inNorthernHemisphere ? "northern" : "southern"); #if USE_GPS == 1 GPS_SERIAL_PORT.begin(GPS_BAUD_RATE); diff --git a/src/inc/Globals.cpp b/src/inc/Globals.cpp index 6ce75167..2461f5b4 100644 --- a/src/inc/Globals.cpp +++ b/src/inc/Globals.cpp @@ -2,4 +2,4 @@ // TODO: Should move this somewhere else... bool inSerialControl = false; // True when the serial port is in control -bool inNorthernHemisphere = true; // Default to northern hemisphere \ No newline at end of file +bool inNorthernHemisphere = true; // Default to northern hemisphere diff --git a/src/inc/Globals.hpp b/src/inc/Globals.hpp index a324372a..dac7ef4f 100644 --- a/src/inc/Globals.hpp +++ b/src/inc/Globals.hpp @@ -17,4 +17,4 @@ PUSH_NO_WARNINGS POP_NO_WARNINGS extern bool inSerialControl; // True when the serial port is in control -extern bool inNorthernHemisphere; \ No newline at end of file +extern bool inNorthernHemisphere; From 87c65c718c34a3be60f1bdd364ee8492ba8145fe Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 01:52:04 -0800 Subject: [PATCH 08/14] V1.12.6 - Updates - Added XGST command to get safe time remaining. - Fixed tracking stepper not restarting on hemisphere switch. - Reset RA and TRK positions to zero on hemipshere switch. - Fixed a bug that caused the firmware to fail to recognize the end of very short slews. - Reduced RA limit checking cadence to 3s --- src/MeadeCommandProcessor.cpp | 21 +++++- src/Mount.cpp | 116 ++++++++++++++++++++++------------ src/Mount.hpp | 7 +- 3 files changed, 99 insertions(+), 45 deletions(-) diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index af73f0b2..eb1b23a7 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -772,6 +772,14 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Returns: // "float#" // +// :XGST# +// Description: +// Get Remaining Safe Time +// Information: +// Get the number of hours before the RA ring reaches its end. +// Returns: +// "float#" +// // :XGT# // Description: // Get Tracking speed @@ -1355,7 +1363,7 @@ String MeadeCommandProcessor::handleMeadeSetInfo(String inCmd) } else if (inCmd[1] == 'P') { - // Set home point + // Set home point :SHP# _mount->setHome(false); } else @@ -1694,9 +1702,16 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) return String(_mount->getStepsPerDegree(DEC_STEPS), 1) + "#"; } } - else if (inCmd[1] == 'S') // :XGS# + else if (inCmd[1] == 'S') { - return String(_mount->getSpeedCalibration(), 5) + "#"; + if (inCmd.length() == 2) // :XGS# + { + return String(_mount->getSpeedCalibration(), 5) + "#"; + } + else if ((inCmd.length() == 3) && (inCmd[2] == 'T')) // :XGST# + { + return String(_mount->checkRALimit(), 7) + "#"; + } } else if (inCmd[1] == 'T') // :XGT# { diff --git a/src/Mount.cpp b/src/Mount.cpp index 3c821cd9..2dc64af3 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -215,16 +215,34 @@ void Mount::readPersistentData() // configureHemisphere // ///////////////////////////////// -void Mount::configureHemisphere(bool inNorthern) +void Mount::configureHemisphere(bool inNorthern, bool force) { - inNorthernHemisphere = inNorthern; - bool invertDir = inNorthernHemisphere ? (RA_INVERT_DIR == 1) : (RA_INVERT_DIR != 1); - LOG(DEBUG_ANY, - "[SYSTEM]: Configured RA steppers for %s hemisphere. DIR Invert is %d", - inNorthernHemisphere ? "northern" : "southern", - invertDir); - _stepperRA->setPinsInverted(invertDir, false, false); - _stepperTRK->setPinsInverted(invertDir, false, false); + if ((inNorthernHemisphere != inNorthern) || force) + { + bool wasTracking = isSlewingTRK(); + LOG(DEBUG_ANY, "[SYSTEM]: Hemisphere changed (or forced update) to %s.", inNorthern ? "northern" : "southern"); + LOG(DEBUG_ANY, "[SYSTEM]: Stopping all steppers."); + stopSlewing(ALL_DIRECTIONS | TRACKING); + waitUntilStopped(ALL_DIRECTIONS); + inNorthernHemisphere = inNorthern; + bool invertDir = inNorthernHemisphere ? (RA_INVERT_DIR == 1) : (RA_INVERT_DIR != 1); + LOG(DEBUG_ANY, "[SYSTEM]: Configured RA steppers, DIR Invert is %d", invertDir); + _stepperRA->setPinsInverted(invertDir, false, false); + _stepperTRK->setPinsInverted(invertDir, false, false); + + LOG(DEBUG_ANY, "[SYSTEM]: Reset RA and TRK positions to 0"); + _stepperTRK->setCurrentPosition(0); + _stepperRA->setCurrentPosition(0); + if (wasTracking) + { + LOG(DEBUG_ANY, "[SYSTEM]: Restarting TRK since it was on."); + startSlewing(TRACKING); + } + } + else + { + LOG(DEBUG_ANY, "[SYSTEM]: Already in %s hemisphere, no action taken.", inNorthernHemisphere ? "northern" : "southern"); + } } ///////////////////////////////// @@ -246,7 +264,7 @@ void Mount::configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t _stepperTRK->setMaxSpeed(2000); _stepperTRK->setAcceleration(15000); - configureHemisphere(inNorthernHemisphere); + configureHemisphere(inNorthernHemisphere, true); } ///////////////////////////////// @@ -1357,16 +1375,16 @@ void Mount::startSlewingToTarget() } _mountStatus |= STATUS_SLEWING | STATUS_SLEWING_TO_TARGET; - moveSteppersTo(targetRAPosition, targetDECPosition, RA_AND_DEC_STEPS); // u-steps (in slew mode) - _totalDECMove = 1.0f * _stepperDEC->distanceToGo(); - _totalRAMove = 1.0f * _stepperRA->distanceToGo(); - LOG(DEBUG_MOUNT, "[MOUNT]: RA Dist: %l, DEC Dist: %l", _stepperRA->distanceToGo(), _stepperDEC->distanceToGo()); - #if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART // Since normal state for DEC is guide microstepping, switch to slew microstepping here. LOG(DEBUG_STEPPERS, "[STEPPERS]: startSlewingToTarget: Switching DEC driver to microsteps(%d)", DEC_SLEW_MICROSTEPPING); _driverDEC->microsteps(DEC_SLEW_MICROSTEPPING == 1 ? 0 : DEC_SLEW_MICROSTEPPING); #endif + _stepperWasRunning = true; + moveSteppersTo(targetRAPosition, targetDECPosition, RA_AND_DEC_STEPS); // u-steps (in slew mode) + _totalDECMove = 1.0f * _stepperDEC->distanceToGo(); + _totalRAMove = 1.0f * _stepperRA->distanceToGo(); + LOG(DEBUG_MOUNT, "[MOUNT]: RA Dist: %l, DEC Dist: %l", _stepperRA->distanceToGo(), _stepperDEC->distanceToGo()); } ///////////////////////////////// @@ -1423,16 +1441,16 @@ void Mount::startSlewingToHome() } _mountStatus |= STATUS_SLEWING | STATUS_SLEWING_TO_TARGET; - moveSteppersTo(targetRAPosition, targetDECPosition, RA_AND_DEC_STEPS); // u-steps (in slew mode) - _totalDECMove = static_cast(_stepperDEC->distanceToGo()); - _totalRAMove = static_cast(_stepperRA->distanceToGo()); - LOG(DEBUG_MOUNT, "[MOUNT]: RA Dist: %l, DEC Dist: %l", _stepperRA->distanceToGo(), _stepperDEC->distanceToGo()); - #if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART // Since normal state for DEC is guide microstepping, switch to slew microstepping here. LOG(DEBUG_STEPPERS, "[STEPPERS]: startSlewingToHome: Switching DEC driver to microsteps(%d)", DEC_SLEW_MICROSTEPPING); _driverDEC->microsteps(DEC_SLEW_MICROSTEPPING == 1 ? 0 : DEC_SLEW_MICROSTEPPING); #endif + _stepperWasRunning = true; + moveSteppersTo(targetRAPosition, targetDECPosition, RA_AND_DEC_STEPS); // u-steps (in slew mode) + _totalDECMove = static_cast(_stepperDEC->distanceToGo()); + _totalRAMove = static_cast(_stepperRA->distanceToGo()); + LOG(DEBUG_MOUNT, "[MOUNT]: RA Dist: %l, DEC Dist: %l", _stepperRA->distanceToGo(), _stepperDEC->distanceToGo()); } ///////////////////////////////// @@ -2739,8 +2757,11 @@ void Mount::loop() } else { - // Check whether we should stop tracking now - checkRALimit(); + // Check whether we should stop tracking every 3 seconds + if (now - _lastTRKCheck > 3000) + { + checkRALimit(); + } if (_mountStatus & STATUS_SLEWING_MANUAL) { @@ -3055,7 +3076,16 @@ void Mount::getDecLimitPositions(float &lowerLimit, float &upperLimit) ///////////////////////////////// void Mount::setHome(bool clearZeroPos) { - LOG(DEBUG_MOUNT, "[MOUNT]: setHome() called"); + LOG(DEBUG_MOUNT, "[MOUNT]: setHome() called. Stopping steppers"); + bool wasTracking = isSlewingTRK(); + stopSlewing(ALL_DIRECTIONS); + waitUntilStopped(ALL_DIRECTIONS); + if (wasTracking) + { + LOG(DEBUG_MOUNT, "[MOUNT]: setHome: Tracking was on, so start it again."); + startSlewing(TRACKING); + } + //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: setHomePre: currentRA is %s", currentRA().ToString()); //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: setHomePre: targetRA is %s", targetRA().ToString()); //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: setHomePre: zeroPos is %s", _zeroPosRA.ToString()); @@ -3068,9 +3098,11 @@ void Mount::setHome(bool clearZeroPos) _stepperRA->setCurrentPosition(0); _stepperDEC->setCurrentPosition(0); _stepperTRK->setCurrentPosition(0); - // TODO: Set New Guide Stepper to 0 + _stepperGUIDE->setCurrentPosition(0); - _targetRA = currentRA(); + _targetRA = currentRA(); + _slewingToHome = false; + _slewingToPark = false; //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: setHomePost: currentRA is %s", currentRA().ToString()); //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: setHomePost: zeroPos is %s", _zeroPosRA.ToString()); @@ -3357,22 +3389,23 @@ void Mount::moveStepperBy(StepperAxis direction, long steps) LOG(DEBUG_STEPPERS, "[STEPPERS]: moveStepperBy: Switching RA driver to microsteps(%d)", RA_SLEW_MICROSTEPPING); _driverRA->microsteps(RA_SLEW_MICROSTEPPING == 1 ? 0 : RA_SLEW_MICROSTEPPING); #endif - moveSteppersTo(_stepperRA->currentPosition() + steps, 0, direction); _mountStatus |= STATUS_SLEWING | STATUS_SLEWING_TO_TARGET; + _stepperWasRunning = true; + moveSteppersTo(_stepperRA->currentPosition() + steps, 0, direction); _totalRAMove = 1.0f * _stepperRA->distanceToGo(); break; case DEC_STEPS: { - moveSteppersTo(0, _stepperDEC->currentPosition() + steps, direction); _mountStatus |= STATUS_SLEWING | STATUS_SLEWING_TO_TARGET; - _totalDECMove = 1.0f * _stepperDEC->distanceToGo(); - #if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART // Since normal state for DEC is guide microstepping, switch to slew microstepping here. LOG(DEBUG_STEPPERS, "[STEPPERS]: moveStepperBy: Switching DEC driver to microsteps(%d)", DEC_SLEW_MICROSTEPPING); _driverDEC->microsteps(DEC_SLEW_MICROSTEPPING == 1 ? 0 : DEC_SLEW_MICROSTEPPING); #endif + _stepperWasRunning = true; + moveSteppersTo(0, _stepperDEC->currentPosition() + steps, direction); + _totalDECMove = 1.0f * _stepperDEC->distanceToGo(); } break; @@ -3811,31 +3844,34 @@ void Mount::testUART_vactual(TMC2209Stepper *driver, int _speed, int _duration) // checkRALimit // ///////////////////////////////// -void Mount::checkRALimit() +float Mount::checkRALimit() { - // Check tracking limits every 5 seconds - if (millis() - _lastTRKCheck < 5000) - return; const float trackedHours = (_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F; // steps / steps/s / 3600 = hours const float homeRA = _zeroPosRA.getTotalHours() + trackedHours; const float RALimit = RA_TRACKING_LIMIT; - const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; - float hourPos = currentRA().getTotalHours(); + LOG(DEBUG_MOUNT_VERBOSE, + "[MOUNT]: checkRALimit: homeRA: %f (ZeroPos: %f + TrkHrs: %f)", + homeRA, + _zeroPosRA.getTotalHours(), + trackedHours); + const float degreePos = (_stepperDEC->currentPosition() / _stepsPerDECDegree) + _zeroPosDEC; + float hourPos = currentRA().getTotalHours(); + LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: degreePosDec: %f , RA hourpos : %f)", degreePos, hourPos); if (inNorthernHemisphere ? degreePos < 0 : degreePos > 0) { hourPos -= 12; if (hourPos < 0) hourPos += 24; + LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: switching RA hourPos to: %f", hourPos); } - LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: homeRA: %f", homeRA); - LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: currentRA: %f", currentRA().getTotalHours()); - LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: currentRA (adjusted): %f", hourPos); + LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: RA hourPos (adjusted): %f", hourPos); float homeCurrentDeltaRA = homeRA - hourPos; + LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: DeltaRA: %f (home:%f - hour:%f)", homeCurrentDeltaRA, homeRA, hourPos); while (homeCurrentDeltaRA > 12) homeCurrentDeltaRA -= 24; while (homeCurrentDeltaRA < -12) homeCurrentDeltaRA += 24; - LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: homeRAdelta: %f", homeCurrentDeltaRA); + LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: checkRALimit: deltaRA: %f => Check against %f", homeCurrentDeltaRA, RALimit); if (homeCurrentDeltaRA > RALimit) { @@ -3843,4 +3879,6 @@ void Mount::checkRALimit() stopSlewing(TRACKING); } _lastTRKCheck = millis(); + + return RALimit - homeCurrentDeltaRA; } diff --git a/src/Mount.hpp b/src/Mount.hpp index ddf889e9..d719470a 100644 --- a/src/Mount.hpp +++ b/src/Mount.hpp @@ -129,7 +129,7 @@ class Mount // Configure the RA stepper motor. This also sets up the TRK stepper on the same pins. void configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration); - void configureHemisphere(bool isNorthern); + void configureHemisphere(bool isNorthern, bool force = false); // Configure the DEC stepper motor. void configureDECStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration); @@ -453,6 +453,9 @@ class Mount byte slewStatus() const; byte mountStatus() const; + // Returns the remaining tracking time available and stops tracking if it reaches zero. + float checkRALimit(); + #if UART_CONNECTION_TEST_TX == 1 #if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART void testRA_UART_TX(); @@ -468,8 +471,6 @@ class Mount #endif #endif - void checkRALimit(); - // Reads values from EEPROM that configure the mount (if previously stored) void readPersistentData(); From 1b1f91223efabae61da04a2504153a15c1f64186 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 13:20:30 -0800 Subject: [PATCH 09/14] V1.12.6 - Updates - Bumped Interrupt Stepper library required to 0.0.2 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 158abc5e..79d0bce9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -92,7 +92,7 @@ debug_build_flags = lib_deps = ${common.lib_deps} jdolinay/avr-debugger @ 1.2 - https://github.com/andre-stefanov/avr-interrupt-stepper@0.0.1 + https://github.com/andre-stefanov/avr-interrupt-stepper@0.0.2 [env:mksgenlv21] extends = env:ramps From f9f7e4b62d0f2361677fbbcc5637fda5239febc3 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 13:43:48 -0800 Subject: [PATCH 10/14] V1.12.6 - Updates Changelog updated, cosmetic tweks to mount code. --- Changelog.md | 7 ++++++- src/Mount.cpp | 15 +++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index c60ff00f..9b2288e2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,12 @@ **V1.12.6 - Updates** +- Fixed all known issues related to running in the southern hemisphere. - Added support for DIR inversion to interrupt stepper library. -- Firmware now determines hemisphere automatically from the given Latitude, switching at the equator. +- Hemisphere no longer needs to be defined in config, firmware determines it automatically from the given Latitude, switching at the equator. - Fixed the logic in Sync call to account for both hemispheres. +- Fixed some logic that stopped tracking when setting home position. +- Fixed a bug that caused the firmware to fail to recognize the end of very short slews. +- Added Meade Extension command to query remaining tracking time +- Added Meade Extension command to query the hemisphere that is set. **V1.12.5 - Updates** - Bound interrupt stepper library to version 0.0.1. diff --git a/src/Mount.cpp b/src/Mount.cpp index 2dc64af3..59bd5e28 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -2757,8 +2757,8 @@ void Mount::loop() } else { - // Check whether we should stop tracking every 3 seconds - if (now - _lastTRKCheck > 3000) + // Check whether we should stop tracking every 5 seconds + if (now - _lastTRKCheck > 5000) { checkRALimit(); } @@ -3295,8 +3295,9 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps, moveDEC); } - moveDEC - -= _zeroPosDEC; // in degs. zeroPosDEC will be zero unless one or more Sync commands have moved it, in which case it is the accumulated offset from zero (home). + // zeroPosDEC will be zero unless one or more Sync commands have moved it, in which case it is the + // accumulated offset from zero (home) in degrees. + moveDEC -= _zeroPosDEC; LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: adjusted DEC by _zeroPosDEC: %f => DEC: %f", _zeroPosDEC, moveDEC); targetRASteps = -moveRA * stepsPerSiderealHour; @@ -3558,21 +3559,15 @@ String Mount::DECString(byte type, byte active) Declination dec; if ((type & TARGET_STRING) == TARGET_STRING) { - //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: DECString: TARGET!"); dec = _targetDEC; } else { - //LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: DECString: CURRENT!"); dec = currentDEC(); } - //LOG(DEBUG_INFO, "[MOUNT]: DECString: Precheck : %s %s %dm %ds", dec.ToString(), dec.getDegreesDisplay().c_str(), dec.getMinutes(), dec.getSeconds()); - // dec.checkHours(); - // LOG(DEBUG_MOUNT_VERBOSE, "[MOUNT]: DECString: Postcheck : %s", dec.ToString()); dec.formatString(scratchBuffer, formatStringsDEC[type & FORMAT_STRING_MASK]); - // sprintf(scratchBuffer, formatStringsDEC[type & FORMAT_STRING_MASK], dec.getDegreesDisplay().c_str(), dec.getMinutes(), dec.getSeconds()); if ((type & FORMAT_STRING_MASK) == LCDMENU_STRING) { scratchBuffer[active * 4 + (active > 0 ? 1 : 0)] = '>'; From 5390a09dbeb7588301cd581ac1f6a88c72e1cc99 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 13:49:29 -0800 Subject: [PATCH 11/14] V1.12.6 - Updates Formatting fixes --- src/Declination.cpp | 4 ++-- src/inc/Globals.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Declination.cpp b/src/Declination.cpp index f4a77b48..ed8c62bd 100644 --- a/src/Declination.cpp +++ b/src/Declination.cpp @@ -89,8 +89,8 @@ const char *Declination::ToString() const *p++ = ' '; *p++ = '('; strcpy(p, String(inNorthernHemisphere ? 90 - fabsf(getTotalHours()) : -90 + fabsf(getTotalHours()), 4).c_str()); - strcat(p,", "); - strcat(p,String(getTotalHours(),4).c_str()); + strcat(p, ", "); + strcat(p, String(getTotalHours(), 4).c_str()); strcat(p, ")"); return achBufDeg; diff --git a/src/inc/Globals.cpp b/src/inc/Globals.cpp index 2461f5b4..ec803da0 100644 --- a/src/inc/Globals.cpp +++ b/src/inc/Globals.cpp @@ -1,5 +1,5 @@ #include "Globals.hpp" // TODO: Should move this somewhere else... -bool inSerialControl = false; // True when the serial port is in control -bool inNorthernHemisphere = true; // Default to northern hemisphere +bool inSerialControl = false; // True when the serial port is in control +bool inNorthernHemisphere = true; // Default to northern hemisphere From 43cf7aed867cd906528442dd3303776642228ab5 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 23:43:23 -0800 Subject: [PATCH 12/14] PR feedback issues --- src/Declination.cpp | 6 +++--- src/Latitude.cpp | 4 ++-- src/Longitude.cpp | 4 ++-- src/Mount.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Declination.cpp b/src/Declination.cpp index ed8c62bd..072caeda 100644 --- a/src/Declination.cpp +++ b/src/Declination.cpp @@ -99,16 +99,16 @@ const char *Declination::ToString() const Declination Declination::ParseFromMeade(String const &s) { Declination result; - LOG(DEBUG_GENERAL, "[DECLINATION]: Declination.Parse(%s) for %s Hemi", s.c_str(), inNorthernHemisphere ? "N" : "S"); + LOG(DEBUG_MEADE, "[DECLINATION]: Declination.Parse(%s) for %s Hemi", s.c_str(), inNorthernHemisphere ? "N" : "S"); // Use the DayTime code to parse it... DayTime dt = DayTime::ParseFromMeade(s); - LOG(DEBUG_GENERAL, "[DECLINATION]: Declination DayTime is %l secs", dt.getTotalSeconds()); + LOG(DEBUG_MEADE, "[DECLINATION]: Declination DayTime is %l secs", dt.getTotalSeconds()); // ...and then correct for hemisphere result.totalSeconds = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - labs(dt.getTotalSeconds()) : -(arcSecondsPerHemisphere / 2) + labs(dt.getTotalSeconds()); - LOG(DEBUG_GENERAL, "[DECLINATION]: Adjust for hemisphere. %s -> %s (%l secs)", s.c_str(), result.ToString(), result.totalSeconds); + LOG(DEBUG_MEADE, "[DECLINATION]: Adjust for hemisphere. %s -> %s (%l secs)", s.c_str(), result.ToString(), result.totalSeconds); return result; } diff --git a/src/Latitude.cpp b/src/Latitude.cpp index f0e99107..b90db767 100644 --- a/src/Latitude.cpp +++ b/src/Latitude.cpp @@ -35,11 +35,11 @@ Latitude Latitude::ParseFromMeade(String const &s) { Latitude result(0.0); - LOG(DEBUG_GENERAL, "[LATITUDE]: Latitude.Parse(%s)", s.c_str()); + LOG(DEBUG_MEADE, "[LATITUDE]: Latitude.Parse(%s)", s.c_str()); // Use the DayTime code to parse it. DayTime dt = DayTime::ParseFromMeade(s); result.totalSeconds = dt.getTotalSeconds(); result.checkHours(); - LOG(DEBUG_GENERAL, "[LATITUDE]: Latitude.Parse(%s) -> %s", s.c_str(), result.ToString()); + LOG(DEBUG_MEADE, "[LATITUDE]: Latitude.Parse(%s) -> %s", s.c_str(), result.ToString()); return result; } diff --git a/src/Longitude.cpp b/src/Longitude.cpp index 9da5dba3..de019770 100644 --- a/src/Longitude.cpp +++ b/src/Longitude.cpp @@ -35,7 +35,7 @@ void Longitude::checkHours() Longitude Longitude::ParseFromMeade(String const &s) { Longitude result(0.0); - LOG(DEBUG_GENERAL, "[LONGITUDE]: Parse(%s)", s.c_str()); + LOG(DEBUG_MEADE, "[LONGITUDE]: Parse(%s)", s.c_str()); // Use the DayTime code to parse it. DayTime dt = DayTime::ParseFromMeade(s); @@ -52,7 +52,7 @@ Longitude Longitude::ParseFromMeade(String const &s) } result.checkHours(); - LOG(DEBUG_GENERAL, "[LONGITUDE]: Parse(%s) -> %s = %ls", s.c_str(), result.ToString(), result.getTotalSeconds()); + LOG(DEBUG_MEADE, "[LONGITUDE]: Parse(%s) -> %s = %ls", s.c_str(), result.ToString(), result.getTotalSeconds()); return result; } diff --git a/src/Mount.cpp b/src/Mount.cpp index 59bd5e28..097f13d5 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -1382,8 +1382,8 @@ void Mount::startSlewingToTarget() #endif _stepperWasRunning = true; moveSteppersTo(targetRAPosition, targetDECPosition, RA_AND_DEC_STEPS); // u-steps (in slew mode) - _totalDECMove = 1.0f * _stepperDEC->distanceToGo(); - _totalRAMove = 1.0f * _stepperRA->distanceToGo(); + _totalDECMove = static_cast(_stepperDEC->distanceToGo()); + _totalRAMove = static_cast(_stepperRA->distanceToGo()); LOG(DEBUG_MOUNT, "[MOUNT]: RA Dist: %l, DEC Dist: %l", _stepperRA->distanceToGo(), _stepperDEC->distanceToGo()); } From 226d9cd3502241da8d762d9bc1196c7b57ad68fd Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 23:48:21 -0800 Subject: [PATCH 13/14] PR feedback - hemisphere default --- Configuration.hpp | 5 +++++ src/Mount.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Configuration.hpp b/Configuration.hpp index 0c2e451d..4d3d95d2 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -47,6 +47,11 @@ #error You have to specify the board #endif +// Default to northern hemisphere +#ifndef NORTHERN_HEMISPHERE + #define NORTHERN_HEMISPHERE 1 +#endif + /** * @brief Display & keypad configuration. * See Constants.hpp for supported DISPLAY_TYPE options. diff --git a/src/Mount.cpp b/src/Mount.cpp index 097f13d5..18341b41 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -88,7 +88,7 @@ void Mount::initializeVariables() { // We are now defaulting to northern hemisphere at 45deg. Switching is now supported // at runtime when the Latitude is received via Meade command. - inNorthernHemisphere = true; // Since we set latitude to +45 below. + inNorthernHemisphere = NORTHERN_HEMISPHERE == 1; _stepsPerRADegree = RA_STEPS_PER_DEGREE; // u-steps per degree when slewing _stepsPerDECDegree = DEC_STEPS_PER_DEGREE; // u-steps per degree when slewing @@ -96,7 +96,7 @@ void Mount::initializeVariables() _mountStatus = 0; _lastDisplayUpdate = 0; _stepperWasRunning = false; - _latitude = Latitude(45.0); + _latitude = Latitude(inNorthernHemisphere? 45.0f : -45.0f); _longitude = Longitude(100.0); _zeroPosDEC = 0.0f; From 75fd55c83bb848a05930b0d924064cd1e9f99dbc Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 10 Jan 2023 23:49:04 -0800 Subject: [PATCH 14/14] Formatting --- Configuration.hpp | 4 ++-- src/Mount.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Configuration.hpp b/Configuration.hpp index 4d3d95d2..9f975d2a 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -48,9 +48,9 @@ #endif // Default to northern hemisphere -#ifndef NORTHERN_HEMISPHERE +#ifndef NORTHERN_HEMISPHERE #define NORTHERN_HEMISPHERE 1 -#endif +#endif /** * @brief Display & keypad configuration. diff --git a/src/Mount.cpp b/src/Mount.cpp index 18341b41..eefd8326 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -96,7 +96,7 @@ void Mount::initializeVariables() _mountStatus = 0; _lastDisplayUpdate = 0; _stepperWasRunning = false; - _latitude = Latitude(inNorthernHemisphere? 45.0f : -45.0f); + _latitude = Latitude(inNorthernHemisphere ? 45.0f : -45.0f); _longitude = Longitude(100.0); _zeroPosDEC = 0.0f;