From 0ddd07d164ca300af4dac31628d87ef107238ffe Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 20 Jul 2024 11:26:52 -0700 Subject: [PATCH] V1.13.7 - Added Az/Alt homing support (#248) --- Changelog.md | 3 ++ Version.h | 2 +- src/EPROMStore.cpp | 58 ++++++++++++++++++++++++++++++ src/EPROMStore.hpp | 22 ++++++++++-- src/MeadeCommandProcessor.cpp | 61 ++++++++++++++++++++++++++----- src/Mount.cpp | 67 +++++++++++++++++++++++++++++++++-- src/Mount.hpp | 5 +++ 7 files changed, 205 insertions(+), 13 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3083545a..3662e697 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +**V1.13.7 - Updates** +- Added ability to keep track of AZ and ALT positions across sessions, set their home positions and slew back to their home positions. + **V1.13.6 - Updates** - Added ability to query homing status during autohoming (:XGAH#) - Fixed a bug in autohoming that would make it fail if it did not pass over the sensor during the initial 30 degree search diff --git a/Version.h b/Version.h index b8d47ad1..c513dc8f 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.13.6" +#define VERSION "V1.13.7" diff --git a/src/EPROMStore.cpp b/src/EPROMStore.cpp index 15f69504..97b92e90 100644 --- a/src/EPROMStore.cpp +++ b/src/EPROMStore.cpp @@ -139,6 +139,8 @@ void EEPROMStore::displayContents() LOG(DEBUG_INFO, "[EEPROM]: Stored Pitch Calibration Angle: %f", getPitchCalibrationAngle()); LOG(DEBUG_INFO, "[EEPROM]: Stored Roll Calibration Angle: %f", getRollCalibrationAngle()); LOG(DEBUG_INFO, "[EEPROM]: Stored RA Homing Offset: %l", getRAHomingOffset()); + LOG(DEBUG_INFO, "[EEPROM]: Stored AZ Position: %l", getAZPosition()); + LOG(DEBUG_INFO, "[EEPROM]: Stored ALT Position: %l", getALTPosition()); LOG(DEBUG_INFO, "[EEPROM]: Stored DEC Homing Offset : %l", getDECHomingOffset()); LOG(DEBUG_INFO, "[EEPROM]: Stored DEC Lower Limit: %l", getDECLowerLimit()); LOG(DEBUG_INFO, "[EEPROM]: Stored DEC Upper Limit: %l", getDECUpperLimit()); @@ -794,3 +796,59 @@ void EEPROMStore::storeDECHomingOffset(int32_t decHomingOffset) updateFlagsExtended(DEC_HOMING_MARKER_FLAG); commit(); // Complete the transaction } + +// Get the current AZ position from home (in steps) +int32_t EEPROMStore::getAZPosition() +{ + int32_t azPosition(0); // microsteps (slew) + + if (isPresentExtended(AZ_POSITION_MARKER_FLAG)) + { + azPosition = readInt32(AZ_POSITION_ADDR); + LOG(DEBUG_EEPROM, "[EEPROM]: AZ position read as %l", azPosition); + } + else + { + LOG(DEBUG_EEPROM, "[EEPROM]: No stored values for AZ position"); + } + + return azPosition; // microsteps (slew) +} + +// Store the current AZ position (in steps) +void EEPROMStore::storeAZPosition(int32_t azPosition) +{ + LOG(DEBUG_EEPROM, "[EEPROM]: Write: Updating AZ Position to %l", azPosition); + + updateInt32(AZ_POSITION_ADDR, azPosition); + updateFlagsExtended(AZ_POSITION_MARKER_FLAG); + commit(); // Complete the transaction +} + +// Get the current ALT position from home (in steps) +int32_t EEPROMStore::getALTPosition() +{ + int32_t altPosition(0); // microsteps (slew) + + if (isPresentExtended(ALT_POSITION_MARKER_FLAG)) + { + altPosition = readInt32(ALT_POSITION_ADDR); + LOG(DEBUG_EEPROM, "[EEPROM]: ALT position read as %l", altPosition); + } + else + { + LOG(DEBUG_EEPROM, "[EEPROM]: No stored values for ALT position"); + } + + return altPosition; // microsteps (slew) +} + +// Store the current ALT position in steps +void EEPROMStore::storeALTPosition(int32_t altPosition) +{ + LOG(DEBUG_EEPROM, "[EEPROM]: Write: Updating ALT Position to %l", altPosition); + + updateInt32(ALT_POSITION_ADDR, altPosition); + updateFlagsExtended(ALT_POSITION_MARKER_FLAG); + commit(); // Complete the transaction +} diff --git a/src/EPROMStore.hpp b/src/EPROMStore.hpp index c51e464e..dd943350 100644 --- a/src/EPROMStore.hpp +++ b/src/EPROMStore.hpp @@ -62,6 +62,12 @@ class EEPROMStore static int16_t getLastFlashedVersion(); static void storeLastFlashedVersion(int16_t lastVersion); + static int32_t getAZPosition(); + static void storeAZPosition(int32_t azPosition); + + static int32_t getALTPosition(); + static void storeALTPosition(int32_t altPosition); + private: ///////////////////////////////// // @@ -85,7 +91,9 @@ class EEPROMStore // If Location 5 is 0xCF, then an extended 16-bit flag is stored in 21/22 and // indicates the additional fields that have been stored: 0000 0000 0000 0000 // ^^^^ ^^^^ ^^^^ ^^^^ - // |||| |||| + // || |||| |||| + // ALT position (62-65) ---------------+| |||| |||| + // AZ Position (58-61) ----------------+ |||| |||| // Last flashed version (56-57) ------------------+||| |||| // DEC Homing Offet (52-55) -------------------+|| |||| // DEC Steps/deg, normalized to 256MS (48-51) -------------------+| |||| @@ -127,6 +135,8 @@ class EEPROMStore DEC_NORM_STEPS_MARKER_FLAG = 0x0020, DEC_HOMING_MARKER_FLAG = 0x0040, LAST_FLASHED_MARKER_FLAG = 0x0080, + AZ_POSITION_MARKER_FLAG = 0x0100, + ALT_POSITION_MARKER_FLAG = 0x0200, }; // These are the offsets to each item stored in the EEPROM @@ -191,7 +201,15 @@ class EEPROMStore _DEC_HOMING_OFFSET_ADDR_3, // Int32 LAST_FLASHED_VERSION = 56, _LAST_FLASHED_VERSION_1, - STORE_SIZE = 64 + AZ_POSITION_ADDR = 58, + _AZ_POSITION_ADDR_1, + _AZ_POSITION_ADDR_2, + _AZ_POSITION_ADDR_3, + ALT_POSITION_ADDR = 62, + _ALT_POSITION_ADDR_1, + _ALT_POSITION_ADDR_2, + _ALT_POSITION_ADDR_3, + STORE_SIZE = 66 }; // Helper functions diff --git a/src/MeadeCommandProcessor.cpp b/src/MeadeCommandProcessor.cpp index 87b3e66b..47f9f2e2 100644 --- a/src/MeadeCommandProcessor.cpp +++ b/src/MeadeCommandProcessor.cpp @@ -544,6 +544,14 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // "1" if search is started // "0" if homing has not been enabled in the local config // +// :MAAH# +// Description: +// Move Azimuth and Altitude to home +// Information: +// If the scope supports automated azimuth and altitutde operations, move AZ and ALT axis to their zero positions. +// Returns: +// "1" +// // :MAZn.nn# // Description: // Move Azimuth @@ -587,7 +595,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // nothing // //------------------------------------------------------------------ -// PARK Extensions +// HOME/PARK Extensions // // :hU# // Description: @@ -597,6 +605,14 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // Returns: // "1" // +// :hZ# +// Description: +// Set home position for AZ and ALT axes +// Information: +// If the mount supports AZ and ALT axes, this call sets their positions to 0 and stores this in persistent storage. +// Returns: +// "1" +// //------------------------------------------------------------------ // QUIT MOVEMENT FAMILY // @@ -710,6 +726,15 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // "1#" if succsessful // "0#" if there is no Digital Level // +// :XGAA# +// Description: +// Get position of AZ and ALT axes +// Information: +// Get the current position in steps of the AZ and ALT axes if they are enabled. +// If an axis is not enabled, this always returns zero as the axis's value. +// Returns: +// "azpos|altpos#" if either axis is enabled +// // :XGAH# // Description: // Get auto homing state @@ -730,7 +755,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp // FINDING_START_REVERSE // FINDING_END // RANGE_FOUND -// +// // If the mount status (:GX#) is not 'Homing' the command returns one of these: // SUCCEEDED // NEVER RUN @@ -1544,6 +1569,13 @@ String MeadeCommandProcessor::handleMeadeMovement(String inCmd) { LOG(DEBUG_MEADE, "[MEADE]: Move Az/Alt"); + if (inCmd[1] == 'A') // :MAA + { + LOG(DEBUG_MEADE, "[MEADE]: Move AZ and ALT to home"); + _mount->moveAZALTToHome(); + return "1"; + } + // Move Azimuth or Altitude by given arcminutes // :MAZ+32.1# or :MAL-32.1# #if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) @@ -1653,19 +1685,24 @@ String MeadeCommandProcessor::handleMeadeMovement(String inCmd) ///////////////////////////// String MeadeCommandProcessor::handleMeadeHome(String inCmd) { - if (inCmd[0] == 'P') - { // Park + if (inCmd[0] == 'P') // :hP + { // Park _mount->park(); } - else if (inCmd[0] == 'F') - { // Home + else if (inCmd[0] == 'F') // :hF + { // Home _mount->startSlewingToHome(); } - else if (inCmd[0] == 'U') - { // Unpark + else if (inCmd[0] == 'U') // :hU + { // Unpark _mount->startSlewing(TRACKING); return "1"; } + else if (inCmd[0] == 'Z') // :hZ + { // Set AZ/ALT home + _mount->setAZALTHome(); + return "1"; + } return ""; } @@ -1780,6 +1817,14 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd) { return _mount->getAutoHomingStates() + "#"; } + else if ((inCmd[1] == 'A') && (inCmd.length() > 2) && (inCmd[2] == 'A')) // :XGAA# + { + long azPos, altPos; + _mount->getAZALTPositions(azPos, altPos); + char scratchBuffer[20]; + sprintf(scratchBuffer, "%ld|%ld#", azPos, altPos); + return String(scratchBuffer); + } else if (inCmd[1] == 'C') // :XGCn.nn*m.mm# { String coords = inCmd.substring(2); diff --git a/src/Mount.cpp b/src/Mount.cpp index c30b4863..d47da2d7 100644 --- a/src/Mount.cpp +++ b/src/Mount.cpp @@ -182,6 +182,13 @@ void Mount::readPersistentData() LOG(DEBUG_INFO, "[MOUNT]: EEPROM: New Flash detected! Flashed from %d to %d.", lastFlashed, version); // Write upgrade code here if needed. lastFlashed is 0 if we have never flashed V1.14.x and beyond EEPROMStore::storeLastFlashedVersion(version); + if (lastFlashed < 11307) + { + LOG(DEBUG_INFO, "[MOUNT]: EEPROM: First time post 1.13.6, setting AZ and ALT home to 0"); + // Introduced these two in 1.13.7 + EEPROMStore::storeALTPosition(0); + EEPROMStore::storeAZPosition(0); + } } else { @@ -230,6 +237,16 @@ void Mount::readPersistentData() } LOG(DEBUG_INFO, "[MOUNT]: EEPROM: DEC limits read as %l -> %l", _decLowerLimit, _decUpperLimit); +#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) + long altPos = EEPROMStore::getALTPosition(); + _stepperALT->setCurrentPosition(altPos); +#endif + +#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) + long azPos = EEPROMStore::getAZPosition(); + _stepperAZ->setCurrentPosition(azPos); +#endif + configureHemisphere(_latitude.getTotalHours() > 0); } @@ -1772,6 +1789,44 @@ void Mount::setSpeed(StepperAxis which, float speedDegsPerSec) #endif } +void Mount::getAZALTPositions(long &azPos, long &altPos) +{ +#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) + azPos = _stepperAZ->currentPosition(); +#else + azPos = 0; +#endif +#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) + altPos = _stepperALT->currentPosition(); +#else + altPos = 0; +#endif +} + +void Mount::moveAZALTToHome() +{ +#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) + enableAzAltMotors(); + _stepperAZ->moveTo(0); +#endif +#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) + enableAzAltMotors(); + _stepperALT->moveTo(0); +#endif +} + +void Mount::setAZALTHome() +{ +#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE) + _stepperAZ->setCurrentPosition(0); + EEPROMStore::storeAZPosition(0); +#endif +#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE) + _stepperALT->setCurrentPosition(0); + EEPROMStore::storeALTPosition(0); +#endif +} + ///////////////////////////////// // // park @@ -2814,6 +2869,8 @@ void Mount::loop() // One of the motors was running last time through the loop, but not anymore, so shutdown the outputs. disableAzAltMotors(); _azAltWasRunning = false; + EEPROMStore::storeAZPosition(_stepperAZ->currentPosition()); + EEPROMStore::storeALTPosition(_stepperALT->currentPosition()); } oneIsRunning = false; @@ -2854,12 +2911,18 @@ void Mount::loop() if (isGuiding()) { now = millis(); - bool stopRaGuiding = now > _guideRaEndTime; - bool stopDecGuiding = now > _guideDecEndTime; + bool stopRaGuiding = (now > _guideRaEndTime) && (_mountStatus & STATUS_GUIDE_PULSE_RA); + bool stopDecGuiding = (now > _guideDecEndTime) && (_mountStatus & STATUS_GUIDE_PULSE_DEC); if (stopRaGuiding || stopDecGuiding) { stopGuiding(stopRaGuiding, stopDecGuiding); } + else + { +#if INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE + updateInfoDisplay(); +#endif + } return; } diff --git a/src/Mount.hpp b/src/Mount.hpp index 384d2fe3..8a2d63ec 100644 --- a/src/Mount.hpp +++ b/src/Mount.hpp @@ -301,6 +301,11 @@ class Mount // Sends the mount to the home position void startSlewingToHome(); + // Move AZ and ALT motors to their zero position + void moveAZALTToHome(); + void getAZALTPositions(long &azPos, long &altPos); + void setAZALTHome(); + // Various status query functions bool isSlewingRAorDEC() const; bool isSlewingIdle() const;