Skip to content

Commit

Permalink
Add homing support to telescope simulator to aid in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Feb 26, 2024
1 parent 27a1963 commit 8b44046
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
67 changes: 55 additions & 12 deletions drivers/telescope/telescope_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()
Expand All @@ -169,6 +163,7 @@ bool ScopeSim::updateProperties()
defineProperty(&GuideNSNP);
defineProperty(&GuideWENP);
defineProperty(&GuideRateNP);
defineProperty(HomeSP);
loadConfig(true, GuideRateNP.name);

if (InitPark())
Expand Down Expand Up @@ -205,6 +200,7 @@ bool ScopeSim::updateProperties()
deleteProperty(GuideNSNP.name);
deleteProperty(GuideWENP.name);
deleteProperty(GuideRateNP.name);
deleteProperty(HomeSP);
}

return true;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 9 additions & 0 deletions drivers/telescope/telescope_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8b44046

Please sign in to comment.