Instrument Neutral Distributed Interface INDI  2.0.2
simplescope.cpp

A simple GOTO telescope that simulator slewing operation.

/*
INDI Developers Manual
Tutorial #2
"Simple Telescope Driver"
We develop a simple telescope simulator.
Refer to README, which contains instruction on how to build this driver, and use it
with an INDI-compatible client.
*/
#include "simplescope.h"
#include "indicom.h"
#include <cmath>
#include <memory>
static std::unique_ptr<SimpleScope> simpleScope(new SimpleScope());
{
// We add an additional debug level so we can log verbose scope status
DBG_SCOPE = INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE");
}
/**************************************************************************************
** We init our properties here. The only thing we want to init are the Debug controls
***************************************************************************************/
{
// ALWAYS call initProperties() of parent first
// Add Debug control so end user can turn debugging/loggin on and off
// Enable simulation mode so that serial connection in INDI::Telescope does not try
// to attempt to perform a physical connection to the serial port.
// Set telescope capabilities. 0 is for the the number of slew rates that we support. We have none for this simple driver.
return true;
}
/**************************************************************************************
** INDI is asking us to check communication with the device via a handshake
***************************************************************************************/
{
// When communicating with a real mount, we check here if commands are receieved
// and acknolowedged by the mount. For SimpleScope, we simply return true.
return true;
}
/**************************************************************************************
** INDI is asking us for our default device name
***************************************************************************************/
{
return "Simple Scope";
}
/**************************************************************************************
** Client is asking us to slew to a new position
***************************************************************************************/
bool SimpleScope::Goto(double ra, double dec)
{
targetRA = ra;
targetDEC = dec;
char RAStr[64] = {0}, DecStr[64] = {0};
// Parse the RA/DEC into strings
fs_sexa(RAStr, targetRA, 2, 3600);
fs_sexa(DecStr, targetDEC, 2, 3600);
// Mark state as slewing
// Inform client we are slewing to a new position
LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
// Success!
return true;
}
/**************************************************************************************
** Client is asking us to abort our motion
***************************************************************************************/
{
return true;
}
/**************************************************************************************
** Client is asking us to report telescope status
***************************************************************************************/
{
static struct timeval ltv
{
0, 0
};
struct timeval tv
{
0, 0
};
double dt = 0, da_ra = 0, da_dec = 0, dx = 0, dy = 0;
int nlocked;
/* update elapsed time since last poll, don't presume exactly POLLMS */
gettimeofday(&tv, nullptr);
if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
ltv = tv;
dt = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
ltv = tv;
// Calculate how much we moved since last time
da_ra = SLEW_RATE * dt;
da_dec = SLEW_RATE * dt;
/* Process per current state. We check the state of EQUATORIAL_EOD_COORDS_REQUEST and act acoordingly */
switch (TrackState)
{
// Wait until we are "locked" into positon for both RA & DEC axis
nlocked = 0;
// Calculate diff in RA
dx = targetRA - currentRA;
// If diff is very small, i.e. smaller than how much we changed since last time, then we reached target RA.
if (fabs(dx) * 15. <= da_ra)
{
currentRA = targetRA;
nlocked++;
}
// Otherwise, increase RA
else if (dx > 0)
currentRA += da_ra / 15.;
// Otherwise, decrease RA
else
currentRA -= da_ra / 15.;
// Calculate diff in DEC
dy = targetDEC - currentDEC;
// If diff is very small, i.e. smaller than how much we changed since last time, then we reached target DEC.
if (fabs(dy) <= da_dec)
{
currentDEC = targetDEC;
nlocked++;
}
// Otherwise, increase DEC
else if (dy > 0)
currentDEC += da_dec;
// Otherwise, decrease DEC
else
currentDEC -= da_dec;
// Let's check if we recahed position for both RA/DEC
if (nlocked == 2)
{
// Let's set state to TRACKING
LOG_INFO("Telescope slew is complete. Tracking...");
}
break;
default:
break;
}
char RAStr[64] = {0}, DecStr[64] = {0};
// Parse the RA/DEC into strings
fs_sexa(RAStr, currentRA, 2, 3600);
fs_sexa(DecStr, currentDEC, 2, 3600);
DEBUGF(DBG_SCOPE, "Current RA: %s Current DEC: %s", RAStr, DecStr);
NewRaDec(currentRA, currentDEC);
return true;
}
void setSimulation(bool enable)
Toggle driver simulation status A driver can run in simulation mode if Simulation option is enabled b...
void addDebugControl()
Add Debug control to the driver.
TelescopeStatus TrackState
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
bool Handshake() override
perform handshake with device to check communication
Definition: simplescope.cpp:61
bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
Definition: simplescope.cpp:79
const char * getDefaultName() override
Definition: simplescope.cpp:71
bool Abort() override
Abort any telescope motion including tracking if possible.
bool initProperties() override
Called to initialize basic properties required all the time.
Definition: simplescope.cpp:40
bool ReadScopeStatus() override
Read telescope status.
#define currentDEC
Definition: ieq45.cpp:48
#define currentRA
Definition: ieq45.cpp:47
double ra
double dec
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition: indicom.c:141
Implementations for common driver routines.
#define LOGF_INFO(fmt,...)
Definition: indilogger.h:82
#define LOG_INFO(txt)
Definition: indilogger.h:74
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
Construct a basic INDI telescope device that simulates GOTO commands.
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
Definition: indilogger.cpp:339
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
Definition: indilogger.cpp:72