Skip to content

Commit

Permalink
V1.13.7 - Added Az/Alt homing support (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClutchplateDude authored Jul 20, 2024
1 parent 247c960 commit 0ddd07d
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
58 changes: 58 additions & 0 deletions src/EPROMStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
}
22 changes: 20 additions & 2 deletions src/EPROMStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/////////////////////////////////
//
Expand All @@ -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) -------------------+| ||||
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
61 changes: 53 additions & 8 deletions src/MeadeCommandProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -587,7 +595,7 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
// nothing
//
//------------------------------------------------------------------
// PARK Extensions
// HOME/PARK Extensions
//
// :hU#
// Description:
Expand All @@ -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
//
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 "";
}

Expand Down Expand Up @@ -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);
Expand Down
67 changes: 65 additions & 2 deletions src/Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0ddd07d

Please sign in to comment.