Skip to content

Commit

Permalink
Added TELESCOPE_CAN_FLIP to capabilities
Browse files Browse the repository at this point in the history
Probably need to discuss if this makes sense. Currently it only
flips, and does not goto the new coordinate.

Also added error checking to the flip commands.
  • Loading branch information
amendolajamie committed Nov 16, 2023
1 parent b244725 commit ac016e3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
107 changes: 105 additions & 2 deletions drivers/telescope/lx200_pegasus_nyx101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LX200NYX101::LX200NYX101()
TELESCOPE_CAN_CONTROL_TRACK |
TELESCOPE_HAS_TIME |
TELESCOPE_HAS_LOCATION |
TELESCOPE_CAN_FLIP |
TELESCOPE_HAS_TRACK_MODE,
SLEW_MODES);
}
Expand Down Expand Up @@ -672,8 +673,12 @@ bool LX200NYX101::ISNewSwitch(const char *dev, const char *name, ISState *states
IPState state = IPS_OK;
if (isConnected())
{
char status[1] = {0};
FlipSP[0].setState(ISS_OFF);
sendCommand(":MN#");
sendCommand(":MN#", status, -1, sizeof(status));
if(*status != '0'){
state = IPS_ALERT;
}
}
FlipSP.setState(state);
FlipSP.apply();
Expand Down Expand Up @@ -788,7 +793,6 @@ bool LX200NYX101::ISNewText(const char *dev, const char *name, char *texts[], ch
{
if(DebugCommandTP[0].isNameMatch(names[i]))
{
char status[DRIVER_LEN] = {0};
sendCommand(texts[i]);
i=n;
}
Expand Down Expand Up @@ -1027,6 +1031,105 @@ bool LX200NYX101::sendCommand(const char * cmd, char * res, int cmd_len, int res
return true;
}

bool LX200NYX101::Flip(double ra, double dec)
{
return GotoInternal(ra, dec, true);
}

bool LX200NYX101::Goto(double ra, double dec)
{
return GotoInternal(ra, dec, false);
}

int LX200NYX101::Flip(int )
{
char status[1] = {0};
sendCommand(":MN#", status, -1, sizeof(status));
return static_cast<int> (*status - '0');
}

bool LX200NYX101::GotoInternal(double ra, double dec, bool flip)
{
const struct timespec timeout = {0, 100000000L};

targetRA = ra;
targetDEC = dec;
char RAStr[64] = {0}, DecStr[64] = {0};
int fracbase = 0;

switch (getLX200EquatorialFormat())
{
case LX200_EQ_LONGER_FORMAT:
fracbase = 360000;
break;
case LX200_EQ_LONG_FORMAT:
case LX200_EQ_SHORT_FORMAT:
default:
fracbase = 3600;
break;
}

fs_sexa(RAStr, targetRA, 2, fracbase);
fs_sexa(DecStr, targetDEC, 2, fracbase);

// If moving, let's stop it first.
if (EqNP.s == IPS_BUSY)
{
if (!isSimulation() && abortSlew(PortFD) < 0)
{
AbortSP.s = IPS_ALERT;
IDSetSwitch(&AbortSP, "Abort slew failed.");
return false;
}

AbortSP.s = IPS_OK;
EqNP.s = IPS_IDLE;
IDSetSwitch(&AbortSP, "Slew aborted.");
IDSetNumber(&EqNP, nullptr);

if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)
{
MovementNSSP.s = IPS_IDLE;
MovementWESP.s = IPS_IDLE;
EqNP.s = IPS_IDLE;
IUResetSwitch(&MovementNSSP);
IUResetSwitch(&MovementWESP);
IDSetSwitch(&MovementNSSP, nullptr);
IDSetSwitch(&MovementWESP, nullptr);
}

// sleep for 100 mseconds
nanosleep(&timeout, nullptr);
}

if (!isSimulation())
{
if (setObjectRA(PortFD, targetRA) < 0 || (setObjectDEC(PortFD, targetDEC)) < 0)
{
EqNP.s = IPS_ALERT;
IDSetNumber(&EqNP, "Error setting RA/DEC.");
return false;
}

int err = 0;

/* Slew reads the '0', that is not the end of the slew */
if ((err = flip ? Flip(PortFD) : Slew(PortFD)))
{
LOGF_ERROR("Error %s to JNow RA %s - DEC %s", flip ? "Flipping" : "Slewing", RAStr, DecStr);
slewError(err);
return false;
}
}

TrackState = SCOPE_SLEWING;
//EqNP.s = IPS_BUSY;

LOGF_INFO("%s to RA: %s - DEC: %s", flip ? "Flipping" : "Slewing", RAStr, DecStr);

return true;
}

void LX200NYX101::hexDump(char * buf, const char * data, int size)
{
for (int i = 0; i < size; i++)
Expand Down
5 changes: 4 additions & 1 deletion drivers/telescope/lx200_pegasus_nyx101.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ class LX200NYX101 : public LX200Generic
virtual bool SetTrackEnabled(bool enabled) override;
virtual bool SetTrackMode(uint8_t mode) override;
virtual bool SetSlewRate(int index) override;
virtual bool Flip(double ra, double dec) override;
virtual bool Goto(double ra, double dec) override;

private:
bool GotoInternal(double ra, double dec, bool flip);
int Flip(int fd);
static constexpr const uint8_t SLEW_MODES {10};
static constexpr const uint8_t DRIVER_LEN {64};
static const char DRIVER_STOP_CHAR { 0x23 };
Expand Down Expand Up @@ -119,7 +123,6 @@ class LX200NYX101 : public LX200Generic
INDI::PropertyNumber MeridianLimitNP {1};
INDI::PropertySwitch SafetyLimitSP {2};


bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
void hexDump(char * buf, const char * data, int size);
std::vector<std::string> split(const std::string &input, const std::string &regex);
Expand Down

0 comments on commit ac016e3

Please sign in to comment.