Skip to content

Commit

Permalink
initial support for slew limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ijessen committed Dec 21, 2023
1 parent ea3b127 commit a816f1f
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 1 deletion.
137 changes: 136 additions & 1 deletion indi-celestronaux/celestronaux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ bool CelestronAUX::initProperties()
CordWrapBaseSP[CW_BASE_SKY].fill("CW_BASE_SKY", "Alignment positions", ISS_OFF);
CordWrapBaseSP.fill(getDeviceName(), "CW_BASE", "CW Position Base", CORDWRAP_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);

/////////////////////////////////////////////////////////////////////////////////////
/// Slew Limits
/////////////////////////////////////////////////////////////////////////////////////

SlewLimitPositionNP[SLEW_LIMIT_AXIS1_MIN].fill("SLEW_LIMIT_AXIS1_MIN", "Axis1 Min", "%.1f", -180, 0, 1, -180);
SlewLimitPositionNP[SLEW_LIMIT_AXIS1_MAX].fill("SLEW_LIMIT_AXIS1_MAX", "Axis1 Max", "%.1f", 0, 180, 1, 180);
SlewLimitPositionNP[SLEW_LIMIT_AXIS2_MIN].fill("SLEW_LIMIT_AXIS2_MIN", "Axis2 Min", "%.1f", -90, 0, 1, -90);
SlewLimitPositionNP[SLEW_LIMIT_AXIS2_MAX].fill("SLEW_LIMIT_AXIS2_MAX", "Axis2 Max", "%.1f", 0, 90, 1, 90);
SlewLimitPositionNP.fill(getDeviceName(), "LIMIT_POS", "Axis Angle Limits", MOUNTINFO_TAB, IP_RW, 60, IPS_IDLE);

Axis1LimitToggleSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
Axis1LimitToggleSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
Axis1LimitToggleSP.fill(getDeviceName(), "AXIS1_LIMIT", "Axis1 Limits", MOUNTINFO_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);

Axis2LimitToggleSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
Axis2LimitToggleSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
Axis2LimitToggleSP.fill(getDeviceName(), "AXIS2_LIMIT", "Axis2 Limits", MOUNTINFO_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);


/////////////////////////////////////////////////////////////////////////////////////
/// Options
/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -480,6 +499,12 @@ bool CelestronAUX::updateProperties()
defineProperty(CordWrapBaseSP);
}

// Slew limits
defineProperty(SlewLimitPositionNP);
defineProperty(Axis1LimitToggleSP);
defineProperty(Axis2LimitToggleSP);


defineProperty(GPSEmuSP);

// Encoders
Expand Down Expand Up @@ -572,6 +597,11 @@ bool CelestronAUX::updateProperties()
deleteProperty(CordWrapBaseSP.getName());
}

// Slew limits
deleteProperty(Axis1LimitToggleSP.getName());
deleteProperty(Axis2LimitToggleSP.getName());
deleteProperty(SlewLimitPositionNP.getName());

deleteProperty(GPSEmuSP.getName());

deleteProperty(EncoderNP.getName());
Expand Down Expand Up @@ -669,6 +699,16 @@ bool CelestronAUX::ISNewNumber(const char *dev, const char *name, double values[
return true;
}

// Slew limits
if (SlewLimitPositionNP.isNameMatch(name))
{
SlewLimitPositionNP.update(values, names, n);
SlewLimitPositionNP.setState(IPS_OK);
SlewLimitPositionNP.apply();
saveConfig(true, SlewLimitPositionNP.getName());
return true;
}

// Horizontal Coords
if (HorizontalCoordsNP.isNameMatch(name))
{
Expand Down Expand Up @@ -837,6 +877,28 @@ bool CelestronAUX::ISNewSwitch(const char *dev, const char *name, ISState *state
return true;
}

// Slew limits
if (Axis1LimitToggleSP.isNameMatch(name)){
Axis1LimitToggleSP.update(states, names, n);
if (Axis1LimitToggleSP[INDI_ENABLED].s == ISS_ON)
Axis1LimitToggleSP.setState(IPS_OK);
else
Axis1LimitToggleSP.setState(IPS_IDLE);
Axis1LimitToggleSP.apply();
return true;
}

if (Axis2LimitToggleSP.isNameMatch(name)){
Axis2LimitToggleSP.update(states, names, n);
if (Axis2LimitToggleSP[INDI_ENABLED].s == ISS_ON)
Axis2LimitToggleSP.setState(IPS_OK);
else
Axis2LimitToggleSP.setState(IPS_IDLE);
Axis2LimitToggleSP.apply();
return true;
}


// Park position base
if (CordWrapBaseSP.isNameMatch(name))
{
Expand Down Expand Up @@ -1555,17 +1617,90 @@ bool CelestronAUX::mountToSkyCoords()
return true;
}


double range180(double r)
{
double res = r;
while (res < -180.0)
res += 360.0;
while (res > 180.0)
res -= 360.0;
return res;
}

bool CelestronAUX::enforceSlewLimits(){

double axis1_angle = range180(AngleNP[AXIS_AZ].value);
double axis2_angle = range180(AngleNP[AXIS_ALT].value);

if ((Axis1LimitToggleSP[INDI_ENABLED].s == ISS_ON && axis1_angle > range180(SlewLimitPositionNP[SLEW_LIMIT_AXIS1_MAX].value) && m_AxisDirection[AXIS_AZ] == FORWARD) ||
(Axis1LimitToggleSP[INDI_ENABLED].s == ISS_ON && axis1_angle < range180(SlewLimitPositionNP[SLEW_LIMIT_AXIS1_MIN].value) && m_AxisDirection[AXIS_AZ] == REVERSE) ||
(Axis2LimitToggleSP[INDI_ENABLED].s == ISS_ON && axis2_angle > range180(SlewLimitPositionNP[SLEW_LIMIT_AXIS2_MAX].value) && m_AxisDirection[AXIS_ALT] == FORWARD) ||
(Axis2LimitToggleSP[INDI_ENABLED].s == ISS_ON && axis2_angle < range180(SlewLimitPositionNP[SLEW_LIMIT_AXIS2_MIN].value) && m_AxisDirection[AXIS_ALT] == REVERSE)){

// set HorizontalCoords state before calling Abort()
// it will be cleared in the Abort() call, but it at least flashes briefly
if (HorizontalCoordsNP.getState() != IPS_IDLE){
HorizontalCoordsNP.setState(IPS_ALERT);
HorizontalCoordsNP.apply();
}

Abort();

if (EqNP.s != IPS_IDLE){
EqNP.s = IPS_ALERT;
IDSetNumber(&EqNP, nullptr);
}

if (HorizontalCoordsNP.getState() != IPS_IDLE){
HorizontalCoordsNP.setState(IPS_ALERT);
HorizontalCoordsNP.apply();
}

if (HomeSP.getState() != IPS_IDLE){
HomeSP.setState(IPS_ALERT);
HomeSP.apply();
}

if (MovementNSSP.s != IPS_IDLE){
MovementNSSP.s = IPS_ALERT;
IDSetSwitch(&MovementNSSP, nullptr);
}

if (MovementWESP.s != IPS_IDLE){
MovementWESP.s = IPS_ALERT;
IDSetSwitch(&MovementWESP, nullptr);
}


if (TrackStateSP.s != IPS_IDLE){
TrackStateSP.s = IPS_ALERT;
IDSetSwitch(&TrackStateSP, nullptr);
}

return false;
}
else
return true;
}




/////////////////////////////////////////////////////////////////////////////////////
///
/////////////////////////////////////////////////////////////////////////////////////
void CelestronAUX::TimerHit()
{
INDI::Telescope::TimerHit();

if(!enforceSlewLimits())
return;

switch (TrackState)
{
case SCOPE_SLEWING:
break;
break;

case SCOPE_TRACKING:
{
Expand Down
9 changes: 9 additions & 0 deletions indi-celestronaux/celestronaux.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class CelestronAUX :
bool isHomingDone(INDI_HO_AXIS axis);
bool m_HomingProgress[2] = {false, false};

bool enforceSlewLimits();

/////////////////////////////////////////////////////////////////////////////////////
/// Tracking
/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -369,6 +371,13 @@ class CelestronAUX :
INDI::PropertySwitch CordWrapBaseSP {2};
enum {CW_BASE_ENC, CW_BASE_SKY};

// Slew limits
INDI::PropertySwitch Axis1LimitToggleSP {2};
INDI::PropertySwitch Axis2LimitToggleSP {2};
INDI::PropertyNumber SlewLimitPositionNP {4};
enum { SLEW_LIMIT_AXIS1_MIN, SLEW_LIMIT_AXIS1_MAX, SLEW_LIMIT_AXIS2_MIN, SLEW_LIMIT_AXIS2_MAX };


// GPS emulator
INDI::PropertySwitch GPSEmuSP {2};
enum { GPSEMU_OFF, GPSEMU_ON };
Expand Down

0 comments on commit a816f1f

Please sign in to comment.