Instrument Neutral Distributed Interface INDI 2.2.5
skywatcherAPIMount.cpp
Go to the documentation of this file.
1
23
24#include "skywatcherAPIMount.h"
25
26#include "indicom.h"
30
31#include <chrono>
32#include <thread>
33
34#include <sys/stat.h>
35
36#define DEBUG_PID
37
38using namespace INDI::AlignmentSubsystem;
39
40// We declare an auto pointer to SkywatcherAPIMount.
41static std::unique_ptr<SkywatcherAPIMount> SkywatcherAPIMountPtr(new SkywatcherAPIMount());
42
43/* Preset Slew Speeds */
44#define SLEWMODES 10
45static double SlewSpeeds[SLEWMODES] = { 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 600.0, 800.0 };
46
51{
52 // Set up the logging pointer in SkyWatcherAPI
53 pChildTelescope = this;
62 SLEWMODES);
63
64 m_LastCustomDirection[AXIS1] = m_LastCustomDirection[AXIS2] = 0;
65 setVersion(1, 8);
66}
67
72{
73 DEBUG(DBG_SCOPE, "SkywatcherAPIMount::Handshake");
74 if (!getActiveConnection()->name().compare("CONNECTION_TCP"))
75 {
77 // reset connection in case of packet loss
79 }
80
82 bool Result = InitMount();
83 DEBUGF(DBG_SCOPE, "SkywatcherAPIMount::Handshake - Result: %d", Result);
84 return Result;
85}
86
91{
92 return "Skywatcher Alt-Az";
93}
94
99{
100 // Allow the base class to initialise its visible before connection properties
102
103 for (size_t i = 0; i < SlewRateSP.count(); ++i)
104 {
105 SlewRateSP[i].setLabel(std::to_string(static_cast<int>(SlewSpeeds[i])) + "x");
106 SlewRateSP[i].setAux(&SlewSpeeds[i]);
107 }
108 SlewRateSP[SlewRateSP.count() - 1].setName("SLEW_MAX");
109
110 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
111 AddTrackMode("TRACK_SOLAR", "Solar");
112 AddTrackMode("TRACK_LUNAR", "Lunar");
113
114 // Add default properties
117
118 // Add alignment properties
120
121 // Force the alignment system to always be on
122 getSwitch("ALIGNMENT_SUBSYSTEM_ACTIVE")[0].setState(ISS_ON);
123
124 // Set up property variables
125 IUFillText(&BasicMountInfoT[MOTOR_CONTROL_FIRMWARE_VERSION], "MOTOR_CONTROL_FIRMWARE_VERSION",
126 "Motor control firmware version", "-");
127 IUFillText(&BasicMountInfoT[MOUNT_CODE], "MOUNT_CODE", "Mount code", "-");
128 IUFillText(&BasicMountInfoT[MOUNT_NAME], "MOUNT_NAME", "Mount name", "-");
129 IUFillText(&BasicMountInfoT[IS_DC_MOTOR], "IS_DC_MOTOR", "Is DC motor", "-");
130 IUFillTextVector(&BasicMountInfoTP, BasicMountInfoT, 4, getDeviceName(), "BASIC_MOUNT_INFO",
131 "Basic mount information", MountInfoTab, IP_RO, 60, IPS_IDLE);
132
133 IUFillNumber(&AxisOneInfoN[MICROSTEPS_PER_REVOLUTION], "MICROSTEPS_PER_REVOLUTION", "Microsteps per revolution",
134 "%.0f", 0, 0xFFFFFF, 1, 0);
135 IUFillNumber(&AxisOneInfoN[STEPPER_CLOCK_FREQUENCY], "STEPPER_CLOCK_FREQUENCY", "Stepper clock frequency", "%.0f", 0,
136 0xFFFFFF, 1, 0);
137 IUFillNumber(&AxisOneInfoN[HIGH_SPEED_RATIO], "HIGH_SPEED_RATIO", "High speed ratio", "%.0f", 0, 0xFFFFFF, 1, 0);
138 IUFillNumber(&AxisOneInfoN[MICROSTEPS_PER_WORM_REVOLUTION], "MICROSTEPS_PER_WORM_REVOLUTION",
139 "Microsteps per worm revolution", "%.0f", 0, 0xFFFFFF, 1, 0);
140
141 IUFillNumberVector(&AxisOneInfoNP, AxisOneInfoN, 4, getDeviceName(), "AXIS_ONE_INFO", "Axis one information",
142 MountInfoTab, IP_RO, 60, IPS_IDLE);
143
144 IUFillSwitch(&AxisOneStateS[FULL_STOP], "FULL_STOP", "FULL_STOP", ISS_OFF);
145 IUFillSwitch(&AxisOneStateS[SLEWING], "SLEWING", "SLEWING", ISS_OFF);
146 IUFillSwitch(&AxisOneStateS[SLEWING_TO], "SLEWING_TO", "SLEWING_TO", ISS_OFF);
147 IUFillSwitch(&AxisOneStateS[SLEWING_FORWARD], "SLEWING_FORWARD", "SLEWING_FORWARD", ISS_OFF);
148 IUFillSwitch(&AxisOneStateS[HIGH_SPEED], "HIGH_SPEED", "HIGH_SPEED", ISS_OFF);
149 IUFillSwitch(&AxisOneStateS[NOT_INITIALISED], "NOT_INITIALISED", "NOT_INITIALISED", ISS_ON);
150 IUFillSwitchVector(&AxisOneStateSP, AxisOneStateS, 6, getDeviceName(), "AXIS_ONE_STATE", "Axis one state",
151 MountInfoTab, IP_RO, ISR_NOFMANY, 60, IPS_IDLE);
152
153 IUFillNumber(&AxisTwoInfoN[MICROSTEPS_PER_REVOLUTION], "MICROSTEPS_PER_REVOLUTION", "Microsteps per revolution",
154 "%.0f", 0, 0xFFFFFF, 1, 0);
155 IUFillNumber(&AxisTwoInfoN[STEPPER_CLOCK_FREQUENCY], "STEPPER_CLOCK_FREQUENCY", "Step timer frequency", "%.0f", 0,
156 0xFFFFFF, 1, 0);
157 IUFillNumber(&AxisTwoInfoN[HIGH_SPEED_RATIO], "HIGH_SPEED_RATIO", "High speed ratio", "%.0f", 0, 0xFFFFFF, 1, 0);
158 IUFillNumber(&AxisTwoInfoN[MICROSTEPS_PER_WORM_REVOLUTION], "MICROSTEPS_PER_WORM_REVOLUTION",
159 "Microsteps per worm revolution", "%.0f", 0, 0xFFFFFF, 1, 0);
160
161 IUFillNumberVector(&AxisTwoInfoNP, AxisTwoInfoN, 4, getDeviceName(), "AXIS_TWO_INFO", "Axis two information",
162 MountInfoTab, IP_RO, 60, IPS_IDLE);
163
164 IUFillSwitch(&AxisTwoStateS[FULL_STOP], "FULL_STOP", "FULL_STOP", ISS_OFF);
165 IUFillSwitch(&AxisTwoStateS[SLEWING], "SLEWING", "SLEWING", ISS_OFF);
166 IUFillSwitch(&AxisTwoStateS[SLEWING_TO], "SLEWING_TO", "SLEWING_TO", ISS_OFF);
167 IUFillSwitch(&AxisTwoStateS[SLEWING_FORWARD], "SLEWING_FORWARD", "SLEWING_FORWARD", ISS_OFF);
168 IUFillSwitch(&AxisTwoStateS[HIGH_SPEED], "HIGH_SPEED", "HIGH_SPEED", ISS_OFF);
169 IUFillSwitch(&AxisTwoStateS[NOT_INITIALISED], "NOT_INITIALISED", "NOT_INITIALISED", ISS_ON);
170 IUFillSwitchVector(&AxisTwoStateSP, AxisTwoStateS, 6, getDeviceName(), "AXIS_TWO_STATE", "Axis two state",
171 MountInfoTab, IP_RO, ISR_NOFMANY, 60, IPS_IDLE);
172
173 IUFillNumber(&AxisOneEncoderValuesN[RAW_MICROSTEPS], "RAW_MICROSTEPS", "Raw Microsteps", "%.0f", 0, 0xFFFFFF, 1, 0);
174 IUFillNumber(&AxisOneEncoderValuesN[MICROSTEPS_PER_ARCSEC], "MICROSTEPS_PER_ARCSEC", "Microsteps/arcsecond",
175 "%.4f", 0, 0xFFFFFF, 1, 0);
176 IUFillNumber(&AxisOneEncoderValuesN[OFFSET_FROM_INITIAL], "OFFSET_FROM_INITIAL", "Offset from initial", "%.0f", 0,
177 0xFFFFFF, 1, 0);
178 IUFillNumber(&AxisOneEncoderValuesN[DEGREES_FROM_INITIAL], "DEGREES_FROM_INITIAL", "Degrees from initial", "%.2f",
179 -1000.0, 1000.0, 1, 0);
180
181 IUFillNumberVector(&AxisOneEncoderValuesNP, AxisOneEncoderValuesN, 4, getDeviceName(), "AXIS1_ENCODER_VALUES",
182 "Axis 1 Encoder values", MountInfoTab, IP_RO, 60, IPS_IDLE);
183
184 IUFillNumber(&AxisTwoEncoderValuesN[RAW_MICROSTEPS], "RAW_MICROSTEPS", "Raw Microsteps", "%.0f", 0, 0xFFFFFF, 1, 0);
185 IUFillNumber(&AxisTwoEncoderValuesN[MICROSTEPS_PER_ARCSEC], "MICROSTEPS_PER_ARCSEC", "Microsteps/arcsecond",
186 "%.4f", 0, 0xFFFFFF, 1, 0);
187 IUFillNumber(&AxisTwoEncoderValuesN[OFFSET_FROM_INITIAL], "OFFSET_FROM_INITIAL", "Offset from initial", "%.0f", 0,
188 0xFFFFFF, 1, 0);
189 IUFillNumber(&AxisTwoEncoderValuesN[DEGREES_FROM_INITIAL], "DEGREES_FROM_INITIAL", "Degrees from initial", "%.2f",
190 -1000.0, 1000.0, 1, 0);
191
192 IUFillNumberVector(&AxisTwoEncoderValuesNP, AxisTwoEncoderValuesN, 4, getDeviceName(), "AXIS2_ENCODER_VALUES",
193 "Axis 2 Encoder values", MountInfoTab, IP_RO, 60, IPS_IDLE);
194 // Register any visible before connection properties
195
196 // Slew modes
197 IUFillSwitch(&SlewModesS[SLEW_SILENT], "SLEW_SILENT", "Silent", ISS_OFF);
198 IUFillSwitch(&SlewModesS[SLEW_NORMAL], "SLEW_NORMAL", "Normal", ISS_ON);
199 IUFillSwitchVector(&SlewModesSP, SlewModesS, 2, getDeviceName(), "TELESCOPE_MOTION_SLEWMODE", "Slew Mode",
201
202 // SoftPEC modes
203 IUFillSwitch(&SoftPECModesS[SOFTPEC_ENABLED], "SOFTPEC_ENABLED", "Enable for tracking", ISS_OFF);
204 IUFillSwitch(&SoftPECModesS[SOFTPEC_DISABLED], "SOFTPEC_DISABLED", "Disabled", ISS_ON);
205 IUFillSwitchVector(&SoftPECModesSP, SoftPECModesS, 2, getDeviceName(), "TELESCOPE_MOTION_SOFTPECMODE",
206 "SoftPEC Mode", MOTION_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
207
208 // SoftPEC value for tracking mode
209 IUFillNumber(&SoftPecN, "SOFTPEC_VALUE", "degree/minute (Alt)", "%1.3f", 0.001, 1.0, 0.001, 0.009);
210 IUFillNumberVector(&SoftPecNP, &SoftPecN, 1, getDeviceName(), "SOFTPEC", "SoftPEC Value", MOTION_TAB, IP_RW, 60,
211 IPS_IDLE);
212
213 // Guiding rates for RA/DEC axes
214 IUFillNumber(&GuidingRatesN[0], "GUIDERA_RATE", "arcsec/seconds (RA)", "%1.3f", 1.0, 6000.0, 1.0, 120.0);
215 IUFillNumber(&GuidingRatesN[1], "GUIDEDEC_RATE", "arcsec/seconds (Dec)", "%1.3f", 1.0, 6000.0, 1.0, 120.0);
216 IUFillNumberVector(&GuidingRatesNP, GuidingRatesN, 2, getDeviceName(), "GUIDE_RATES", "Guide Rates", MOTION_TAB,
217 IP_RW, 60, IPS_IDLE);
218
219 // AUX Encoders
220 AUXEncoderSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_ON);
221 AUXEncoderSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_OFF);
222 AUXEncoderSP.fill(getDeviceName(), "AUX_ENCODERS", "AUX Encoders", TRACKING_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
223 AUXEncoderSP.load();
224
225 // Snap port
226 SnapPortSP[INDI_ENABLED].fill("INDI_ENABLED", "On", ISS_OFF);
227 SnapPortSP[INDI_DISABLED].fill("INDI_DISABLED", "Off", ISS_ON);
228 SnapPortSP.fill(getDeviceName(), "SNAP_PORT", "Snap Port", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
229
230 // PID Control
231 Axis1PIDNP[Propotional].fill("Propotional", "Propotional", "%.2f", 0.1, 100, 1, 0.1);
232 Axis1PIDNP[Derivative].fill("Derivative", "Derivative", "%.2f", 0, 500, 10, 0.05);
233 Axis1PIDNP[Integral].fill("Integral", "Integral", "%.2f", 0, 500, 10, 0.05);
234 Axis1PIDNP.fill(getDeviceName(), "AXIS1_PID", "Axis1 PID", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
235
236 Axis2PIDNP[Propotional].fill("Propotional", "Propotional", "%.2f", 0.1, 100, 1, 0.2);
237 Axis2PIDNP[Derivative].fill("Derivative", "Derivative", "%.2f", 0, 100, 10, 0.1);
238 Axis2PIDNP[Integral].fill("Integral", "Integral", "%.2f", 0, 100, 10, 0.1);
239 Axis2PIDNP.fill(getDeviceName(), "AXIS2_PID", "Axis2 PID", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
240
241 // Dead Zone
242 AxisDeadZoneNP[AXIS1].fill("AXIS1", "AZ (steps)", "%.f", 0, 100, 10, 10);
243 AxisDeadZoneNP[AXIS2].fill("AXIS2", "AL (steps)", "%.f", 0, 100, 10, 10);
244 AxisDeadZoneNP.fill(getDeviceName(), "DEAD_ZONE", "Dead Zone", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
245
246 // Clock Multiplier
247 AxisClockNP[AXIS1].fill("AXIS1", "AZ %", "%.f", 1, 200, 10, 100);
248 AxisClockNP[AXIS2].fill("AXIS2", "AL %", "%.f", 1, 200, 10, 100);
249 AxisClockNP.fill(getDeviceName(), "AXIS_CLOCK", "Clock Rate", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
250
251 // Offsets
252 AxisOffsetNP[RAOffset].fill("RAOffset", "RA (deg)", "%.2f", -1, 1, 0.05, 0);
253 AxisOffsetNP[DEOffset].fill("DEOffset", "DE (deg)", "%.2f", -1, 1, 0.05, 0);
254 AxisOffsetNP[AZSteps].fill("AZEncoder", "AZ (steps)", "%.f", -10000, 10000, 1000, 0);
255 AxisOffsetNP[ALSteps].fill("ALEncoder", "AL (steps)", "%.f", -10000, 10000, 1000, -100.0);
256 AxisOffsetNP[JulianOffset].fill("JulianOffset", "JD (s)", "%.f", -5, 5, 0.1, 0);
257 AxisOffsetNP.fill(getDeviceName(), "AXIS_OFFSET", "Offsets", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
258
259 // Tracking Rate
260 Axis1TrackRateNP[TrackDirection].fill("TrackDirection", "West/East", "%.f", 0, 1, 1, 0);
261 Axis1TrackRateNP[TrackClockRate].fill("TrackClockRate", "Freq/Step (Hz/s)", "%.f", 0, 16000000, 500000, 0);
262 Axis1TrackRateNP.fill(getDeviceName(), "AXIS1TrackRate", "Axis 1 Track", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
263
264 Axis2TrackRateNP[TrackDirection].fill("TrackDirection", "North/South", "%.f", 0, 1, 1, 0);
265 Axis2TrackRateNP[TrackClockRate].fill("TrackClockRate", "Freq/Stel (Hz/s)", "%.f", 0, 16000000, 500000, 0);
266 Axis2TrackRateNP.fill(getDeviceName(), "AXIS2TrackRate", "Axis 2 Track", TRACKING_TAB, IP_RW, 60, IPS_IDLE);
267
268
270
271 tcpConnection->setDefaultHost("192.168.4.1");
272 tcpConnection->setDefaultPort(11880);
273 tcpConnection->setConnectionType(Connection::TCP::TYPE_UDP);
274
275 if (strstr(getDeviceName(), "Wired"))
276 {
278 }
279 else if (strstr(getDeviceName(), "GTi"))
280 {
282 tcpConnection->setLANSearchEnabled(true);
283 }
284
286
287 // Guiding support
290
291 return true;
292}
293
297bool SkywatcherAPIMount::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
298 char *formats[], char *names[], int n)
299{
300 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
301 {
302 // It is for us
303 ProcessAlignmentBLOBProperties(this, name, sizes, blobsizes, blobs, formats, names, n);
304 }
305 // Pass it up the chain
306 return INDI::Telescope::ISNewBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
307}
308
312bool SkywatcherAPIMount::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
313{
314 // Check guider interface
315 if (GI::processNumber(dev, name, values, names, n))
316 return true;
317
318 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
319 {
320 ProcessAlignmentNumberProperties(this, name, values, names, n);
321
322 if (strcmp(name, "SOFTPEC") == 0)
323 {
324 SoftPecNP.s = IPS_OK;
325 IUUpdateNumber(&SoftPecNP, values, names, n);
326 IDSetNumber(&SoftPecNP, nullptr);
327 return true;
328 }
329
330 if (strcmp(name, "GUIDE_RATES") == 0)
331 {
332 ResetGuidePulses();
333 GuidingRatesNP.s = IPS_OK;
334 IUUpdateNumber(&GuidingRatesNP, values, names, n);
335 IDSetNumber(&GuidingRatesNP, nullptr);
336 return true;
337 }
338
339 // Dead Zone
340 if (AxisDeadZoneNP.isNameMatch(name))
341 {
342 AxisDeadZoneNP.update(values, names, n);
343 AxisDeadZoneNP.setState(IPS_OK);
344 AxisDeadZoneNP.apply();
345 saveConfig(true, AxisDeadZoneNP.getName());
346 return true;
347 }
348
349 // Clock Rate
350 if (AxisClockNP.isNameMatch(name))
351 {
352 AxisClockNP.update(values, names, n);
353 AxisClockNP.setState(IPS_OK);
354 AxisClockNP.apply();
355 saveConfig(true, AxisClockNP.getName());
356 return true;
357 }
358
359 // Offsets
360 if (AxisOffsetNP.isNameMatch(name))
361 {
362 AxisOffsetNP.update(values, names, n);
363 AxisOffsetNP.setState(IPS_OK);
364 AxisOffsetNP.apply();
365 saveConfig(true, AxisOffsetNP.getName());
366 return true;
367 }
368
369 // Axis 1
370 if (Axis1TrackRateNP.isNameMatch(name))
371 {
372 Axis1TrackRateNP.update(values, names, n);
373 Axis1TrackRateNP.setState(IPS_OK);
374 Axis1TrackRateNP.apply();
375 saveConfig(true, Axis1TrackRateNP.getName());
376 return true;
377 }
378
379 // Axis 2
380 if (Axis2TrackRateNP.isNameMatch(name))
381 {
382 Axis2TrackRateNP.update(values, names, n);
383 Axis2TrackRateNP.setState(IPS_OK);
384 Axis2TrackRateNP.apply();
385 saveConfig(true, Axis2TrackRateNP.getName());
386 return true;
387 }
388
389 // Axis1 PID
390 if (Axis1PIDNP.isNameMatch(name))
391 {
392 Axis1PIDNP.update(values, names, n);
393 Axis1PIDNP.setState(IPS_OK);
394 Axis1PIDNP.apply();
395 saveConfig(Axis1PIDNP);
396
397 m_Controllers[AXIS1].reset(new PID(getPollingPeriod() / 1000, 50, -50,
398 Axis1PIDNP[Propotional].getValue(),
399 Axis1PIDNP[Derivative].getValue(),
400 Axis1PIDNP[Integral].getValue()));
401 return true;
402 }
403
404 // Axis2 PID
405 if (Axis2PIDNP.isNameMatch(name))
406 {
407 Axis2PIDNP.update(values, names, n);
408 Axis2PIDNP.setState(IPS_OK);
409 Axis2PIDNP.apply();
410 saveConfig(Axis2PIDNP);
411
412 m_Controllers[AXIS2].reset(new PID(getPollingPeriod() / 1000, 50, -50,
413 Axis2PIDNP[Propotional].getValue(),
414 Axis2PIDNP[Derivative].getValue(),
415 Axis2PIDNP[Integral].getValue()));
416 return true;
417 }
418
419
420 // Let our driver do sync operation in park position
421 if (strcmp(name, "EQUATORIAL_EOD_COORD") == 0)
422 {
423 double ra = -1;
424 double dec = -100;
425
426 for (int x = 0; x < n; x++)
427 {
428 if (EqNP[AXIS_RA].isNameMatch(names[x]))
429 ra = values[x];
430 else if (EqNP[AXIS_DE].isNameMatch(names[x]))
431 dec = values[x];
432 }
433 if ((ra >= 0) && (ra <= 24) && (dec >= -90) && (dec <= 90))
434 {
435 if (CoordSP.isSwitchOn("SYNC") && isParked())
436 {
437 return Sync(ra, dec);
438 }
439 }
440 }
441 }
442 // Pass it up the chain
443 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
444}
445
449bool SkywatcherAPIMount::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
450{
451 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
452 {
453 // Auxiliary Encoders
454 if (AUXEncoderSP.isNameMatch(name))
455 {
456 AUXEncoderSP.update(states, names, n);
457 AUXEncoderSP.setState(IPS_OK);
458 AUXEncoderSP.apply();
459 auto enabled = AUXEncoderSP.findOnSwitchIndex() == INDI_ENABLED;
460 TurnRAEncoder(enabled);
461 TurnDEEncoder(enabled);
462 saveConfig(AUXEncoderSP);
463 return true;
464 }
465
466 // Snap Port
467 if (SnapPortSP.isNameMatch(name))
468 {
469 SnapPortSP.update(states, names, n);
470 auto enabled = SnapPortSP.findOnSwitchIndex() == INDI_ENABLED;
471 toggleSnapPort(enabled);
472 if (enabled)
473 LOG_INFO("Toggling snap port on...");
474 else
475 LOG_INFO("Toggling snap port off...");
476 SnapPortSP.setState(enabled ? IPS_OK : IPS_IDLE);
477 SnapPortSP.apply();
478 return true;
479 }
480
481 ProcessAlignmentSwitchProperties(this, name, states, names, n);
482 }
483 // Pass it up the chain
484 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
485}
486
490bool SkywatcherAPIMount::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
491{
492 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
493 {
494 ProcessAlignmentTextProperties(this, name, texts, names, n);
495 }
496 // Pass it up the chain
497 return INDI::Telescope::ISNewText(dev, name, texts, names, n);
498}
499
503bool SkywatcherAPIMount::Goto(double ra, double dec)
504{
505 if (m_IterativeGOTOPending)
506 {
507 char RAStr[32], DecStr[32];
508 fs_sexa(RAStr, m_SkyCurrentRADE.rightascension, 2, 3600);
509 fs_sexa(DecStr, m_SkyCurrentRADE.declination, 2, 3600);
510 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Iterative GOTO RA %lf DEC %lf (Current Sky RA %s DE %s)", ra, dec, RAStr,
511 DecStr);
512 }
513 else
514 {
515 if (TrackState != SCOPE_IDLE)
516 Abort();
517
518 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "GOTO RA %lf DEC %lf", ra, dec);
519
520 auto onSwitch = CoordSP.findOnSwitch();
521 if (onSwitch && (onSwitch->isNameMatch("TRACK") || onSwitch->isNameMatch("SLEW")))
522 {
523 char RAStr[32], DecStr[32];
524 fs_sexa(RAStr, ra, 2, 3600);
525 fs_sexa(DecStr, dec, 2, 3600);
526 m_SkyTrackingTarget.rightascension = ra;
527 m_SkyTrackingTarget.declination = dec;
528 LOGF_INFO("Goto target RA %s DEC %s", RAStr, DecStr);
529 }
530 }
531
532 INDI::IHorizontalCoordinates AltAz { 0, 0 };
534
535 // Transform Celestial to Telescope coordinates.
536 // We have no good way to estimate how long will the mount takes to reach target (with deceleration,
537 // and not just speed). So we will use iterative GOTO once the first GOTO is complete.
538 if (TransformCelestialToTelescopeJD(ra, dec, ln_get_julian_from_sys(), TDV))
539 {
540 INDI::IEquatorialCoordinates EquatorialCoordinates { 0, 0 };
542 INDI::HorizontalToEquatorial(&AltAz, &m_Location, ln_get_julian_from_sys(), &EquatorialCoordinates);
543
544 char RAStr[32], DecStr[32];
545 fs_sexa(RAStr, EquatorialCoordinates.rightascension, 2, 3600);
546 fs_sexa(DecStr, EquatorialCoordinates.declination, 2, 3600);
547
548 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Sky -> Mount RA %s DE %s (TDV x %lf y %lf z %lf)", RAStr, DecStr, TDV.x,
549 TDV.y, TDV.z);
550 }
551 else
552 {
553 // Try a conversion with the stored observatory position if any
554 INDI::IEquatorialCoordinates EquatorialCoordinates { 0, 0 };
555 EquatorialCoordinates.rightascension = ra;
556 EquatorialCoordinates.declination = dec;
557 INDI::EquatorialToHorizontal(&EquatorialCoordinates, &m_Location, ln_get_julian_from_sys(), &AltAz);
560 {
561 case ZENITH:
562 break;
563
565 // Rotate the TDV coordinate system clockwise (negative) around the y axis by 90 minus
566 // the (positive)observatory latitude. The vector itself is rotated anticlockwise
567 TDV.RotateAroundY(m_Location.latitude - 90.0);
568 break;
569
571 // Rotate the TDV coordinate system anticlockwise (positive) around the y axis by 90 plus
572 // the (negative)observatory latitude. The vector itself is rotated clockwise
573 TDV.RotateAroundY(m_Location.latitude + 90.0);
574 break;
575 }
577 }
578
580 "Sky -> Mount AZ %lf° (%ld) AL %lf° (%ld)",
581 AltAz.azimuth,
582 DegreesToMicrosteps(AXIS1, AltAz.azimuth),
583 AltAz.altitude,
584 DegreesToMicrosteps(AXIS2, AltAz.altitude));
585
586 // Update the current encoder positions
589
590 long AzimuthOffsetMicrosteps = DegreesToMicrosteps(AXIS1,
591 AltAz.azimuth) + ZeroPositionEncoders[AXIS1] - (CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue());
592 long AltitudeOffsetMicrosteps = DegreesToMicrosteps(AXIS2,
593 AltAz.altitude) + ZeroPositionEncoders[AXIS2] - (CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue());
594
595 if (AzimuthOffsetMicrosteps > MicrostepsPerRevolution[AXIS1] / 2)
596 {
597 // Going the long way round - send it the other way
598 AzimuthOffsetMicrosteps -= MicrostepsPerRevolution[AXIS1];
599 }
600
601 // Do I need to take out any complete revolutions before I do this test?
602 if (AltitudeOffsetMicrosteps > MicrostepsPerRevolution[AXIS2] / 2)
603 {
604 // Going the long way round - send it the other way
605 AltitudeOffsetMicrosteps -= MicrostepsPerRevolution[AXIS2];
606 }
607
608 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Current Axis1 %ld microsteps (Zero %ld) Axis2 %ld microsteps (Zero %ld)",
610 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Azimuth offset %ld microsteps | Altitude offset %ld microsteps",
611 AzimuthOffsetMicrosteps, AltitudeOffsetMicrosteps);
612
613 SilentSlewMode = (IUFindSwitch(&SlewModesSP, "SLEW_SILENT") != nullptr
614 && IUFindSwitch(&SlewModesSP, "SLEW_SILENT")->s == ISS_ON);
615
617 {
618 long deltaAz = DegreesToMicrosteps(AXIS1, AZ_BACKLASH_DEG);
619 long deltaAlt = DegreesToMicrosteps(AXIS2, ALT_BACKLASH_DEG);
620 AzimuthOffsetMicrosteps -= deltaAz;
621 AltitudeOffsetMicrosteps -= deltaAlt;
622 }
623 SlewTo(AXIS1, AzimuthOffsetMicrosteps);
624 SlewTo(AXIS2, AltitudeOffsetMicrosteps);
625
627
628 return true;
629}
630
635{
637
638 if (isConnected())
639 {
640 // Fill in any real values now available MCInit should have been called already
641 UpdateDetailedMountInformation(false);
642
643 // Define our connected only properties to the base driver
644 // e.g. defineProperty(MyNumberVectorPointer);
645 // This will register our properties and send a IDDefXXXX mewssage to any connected clients
646 defineProperty(&BasicMountInfoTP);
647 defineProperty(&AxisOneInfoNP);
648 defineProperty(&AxisOneStateSP);
649 defineProperty(&AxisTwoInfoNP);
650 defineProperty(&AxisTwoStateSP);
651 defineProperty(&AxisOneEncoderValuesNP);
652 defineProperty(&AxisTwoEncoderValuesNP);
653 defineProperty(&SlewModesSP);
654 defineProperty(&SoftPECModesSP);
655 defineProperty(&SoftPecNP);
656 defineProperty(&GuidingRatesNP);
659 }
660}
661
666{
667 ISwitch *Switch = SlewRateSP.findOnSwitch();
668 return *(static_cast<double *>(Switch->aux));
669}
670
675{
676 double speed =
678 const char *dirStr = (dir == DIRECTION_NORTH) ? "North" : "South";
679
680 switch (command)
681 {
682 case MOTION_START:
683 DEBUGF(DBG_SCOPE, "Starting Slew %s", dirStr);
684 // Ignore the silent mode because MoveNS() is called by the manual motion UI controls.
685 Slew(AXIS2, speed, true);
686 m_ManualMotionActive[AXIS2] = true;
687 break;
688
689 case MOTION_STOP:
690 DEBUGF(DBG_SCOPE, "Stopping Slew %s", dirStr);
692 break;
693 }
694
695 return true;
696}
697
702{
703 double speed =
705 const char *dirStr = (dir == DIRECTION_WEST) ? "West" : "East";
706
707 switch (command)
708 {
709 case MOTION_START:
710 DEBUGF(DBG_SCOPE, "Starting Slew %s", dirStr);
711 // Ignore the silent mode because MoveNS() is called by the manual motion UI controls.
712 Slew(AXIS1, speed, true);
713 m_ManualMotionActive[AXIS1] = true;
714 break;
715
716 case MOTION_STOP:
717 DEBUGF(DBG_SCOPE, "Stopping Slew %s", dirStr);
719 break;
720 }
721
722 return true;
723}
724
729{
730 // Move the telescope to the desired position
731 long AltitudeOffsetMicrosteps = GetAxis2Park() - CurrentEncoders[AXIS2];
732 long AzimuthOffsetMicrosteps = GetAxis1Park() - CurrentEncoders[AXIS1];
734 "Parking: Altitude offset %ld microsteps Azimuth offset %ld microsteps", AltitudeOffsetMicrosteps,
735 AzimuthOffsetMicrosteps);
736
737 if (IUFindSwitch(&SlewModesSP, "SLEW_SILENT") != nullptr && IUFindSwitch(&SlewModesSP, "SLEW_SILENT")->s == ISS_ON)
738 {
739 SilentSlewMode = true;
740 }
741 else
742 {
743 SilentSlewMode = false;
744 }
745 SlewTo(AXIS1, AzimuthOffsetMicrosteps);
746 SlewTo(AXIS2, AltitudeOffsetMicrosteps);
747
749 return true;
750}
751
756{
757 SetParked(false);
758 return true;
759}
760
765{
766 if (enabled)
767 {
769 resetTracking();
770 m_SkyTrackingTarget.rightascension = EqNP[AXIS_RA].getValue();
771 m_SkyTrackingTarget.declination = EqNP[AXIS_DE].getValue();
772 }
773 else
774 {
779 m_ManualMotionActive[AXIS1] = m_ManualMotionActive[AXIS2] = false;
780
781 if (GuideNSNP.getState() == IPS_BUSY || GuideWENP.getState() == IPS_BUSY)
782 {
783 GuideNSNP.setState(IPS_IDLE);
784 GuideWENP.setState(IPS_IDLE);
785 GuideNSNP[0].setValue(0);
786 GuideNSNP[1].setValue(0);
787 GuideWENP[0].setValue(0);
788 GuideWENP[1].setValue(0);
789 GuideNSNP.apply();
790 GuideWENP.apply();
791 }
792 }
793
794 return true;
795}
796
801{
802 if (!GetStatus(AXIS1))
803 return false;
804
805 if (!GetStatus(AXIS2))
806 return false;
807
808 // Update Axis Position
809 if (!GetEncoder(AXIS1))
810 return false;
811 if (!GetEncoder(AXIS2))
812 return false;
813
814 UpdateDetailedMountInformation(true);
815
816 bool resetTrackingTimers = false;
817
818 // Calculate new RA DEC
819 INDI::IHorizontalCoordinates AltAz { 0, 0 };
820 AltAz.azimuth = range360(MicrostepsToDegrees(AXIS1,
821 CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue() - ZeroPositionEncoders[AXIS1]));
822 AltAz.altitude = MicrostepsToDegrees(AXIS2,
823 CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue() - ZeroPositionEncoders[AXIS2]);
824 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Axis1 encoder %ld (Zero %ld) -> AZ %lf°",
826 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Axis2 encoder %ld (Zero %ld) -> AL %lf°",
828
829 // Update current horizontal coords.
830 m_MountAltAz = AltAz;
831
832 // Get equatorial coords.
833 getCurrentRADE(AltAz, m_SkyCurrentRADE);
834 char RAStr[32], DecStr[32];
835 fs_sexa(RAStr, m_SkyCurrentRADE.rightascension, 2, 3600);
836 fs_sexa(DecStr, m_SkyCurrentRADE.declination, 2, 3600);
837 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Sky RA %s DE %s", RAStr, DecStr);
838
840 {
841 if ((AxesStatus[AXIS1].FullStop) && (AxesStatus[AXIS2].FullStop))
842 {
843 // If iterative GOTO was already engaged, stop it.
844 if (m_IterativeGOTOPending)
845 m_IterativeGOTOPending = false;
846 // If not, then perform the iterative GOTO once more.
847 else
848 {
849 m_IterativeGOTOPending = true;
850 return Goto(m_SkyTrackingTarget.rightascension, m_SkyTrackingTarget.declination);
851 }
852
853 auto onSwitch = CoordSP.findOnSwitch();
854 if (onSwitch && (onSwitch->isNameMatch("TRACK")))
855 {
856 // Goto has finished start tracking
858 resetTrackingTimers = true;
859 LOG_INFO("Tracking started.");
860 }
861 else
862 {
864 }
865 }
866 }
867 else if (TrackState == SCOPE_PARKING)
868 {
869 if (!IsInMotion(AXIS1) && !IsInMotion(AXIS2))
870 {
873 SetParked(true);
874 }
875 }
876
877 if (resetTrackingTimers)
878 resetTracking();
879
880 NewRaDec(m_SkyCurrentRADE.rightascension, m_SkyCurrentRADE.declination);
881 return true;
882}
883
887bool SkywatcherAPIMount::getCurrentAltAz(INDI::IHorizontalCoordinates &altaz)
888{
889 // Update Axis Position
891 {
893 CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue() - ZeroPositionEncoders[AXIS1]));
895 CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue() - ZeroPositionEncoders[AXIS2]);
896 return true;
897 }
898
899 return false;
900}
901
905bool SkywatcherAPIMount::getCurrentRADE(INDI::IHorizontalCoordinates altaz, INDI::IEquatorialCoordinates &rade)
906{
907 TelescopeDirectionVector TDV = TelescopeDirectionVectorFromAltitudeAzimuth(altaz);
908 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "TDV x %lf y %lf z %lf", TDV.x, TDV.y, TDV.z);
909
910 double RightAscension, Declination;
911 if (!TransformTelescopeToCelestialJD(TDV, RightAscension, Declination, ln_get_julian_from_sys()))
912 {
913 TelescopeDirectionVector RotatedTDV(TDV);
915 {
916 case ZENITH:
917 break;
918
920 // Rotate the TDV coordinate system anticlockwise (positive) around the y axis by 90 minus
921 // the (positive)observatory latitude. The vector itself is rotated clockwise
922 RotatedTDV.RotateAroundY(90.0 - m_Location.latitude);
924 break;
925
927 // Rotate the TDV coordinate system clockwise (negative) around the y axis by 90 plus
928 // the (negative)observatory latitude. The vector itself is rotated anticlockwise
929 RotatedTDV.RotateAroundY(-90.0 - m_Location.latitude);
931 break;
932 }
933
934 INDI::IEquatorialCoordinates EquatorialCoordinates;
935 INDI::HorizontalToEquatorial(&altaz, &m_Location, ln_get_julian_from_sys(), &EquatorialCoordinates);
936 RightAscension = EquatorialCoordinates.rightascension;
937 Declination = EquatorialCoordinates.declination;
938 }
939
940 rade.rightascension = RightAscension;
941 rade.declination = Declination;
942 return true;
943}
948{
950
951 Axis1PIDNP.save(fp);
952 Axis2PIDNP.save(fp);
953 AxisDeadZoneNP.save(fp);
954 AxisClockNP.save(fp);
955 AxisOffsetNP.save(fp);
956 Axis1TrackRateNP.save(fp);
957 Axis2TrackRateNP.save(fp);
958 AUXEncoderSP.save(fp);
959
961}
962
966bool SkywatcherAPIMount::Sync(double ra, double dec)
967{
968 DEBUG(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "SkywatcherAPIMount::Sync");
969
970 // Compute a telescope direction vector from the current encoders
971 if (!GetEncoder(AXIS1))
972 return false;
973 if (!GetEncoder(AXIS2))
974 return false;
975
976 // Syncing is treated specially when the telescope position is known in park position to spare
977 // "a huge-jump point" in the alignment model.
978 if (isParked())
979 {
980 INDI::IHorizontalCoordinates AltAz { 0, 0 };
982
983 if (TransformCelestialToTelescopeJD(ra, dec, ln_get_julian_from_sys(), TDV))
984 {
986 double OrigAlt = AltAz.altitude;
989 LOGF_INFO("Sync (Alt: %lf Az: %lf) in park position", OrigAlt, AltAz.azimuth);
990 GetAlignmentDatabase().clear();
991 return true;
992 }
993 }
994
995 // Might as well do this
996 UpdateDetailedMountInformation(true);
997
998 INDI::IHorizontalCoordinates AltAz { 0, 0 };
999
1000 AltAz.azimuth = range360(MicrostepsToDegrees(AXIS1,
1001 CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue() - ZeroPositionEncoders[AXIS1]));
1002 AltAz.altitude = MicrostepsToDegrees(AXIS2,
1003 CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue() - ZeroPositionEncoders[AXIS2]);
1004
1005 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Axis1 encoder %ld initial %ld AZ %lf°",
1007 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "Axis2 encoder %ld initial %ld AL %lf°",
1008 CurrentEncoders[AXIS2], ZeroPositionEncoders[AXIS2], AltAz.altitude);
1009
1010 AlignmentDatabaseEntry NewEntry;
1011 NewEntry.ObservationJulianDate = ln_get_julian_from_sys();
1012 NewEntry.RightAscension = ra;
1013 NewEntry.Declination = dec;
1015 NewEntry.PrivateDataSize = 0;
1016
1017 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "New sync point Date %lf RA %lf DEC %lf TDV(x %lf y %lf z %lf)",
1018 NewEntry.ObservationJulianDate, NewEntry.RightAscension, NewEntry.Declination, NewEntry.TelescopeDirection.x,
1019 NewEntry.TelescopeDirection.y, NewEntry.TelescopeDirection.z);
1020
1021 m_IterativeGOTOPending = false;
1022
1023 if (!CheckForDuplicateSyncPoint(NewEntry))
1024 {
1025 GetAlignmentDatabase().push_back(NewEntry);
1026
1027 // Tell the client about size change
1028 UpdateSize();
1029
1030 // Tell the math plugin to reinitialise
1031 Initialise(this);
1032
1033 // Force read before restarting
1035
1036 // The tracking seconds should be reset to restart the drift compensation
1037 resetTracking();
1038
1039 return true;
1040 }
1041 return false;
1042}
1043
1048{
1049 //DEBUG(DBG_SCOPE, "SkywatcherAPIMount::Abort");
1050 m_IterativeGOTOPending = false;
1051 SlowStop(AXIS1);
1052 SlowStop(AXIS2);
1054 m_ManualMotionActive[AXIS1] = m_ManualMotionActive[AXIS2] = false;
1055
1056 if (GuideNSNP.getState() == IPS_BUSY || GuideWENP.getState() == IPS_BUSY)
1057 {
1058 GuideNSNP.setState(IPS_IDLE);
1059 GuideWENP.setState(IPS_IDLE);
1060 GuideNSNP[0].setValue(0);
1061 GuideNSNP[1].setValue(0);
1062 GuideWENP[0].setValue(0);
1063 GuideWENP[1].setValue(0);
1064
1065 LOG_INFO("Guide aborted.");
1066 GuideNSNP.apply();
1067 GuideWENP.apply();
1068
1069 return true;
1070 }
1071
1072 return true;
1073}
1074
1079{
1080 // Call parent to read ReadScopeStatus
1082
1083 switch (TrackState)
1084 {
1085 case SCOPE_SLEWING:
1086 GuideDeltaAlt = 0;
1087 GuideDeltaAz = 0;
1088 ResetGuidePulses();
1089 GuidingPulses.clear();
1090 break;
1091
1092 case SCOPE_TRACKING:
1093 {
1094 // Check if manual motion in progress but we stopped
1095 bool manualMotionStopped = false;
1096 // Check each axis individually - the other may still be driven (tracking) and never stop on its own.
1097 for (AXISID axis : { AXIS1, AXIS2 })
1098 {
1099 auto &movementSP = (axis == AXIS1) ? MovementWESP : MovementNSSP;
1100 // check that for this axis the motor is not in motion and the user isn't feeding input (movement switch prop)
1101 if (m_ManualMotionActive[axis] && !IsInMotion(axis) && movementSP.getState() != IPS_BUSY)
1102 {
1103 m_ManualMotionActive[axis] = false;
1104 manualMotionStopped = true;
1105 }
1106 }
1107 // if either axis was being moved manually but has now stopped, reset tracking.
1108 if (manualMotionStopped)
1109 {
1110 resetTracking();
1111 m_SkyTrackingTarget.rightascension = EqNP[AXIS_RA].getValue();
1112 m_SkyTrackingTarget.declination = EqNP[AXIS_DE].getValue();
1113 }
1114 // If we're manually moving by WESN controls, update the tracking coordinates.
1115 if (m_ManualMotionActive[AXIS1] || m_ManualMotionActive[AXIS2])
1116 {
1117 break;
1118 }
1119 else
1120 {
1121 // TODO add switch to select between them
1122 //trackUsingPID();
1123 trackUsingPredictiveRates();
1124 }
1125
1126 break;
1127 }
1128
1129 default:
1130 GuideDeltaAlt = 0;
1131 GuideDeltaAz = 0;
1132 ResetGuidePulses();
1133 GuidingPulses.clear();
1134 break;
1135 }
1136}
1137
1141bool SkywatcherAPIMount::updateLocation(double latitude, double longitude, double elevation)
1142{
1143 //DEBUG(DBG_SCOPE, "SkywatcherAPIMount::updateLocation");
1144 UpdateLocation(latitude, longitude, elevation);
1145 return true;
1146}
1147
1152{
1154
1155 if (isConnected())
1156 {
1157 // Update location if loaded already from config
1158 if (m_Location.longitude > 0)
1159 UpdateLocation(m_Location.latitude, m_Location.longitude, m_Location.elevation);
1160
1161 // Fill in any real values now available MCInit should have been called already
1162 UpdateDetailedMountInformation(false);
1163
1164 // Define our connected only properties to the base driver
1165 // e.g. defineProperty(MyNumberVectorPointer);
1166 // This will register our properties and send a IDDefXXXX message to any connected clients
1167 // I have now idea why I have to do this here as well as in ISGetProperties. It makes me
1168 // concerned there is a design or implementation flaw somewhere.
1169 defineProperty(&BasicMountInfoTP);
1170 defineProperty(&AxisOneInfoNP);
1171 defineProperty(&AxisOneStateSP);
1172 defineProperty(&AxisTwoInfoNP);
1173 defineProperty(&AxisTwoStateSP);
1174 defineProperty(&AxisOneEncoderValuesNP);
1175 defineProperty(&AxisTwoEncoderValuesNP);
1176 defineProperty(&SlewModesSP);
1177 defineProperty(&SoftPECModesSP);
1178 defineProperty(&SoftPecNP);
1179 defineProperty(&GuidingRatesNP);
1180 defineProperty(Axis1PIDNP);
1181 defineProperty(Axis2PIDNP);
1182 defineProperty(AxisDeadZoneNP);
1183 defineProperty(AxisClockNP);
1184 defineProperty(AxisOffsetNP);
1185 defineProperty(Axis1TrackRateNP);
1186 defineProperty(Axis2TrackRateNP);
1187
1188 if (HasAuxEncoders())
1189 {
1190 // Since config is loaded, let's use this as starting point.
1191 // We should not force AUX encoders if the user explicitly turned them off.
1192 auto enabled = AUXEncoderSP[INDI_ENABLED].getState() == ISS_ON;
1193 LOGF_INFO("AUX encoders detected. Turning %s...", enabled ? "on" : "off");
1194 TurnRAEncoder(enabled);
1195 TurnDEEncoder(enabled);
1196 defineProperty(AUXEncoderSP);
1197 }
1198
1199 if (InitPark())
1200 {
1201 // If loading parking data is successful, we just set the default parking values.
1204 }
1205 else
1206 {
1207 // Otherwise, we set all parking data to default in case no parking data is found.
1208 SetAxis1Park(0x800000);
1209 SetAxis2Park(0x800000);
1210 SetAxis1ParkDefault(0x800000);
1211 SetAxis2ParkDefault(0x800000);
1212 }
1213
1214 if (isParked())
1215 {
1218
1219 }
1220 return true;
1221 }
1222 else
1223 {
1224 // Delete any connected only properties from the base driver's list
1225 // e.g. deleteProperty(MyNumberVector.name);
1226 deleteProperty(BasicMountInfoTP.name);
1227 deleteProperty(AxisOneInfoNP.name);
1228 deleteProperty(AxisOneStateSP.name);
1229 deleteProperty(AxisTwoInfoNP.name);
1230 deleteProperty(AxisTwoStateSP.name);
1231 deleteProperty(AxisOneEncoderValuesNP.name);
1232 deleteProperty(AxisTwoEncoderValuesNP.name);
1233 deleteProperty(SlewModesSP.name);
1234 deleteProperty(SoftPECModesSP.name);
1235 deleteProperty(SoftPecNP.name);
1236 deleteProperty(GuidingRatesNP.name);
1237 deleteProperty(Axis1PIDNP);
1238 deleteProperty(Axis2PIDNP);
1239 deleteProperty(AxisDeadZoneNP);
1240 deleteProperty(AxisClockNP);
1241 deleteProperty(AxisOffsetNP);
1242 deleteProperty(Axis1TrackRateNP);
1243 deleteProperty(Axis2TrackRateNP);
1244
1245 if (HasAuxEncoders())
1246 deleteProperty(AUXEncoderSP);
1247
1248 return true;
1249 }
1250
1252}
1253
1258{
1259 GuidingPulse Pulse;
1260
1261 CalculateGuidePulses();
1262 Pulse.DeltaAz = NorthPulse.DeltaAz;
1263 Pulse.DeltaAlt = NorthPulse.DeltaAlt;
1264 Pulse.Duration = ms;
1265 Pulse.OriginalDuration = ms;
1266 GuidingPulses.push_back(Pulse);
1267 return IPS_OK;
1268}
1269
1274{
1275 GuidingPulse Pulse;
1276
1277 CalculateGuidePulses();
1278 Pulse.DeltaAz = -NorthPulse.DeltaAz;
1279 Pulse.DeltaAlt = -NorthPulse.DeltaAlt;
1280 Pulse.Duration = ms;
1281 Pulse.OriginalDuration = ms;
1282 GuidingPulses.push_back(Pulse);
1283 return IPS_OK;
1284}
1285
1290{
1291 GuidingPulse Pulse;
1292
1293 CalculateGuidePulses();
1294 Pulse.DeltaAz = WestPulse.DeltaAz;
1295 Pulse.DeltaAlt = WestPulse.DeltaAlt;
1296 Pulse.Duration = ms;
1297 Pulse.OriginalDuration = ms;
1298 GuidingPulses.push_back(Pulse);
1299 return IPS_OK;
1300}
1301
1306{
1307 GuidingPulse Pulse;
1308
1309 CalculateGuidePulses();
1310 Pulse.DeltaAz = -WestPulse.DeltaAz;
1311 Pulse.DeltaAlt = -WestPulse.DeltaAlt;
1312 Pulse.Duration = ms;
1313 Pulse.OriginalDuration = ms;
1314 GuidingPulses.push_back(Pulse);
1315 return IPS_OK;
1316}
1317
1321void SkywatcherAPIMount::CalculateGuidePulses()
1322{
1323 if (NorthPulse.Duration != 0 || WestPulse.Duration != 0)
1324 return;
1325
1326 // Calculate the west reference delta
1327 // Note: The RA is multiplied by 3.75 (90/24) to be more comparable with DEC values.
1328 const double WestRate = IUFindNumber(&GuidingRatesNP, "GUIDERA_RATE")->value / 10 * -1.0 / 60 / 60 * 3.75 / 100;
1329
1330 ConvertGuideCorrection(WestRate, 0, WestPulse.DeltaAlt, WestPulse.DeltaAz);
1331 WestPulse.Duration = 1;
1332
1333 // Calculate the north reference delta
1334 // Note: By some reason, it must be multiplied by 100 to match with the RA values.
1335 const double NorthRate = IUFindNumber(&GuidingRatesNP, "GUIDEDEC_RATE")->value / 10 * 1.0 / 60 / 60 * 100 / 100;
1336
1337 ConvertGuideCorrection(0, NorthRate, NorthPulse.DeltaAlt, NorthPulse.DeltaAz);
1338 NorthPulse.Duration = 1;
1339}
1340
1344void SkywatcherAPIMount::ResetGuidePulses()
1345{
1346 NorthPulse.Duration = 0;
1347 WestPulse.Duration = 0;
1348}
1349
1353void SkywatcherAPIMount::ConvertGuideCorrection(double delta_ra, double delta_dec, double &delta_alt, double &delta_az)
1354{
1355 INDI::IHorizontalCoordinates OldAltAz { 0, 0 };
1356 INDI::IHorizontalCoordinates NewAltAz { 0, 0 };
1357 TelescopeDirectionVector OldTDV;
1358 TelescopeDirectionVector NewTDV;
1359
1360 TransformCelestialToTelescopeJD(m_SkyTrackingTarget.rightascension, m_SkyTrackingTarget.declination,
1361 ln_get_julian_from_sys(), OldTDV);
1363 TransformCelestialToTelescopeJD(m_SkyTrackingTarget.rightascension + delta_ra,
1364 m_SkyTrackingTarget.declination + delta_dec, ln_get_julian_from_sys(), NewTDV);
1366 delta_alt = NewAltAz.altitude - OldAltAz.altitude;
1367 delta_az = NewAltAz.azimuth - OldAltAz.azimuth;
1368}
1369
1373void SkywatcherAPIMount::SkywatcherMicrostepsFromTelescopeDirectionVector(
1374 const TelescopeDirectionVector TelescopeDirectionVector, long &Axis1Microsteps, long &Axis2Microsteps)
1375{
1376 // For the time being I assume that all skywathcer mounts share the same encoder conventions
1377 double Axis1Angle = 0;
1378 double Axis2Angle = 0;
1379 SphericalCoordinateFromTelescopeDirectionVector(TelescopeDirectionVector, Axis1Angle,
1382
1383 Axis1Microsteps = RadiansToMicrosteps(AXIS1, Axis1Angle);
1384 Axis2Microsteps = RadiansToMicrosteps(AXIS2, Axis2Angle);
1385}
1386
1391SkywatcherAPIMount::TelescopeDirectionVectorFromSkywatcherMicrosteps(long Axis1Microsteps, long Axis2Microsteps)
1392{
1393 // For the time being I assume that all skywathcer mounts share the same encoder conventions
1394 double Axis1Angle = MicrostepsToRadians(AXIS1, Axis1Microsteps);
1395 double Axis2Angle = MicrostepsToRadians(AXIS2, Axis2Microsteps);
1398}
1399
1403void SkywatcherAPIMount::UpdateDetailedMountInformation(bool InformClient)
1404{
1405 bool BasicMountInfoHasChanged = false;
1406
1407 if (std::string(BasicMountInfoT[MOTOR_CONTROL_FIRMWARE_VERSION].text) != std::to_string(MCVersion))
1408 {
1409 IUSaveText(&BasicMountInfoT[MOTOR_CONTROL_FIRMWARE_VERSION], std::to_string(MCVersion).c_str());
1410 BasicMountInfoHasChanged = true;
1411 }
1412 if (std::string(BasicMountInfoT[MOUNT_CODE].text) != std::to_string(MountCode))
1413 {
1414 IUSaveText(&BasicMountInfoT[MOUNT_CODE], std::to_string(MountCode).c_str());
1416 BasicMountInfoHasChanged = true;
1417 }
1418 if (std::string(BasicMountInfoT[IS_DC_MOTOR].text) != std::to_string(IsDCMotor))
1419 {
1420 IUSaveText(&BasicMountInfoT[IS_DC_MOTOR], std::to_string(IsDCMotor).c_str());
1421 BasicMountInfoHasChanged = true;
1422 }
1423 if (BasicMountInfoHasChanged && InformClient)
1424 IDSetText(&BasicMountInfoTP, nullptr);
1425
1426 IUSaveText(&BasicMountInfoT[MOUNT_NAME], mountTypeToString(MountCode));
1427
1428 bool AxisOneInfoHasChanged = false;
1429
1430 if (AxisOneInfoN[MICROSTEPS_PER_REVOLUTION].value != MicrostepsPerRevolution[0])
1431 {
1432 AxisOneInfoN[MICROSTEPS_PER_REVOLUTION].value = MicrostepsPerRevolution[0];
1433 AxisOneInfoHasChanged = true;
1434 }
1435 if (AxisOneInfoN[STEPPER_CLOCK_FREQUENCY].value != StepperClockFrequency[0])
1436 {
1437 AxisOneInfoN[STEPPER_CLOCK_FREQUENCY].value = StepperClockFrequency[0];
1438 AxisOneInfoHasChanged = true;
1439 }
1440 if (AxisOneInfoN[HIGH_SPEED_RATIO].value != HighSpeedRatio[0])
1441 {
1442 AxisOneInfoN[HIGH_SPEED_RATIO].value = HighSpeedRatio[0];
1443 AxisOneInfoHasChanged = true;
1444 }
1445 if (AxisOneInfoN[MICROSTEPS_PER_WORM_REVOLUTION].value != MicrostepsPerWormRevolution[0])
1446 {
1447 AxisOneInfoN[MICROSTEPS_PER_WORM_REVOLUTION].value = MicrostepsPerWormRevolution[0];
1448 AxisOneInfoHasChanged = true;
1449 }
1450 if (AxisOneInfoHasChanged && InformClient)
1451 IDSetNumber(&AxisOneInfoNP, nullptr);
1452
1453 bool AxisOneStateHasChanged = false;
1454 if (AxisOneStateS[FULL_STOP].s != (AxesStatus[0].FullStop ? ISS_ON : ISS_OFF))
1455 {
1456 AxisOneStateS[FULL_STOP].s = AxesStatus[0].FullStop ? ISS_ON : ISS_OFF;
1457 AxisOneStateHasChanged = true;
1458 }
1459 if (AxisOneStateS[SLEWING].s != (AxesStatus[0].Slewing ? ISS_ON : ISS_OFF))
1460 {
1461 AxisOneStateS[SLEWING].s = AxesStatus[0].Slewing ? ISS_ON : ISS_OFF;
1462 AxisOneStateHasChanged = true;
1463 }
1464 if (AxisOneStateS[SLEWING_TO].s != (AxesStatus[0].SlewingTo ? ISS_ON : ISS_OFF))
1465 {
1466 AxisOneStateS[SLEWING_TO].s = AxesStatus[0].SlewingTo ? ISS_ON : ISS_OFF;
1467 AxisOneStateHasChanged = true;
1468 }
1469 if (AxisOneStateS[SLEWING_FORWARD].s != (AxesStatus[0].SlewingForward ? ISS_ON : ISS_OFF))
1470 {
1471 AxisOneStateS[SLEWING_FORWARD].s = AxesStatus[0].SlewingForward ? ISS_ON : ISS_OFF;
1472 AxisOneStateHasChanged = true;
1473 }
1474 if (AxisOneStateS[HIGH_SPEED].s != (AxesStatus[0].HighSpeed ? ISS_ON : ISS_OFF))
1475 {
1476 AxisOneStateS[HIGH_SPEED].s = AxesStatus[0].HighSpeed ? ISS_ON : ISS_OFF;
1477 AxisOneStateHasChanged = true;
1478 }
1479 if (AxisOneStateS[NOT_INITIALISED].s != (AxesStatus[0].NotInitialized ? ISS_ON : ISS_OFF))
1480 {
1481 AxisOneStateS[NOT_INITIALISED].s = AxesStatus[0].NotInitialized ? ISS_ON : ISS_OFF;
1482 AxisOneStateHasChanged = true;
1483 }
1484 if (AxisOneStateHasChanged && InformClient)
1485 IDSetSwitch(&AxisOneStateSP, nullptr);
1486
1487 bool AxisTwoInfoHasChanged = false;
1488 if (AxisTwoInfoN[MICROSTEPS_PER_REVOLUTION].value != MicrostepsPerRevolution[1])
1489 {
1490 AxisTwoInfoN[MICROSTEPS_PER_REVOLUTION].value = MicrostepsPerRevolution[1];
1491 AxisTwoInfoHasChanged = true;
1492 }
1493 if (AxisTwoInfoN[STEPPER_CLOCK_FREQUENCY].value != StepperClockFrequency[1])
1494 {
1495 AxisTwoInfoN[STEPPER_CLOCK_FREQUENCY].value = StepperClockFrequency[1];
1496 AxisTwoInfoHasChanged = true;
1497 }
1498 if (AxisTwoInfoN[HIGH_SPEED_RATIO].value != HighSpeedRatio[1])
1499 {
1500 AxisTwoInfoN[HIGH_SPEED_RATIO].value = HighSpeedRatio[1];
1501 AxisTwoInfoHasChanged = true;
1502 }
1503 if (AxisTwoInfoN[MICROSTEPS_PER_WORM_REVOLUTION].value != MicrostepsPerWormRevolution[1])
1504 {
1505 AxisTwoInfoN[MICROSTEPS_PER_WORM_REVOLUTION].value = MicrostepsPerWormRevolution[1];
1506 AxisTwoInfoHasChanged = true;
1507 }
1508 if (AxisTwoInfoHasChanged && InformClient)
1509 IDSetNumber(&AxisTwoInfoNP, nullptr);
1510
1511 bool AxisTwoStateHasChanged = false;
1512 if (AxisTwoStateS[FULL_STOP].s != (AxesStatus[1].FullStop ? ISS_ON : ISS_OFF))
1513 {
1514 AxisTwoStateS[FULL_STOP].s = AxesStatus[1].FullStop ? ISS_ON : ISS_OFF;
1515 AxisTwoStateHasChanged = true;
1516 }
1517 if (AxisTwoStateS[SLEWING].s != (AxesStatus[1].Slewing ? ISS_ON : ISS_OFF))
1518 {
1519 AxisTwoStateS[SLEWING].s = AxesStatus[1].Slewing ? ISS_ON : ISS_OFF;
1520 AxisTwoStateHasChanged = true;
1521 }
1522 if (AxisTwoStateS[SLEWING_TO].s != (AxesStatus[1].SlewingTo ? ISS_ON : ISS_OFF))
1523 {
1524 AxisTwoStateS[SLEWING_TO].s = AxesStatus[1].SlewingTo ? ISS_ON : ISS_OFF;
1525 AxisTwoStateHasChanged = true;
1526 }
1527 if (AxisTwoStateS[SLEWING_FORWARD].s != (AxesStatus[1].SlewingForward ? ISS_ON : ISS_OFF))
1528 {
1529 AxisTwoStateS[SLEWING_FORWARD].s = AxesStatus[1].SlewingForward ? ISS_ON : ISS_OFF;
1530 AxisTwoStateHasChanged = true;
1531 }
1532 if (AxisTwoStateS[HIGH_SPEED].s != (AxesStatus[1].HighSpeed ? ISS_ON : ISS_OFF))
1533 {
1534 AxisTwoStateS[HIGH_SPEED].s = AxesStatus[1].HighSpeed ? ISS_ON : ISS_OFF;
1535 AxisTwoStateHasChanged = true;
1536 }
1537 if (AxisTwoStateS[NOT_INITIALISED].s != (AxesStatus[1].NotInitialized ? ISS_ON : ISS_OFF))
1538 {
1539 AxisTwoStateS[NOT_INITIALISED].s = AxesStatus[1].NotInitialized ? ISS_ON : ISS_OFF;
1540 AxisTwoStateHasChanged = true;
1541 }
1542 if (AxisTwoStateHasChanged && InformClient)
1543 IDSetSwitch(&AxisTwoStateSP, nullptr);
1544
1545 bool AxisOneEncoderValuesHasChanged = false;
1546 if ((AxisOneEncoderValuesN[RAW_MICROSTEPS].value != CurrentEncoders[AXIS1]) ||
1547 (AxisOneEncoderValuesN[OFFSET_FROM_INITIAL].value != CurrentEncoders[AXIS1] - ZeroPositionEncoders[AXIS1]))
1548 {
1549 AxisOneEncoderValuesN[RAW_MICROSTEPS].value = CurrentEncoders[AXIS1];
1550 AxisOneEncoderValuesN[MICROSTEPS_PER_ARCSEC].value = MicrostepsPerDegree[AXIS1] / 3600.0;
1551 AxisOneEncoderValuesN[OFFSET_FROM_INITIAL].value = CurrentEncoders[AXIS1] - ZeroPositionEncoders[AXIS1];
1552 AxisOneEncoderValuesN[DEGREES_FROM_INITIAL].value =
1554 AxisOneEncoderValuesHasChanged = true;
1555 }
1556 if (AxisOneEncoderValuesHasChanged && InformClient)
1557 IDSetNumber(&AxisOneEncoderValuesNP, nullptr);
1558
1559 bool AxisTwoEncoderValuesHasChanged = false;
1560 if ((AxisTwoEncoderValuesN[RAW_MICROSTEPS].value != CurrentEncoders[AXIS2]) ||
1561 (AxisTwoEncoderValuesN[OFFSET_FROM_INITIAL].value != CurrentEncoders[AXIS2] - ZeroPositionEncoders[AXIS2]))
1562 {
1563 AxisTwoEncoderValuesN[RAW_MICROSTEPS].value = CurrentEncoders[AXIS2];
1564 AxisTwoEncoderValuesN[MICROSTEPS_PER_ARCSEC].value = MicrostepsPerDegree[AXIS2] / 3600.0;
1565 AxisTwoEncoderValuesN[OFFSET_FROM_INITIAL].value = CurrentEncoders[AXIS2] - ZeroPositionEncoders[AXIS2];
1566 AxisTwoEncoderValuesN[DEGREES_FROM_INITIAL].value =
1568 AxisTwoEncoderValuesHasChanged = true;
1569 }
1570 if (AxisTwoEncoderValuesHasChanged && InformClient)
1571 IDSetNumber(&AxisTwoEncoderValuesNP, nullptr);
1572}
1573
1583
1588{
1589 // Zero azimuth looking north/south (depending on hemisphere)
1592 return true;
1593}
1594
1598void SkywatcherAPIMount::resetTracking()
1599{
1600 m_TrackingRateTimer.restart();
1601 GuideDeltaAlt = 0;
1602 GuideDeltaAz = 0;
1603 m_Controllers[AXIS_AZ].reset(new PID(std::max(0.001, getPollingPeriod() / 1000.), 1000, -1000,
1604 Axis1PIDNP[Propotional].getValue(),
1605 Axis1PIDNP[Derivative].getValue(),
1606 Axis1PIDNP[Integral].getValue()));
1607 m_Controllers[AXIS_AZ]->setIntegratorLimits(-1000, 1000);
1608 m_Controllers[AXIS_ALT].reset(new PID(std::max(0.001, getPollingPeriod() / 1000.), 1000, -1000,
1609 Axis2PIDNP[Propotional].getValue(),
1610 Axis2PIDNP[Derivative].getValue(),
1611 Axis2PIDNP[Integral].getValue()));
1612 m_Controllers[AXIS_ALT]->setIntegratorLimits(-1000, 1000);
1613 ResetGuidePulses();
1614}
1615
1619bool SkywatcherAPIMount::trackByRate(AXISID axis, double rate)
1620{
1621 if (std::abs(rate) > 0 && rate == m_LastTrackRate[axis])
1622 return true;
1623
1624 m_LastTrackRate[axis] = rate;
1625
1626 // If we are already stopped and rate is zero, we immediately return
1627 if (AxesStatus[axis].FullStop && rate == 0)
1628 return true;
1629 // If rate is zero, or direction changed then we should stop.
1630 else if (!AxesStatus[axis].FullStop && (rate == 0 || (AxesStatus[axis].SlewingForward && rate < 0)
1631 || (!AxesStatus[axis].SlewingForward && rate > 0)))
1632 {
1633 SlowStop(axis);
1634 LOGF_DEBUG("Tracking -> %s direction change.", (axis == AXIS1 ? "Axis 1" : "Axis 2"));
1635 return true;
1636 }
1637
1638 char Direction = rate > 0 ? '0' : '1';
1639 auto stepsPerSecond = static_cast<uint32_t>(std::abs(rate * (axis == AXIS1 ?
1640 AxisOneEncoderValuesN[MICROSTEPS_PER_ARCSEC].value : AxisTwoEncoderValuesN[MICROSTEPS_PER_ARCSEC].value)));
1641 auto clockRate = (StepperClockFrequency[axis] / std::max(1u, stepsPerSecond));
1642
1643 if (AxesStatus[axis].FullStop)
1644 {
1645 LOGF_DEBUG("Tracking -> %s restart.", (axis == AXIS1 ? "Axis 1" : "Axis 2"));
1646 SetAxisMotionMode(axis, '1', Direction);
1647 SetClockTicksPerMicrostep(axis, clockRate);
1648 StartAxisMotion(axis);
1649 }
1650 else
1651 {
1652 SetClockTicksPerMicrostep(axis, clockRate);
1653 }
1654
1655 return true;
1656}
1657
1661bool SkywatcherAPIMount::trackUsingPID()
1662{
1663 // Continue or start tracking
1664 // Calculate where the mount needs to be in POLLMS time
1665 // TODO may need to make this longer to get a meaningful result
1666 //double JulianOffset = (getCurrentPollingPeriod() / 1000) / (24.0 * 60 * 60);
1667 TelescopeDirectionVector TDV;
1668 INDI::IHorizontalCoordinates AltAz { 0, 0 };
1669
1670 // We modify the SkyTrackingTarget for non-sidereal objects (Moon or Sun)
1671 // The Moon and Sun appear to move eastward (increasing RA) relative to the stars
1672 // because their westward motion due to Earth's rotation is slower than the sidereal rate.
1673 if (TrackModeSP[TRACK_LUNAR].getState() == ISS_ON)
1674 {
1675 // TRACKRATE_LUNAR: how many arcsecs/sec the Moon moves westward (apparent motion)
1676 // TRACKRATE_SIDEREAL: how many arcsecs/sec the stars move westward (apparent motion)
1677 // Since the Moon moves slower westward, it effectively moves eastward relative to stars
1678 double dRA = (TRACKRATE_SIDEREAL - TRACKRATE_LUNAR) * m_TrackingRateTimer.elapsed() / 1000.0;
1679 m_SkyTrackingTarget.rightascension += dRA / (3600.0 * 15.0);
1680 m_TrackingRateTimer.restart();
1681 }
1682 else if (TrackModeSP[TRACK_SOLAR].getState() == ISS_ON)
1683 {
1684 // Similar logic: Sun moves slower westward than stars, so it moves eastward relative to stars
1685 double dRA = (TRACKRATE_SIDEREAL - TRACKRATE_SOLAR) * m_TrackingRateTimer.elapsed() / 1000.0;
1686 m_SkyTrackingTarget.rightascension += dRA / (3600.0 * 15.0);
1687 m_TrackingRateTimer.restart();
1688 }
1689
1690 auto ra = m_SkyTrackingTarget.rightascension + AxisOffsetNP[RAOffset].getValue() / 15.0;
1691 auto de = m_SkyTrackingTarget.declination + AxisOffsetNP[DEOffset].getValue();
1692 auto JDOffset = AxisOffsetNP[JulianOffset].getValue() / 86400.0;
1693
1694 if (TransformCelestialToTelescopeJD(ra, de, ln_get_julian_from_sys() + JDOffset, TDV))
1695 {
1696 DEBUGF(INDI::AlignmentSubsystem::DBG_ALIGNMENT, "TDV x %lf y %lf z %lf", TDV.x, TDV.y, TDV.z);
1698 }
1699 else
1700 {
1701 INDI::IEquatorialCoordinates EquatorialCoordinates { ra, de };
1702 INDI::EquatorialToHorizontal(&EquatorialCoordinates, &m_Location, ln_get_julian_from_sys() + JDOffset, &AltAz);
1703 }
1704
1706 "New Tracking Target AZ %lf° (%ld microsteps) AL %lf° (%ld microsteps) ",
1707 AltAz.azimuth,
1709 AltAz.altitude,
1710 DegreesToMicrosteps(AXIS2, AltAz.altitude));
1711
1712 // Calculate the auto-guiding delta degrees
1713 double DeltaAlt = 0;
1714 double DeltaAz = 0;
1715
1716 getGuidePulses(DeltaAz, DeltaAlt);
1717
1718 long SetPoint[2] = {0, 0}, Measurement[2] = {0, 0}, Error[2] = {0, 0};
1719 double TrackingRate[2] = {0, 0};
1720
1721 SetPoint[AXIS1] = DegreesToMicrosteps(AXIS1, AltAz.azimuth + GuideDeltaAz);
1722 Measurement[AXIS1] = CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue() - ZeroPositionEncoders[AXIS1];
1723
1724 SetPoint[AXIS2] = DegreesToMicrosteps(AXIS2, AltAz.altitude + GuideDeltaAlt);
1725 Measurement[AXIS2] = CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue() - ZeroPositionEncoders[AXIS2];
1726
1727 // Going the long way round - send it the other way
1728 while (SetPoint[AXIS1] > MicrostepsPerRevolution[AXIS1] / 2)
1729 SetPoint[AXIS1] -= MicrostepsPerRevolution[AXIS1];
1730
1731 while (SetPoint[AXIS2] > MicrostepsPerRevolution[AXIS2] / 2)
1732 SetPoint[AXIS2] -= MicrostepsPerRevolution[AXIS2];
1733
1734 Error[AXIS1] = SetPoint[AXIS1] - Measurement[AXIS1];
1735 Error[AXIS2] = SetPoint[AXIS2] - Measurement[AXIS2];
1736
1737 auto Axis1CustomClockRate = Axis1TrackRateNP[TrackClockRate].getValue();
1738
1739 if (!AxesStatus[AXIS1].FullStop && (
1740 (Axis1CustomClockRate == 0 && ((AxesStatus[AXIS1].SlewingForward && (Error[AXIS1] < -AxisDeadZoneNP[AXIS1].getValue())) ||
1741 (!AxesStatus[AXIS1].SlewingForward && (Error[AXIS1] > AxisDeadZoneNP[AXIS1].getValue())))) ||
1742 (Axis1CustomClockRate > 0 && Axis1TrackRateNP[TrackDirection].getValue() != m_LastCustomDirection[AXIS1])))
1743 {
1744 m_LastCustomDirection[AXIS1] = Axis1TrackRateNP[TrackDirection].getValue();
1745 // Direction change whilst axis running
1746 // Abandon tracking for this clock tick
1747 LOG_DEBUG("Tracking -> AXIS1 direction change.");
1748 LOGF_DEBUG("AXIS1 Setpoint %d Measurement %d Error %d Rate %f",
1749 SetPoint[AXIS1],
1750 Measurement[AXIS1],
1751 Error[AXIS1],
1752 TrackingRate[AXIS1]);
1753 SlowStop(AXIS1);
1754 }
1755 else
1756 {
1757 TrackingRate[AXIS1] = m_Controllers[AXIS1]->calculate(SetPoint[AXIS1], Measurement[AXIS1]);
1758 char Direction = TrackingRate[AXIS1] > 0 ? '0' : '1';
1759 TrackingRate[AXIS1] = std::fabs(TrackingRate[AXIS1]);
1760 if (TrackingRate[AXIS1] != 0)
1761 {
1762 auto clockRate = (StepperClockFrequency[AXIS1] / TrackingRate[AXIS1]) * (AxisClockNP[AXIS1].getValue() / 100.0);
1763
1764 if (Axis1CustomClockRate > 0)
1765 {
1766 clockRate = Axis1CustomClockRate;
1767 Direction = Axis1TrackRateNP[TrackDirection].getValue() == 0 ? '0' : '1';
1768 }
1769
1770 LOGF_DEBUG("AXIS1 Setpoint %d Measurement %d Error %d Rate %f Freq %f Dir %s",
1771 SetPoint[AXIS1],
1772 Measurement[AXIS1],
1773 Error[AXIS1],
1774 TrackingRate[AXIS1],
1775 clockRate,
1776 Direction == '0' ? "Forward" : "Backward");
1777#ifdef DEBUG_PID
1778 LOGF_DEBUG("Tracking AZ P: %f I: %f D: %f",
1779 m_Controllers[AXIS1]->proportionalTerm(),
1780 m_Controllers[AXIS1]->integralTerm(),
1781 m_Controllers[AXIS1]->derivativeTerm());
1782#endif
1783
1784 SetClockTicksPerMicrostep(AXIS1, clockRate);
1785 if (AxesStatus[AXIS1].FullStop)
1786 {
1787 LOG_DEBUG("Tracking -> AXIS1 restart.");
1790 }
1791 }
1792 }
1793
1794
1795 auto Axis2CustomClockRate = Axis2TrackRateNP[TrackClockRate].getValue();
1796
1797 if (!AxesStatus[AXIS2].FullStop && (
1798 (Axis2CustomClockRate == 0 && ((AxesStatus[AXIS2].SlewingForward && (Error[AXIS2] < -AxisDeadZoneNP[AXIS2].getValue())) ||
1799 (!AxesStatus[AXIS2].SlewingForward && (Error[AXIS2] > AxisDeadZoneNP[AXIS2].getValue())))) ||
1800 (Axis2CustomClockRate > 0 && Axis2TrackRateNP[TrackDirection].getValue() != m_LastCustomDirection[AXIS2])))
1801 {
1802 m_LastCustomDirection[AXIS2] = Axis2TrackRateNP[TrackDirection].getValue();
1803
1804 LOG_DEBUG("Tracking -> AXIS2 direction change.");
1805 LOGF_DEBUG("AXIS2 Setpoint %d Measurement %d Error %d Rate %f",
1806 SetPoint[AXIS2],
1807 Measurement[AXIS2],
1808 Error[AXIS2],
1809 TrackingRate[AXIS2]);
1810 SlowStop(AXIS2);
1811 }
1812 else
1813 {
1814 TrackingRate[AXIS2] = m_Controllers[AXIS2]->calculate(SetPoint[AXIS2], Measurement[AXIS2]);
1815 char Direction = TrackingRate[AXIS2] > 0 ? '0' : '1';
1816 TrackingRate[AXIS2] = std::fabs(TrackingRate[AXIS2]);
1817 if (TrackingRate[AXIS2] != 0)
1818 {
1819 auto clockRate = StepperClockFrequency[AXIS2] / TrackingRate[AXIS2] * (AxisClockNP[AXIS2].getValue() / 100.0);
1820
1821 if (Axis2CustomClockRate > 0)
1822 {
1823 clockRate = Axis2CustomClockRate;
1824 Direction = Axis2TrackRateNP[TrackDirection].getValue() == 0 ? '0' : '1';
1825 }
1826
1827 LOGF_DEBUG("AXIS2 Setpoint %d Measurement %d Error %d Rate %f Freq %f Dir %s",
1828 SetPoint[AXIS2],
1829 Measurement[AXIS2],
1830 Error[AXIS2],
1831 TrackingRate[AXIS2],
1832 clockRate,
1833 Error[AXIS2] > 0 ? "Forward" : "Backward");
1834#ifdef DEBUG_PID
1835 LOGF_DEBUG("Tracking AZ P: %f I: %f D: %f",
1836 m_Controllers[AXIS2]->proportionalTerm(),
1837 m_Controllers[AXIS2]->integralTerm(),
1838 m_Controllers[AXIS2]->derivativeTerm());
1839#endif
1840
1841 SetClockTicksPerMicrostep(AXIS2, clockRate);
1842 if (AxesStatus[AXIS2].FullStop)
1843 {
1844 LOG_DEBUG("Tracking -> AXIS2 restart.");
1847 }
1848 }
1849 }
1850
1851 return true;
1852}
1853
1857bool SkywatcherAPIMount::trackUsingPredictiveRates()
1858{
1859 TelescopeDirectionVector TDV;
1860 TelescopeDirectionVector futureTDV;
1861 TelescopeDirectionVector pastTDV;
1862 INDI::IHorizontalCoordinates targetMountAxisCoordinates { 0, 0 };
1863 INDI::IHorizontalCoordinates pastMountAxisCoordinates { 0, 0 };
1864 INDI::IHorizontalCoordinates futureMountAxisCoordinates { 0, 0 };
1865 // time step for tracking rate estimation in seconds
1866 double timeStep { 5.0 };
1867 // The same in days
1868 double JDoffset { timeStep / (60 * 60 * 24) } ;
1869
1870 // We modify the SkyTrackingTarget for non-sidereal objects (Moon or Sun)
1871 // The Moon and Sun appear to move eastward (increasing RA) relative to the stars
1872 // because their westward motion due to Earth's rotation is slower than the sidereal rate.
1873 if (TrackModeSP[TRACK_LUNAR].getState() == ISS_ON)
1874 {
1875 // TRACKRATE_LUNAR: how many arcsecs/sec the Moon moves westward (apparent motion)
1876 // TRACKRATE_SIDEREAL: how many arcsecs/sec the stars move westward (apparent motion)
1877 // Since the Moon moves slower westward, it effectively moves eastward relative to stars
1878 double dRA = (TRACKRATE_SIDEREAL - TRACKRATE_LUNAR) * m_TrackingRateTimer.elapsed() / 1000.0;
1879 m_SkyTrackingTarget.rightascension += (dRA / 3600.0) / 15.0;
1880 m_TrackingRateTimer.restart();
1881 }
1882 else if (TrackModeSP[TRACK_SOLAR].getState() == ISS_ON)
1883 {
1884 // Similar logic: Sun moves slower westward than stars, so it moves eastward relative to stars
1885 double dRA = (TRACKRATE_SIDEREAL - TRACKRATE_SOLAR) * m_TrackingRateTimer.elapsed() / 1000.0;
1886 m_SkyTrackingTarget.rightascension += (dRA / 3600.0) / 15.0;
1887 m_TrackingRateTimer.restart();
1888 }
1889
1890 // Start by transforming tracking target celestial coordinates to telescope coordinates.
1891 double JDnow {ln_get_julian_from_sys()};
1892 if (TransformCelestialToTelescopeJD(m_SkyTrackingTarget.rightascension, m_SkyTrackingTarget.declination,
1893 JDnow, TDV))
1894 {
1895 // If mount is Alt-Az then that's all we need to do
1896 AltitudeAzimuthFromTelescopeDirectionVector(TDV, targetMountAxisCoordinates);
1897 TransformCelestialToTelescopeJD(m_SkyTrackingTarget.rightascension, m_SkyTrackingTarget.declination,
1898 JDnow + JDoffset, futureTDV);
1899 AltitudeAzimuthFromTelescopeDirectionVector(futureTDV, futureMountAxisCoordinates);
1900 TransformCelestialToTelescopeJD(m_SkyTrackingTarget.rightascension, m_SkyTrackingTarget.declination,
1901 JDnow - JDoffset, pastTDV);
1902 AltitudeAzimuthFromTelescopeDirectionVector(pastTDV, pastMountAxisCoordinates);
1903
1904 }
1905 // If transformation failed.
1906 else
1907 {
1908 INDI::IEquatorialCoordinates EquatorialCoordinates { 0, 0 };
1909 EquatorialCoordinates.rightascension = m_SkyTrackingTarget.rightascension;
1910 EquatorialCoordinates.declination = m_SkyTrackingTarget.declination;
1911 INDI::EquatorialToHorizontal(&EquatorialCoordinates, &m_Location, JDnow, &targetMountAxisCoordinates);
1912 INDI::EquatorialToHorizontal(&EquatorialCoordinates, &m_Location, JDnow + JDoffset, &futureMountAxisCoordinates);
1913 INDI::EquatorialToHorizontal(&EquatorialCoordinates, &m_Location, JDnow - JDoffset, &pastMountAxisCoordinates);
1914 }
1915
1916 double azGuideOffset = 0, altGuideOffset = 0;
1917 getGuidePulses(azGuideOffset, altGuideOffset);
1918
1919 // Now add the guiding offsets, if any.
1920 targetMountAxisCoordinates.azimuth += azGuideOffset;
1921 pastMountAxisCoordinates.azimuth += azGuideOffset;
1922 futureMountAxisCoordinates.azimuth += azGuideOffset;
1923
1924 targetMountAxisCoordinates.altitude += altGuideOffset;
1925 pastMountAxisCoordinates.altitude += altGuideOffset;
1926 futureMountAxisCoordinates.altitude += altGuideOffset;
1927
1928 // Calculate expected tracking rates
1929 double predRate[2] = {0, 0};
1930 // Central difference, error quadratic in timestep
1931 // Rates in deg/s
1932 predRate[AXIS_AZ] = range180(AzimuthToDegrees(futureMountAxisCoordinates.azimuth - pastMountAxisCoordinates.azimuth)) /
1933 timeStep / 2;
1934 predRate[AXIS_ALT] = (futureMountAxisCoordinates.altitude - pastMountAxisCoordinates.altitude) / timeStep / 2;
1935
1936 // Rates arcsec/s
1937 predRate[AXIS_AZ] = 3600 * predRate[AXIS_AZ];
1938 predRate[AXIS_ALT] = 3600 * predRate[AXIS_ALT];
1939
1940 LOGF_DEBUG("Predicted positions (AZ): %9.4f %9.4f (now, future, degs)",
1941 AzimuthToDegrees(targetMountAxisCoordinates.azimuth),
1942 AzimuthToDegrees(futureMountAxisCoordinates.azimuth)) ;
1943 LOGF_DEBUG("Predicted positions (AL): %9.4f %9.4f (now, future, degs)", targetMountAxisCoordinates.altitude,
1944 futureMountAxisCoordinates.altitude);
1945 LOGF_DEBUG("Predicted Rates (AZ, ALT): %9.4f %9.4f (arcsec/s)", predRate[AXIS_AZ], predRate[AXIS_ALT]);
1946
1947 // If we had guiding pulses active, mark them as complete
1948 if (GuideWENP.getState() == IPS_BUSY)
1950 if (GuideNSNP.getState() == IPS_BUSY)
1952
1953 // Next get current alt-az
1954 INDI::IHorizontalCoordinates currentAltAz { 0, 0 };
1955
1956 // Current Azimuth
1957 auto Axis1Steps = CurrentEncoders[AXIS1] - AxisOffsetNP[AZSteps].getValue() - ZeroPositionEncoders[AXIS1];
1958 currentAltAz.azimuth = DegreesToAzimuth(MicrostepsToDegrees(AXIS1, Axis1Steps));
1959 // Current Altitude
1960 auto Axis2Steps = CurrentEncoders[AXIS2] - AxisOffsetNP[ALSteps].getValue() - ZeroPositionEncoders[AXIS2];
1961 currentAltAz.altitude = MicrostepsToDegrees(AXIS2, Axis2Steps);
1962
1963 // Offset between target and current horizontal coordinates in arcsecs
1964 double offsetAngle[2] = {0, 0};
1965 offsetAngle[AXIS_AZ] = range180(targetMountAxisCoordinates.azimuth - currentAltAz.azimuth) * 3600;
1966 offsetAngle[AXIS_ALT] = (targetMountAxisCoordinates.altitude - currentAltAz.altitude) * 3600;
1967
1968 int32_t targetSteps[2] = {0, 0};
1969 int32_t offsetSteps[2] = {0, 0};
1970 double trackRates[2] = {0, 0};
1971
1972 // Convert offsets from arcsecs to steps
1973 offsetSteps[AXIS_AZ] = offsetAngle[AXIS_AZ] * AxisOneEncoderValuesN[MICROSTEPS_PER_ARCSEC].value;
1974 offsetSteps[AXIS_ALT] = offsetAngle[AXIS_ALT] * AxisTwoEncoderValuesN[MICROSTEPS_PER_ARCSEC].value;
1975
1977 {
1978 m_OffsetSwitchSettle[AXIS_AZ] = 0;
1979 m_LastOffset[AXIS_AZ] = offsetSteps[AXIS_AZ];
1980 targetSteps[AXIS_AZ] = DegreesToMicrosteps(AXIS1, AzimuthToDegrees(targetMountAxisCoordinates.azimuth));
1981 // Track rate: predicted + PID controlled correction based on tracking error: offsetSteps
1982 trackRates[AXIS_AZ] = predRate[AXIS_AZ] + m_Controllers[AXIS_AZ]->calculate(0, -offsetAngle[AXIS_AZ]);
1983 //
1984 // make sure we never change direction of the trackRate - reduce to predRate * MIN_TRACK_RATE_FACTOR in same direction
1985 // since tracking direction change can lead to poor tracking
1986 //
1987 double minTrackRate = predRate[AXIS_AZ] * MIN_TRACK_RATE_FACTOR;
1988 if(trackRates[AXIS_AZ] * predRate[AXIS_AZ] < 0 || std::abs(trackRates[AXIS_AZ]) < std::abs(minTrackRate))
1989 trackRates[AXIS_AZ] = minTrackRate;
1990
1991 LOGF_DEBUG("Tracking AZ Now: %8.f Target: %8d Offset: %8d Rate: %8.2f", Axis1Steps, targetSteps[AXIS_AZ],
1992 offsetSteps[AXIS_AZ], trackRates[AXIS_AZ]);
1993#ifdef DEBUG_PID
1994 LOGF_DEBUG("Tracking AZ P: %8.1f I: %8.1f D: %8.1f O: %8.1f",
1995 m_Controllers[AXIS_AZ]->proportionalTerm(),
1996 m_Controllers[AXIS_AZ]->integralTerm(),
1997 m_Controllers[AXIS_AZ]->derivativeTerm(),
1998 trackRates[AXIS_AZ] - predRate[AXIS_AZ]);
1999#endif
2000
2001 // Set the tracking rate
2002 trackByRate(AXIS1, trackRates[AXIS_AZ]);
2003 }
2004
2006 {
2007 m_OffsetSwitchSettle[AXIS_ALT] = 0;
2008 m_LastOffset[AXIS_ALT] = offsetAngle[AXIS_ALT];
2009 targetSteps[AXIS_ALT] = DegreesToMicrosteps(AXIS2, targetMountAxisCoordinates.altitude);
2010 // Track rate: predicted + PID controlled correction based on tracking error: offsetSteps
2011 trackRates[AXIS_ALT] = predRate[AXIS_ALT] + m_Controllers[AXIS_ALT]->calculate(0, -offsetAngle[AXIS_ALT]);
2012
2013 //
2014 // make sure we never change direction of the trackRate - reduce to predRate * MIN_TRACK_RATE_FACTOR in same direction
2015 // since tracking direction change can lead to poor tracking
2016 //
2017 double minTrackRate = predRate[AXIS_ALT] * MIN_TRACK_RATE_FACTOR;
2018 if(trackRates[AXIS_ALT] * predRate[AXIS_ALT] < 0 || std::abs(trackRates[AXIS_ALT]) < std::abs(minTrackRate))
2019 trackRates[AXIS_ALT] = minTrackRate;
2020
2021 LOGF_DEBUG("Tracking AL Now: %8.f Target: %8d Offset: %8d Rate: %8.2f", Axis2Steps,
2022 targetSteps[AXIS_ALT],
2023 offsetSteps[AXIS_ALT], trackRates[AXIS_ALT]);
2024#ifdef DEBUG_PID
2025 LOGF_DEBUG("Tracking AL P: %8.1f I: %8.1f D: %8.1f O: %8.1f",
2026 m_Controllers[AXIS_ALT]->proportionalTerm(),
2027 m_Controllers[AXIS_ALT]->integralTerm(),
2028 m_Controllers[AXIS_ALT]->derivativeTerm(),
2029 trackRates[AXIS_ALT] - predRate[AXIS_ALT]);
2030#endif
2031 trackByRate(AXIS2, trackRates[AXIS_ALT]);
2032 }
2033
2034 return true;
2035}
2036
2040double SkywatcherAPIMount::AzimuthToDegrees(double degree)
2041{
2042 if (isNorthHemisphere())
2043 return range360(degree);
2044 else
2045 return range360(degree + 180);
2046}
2047
2051double SkywatcherAPIMount::DegreesToAzimuth(double degree)
2052{
2053 if (isNorthHemisphere())
2054 return range360(degree);
2055 else
2056 return range360(degree + 180);
2057}
2058
2059void SkywatcherAPIMount::getGuidePulses(double &az, double &alt)
2060{
2061 double DeltaAz = 0, DeltaAlt = 0;
2062
2063 for (auto Iter = GuidingPulses.begin(); Iter != GuidingPulses.end(); )
2064 {
2065 // We treat the guide calibration specially
2066 if (Iter->OriginalDuration == 1000)
2067 {
2068 DeltaAlt += Iter->DeltaAlt;
2069 DeltaAz += Iter->DeltaAz;
2070 }
2071 else
2072 {
2073 DeltaAlt += Iter->DeltaAlt / 2;
2074 DeltaAz += Iter->DeltaAz / 2;
2075 }
2076 Iter->Duration -= getCurrentPollingPeriod();
2077
2078 if (Iter->Duration < static_cast<int>(getCurrentPollingPeriod()))
2079 {
2080 Iter = GuidingPulses.erase(Iter);
2081 if (Iter == GuidingPulses.end())
2082 {
2083 break;
2084 }
2085 continue;
2086 }
2087 ++Iter;
2088 }
2089
2090 az = DeltaAlt;
2091 alt = DeltaAz;
2092}
void ProcessAlignmentNumberProperties(Telescope *pTelescope, const char *name, double values[], char *names[], int n)
Call this function from within the ISNewNumber processing path. The function will handle any alignmen...
void ProcessAlignmentSwitchProperties(Telescope *pTelescope, const char *name, ISState *states, char *names[], int n)
Call this function from within the ISNewSwitch processing path. The function will handle any alignmen...
void InitAlignmentProperties(Telescope *pTelescope)
Initialize alignment subsystem properties. It is recommended to call this function within initPropert...
void ProcessAlignmentBLOBProperties(Telescope *pTelescope, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Call this function from within the ISNewBlob processing path. The function will handle any alignment ...
void SaveAlignmentConfigProperties(FILE *fp)
Call this function to save persistent alignment related properties. This function should be called fr...
void ProcessAlignmentTextProperties(Telescope *pTelescope, const char *name, char *texts[], char *names[], int n)
Call this function from within the ISNewText processing path. The function will handle any alignment ...
bool CheckForDuplicateSyncPoint(const AlignmentDatabaseEntry &CandidateEntry, double Tolerance=0.1) const
Check if a entry already exists in the database.
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
void UpdateLocation(double latitude, double longitude, double elevation)
Call this function from within the updateLocation processing path.
void UpdateSize()
Call this function when the number of entries in the database changes.
bool TransformTelescopeToCelestialJD(const TelescopeDirectionVector &ApparentTelescopeDirectionVector, double &RightAscension, double &Declination, double JulianDate)
TransformTelescopeToCelestialJD Transforms Mount Coords to Celestial (Sky) Coordinates.
bool TransformCelestialToTelescopeJD(double RightAscension, double Declination, double JulianDate, TelescopeDirectionVector &ApparentTelescopeDirectionVector)
TransformCelestialToTelescopeJD Transforms Celestial (Sky) Coords to Mount Coordinates.
bool Initialise(InMemoryDatabase *pInMemoryDatabase)
Initialise or re-initialise the math plugin. Re-reading the in memory database as necessary.
MountAlignment_t GetApproximateMountAlignment()
Get the approximate alignment of the mount.
void SetApproximateMountAlignmentFromMountType(MountType_t Type)
Call this function to set the ApproximateMountAlignment property of the current Math Plugin....
const TelescopeDirectionVector TelescopeDirectionVectorFromSphericalCoordinate(const double AzimuthAngle, AzimuthAngleDirection_t AzimuthAngleDirection, const double PolarAngle, PolarAngleDirection_t PolarAngleDirection)
Calculates a telescope direction vector from the supplied spherical coordinate information.
void SphericalCoordinateFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, double &AzimuthAngle, AzimuthAngleDirection_t AzimuthAngleDirection, double &PolarAngle, PolarAngleDirection_t PolarAngleDirection)
Calculates a spherical coordinate from the supplied telescope direction vector.
const TelescopeDirectionVector TelescopeDirectionVectorFromAltitudeAzimuth(INDI::IHorizontalCoordinates HorizontalCoordinates)
Calculates a normalised direction vector from the supplied altitude and azimuth.
void AltitudeAzimuthFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, INDI::IHorizontalCoordinates &HorizontalCoordinates)
Calculates an altitude and azimuth from the supplied normalised direction vector and declination.
bool isConnected() const
INDI::PropertySwitch getSwitch(const char *name) const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void addConfigurationControl()
Add Configuration control to the driver.
void setActiveConnection(Connection::Interface *existingConnection)
setActiveConnection Switch the active connection to the passed connection plugin
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
uint32_t getDriverInterface() const
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
Connection::Interface * getActiveConnection()
void addDebugControl()
Add Debug control to the driver.
int64_t restart()
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
INDI::PropertyNumber GuideNSNP
virtual void GuideComplete(INDI_EQ_AXIS axis)
Call GuideComplete once the guiding pulse is complete.
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
INDI::PropertyNumber GuideWENP
void initProperties(const char *groupName)
Initialize guider properties. It is recommended to call this function within initProperties() of your...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
void setState(IPState state)
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
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.
virtual void TimerHit() override
Called when setTimer() time is up.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
double GetAxis1Park() const
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
double GetAxis2Park() const
bool isParked()
isParked is mount currently parked?
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
Connection::Serial * serialConnection
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
Connection::TCP * tcpConnection
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
IGeographicCoordinates m_Location
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
Definition pid.h:29
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual void TimerHit() override
Called when setTimer() time is up.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual const char * getDefaultName() override
Misc.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool Handshake() override
Communication.
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Park() override
Parking.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Motion.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual IPState GuideNorth(uint32_t ms) override
Guiding.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
double MicrostepsToRadians(AXISID Axis, long Microsteps)
Convert microsteps to angle in radians.
void TurnRAEncoder(bool on)
void SetSerialPort(int port)
Set the serail port to be usb for mount communication.
static constexpr double SIDEREALRATE
double MicrostepsToDegrees(AXISID Axis, long Microsteps)
Convert microsteps to angle in degrees.
unsigned long MountCode
void SlewTo(AXISID Axis, long OffsetInMicrosteps, bool verbose=true)
Slew to the given offset and stop.
long ZeroPositionEncoders[2]
Zero position encoder values (microsteps).
unsigned int DBG_SCOPE
long CurrentEncoders[2]
Current encoder values (microsteps).
bool GetStatus(AXISID Axis)
unsigned long MCVersion
long RadiansToMicrosteps(AXISID Axis, double AngleInRadians)
Convert angle in radians to microsteps.
bool SetEncoder(AXISID Axis, long Microsteps)
Set axis encoder to the specified value.
void TurnDEEncoder(bool on)
long PolarisPositionEncoders[2]
Polaris position (initial) encoder values (microsteps).
bool GetEncoder(AXISID Axis)
Set the CurrentEncoders status variable to the current encoder value in microsteps for the specified ...
long MicrostepsPerWormRevolution[2]
long HighSpeedRatio[2]
double MicrostepsPerDegree[2]
long DegreesToMicrosteps(AXISID Axis, double AngleInDegrees)
Convert angle in degrees to microsteps.
bool SlowStop(AXISID Axis)
Bring the axis to slow stop in the distance specified by SetSlewModeDeccelerationRampLength.
bool StartAxisMotion(AXISID Axis)
Start the axis slewing in the previously selected mode.
bool InitMount()
Initialize the communication to the mount.
void Slew(AXISID Axis, double SpeedInRadiansPerSecond, bool IgnoreSilentMode=true)
Start the axis slewing at the given rate.
bool SetAxisMotionMode(AXISID Axis, char Func, char Direction)
Set the motion mode per the specified axis.
long MicrostepsPerRevolution[2]
bool IsInMotion(AXISID Axis)
Check if an axis is moving.
long StepperClockFrequency[2]
bool toggleSnapPort(bool enabled)
Toggle the snap port on or off.
bool SetClockTicksPerMicrostep(AXISID Axis, long ClockTicksPerMicrostep)
Set the PIC internal divider variable which determines how many clock interrupts have to occur betwee...
INDI::Telescope * pChildTelescope
static const char * mountTypeToString(uint8_t type)
AXISSTATUS AxesStatus[2]
const char * GUIDE_TAB
GUIDE_TAB Where all the properties for guiding are located.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MovementWESP
INDI::PropertySwitch CoordSP
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_NOFMANY
Definition indiapi.h:173
@ ISR_ATMOST1
Definition indiapi.h:172
@ AXIS_DE
@ AXIS_RA
@ AXIS_AZ
@ AXIS_ALT
INDI_DIR_WE
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_NORTH
void tty_set_generic_udp_format(int enabled)
Definition indicom.c:364
void tty_set_auto_reset_udp_session(int flag)
automatically reset UDP session on write
Definition indicom.c:354
double range180(double r)
range180 Limits an angle to be between -180 to +180 degrees
Definition indicom.c:1331
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition indicom.c:1321
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:130
Implementations for common driver routines.
const char * Direction[]
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:509
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition indidevapi.c:275
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
ISwitch * IUFindSwitch(const ISwitchVectorProperty *svp, const char *name)
Find an ISwitch member in a vector switch property.
Definition indidevapi.c:285
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
Definition indidevapi.c:416
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
INDI::GuiderInterface GI
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
Definition indilogger.h:56
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_INFO(txt)
Definition indilogger.h:74
#define DEBUGF(priority, msg,...)
Definition indilogger.h:57
#define TRACKRATE_SOLAR
Definition indimacros.h:45
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
#define TRACKRATE_LUNAR
Definition indimacros.h:48
#define getDeviceName
Namespace to encapsulate the INDI Alignment Subsystem classes. For more information see "INDI Alignme...
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
void HorizontalToEquatorial(IHorizontalCoordinates *object, IGeographicCoordinates *observer, double JD, IEquatorialCoordinates *position)
HorizontalToEquatorial Calculate Equatorial EOD Coordinates from horizontal coordinates.
Definition libastro.cpp:161
#define SLEWMODES
Definition paramount.cpp:68
Entry in the in memory alignment database.
Definition Common.h:152
double RightAscension
Right ascension in decimal hours. N.B. libnova works in decimal degrees so conversion is always neede...
Definition Common.h:190
TelescopeDirectionVector TelescopeDirection
Normalised vector giving telescope pointing direction. This is referred to elsewhere as the "apparent...
Definition Common.h:197
double Declination
Declination in decimal degrees.
Definition Common.h:193
int PrivateDataSize
This size in bytes of any private data.
Definition Common.h:203
Holds a normalised direction vector (direction cosines).
Definition Common.h:69
void RotateAroundY(double Angle)
Rotate the reference frame around the Y axis. This has the affect of rotating the vector itself in th...
Definition Common.cpp:18
One switch descriptor.