From 8b44046d891ee6bcbc93a4ebe85ed555c045f4ff Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Mon, 26 Feb 2024 22:48:30 +0300 Subject: [PATCH] Add homing support to telescope simulator to aid in testing --- drivers/telescope/telescope_simulator.cpp | 67 +++++++++++++++++++---- drivers/telescope/telescope_simulator.h | 9 +++ 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/drivers/telescope/telescope_simulator.cpp b/drivers/telescope/telescope_simulator.cpp index e4a5900f0d..efc9c43f25 100644 --- a/drivers/telescope/telescope_simulator.cpp +++ b/drivers/telescope/telescope_simulator.cpp @@ -114,6 +114,11 @@ bool ScopeSim::initProperties() AddTrackMode("TRACK_LUNAR", "Lunar"); AddTrackMode("TRACK_CUSTOM", "Custom"); + HomeSP[Find].fill("FIND", "Find", ISS_OFF); + HomeSP[Set].fill("SET", "Set As Current", ISS_OFF); + HomeSP[Go].fill("GO", "Go", ISS_OFF); + HomeSP.fill(getDeviceName(), "TELESCOPE_HOME", "Home", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); + // RA is a rotating frame, while HA or Alt/Az is not SetParkDataType(PARK_HA_DEC); @@ -145,17 +150,6 @@ void ScopeSim::ISGetProperties(const char *dev) defineProperty(&flipHourAngleNP); loadConfig(true, flipHourAngleNP.name); #endif - /* - if (isConnected()) - { - defineProperty(&GuideNSNP); - defineProperty(&GuideWENP); - defineProperty(&GuideRateNP); - defineProperty(&EqPENV); - defineProperty(&PEErrNSSP); - defineProperty(&PEErrWESP); - } - */ } bool ScopeSim::updateProperties() @@ -169,6 +163,7 @@ bool ScopeSim::updateProperties() defineProperty(&GuideNSNP); defineProperty(&GuideWENP); defineProperty(&GuideRateNP); + defineProperty(HomeSP); loadConfig(true, GuideRateNP.name); if (InitPark()) @@ -205,6 +200,7 @@ bool ScopeSim::updateProperties() deleteProperty(GuideNSNP.name); deleteProperty(GuideWENP.name); deleteProperty(GuideRateNP.name); + deleteProperty(HomeSP); } return true; @@ -262,7 +258,15 @@ bool ScopeSim::ReadScopeStatus() TrackState = SCOPE_TRACKING; SetTrackEnabled(true); EqNP.s = IPS_IDLE; - LOG_INFO("Telescope slew is complete. Tracking..."); + + if (HomeSP.getState() == IPS_BUSY) + { + HomeSP.setState(IPS_OK); + HomeSP.apply(); + LOG_INFO("Home position reached."); + } + else + LOG_INFO("Telescope slew is complete. Tracking..."); // check the slew accuracy auto dRa = targetRA - currentRA; @@ -446,6 +450,45 @@ bool ScopeSim::ISNewSwitch(const char *dev, const char *name, ISState *states, c { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { + // Home Position + if (HomeSP.isNameMatch(name)) + { + HomeSP.update(states, names, n); + auto onSwitch = HomeSP.findOnSwitchIndex(); + if (onSwitch == Find) + { + HomeSP.setState(IPS_BUSY); + LOG_INFO("Finding home position..."); + m_Home[AXIS_RA] = alignment.lst().Hours(); + m_Home[AXIS_DE] = LocationN[LOCATION_LATITUDE].value > 0 ? 90 : -90; + Goto(m_Home[AXIS_RA], m_Home[AXIS_DE]); + } + else if (onSwitch == Set) + { + HomeSP.setState(IPS_OK); + m_Home[AXIS_RA] = (alignment.lst() - Angle(EqN[AXIS_RA].value, Angle::HOURS)).HoursHa(); + m_Home[AXIS_DE] = EqN[AXIS_DE].value; + LOG_INFO("Setting home position to current position."); + } + else if (onSwitch == Go) + { + HomeSP.setState(IPS_BUSY); + LOG_INFO("Going to home position."); + if (m_Home[AXIS_RA] == 0) + { + m_Home[AXIS_RA] = 0; + m_Home[AXIS_DE] = LocationN[LOCATION_LATITUDE].value > 0 ? 90 : -90; + } + + // Home HA to home RA + auto ra = (alignment.lst() - Angle(m_Home[AXIS_RA], Angle::HOURS)).Hours(); + Goto(ra, m_Home[AXIS_DE]); + } + + HomeSP.reset(); + HomeSP.apply(); + return true; + } #ifdef USE_SIM_TAB if (strcmp(name, mountTypeSP.name) == 0) { diff --git a/drivers/telescope/telescope_simulator.h b/drivers/telescope/telescope_simulator.h index 65fa9333f3..92a5c2c2de 100644 --- a/drivers/telescope/telescope_simulator.h +++ b/drivers/telescope/telescope_simulator.h @@ -106,6 +106,15 @@ class ScopeSim : public INDI::Telescope, public INDI::GuiderInterface INumber GuideRateN[2]; INumberVectorProperty GuideRateNP; + INDI::PropertySwitch HomeSP {3}; + enum + { + Find, + Set, + Go + }; + double m_Home[2] = {0, 0}; + Axis axisPrimary { "HaAxis" }; // hour angle mount axis Axis axisSecondary { "DecAxis" }; // declination mount axis