-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstroTrac.h
executable file
·171 lines (121 loc) · 5.49 KB
/
AstroTrac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#ifdef SB_MAC_BUILD
#include <unistd.h>
#endif
// C++ includes
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include "../../licensedinterfaces/sberrorx.h"
#include "../../licensedinterfaces/theskyxfacadefordriversinterface.h"
#include "../../licensedinterfaces/sleeperinterface.h"
#include "../../licensedinterfaces/serxinterface.h"
#include "../../licensedinterfaces/loggerinterface.h"
#include "../../licensedinterfaces/mountdriverinterface.h"
#include "../../licensedinterfaces/mount/asymmetricalequatorialinterface.h"
// #include "StopWatch.h"
// #define PLUGIN_DEBUG 1 // define this to have log files, 1 = bad stuff only, 2 and up.. full debug
#define DRIVER_VERSION 1.0
#define AT_SIDEREAL_SPEED 15.04106864 // Arc sec/s required to maintain siderial tracking
enum AstroTracErrors {PLUGIN_OK=0, NOT_CONNECTED, PLUGIN_CANT_CONNECT, PLUGIN_BAD_CMD_RESPONSE, COMMAND_FAILED, PLUGIN_ERROR};
#define SERIAL_BUFFER_SIZE 256
#define MAX_TIMEOUT 100
#define PLUGIN_LOG_BUFFER_SIZE 256
#define ERR_PARSE 1
#define PLUGIN_NB_SLEW_SPEEDS 11
#define MAXSENDTRIES 3 // Maximum number of attempts to send a mesage to the mount
// Define Class for Astrometric Instruments AstroTrac controller.
class AstroTrac
{
public:
AstroTrac();
~AstroTrac();
int Connect(char *pszPort);
int Disconnect();
bool isConnected() const { return m_bIsConnected; }
void setSerxPointer(SerXInterface *p) { m_pSerx = p; }
void setTSX(TheSkyXFacadeForDriversInterface *pTSX) { m_pTsx = pTSX;};
void setSleeper(SleeperInterface *pSleeper) { m_pSleeper = pSleeper;};
int getFirmwareVersion(std::string &sFirmware);
void setMountMode(MountTypeInterface::Type mountType);
MountTypeInterface::Type mountType();
int getHaAndDec(double &dHa, double &dDec);
int syncTo(double dHa, double dDec);
int isAligned(bool &bAligned);
int setTrackingRates(bool bTrackingOn, bool bIgnoreRates, double dTrackRaArcSecPerSec, double dTrackDecArcSecPerSec);
int getTrackRates(bool &bTrackingOn, double &dTrackRaArcSecPerSec, double &dTrackDecArcSecPerSec);
int startSlewTo(double dHa, double dDec, double dRa);
int isSlewToComplete(bool &bComplete);
int endSlewTo();
int startOpenLoopMove(const MountDriverInterface::MoveDir Dir, unsigned int nRate);
int stopOpenLoopMove();
int getNbSlewRates();
int getRateName(int nZeroBasedIndex, std::string &sOut);
int gotoPark(double dHa, double dDEc);
int GetIsParkingComplete(bool &bComplete);
bool GetIsParked() const { return m_bisParked; }
int unPark() {m_bisParked = false; return PLUGIN_OK; };
bool GetIsBeyondThePole() const { return m_bIsBTP; }
int Abort();
private:
SerXInterface *m_pSerx;
LoggerInterface *m_pLogger;
TheSkyXFacadeForDriversInterface *m_pTsx;
SleeperInterface *m_pSleeper;
bool m_bDebugLog;
char m_szLogBuffer[PLUGIN_LOG_BUFFER_SIZE];
bool m_bIsConnected; // Connected to the mount?
std::string m_sFirmwareVersion;
bool m_bNorthernHemisphere;
MountTypeInterface::Type m_mountType;
// Latest RA and DEC encoder positions
double m_dHAEncoder = 0.0;
double m_dDecEncoder = 0.0;
// Save the state of last tracking request
bool m_bTracking = true;
double m_dRATrackingRate = 0.0;
double m_dDETrackingRate = 0.0;
// Parking variables
bool m_bisParked = false;
bool m_bParkingInProgress = false;
// Flag to tell slewing that aborted
bool m_bSlewingAborted = false;
// Variables to calculate slew time and improve Slew
double m_dVSlewMax = 3 * 3600.0; // Maximum slew velocity - 3 deg/sec in arcsec/sec
double m_dAslew = 3600.0; // Slew Acceleration - arcsec/sec
double m_dSlewOffset = 0.0; // How wrong was last slew? Store and attempt to correct in next slew
double m_dGotoRATarget; // Current Target RA - to allow slew offset to be calculated
MountDriverInterface::MoveDir m_nOpenLoopDir;
// limits don't change mid-course so we cache them
bool m_bIsBTP = false;
bool m_bLimitCached;
double m_dHoursEast;
double m_dHoursWest;
int AstroTracSendCommand(const char *pszCmd, char *pszResult, unsigned int nResultMaxLen);
int AstroTracSendCommandInnerLoop(const char *pszCmd, char *pszResult, unsigned int nResultMaxLen);
int AstroTracreadResponse(unsigned char *pszRespBuffer, unsigned int bufferLen);
// Functions to encapsulate transform from drive 1 and drive 2 position angles to positions on the sky
void EncoderValuesfromHAanDEC(double dHa, double dDec, double &RAEncoder, double &DEEncoder, bool bUseBTP);
void HAandDECfromEncoderValues(double RAEncoder, double DEEncoder, double &dHa, double &dDec);
// Function to calculate slew time
double slewTime(double dDist);
std::vector<std::string> m_svSlewRateNames = {"0.5x", "1x (siderial)", "2x", "4x", "8x", "16x", "32x", "64x", "128x", "256x", "512x"};
std::vector<double> m_dvSlewRates = {0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0};
// CStopWatch timer;
#ifdef PLUGIN_DEBUG
std::string m_sLogfilePath;
// timestamp for logs
char *timestamp;
time_t ltime;
FILE *Logfile; // LogFile
#endif
};