Skip to content

Commit

Permalink
Update EQMod to be in line with INDI homing standards
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Jul 29, 2024
1 parent 44fed1c commit 15bcfc8
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 190 deletions.
6 changes: 6 additions & 0 deletions debian/indi-eqmod/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
indi-eqmod (1.3) bionic; urgency=medium

* Update homing to be in line with INDI standards

-- Jasem Mutlaq <[email protected]> Mon, 29 Jul 2024 09:00:00 +0300

indi-eqmod (1.0) bionic; urgency=medium

* Add LED Brightness control.
Expand Down
4 changes: 2 additions & 2 deletions indi-eqmod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT(indi-eqmod C CXX)
cmake_minimum_required(VERSION 3.16)
PROJECT(indi-eqmod C CXX)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")
Expand All @@ -13,7 +13,7 @@ find_package(ZLIB REQUIRED)
find_package(GSL REQUIRED)

set(EQMOD_VERSION_MAJOR 1)
set(EQMOD_VERSION_MINOR 2)
set(EQMOD_VERSION_MINOR 3)

if (CYGWIN)
add_definitions(-U__STRICT_ANSI__)
Expand Down
271 changes: 118 additions & 153 deletions indi-eqmod/eqmodbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ void EQMod::ISGetProperties(const char *dev)
#if defined WITH_ALIGN || defined WITH_ALIGN_GEEHALEL
defineProperty(AlignSyncModeSP);
#endif
if (mount->HasHomeIndexers())
{
defineProperty(AutoHomeSP);
}

if (mount->HasAuxEncoders())
{
Expand Down Expand Up @@ -416,7 +412,6 @@ bool EQMod::loadProperties()
SyncManageSP = getSwitch("SYNCMANAGE");
BacklashNP = getNumber("BACKLASH");
UseBacklashSP = getSwitch("USEBACKLASH");
AutoHomeSP = getSwitch("AUTOHOME");
AuxEncoderSP = getSwitch("AUXENCODER");
AuxEncoderNP = getNumber("AUXENCODERVALUES");
ST4GuideRateNSSP = getSwitch("ST4_GUIDE_RATE_NS");
Expand Down Expand Up @@ -456,6 +451,40 @@ bool EQMod::loadProperties()

bool EQMod::updateProperties()
{
// JM 2024.07.29: Need to run this *before* Telescope::updateProperty so we can check if
// the mount supports homing since we need to update the telescope capabilities accordingly.
if (isConnected())
{
try
{
mount->InquireBoardVersion(MountInformationTP);

for (const auto &it : MountInformationTP)
{
LOGF_DEBUG("Got Board Property %s: %s", it.getName(), it.getText());
}

mount->InquireRAEncoderInfo(SteppersNP);
mount->InquireDEEncoderInfo(SteppersNP);

for (const auto &it : SteppersNP)
{
LOGF_DEBUG("Got Encoder Property %s: %.0f", it.getLabel(), it.getValue());
}

mount->InquireFeatures();
if (mount->HasHomeIndexers())
{
LOG_INFO("Mount has home indexers. Enabling Autohome.");
SetTelescopeCapability(GetTelescopeCapability() | TELESCOPE_CAN_HOME_FIND, SLEWMODES);
}
}
catch (EQModError &e)
{
return (e.DefaultHandleException(this));
}
}

INDI::Telescope::updateProperties();

if (isConnected())
Expand Down Expand Up @@ -495,28 +524,6 @@ bool EQMod::updateProperties()
#endif
try
{
mount->InquireBoardVersion(MountInformationTP);

for (const auto &it : MountInformationTP)
{
LOGF_DEBUG("Got Board Property %s: %s", it.getName(), it.getText());
}

mount->InquireRAEncoderInfo(SteppersNP);
mount->InquireDEEncoderInfo(SteppersNP);

for (const auto &it : SteppersNP)
{
LOGF_DEBUG("Got Encoder Property %s: %.0f", it.getLabel(), it.getValue());
}

mount->InquireFeatures();
if (mount->HasHomeIndexers())
{
LOG_INFO("Mount has home indexers. Enabling Autohome.");
defineProperty(AutoHomeSP);
}

if (mount->HasAuxEncoders())
{
defineProperty(AuxEncoderSP);
Expand Down Expand Up @@ -585,13 +592,6 @@ bool EQMod::updateProperties()
INumber *elevation = IUFindNumber(&LocationNP, "ELEV");
if (latitude && longitude && elevation)
updateLocation(latitude->value, longitude->value, elevation->value);
// else
// updateLocation(0.0, 0.0, 0.0);

// if ((latitude) && (latitude->value < 0.0))
// SetSouthernHemisphere(true);
// else
// SetSouthernHemisphere(false);

sendTimeFromSystem();
}
Expand Down Expand Up @@ -630,8 +630,6 @@ bool EQMod::updateProperties()
deleteProperty(ST4GuideRateWESP);
deleteProperty(LEDBrightnessNP);

if (mount->HasHomeIndexers())
deleteProperty(AutoHomeSP);
if (mount->HasAuxEncoders())
{
deleteProperty(AuxEncoderSP);
Expand Down Expand Up @@ -1103,17 +1101,6 @@ bool EQMod::ReadScopeStatus()
}
}

if (AutohomeState == AUTO_HOME_CONFIRM)
{
if (ah_confirm_timeout > 0)
ah_confirm_timeout -= 1;
if (ah_confirm_timeout == 0)
{
AutohomeState = AUTO_HOME_IDLE;
LOG_INFO("Autohome confirm timeout.");
}
}

if (TrackState == SCOPE_AUTOHOMING)
{
uint32_t indexRA = 0, indexDE = 0;
Expand All @@ -1122,7 +1109,6 @@ bool EQMod::ReadScopeStatus()
switch (AutohomeState)
{
case AUTO_HOME_IDLE:
case AUTO_HOME_CONFIRM:
AutohomeState = AUTO_HOME_IDLE;
TrackState = SCOPE_IDLE;
RememberTrackState = TrackState;
Expand Down Expand Up @@ -1410,9 +1396,9 @@ bool EQMod::ReadScopeStatus()
TrackState = SCOPE_IDLE;
RememberTrackState = TrackState;
AutohomeState = AUTO_HOME_IDLE;
AutoHomeSP.setState(IPS_IDLE);
AutoHomeSP.reset();
AutoHomeSP.apply();
HomeSP.setState(IPS_IDLE);
HomeSP.reset();
HomeSP.apply();
LOG_INFO("Autohome: end");
}
else
Expand Down Expand Up @@ -2791,105 +2777,6 @@ bool EQMod::ISNewSwitch(const char *dev, const char *name, ISState *states, char
}

//if (MountInformationTP && MountInformationTP->tp && (!strcmp(MountInformationTP->tp[0].text, "EQ8") || !strcmp(MountInformationTP->tp[0].text, "AZEQ6"))) {
if (mount->HasHomeIndexers())
{
if (AutoHomeSP && AutoHomeSP.isNameMatch(name))
{
if ((TrackState != SCOPE_IDLE) && (TrackState != SCOPE_AUTOHOMING))
{
if (TrackState != SCOPE_AUTOHOMING)
{
AutoHomeSP.setState(IPS_IDLE);
AutoHomeSP.reset();
AutoHomeSP.apply();
}
LOG_WARN("Can not start AutoHome. Scope not idle");
return true;
}

if (TrackState == SCOPE_AUTOHOMING)
{
AutoHomeSP.setState(IPS_IDLE);
AutoHomeSP.reset();
AutoHomeSP.apply();
LOG_WARN("Aborting AutoHome.");
Abort();
return true;
}

if (AutohomeState == AUTO_HOME_IDLE)
{
AutoHomeSP.setState(IPS_OK);
AutoHomeSP.reset();
AutoHomeSP.apply();
LOG_WARN("*** AutoHome NOT TESTED. Press PERFORM AGAIN TO CONFIRM. ***");
AutohomeState = AUTO_HOME_CONFIRM;
ah_confirm_timeout = 10;
return true;
}
if (AutohomeState == AUTO_HOME_CONFIRM)
{
AutoHomeSP.update(states, names, n);
AutoHomeSP.setState(IPS_BUSY);
LOG_INFO("Starting Autohome.");
AutoHomeSP.apply();
TrackState = SCOPE_AUTOHOMING;
try
{
LOG_INFO("AutoHome phase 1: turning off aux encoders");
mount->TurnRAEncoder(false);
mount->TurnDEEncoder(false);
LOG_INFO("AutoHome phase 1: resetting home position indexes");
mount->ResetRAIndexer();
mount->ResetDEIndexer();
LOG_INFO(
"AutoHome phase 1: reading home position indexes to set directions");
mount->GetRAIndexer();
mount->GetDEIndexer();
LOGF_INFO(
"AutoHome phase 1: read home position indexes: RA=0x%x DE=0x%x",
mount->GetlastreadRAIndexer(), mount->GetlastreadDEIndexer());
if (mount->GetlastreadRAIndexer() == 0)
ah_bSlewingUp_RA = true;
else
ah_bSlewingUp_RA = false;
if (mount->GetlastreadDEIndexer() == 0)
ah_bSlewingUp_DE = true;
else
ah_bSlewingUp_DE = false;
ah_iPosition_RA = mount->GetRAEncoder();
ah_iPosition_DE = mount->GetDEEncoder();
ah_iChanges = (5 * mount->GetRAEncoderTotal()) / 360;
if (ah_bSlewingUp_RA)
ah_iPosition_RA = ah_iPosition_RA - ah_iChanges;
else
ah_iPosition_RA = ah_iPosition_RA + ah_iChanges;
ah_iChanges = (5 * mount->GetDEEncoderTotal()) / 360;
if (ah_bSlewingUp_DE)
ah_iPosition_DE = ah_iPosition_DE - ah_iChanges;
else
ah_iPosition_DE = ah_iPosition_DE + ah_iChanges;
LOG_INFO(
"AutoHome phase 1: trying to move further away from home position");
LOGF_INFO(
"AutoHome phase 1: slewing to RA=0x%x (up=%c) DE=0x%x (up=%c)", ah_iPosition_RA,
(ah_bSlewingUp_RA ? '1' : '0'), ah_iPosition_DE, (ah_bSlewingUp_DE ? '1' : '0'));
mount->AbsSlewTo(ah_iPosition_RA, ah_iPosition_DE, ah_bSlewingUp_RA, ah_bSlewingUp_DE);
AutohomeState = AUTO_HOME_WAIT_PHASE1;
}
catch (EQModError e)
{
AutoHomeSP.setState(IPS_ALERT);
AutoHomeSP.reset();
AutoHomeSP.apply();
AutohomeState = AUTO_HOME_IDLE;
TrackState = SCOPE_IDLE;
RememberTrackState = TrackState;
return (e.DefaultHandleException(this));
}
}
}
}

if (mount->HasAuxEncoders())
{
Expand Down Expand Up @@ -3310,9 +3197,9 @@ bool EQMod::Abort()
IDSetSwitch(TrackModeSP, nullptr);
#endif
AutohomeState = AUTO_HOME_IDLE;
AutoHomeSP.setState(IPS_IDLE);
AutoHomeSP.reset();
AutoHomeSP.apply();
HomeSP.setState(IPS_IDLE);
HomeSP.reset();
HomeSP.apply();

TrackState = SCOPE_IDLE;
RememberTrackState = TrackState;
Expand Down Expand Up @@ -3719,3 +3606,81 @@ bool EQMod::SetTrackEnabled(bool enabled)

return true;
}

IPState EQMod::ExecuteHomeAction(TelescopeHomeAction action)
{
if (action != HOME_FIND)
return IPS_ALERT;

if ((TrackState != SCOPE_IDLE) && (TrackState != SCOPE_AUTOHOMING))
{
LOG_WARN("Can not start AutoHome. Scope not idle");
return IPS_IDLE;
}

if (TrackState == SCOPE_AUTOHOMING)
{
LOG_WARN("Aborting AutoHome.");
Abort();
return IPS_IDLE;
}

if (AutohomeState == AUTO_HOME_IDLE)
{
LOG_INFO("Starting Autohome.");
TrackState = SCOPE_AUTOHOMING;
try
{
LOG_INFO("AutoHome phase 1: turning off aux encoders");
mount->TurnRAEncoder(false);
mount->TurnDEEncoder(false);
LOG_INFO("AutoHome phase 1: resetting home position indexes");
mount->ResetRAIndexer();
mount->ResetDEIndexer();
LOG_INFO(
"AutoHome phase 1: reading home position indexes to set directions");
mount->GetRAIndexer();
mount->GetDEIndexer();
LOGF_INFO(
"AutoHome phase 1: read home position indexes: RA=0x%x DE=0x%x",
mount->GetlastreadRAIndexer(), mount->GetlastreadDEIndexer());
if (mount->GetlastreadRAIndexer() == 0)
ah_bSlewingUp_RA = true;
else
ah_bSlewingUp_RA = false;
if (mount->GetlastreadDEIndexer() == 0)
ah_bSlewingUp_DE = true;
else
ah_bSlewingUp_DE = false;
ah_iPosition_RA = mount->GetRAEncoder();
ah_iPosition_DE = mount->GetDEEncoder();
ah_iChanges = (5 * mount->GetRAEncoderTotal()) / 360;
if (ah_bSlewingUp_RA)
ah_iPosition_RA = ah_iPosition_RA - ah_iChanges;
else
ah_iPosition_RA = ah_iPosition_RA + ah_iChanges;
ah_iChanges = (5 * mount->GetDEEncoderTotal()) / 360;
if (ah_bSlewingUp_DE)
ah_iPosition_DE = ah_iPosition_DE - ah_iChanges;
else
ah_iPosition_DE = ah_iPosition_DE + ah_iChanges;
LOG_INFO(
"AutoHome phase 1: trying to move further away from home position");
LOGF_INFO(
"AutoHome phase 1: slewing to RA=0x%x (up=%c) DE=0x%x (up=%c)", ah_iPosition_RA,
(ah_bSlewingUp_RA ? '1' : '0'), ah_iPosition_DE, (ah_bSlewingUp_DE ? '1' : '0'));
mount->AbsSlewTo(ah_iPosition_RA, ah_iPosition_DE, ah_bSlewingUp_RA, ah_bSlewingUp_DE);
AutohomeState = AUTO_HOME_WAIT_PHASE1;
return IPS_BUSY;
}
catch (EQModError e)
{
AutohomeState = AUTO_HOME_IDLE;
TrackState = SCOPE_IDLE;
RememberTrackState = TrackState;
return IPS_ALERT;
}
}

return IPS_ALERT;
}
Loading

0 comments on commit 15bcfc8

Please sign in to comment.