-
Notifications
You must be signed in to change notification settings - Fork 3
/
pimoco_mount.h
executable file
·293 lines (204 loc) · 11.3 KB
/
pimoco_mount.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
PiMoCo: Raspberry Pi Telescope Mount and Focuser Control
Copyright (C) 2021 Markus Noga
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef PIMOCO_MOUNT_H
#define PIMOCO_MOUNT_H
#include <libindi/indicom.h>
#include <libindi/inditelescope.h>
#include <libindi/indiguiderinterface.h>
#include "pimoco_stepper.h"
// Indi class for pimoco mounts
class PimocoMount : public INDI::Telescope, public INDI::GuiderInterface {
public:
// Creates a Pimoco mount
PimocoMount();
// Destroys this pimoco focuser. Stops device motion for safety's sake
~PimocoMount();
virtual const char *getDefaultName() override;
virtual bool initProperties() override;
virtual bool updateProperties() override;
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override;
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
virtual bool ISSnoopDevice(XMLEle *root) override;
// Updates number vector property with the given values if res is true and display status IPS_OK, else display status IPS_ALERT. Returns res for convenience.
bool ISUpdateNumber(INumberVectorProperty *NP, double values[], char *names[], int n, bool res);
enum {
TRACK_KING = TRACK_CUSTOM+1,
};
protected:
virtual bool saveConfigItems(FILE *fp) override;
virtual bool Connect() override;
virtual bool Disconnect() override;
virtual bool Handshake() override;
virtual void TimerHit() override;
// Updates HA/Dec rates if guiding timeouts are reached. Returns true on success, else false.
bool guiderTimerHit();
virtual bool ReadScopeStatus() override;
// Returns next timer interval in milliseconds. Guiding has priority, then Goto tracking, else base polling rate.
uint32_t getNextTimerInterval();
// Returns next guider timer interval in milliseconds.
uint32_t getGuiderTimerInterval();
virtual bool Abort() override;
virtual bool SetTrackEnabled(bool enabled) override;
virtual bool SetTrackMode(uint8_t mode) override;
virtual bool SetTrackRate(double raRate, double deRate) override;
// syncs custom tracking rate to average motion since last sync
bool syncTrackRate();
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
virtual bool SetSlewRate(int index) override;
virtual bool Sync(double equRA, double equDec) override;
// Syncs to given device HA/Dec coordinates
bool SyncDeviceHADec(double deviceHA, double deviceDec);
virtual bool Goto(double equRA, double equDec) override;
// Executes a goto command to given equatorial RA, Dec and pier side. If pier side is not forced, also tries the other side
// to meet mount limits. Returns immediately with true on success, false on failure.
bool Goto(double equRA, double equDec, TelescopePierSide equPS, bool forcePierSide);
virtual bool SetParkPosition(double Axis1Value, double Axis2Value) override;
virtual bool SetCurrentPark() override;
virtual bool SetDefaultPark() override;
virtual bool Park() override;
virtual bool UnPark() override;
virtual IPState GuideNorth(uint32_t ms) override;
virtual IPState GuideSouth(uint32_t ms) override;
virtual IPState GuideEast(uint32_t ms) override;
virtual IPState GuideWest(uint32_t ms) override;
// Returns local apparent sidereal time in hours now
double getLocalSiderealTime();
// Returns current realtime clock in milliseconds
static uint64_t getTimeMillis();
// Converts given value into native dec range of [-180,180) degrees
static double rangeDecNative(double r);
// Internal tracking methods
//
// Gets tracking mode
uint8_t getTrackMode() const { return IUFindOnSwitchIndex(&TrackModeSP); }
// Gets tracking rate for RA for current tracking mode
double getTrackRateRA() const {
uint8_t mode=getTrackMode();
return (mode==TRACK_CUSTOM) ? trackRateCustomRA : trackRates[mode];
}
// Gets tracking rate for Dec for current tracking mode
double getTrackRateDec() const {
uint8_t mode=getTrackMode();
return (mode==TRACK_CUSTOM) ? trackRateCustomDec : 0;
}
// Returns current tracking or manual slew speed for HA
double getArcsecPerSecHA();
// Returns current tracking or manual slew speed for Dec
double getArcsecPerSecDec();
// Apply current tracking status, mode and rate to steppers. Checks mount limits and resets scope to idle if violated. Returns true on success, else failure
bool applyTracking(bool updateRA=true, bool updateDec=true);
// Converts device coordinates to equatorial coordinates. If local sidereal time below zero is given, uses current time
void equatorialFromDevice(double *equRA, double *equDec, TelescopePierSide *equPS, double deviceHA, double deviceDec, double lst=-1);
// Converts equatorial coordinates into device coordinates. If local sidereal time below zero is given, uses current time.
// Returns true on success, false if the device coordniates are outside defined bounds
bool deviceFromEquatorial(double *deviceHA, double *deviceDec, double equRA, double equDec, TelescopePierSide equPS, double lst=-1);
// Converts equatorial coordinates to device coordinates. If Julian date below zero is given, uses current time.
void horizonFromEquatorial(double *horAlt, double *horAz, double eqRA, double eqDec, double jd=-1);
// Calculate refraction in arc minutes from the given apparent altitude, air pressure and temperature
static double refractionArcminsFromApparentAltitude(double appAltDegrees, double pressureMillibars, double tempCelsius);
// Calculate refraction in arc minutes from the given true altitude, air pressure and temperature
static double refractionArcminsFromTrueAltitude(double appAltDegrees, double pressureMillibars, double tempCelsius);
// Applies mount limits to current position and direction of motion. Stops all motion and updates scope status if out of bounds and in wrong direction. Returns true if motion OK, else false
bool applyLimits(double arcsecPerSecHA, double arcsecPerSecDec);
// Checks given hour angle against mount limits. Returns true if within bounds, else false
bool checkLimitsHA(double deviceHA);
// Checks given hour angle and hour angle velocity against mount limits. Returns true if within bounds, else false
bool checkLimitsHA(double deviceHA, double haArcsecPerSec);
// Checks given altitude against mount altitude limits. Returns true if within bounds, else false
bool checkLimitsAlt(double horAlt);
// Checks given altitude and altitude velocity against mount altitude limits. Returns true if within bounds, else false
bool checkLimitsAlt(double horAlt, double deviceHA, double deviceDec, double haArcsecPerSec, double decArcsecPerSec, double jd, double lst);
// Physical connector GPIO pin numbers for stepper DIAG0 lines
enum {
HA_DIAG0_PIN = 35,
DEC_DIAG0_PIN = 36,
};
Stepper stepperHA;
Stepper stepperDec;
const char *spiDeviceFilenameHA;
const char *spiDeviceFilenameDec;
// Tracking rates for sidereal, solar, lunar and custom (defaults to sidereal)
static const double trackRates[];
// Tracking rate variable names
static const char *trackRateNames[];
// Tracking rate UI labels
static const char *trackRateLabels[];
// Custom tracking rates for both axes. Active only in mode TRACK_CUSTOM
double trackRateCustomRA =trackRates[TRACK_CUSTOM], trackRateCustomDec=0;
// Stores if the scope was tracking before a goto slew was initiated. Required to work around INDI bug
bool wasTrackingBeforeSlew=false;
// Device HA/Dec position of last track rate sync button press
double syncTrackRateHA=0, syncTrackRateDec=0;
// Milliseconds timestamp of last tracking rate sync
uint64_t syncTrackRateMs=0;
// Target equatorial position for gotos. For periodic refresh of the HA-based actual hardware gotos as time progresses
double gotoTargetRA=0, gotoTargetDec=0;
// Target side of pier for gotos
TelescopePierSide gotoTargetPS=PIER_EAST;
// Speed up polling frequency once gotos are closer than this number of degrees
static const double gotoSpeedupPollingDegrees;
// Manual slewing speed active on the given axis, or zero if inactive
double manualSlewArcsecPerSecRA=0, manualSlewArcsecPerSecDec=0;
// Flag: guider pulse currently active on the given axis
bool guiderActiveRA=false, guiderActiveDec=false;
// Timeouts for guider pulse
uint64_t guiderTimeoutRA, guiderTimeoutDec;
enum {
NUM_SLEW_RATES = 4
} SlewRatesType;
// UI controls
//
INumber DeviceCoordN[2]={};
INumberVectorProperty DeviceCoordNP;
INumber TimeN[2]={};
INumberVectorProperty TimeNP;
INumber AltAzN[2]={};
INumberVectorProperty AltAzNP;
INumber HAMotorN[Stepper::MOTORN_SIZE]={};
INumberVectorProperty HAMotorNP;
ISwitch HAMSwitchS[Stepper::MSWITCHS_SIZE]={};
ISwitchVectorProperty HAMSwitchSP;
INumber HARampN[Stepper::RAMPN_SIZE]={};
INumberVectorProperty HARampNP;
INumber DecMotorN[Stepper::MOTORN_SIZE]={};
INumberVectorProperty DecMotorNP;
ISwitch DecMSwitchS[Stepper::MSWITCHS_SIZE]={};
ISwitchVectorProperty DecMSwitchSP;
INumber DecRampN[Stepper::RAMPN_SIZE]={};
INumberVectorProperty DecRampNP;
INumber SlewRatesN[NUM_SLEW_RATES]={};
INumberVectorProperty SlewRatesNP;
ISwitch SyncTrackRateS[2]={};
ISwitchVectorProperty SyncTrackRateSP;
ISwitch SyncToParkS[1]={};
ISwitchVectorProperty SyncToParkSP;
INumber GuiderSpeedN[1]={};
INumberVectorProperty GuiderSpeedNP;
INumber GuiderMaxPulseN[1]={};
INumberVectorProperty GuiderMaxPulseNP;
INumber HALimitsN[2]={};
INumberVectorProperty HALimitsNP;
INumber AltLimitsN[2]={};
INumberVectorProperty AltLimitsNP;
public:
// Names of the mount configuration tabs
static const char *HA_TAB;
static const char *DEC_TAB;
};
#endif // PIMOCO_MOUNT_H