Instrument Neutral Distributed Interface INDI 2.2.5
astrotrac.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 Driver for using TheSky6 Pro Scripted operations for mounts via the TCP server.
5 While this technically can operate any mount connected to the TheSky6 Pro, it is
6 intended for AstroTrac mounts control.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License version 2 as published by the Free Software Foundation.
11 .
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16 .
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*******************************************************************************/
22
23#include "astrotrac.h"
24
25#include "indicom.h"
26#include "inditimer.h"
28#include <libnova/sidereal_time.h>
29#include <libnova/transform.h>
30
31#include <cmath>
32#include <cstring>
33#include <memory>
34#include <regex>
35#include <array>
36#include <termios.h>
37
38std::unique_ptr<AstroTrac> AstroTrac_mount(new AstroTrac());
39const std::array<uint32_t, AstroTrac::SLEW_MODES> AstroTrac::SLEW_SPEEDS = {{1, 2, 4, 8, 32, 64, 128, 600, 700, 800}};
40
41using namespace INDI::AlignmentSubsystem;
42
54
56{
57 return "AstroTrac";
58}
59
64{
66
67 // Track Modes
68 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
69 AddTrackMode("TRACK_SOLAR", "Solar");
70 AddTrackMode("TRACK_LUNAR", "Lunar");
71 AddTrackMode("TRACK_CUSTOM", "Custom");
72
73 // Slew Speeds
74 for (uint8_t i = 0; i < SLEW_MODES; i++)
75 {
76 SlewRateSP[i].setLabel(std::to_string(SLEW_SPEEDS[i]) + "x");
77 SlewRateSP[i].setAux((void *)&SLEW_SPEEDS[i]);
78 }
79 SlewRateSP[5].setState(ISS_ON);
80
81 // Mount Type: GEM, or Fork for the single arm setup (no meridian flip).
82 if (!MountTypeSP.load())
83 {
84 // Older configurations stored it in MOUNT_TYPE (0 = GEM, 1 = Single Arm).
85 int legacyType = 0;
86 if (IUGetConfigOnSwitchIndex(getDeviceName(), "MOUNT_TYPE", &legacyType) == 0 && legacyType == 1)
88 }
89
90 // Acceleration
91 AccelerationNP[AXIS_RA].fill("AXIS_RA", "RA arcsec/sec^2", "%.2f", 0, 3600, 100, 0);
92 AccelerationNP[AXIS_DE].fill("AXIS_DE", "DE arcsec/sec^2", "%.2f", 0, 3600, 100, 0);
93 AccelerationNP.fill(getDeviceName(), "MOUNT_ACCELERATION", "Acceleration", MOTION_TAB, IP_RW, 60, IPS_IDLE);
94
95 // Encoders
96 EncoderNP[AXIS_RA].fill("AXIS_RA", "Hour Angle", "%.2f", -3600, 3600, 100, 0);
97 EncoderNP[AXIS_DE].fill("AXIS_DE", "Declination", "%.2f", -3600, 3600, 100, 0);
98 EncoderNP.fill(getDeviceName(), "MOUNT_ENCODERS", "Encoders", MOTION_TAB, IP_RW, 60, IPS_IDLE);
99
100 // How fast to guide compared to sidereal rate.
101 // The default rate is 0.1x sidereal, which is apparently the best for the mount accoring to the author of X2 plugin.
102 // Users may need to calibrate guiding for longer to see movement
103 GuideRateNP[AXIS_RA].fill("GUIDE_RATE_WE", "W/E Rate", "%g", 0, 1, 0.1, 0.1);
104 GuideRateNP[AXIS_DE].fill("GUIDE_RATE_NS", "N/S Rate", "%g", 0, 1, 0.1, 0.1);
105 GuideRateNP.fill(getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RW, 0, IPS_IDLE);
106
108
110
112
113 tcpConnection->setDefaultHost("192.168.1.1");
114 tcpConnection->setDefaultPort(23);
115
117
119
121 // set mount type to alignment subsystem
123 // Init Math plugin
124 Initialise(this);
125
126 // Force the alignment system to always be on
127 getSwitch("ALIGNMENT_SUBSYSTEM_ACTIVE")[0].setState(ISS_ON);
128
129 return true;
130}
131
136{
138
139 if (isConnected())
140 {
141 getAcceleration(AXIS_RA);
142 getAcceleration(AXIS_DE);
143 getVelocity(AXIS_RA);
144 getVelocity(AXIS_DE);
145
146 defineProperty(FirmwareTP);
147 defineProperty(AccelerationNP);
148 defineProperty(EncoderNP);
149 defineProperty(GuideRateNP);
150
151 // Initial AZ/AL parking position.
152 if (InitPark())
153 {
154 // If loading parking data is successful, we just set the default parking values.
157 }
158 else
159 {
160 // Otherwise, we set all parking data to default in case no parking data is found.
161 SetAxis1Park(0);
162 SetAxis2Park(0);
165 }
166 }
167 else
168 {
169 deleteProperty(FirmwareTP);
170 deleteProperty(AccelerationNP);
171 deleteProperty(EncoderNP);
172 deleteProperty(GuideRateNP);
173 }
174
176
177
178 return true;
179}
180
185{
186 return getVersion();
187}
188
192bool AstroTrac::getVersion()
193{
194 char response[DRIVER_LEN] = {0};
195 if (sendCommand("<1zv?>", response))
196 {
197 FirmwareTP[0].setText(response + 4, 4);
198 return true;
199 }
200
201 return false;
202}
203
207bool AstroTrac::getAcceleration(INDI_EQ_AXIS axis)
208{
209 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
210 snprintf(command, DRIVER_LEN, "<%da?>", axis + 1);
211 if (sendCommand(command, response))
212 {
213 try
214 {
215 std::string acceleration = std::regex_replace(
216 response,
217 std::regex("<.a(\\d+)>"),
218 std::string("$1"));
219
220 AccelerationNP[axis].setValue(std::stoi(acceleration));
221 return true;
222 }
223 catch (...)
224 {
225 LOGF_DEBUG("Failed to parse acceleration (%s)", response);
226 }
227 }
228
229 return false;
230}
231
235bool AstroTrac::setAcceleration(INDI_EQ_AXIS axis, uint32_t a)
236{
237 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
238
239 snprintf(command, DRIVER_LEN, "<%da%u>", axis + 1, a);
240 if (sendCommand(command, response))
241 return response[3] == '#';
242
243 return false;
244}
245
249bool AstroTrac::getVelocity(INDI_EQ_AXIS axis, double &value)
250{
251 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
252 snprintf(command, DRIVER_LEN, "<%dv?>", axis + 1);
253 if (sendCommand(command, response))
254 {
255 try
256 {
257 std::string velocity = std::regex_replace(
258 response,
259 std::regex("<.v([+-]?[0-9]+\\.[0-9]+?)>"),
260 std::string("$1"));
261
262 value = std::stod(velocity) * (m_Location.latitude >= 0 ? 1 : -1);
263 return true;
264 }
265 catch (...)
266 {
267 LOGF_DEBUG("Failed to parse velocity (%s)", response);
268 }
269 }
270
271 value = 0.0;
272 return false;
273}
274
278bool AstroTrac::getVelocity(INDI_EQ_AXIS axis)
279{
280 double velocity(0);
281 if (getVelocity(axis, velocity))
282 {
283 TrackRateNP[axis].setValue(velocity);
284 return true;
285 }
286 return false;
287}
288
292bool AstroTrac::setVelocity(INDI_EQ_AXIS axis, double value)
293{
294 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
295
296 // Reverse value depending on hemisphere
297 snprintf(command, DRIVER_LEN, "<%dve%f>", axis + 1, value * (m_Location.latitude >= 0 ? 1 : -1));
298 if (sendCommand(command, response))
299 return response[4] == '#';
300
301 return false;
302}
303
307bool AstroTrac::stopMotion(INDI_EQ_AXIS axis)
308{
309 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
310
311 snprintf(command, DRIVER_LEN, "<%dx>", axis + 1);
312 if (sendCommand(command, response))
313 return response[3] == '#';
314
315 return false;
316}
317
321bool AstroTrac::isSlewComplete()
322{
323 char HAResponse[DRIVER_LEN] = {0}, DEResponse[DRIVER_LEN] = {0};
324 if (sendCommand("<1t?>", HAResponse) && sendCommand("<2t?>", DEResponse))
325 {
326 return (HAResponse[3] == '0' && DEResponse[3] == '0');
327 }
328
329 return false;
330}
331
335bool AstroTrac::syncEncoder(INDI_EQ_AXIS axis, double value)
336{
337 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
338
339 snprintf(command, DRIVER_LEN, "<%dy%f>", axis + 1, value);
340 if (sendCommand(command, response))
341 return response[3] == '#';
342
343 return false;
344}
345
349bool AstroTrac::slewEncoder(INDI_EQ_AXIS axis, double value)
350{
351 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
352
353 snprintf(command, DRIVER_LEN, "<%dp%f>", axis + 1, value);
354 if (sendCommand(command, response))
355 return response[3] == '#';
356
357 return false;
358}
359
366bool AstroTrac::getEncoderPosition(INDI_EQ_AXIS axis)
367{
368 char command[DRIVER_LEN] = {0}, response[DRIVER_LEN] = {0};
369 snprintf(command, DRIVER_LEN, "<%dp?>", axis + 1);
370 if (sendCommand(command, response))
371 {
372 try
373 {
374 char regex_str[64] = {0};
375 snprintf(regex_str, 64, "<%dp([+-]?[0-9]+\\.[0-9]+?)>", axis + 1);
376 std::string position = std::regex_replace(
377 response,
378 std::regex(regex_str),
379 std::string("$1"));
380
381 EncoderNP[axis].setValue(std::stod(position));
382 return true;
383 }
384 catch (...)
385 {
386 try
387 {
388 // Check if the response for the other axis
389 INDI_EQ_AXIS other = (axis == AXIS_RA) ? AXIS_DE : AXIS_RA;
390 char regex_str[64] = {0};
391 snprintf(regex_str, 64, "<%dp([+-]?[0-9]+\\.[0-9]+?)>", other + 1);
392 std::string position = std::regex_replace(
393 response,
394 std::regex(regex_str),
395 std::string("$1"));
396
397 EncoderNP[other].setValue(std::stod(position));
398 return true;
399 }
400 catch (...)
401 {
402 LOGF_DEBUG("Failed to parse position (%s)", response);
403 }
404 }
405 }
406
407 return false;
408}
409
417void AstroTrac::getRADEFromEncoders(double haEncoder, double deEncoder, double &ra, double &de, TelescopePierSide &pierSide)
418{
419 static const double jitter = 0.0005;
420 double ha = 0;
421
422 // Take care of jitter
423 if (haEncoder > jitter * -1 && haEncoder < jitter)
424 haEncoder = 0;
425 if (deEncoder > jitter * -1 && deEncoder < jitter)
426 deEncoder = 0;
427
428 // Northern Hemisphere
429 if (LocationNP[LOCATION_LATITUDE].getValue() >= 0)
430 {
431 // "Normal" Pointing State (West, looking East)
432 if (getMountType() == MOUNT_EQ_FORK || deEncoder >= 0)
433 {
434 de = std::min(90 - deEncoder, 90.0);
435 ha = -6.0 + (haEncoder / 360.0) * 24.0;
436 pierSide = PIER_WEST;
437 }
438 // "Reversed" Pointing State (East, looking West)
439 else
440 {
441 de = 90 + deEncoder;
442 ha = 6.0 + (haEncoder / 360.0) * 24.0;
443 pierSide = PIER_EAST;
444 }
445 }
446 // Southern Hemisphere
447 else
448 {
449 // "Normal" Pointing State (West, looking East)
450 if (getMountType() == MOUNT_EQ_FORK || deEncoder <= 0)
451 {
452 de = std::max(-90 - deEncoder, -90.0);
453 ha = -6.0 - (haEncoder / 360.0) * 24.0;
454 pierSide = PIER_WEST;
455 }
456 // "Reversed" Pointing State (East, looking West)
457 else
458 {
459 de = -90 + deEncoder;
460 ha = 6.0 - (haEncoder / 360.0) * 24.0;
461 pierSide = PIER_EAST;
462 }
463 }
464
465 double lst = get_local_sidereal_time(LocationNP[LOCATION_LONGITUDE].getValue());
466 ra = range24(lst - ha);
467
468 char RAStr[32] = {0}, DecStr[32] = {0};
469 fs_sexa(RAStr, ra, 2, 3600);
470 fs_sexa(DecStr, de, 2, 3600);
471 LOGF_DEBUG("Encoders HA: %.4f DE: %.4f Processed: HA: %.4f DE: %.4f (%s) LST: %.4f RA: %.4f (%s)",
472 haEncoder, deEncoder, ha, de, DecStr, lst, ra, RAStr);
473}
474
481void AstroTrac::getEncodersFromRADE(double ra, double de, double &haEncoder, double &deEncoder)
482{
483 double lst = get_local_sidereal_time(LocationNP[LOCATION_LONGITUDE].getValue());
484 double dHA = rangeHA(lst - ra);
485 // Northern Hemisphere
486 if (LocationNP[LOCATION_LATITUDE].getValue() >= 0)
487 {
488 // "Normal" Pointing State (East, looking West)
489 if (getMountType() == MOUNT_EQ_FORK || dHA <= 0)
490 {
491 deEncoder = -(de - 90.0);
492 haEncoder = (dHA + 6.0) * 360.0 / 24.0;
493 }
494 // "Reversed" Pointing State (West, looking East)
495 else
496 {
497 deEncoder = de - 90.0;
498 haEncoder = (dHA - 6.0) * 360.0 / 24.0;
499 }
500 }
501 else
502 {
503 // "Normal" Pointing State (East, looking West)
504 if (getMountType() == MOUNT_EQ_FORK || dHA <= 0)
505 {
506 deEncoder = -(de + 90.0);
507 haEncoder = -(dHA + 6.0) * 360.0 / 24.0;
508 }
509 // "Reversed" Pointing State (West, looking East)
510 else
511 {
512 deEncoder = (de + 90.0);
513 haEncoder = -(dHA - 6.0) * 360 / 24.0;
514 }
515 }
516}
517
521bool AstroTrac::Sync(double ra, double dec)
522{
523 AlignmentDatabaseEntry NewEntry;
524 NewEntry.ObservationJulianDate = ln_get_julian_from_sys();
525 // Actual Celestial Coordinates
526 NewEntry.RightAscension = ra;
527 NewEntry.Declination = dec;
528 // Apparent Telescope Coordinates
529 NewEntry.TelescopeDirection = TelescopeDirectionVectorFromEquatorialCoordinates(m_MountInternalCoordinates);
530 NewEntry.PrivateDataSize = 0;
531
532 if (!CheckForDuplicateSyncPoint(NewEntry, 0.001))
533 {
534 GetAlignmentDatabase().push_back(NewEntry);
535
536 // Tell the client about size change
537 UpdateSize();
538
539 // Tell the math plugin to reinitiali
540 Initialise(this);
541
542 char RAStr[32], DecStr[32];
543 fs_sexa(RAStr, ra, 2, 3600);
544 fs_sexa(DecStr, dec, 2, 3600);
545 LOGF_INFO("Syncing to JNOW RA %s - DEC %s", RAStr, DecStr);
546
547 return true;
548 }
549
550 LOGF_DEBUG("Sync - duplicate entry RA: %lf(%lf) DEC: %lf", ra * 360.0 / 24.0, ra, dec);
551 return false;
552}
553
557bool AstroTrac::Goto(double ra, double dec)
558{
559 double haEncoder = 0, deEncoder = 0;
560 INDI::IEquatorialCoordinates telescopeCoordinates;
561 if (getTelescopeFromSkyCoordinates(ra, dec, telescopeCoordinates))
562 {
563 char mountRAString[32] = {0}, mountDEString[32] = {0}, skyRAString[32] = {0}, skyDEString[32] = {0};
564 fs_sexa(mountRAString, telescopeCoordinates.rightascension, 2, 3600);
565 fs_sexa(mountDEString, telescopeCoordinates.declination, 2, 3600);
566 fs_sexa(skyRAString, ra, 2, 3600);
567 fs_sexa(skyDEString, dec, 2, 3600);
568
569 LOGF_DEBUG("GOTO Sky RA: %s DE: %s ---> Mount RA: %s DE: %s", skyRAString, skyDEString, mountRAString, mountDEString);
570
571 getEncodersFromRADE(telescopeCoordinates.rightascension, telescopeCoordinates.declination, haEncoder, deEncoder);
572
573 // Account for acceletaion, max speed, and deceleration by the time we get there.
574 // Get time in seconds
575 double tHA = calculateSlewTime(haEncoder - EncoderNP[AXIS_RA].getValue());
576 // Adjust for hemisphere. Convert time to delta degrees
577 tHA = tHA * (m_Location.latitude >= 0 ? 1 : -1) * TRACKRATE_SIDEREAL / 3600;
578
579 LOGF_DEBUG("GOTO Encoders HA: %.4f (%.4f + %.4f) DE: %.4f", haEncoder + tHA, haEncoder, tHA, deEncoder);
580
581 // Now go to each encoder
582 bool rc1 = slewEncoder(AXIS_RA, haEncoder + tHA);
583 bool rc2 = slewEncoder(AXIS_DE, deEncoder);
584
585 if (rc1 && rc2)
586 {
588
589 char RAStr[32], DecStr[32];
590 fs_sexa(RAStr, ra, 2, 3600);
591 fs_sexa(DecStr, dec, 2, 3600);
592 LOGF_INFO("Slewing to JNOW RA %s - DEC %s", RAStr, DecStr);
593 return true;
594 }
595 }
596
597 return false;
598}
599
605double AstroTrac::calculateSlewTime(double distance)
606{
607 // Firstly throw away sign of distance - don't care about direction - and convert to arcsec
608 distance = fabs(distance) * 3600.0;
609
610 // Now estimate how far mount travels during acceleration and deceleration period
611 double accelerate_decelerate = MAX_SLEW_VELOCITY * MAX_SLEW_VELOCITY / AccelerationNP[AXIS_RA].getValue();
612
613 // If distance less than this, then calculate using acceleration forumlae:
614 if (distance < accelerate_decelerate)
615 {
616 return (2 * sqrt(distance / AccelerationNP[AXIS_RA].getValue()));
617 }
618 else
619 {
620 // Time is equal to twice the time required to accelerate or decelerate, plus the remaining distance at max slew speed
621 return (2.0 * MAX_SLEW_VELOCITY / AccelerationNP[AXIS_RA].getValue() + (distance - accelerate_decelerate) /
622 MAX_SLEW_VELOCITY);
623 }
624}
625
630{
632 double ra = 0, de = 0, skyRA = 0, skyDE = 0;
634
635 if (isSimulation())
636 simulateMount();
637
638 double lastHAEncoder = EncoderNP[AXIS_RA].getValue();
639 double lastDEEncoder = EncoderNP[AXIS_DE].getValue();
640 if (getEncoderPosition(AXIS_RA) && getEncoderPosition(AXIS_DE))
641 {
642 getRADEFromEncoders(EncoderNP[AXIS_RA].getValue(), EncoderNP[AXIS_DE].getValue(), ra, de, side);
643 // Send to client if changed.
644 if (std::fabs(lastHAEncoder - EncoderNP[AXIS_RA].getValue()) > 0
645 || std::fabs(lastDEEncoder - EncoderNP[AXIS_DE].getValue()) > 0)
646 {
647 EncoderNP.apply();
648 }
649 }
650 else
651 return false;
652
654 {
655 if (isSlewComplete())
656 {
658 {
659 LOG_INFO("Slew complete, tracking...");
661 SetTrackEnabled(true);
662 }
663 // Parking
664 else
665 {
666 SetTrackEnabled(false);
667 SetParked(true);
668 }
669 }
670 }
671
672 m_MountInternalCoordinates.rightascension = ra;
673 m_MountInternalCoordinates.declination = de;
674 TDV = TelescopeDirectionVectorFromEquatorialCoordinates(m_MountInternalCoordinates);
675
676 if (TransformTelescopeToCelestialJD(TDV, skyRA, skyDE, ln_get_julian_from_sys()))
677 {
678 // double lst = get_local_sidereal_time(LocationNP[LOCATION_LONGITUDE].getValue());
679 // double dHA = rangeHA(lst - skyRA);
680 setPierSide(side);
681
682 char mountRAString[32] = {0}, mountDEString[32] = {0}, skyRAString[32] = {0}, skyDEString[32] = {0};
683 fs_sexa(mountRAString, ra, 2, 3600);
684 fs_sexa(mountDEString, de, 2, 3600);
685 fs_sexa(skyRAString, skyRA, 2, 3600);
686 fs_sexa(skyDEString, skyDE, 2, 3600);
687
688 LOGF_DEBUG("Mount RA: %s DE: %s ---> Sky RA: %s DE: %s", mountRAString, mountDEString, skyRAString, skyDEString);
689
690 NewRaDec(skyRA, skyDE);
691 return true;
692 }
693
694 LOG_ERROR("TransformTelescopeToCelestial failed in ReadScopeStatus");
695 return false;
696}
697
701bool AstroTrac::getTelescopeFromSkyCoordinates(double ra, double de, INDI::IEquatorialCoordinates &telescopeCoordinates)
702{
704 if (TransformCelestialToTelescopeJD(ra, de, ln_get_julian_from_sys(), TDV))
705 {
706 EquatorialCoordinatesFromTelescopeDirectionVector(TDV, telescopeCoordinates);
707 LOGF_DEBUG("TransformCelestialToTelescope: RA=%lf DE=%lf, TDV (x :%lf, y: %lf, z: %lf), local hour RA %lf DEC %lf",
708 ra, de, TDV.x, TDV.y, TDV.z, telescopeCoordinates.rightascension, telescopeCoordinates.declination);
709 return true;
710 }
711
712 return false;
713}
714
719{
720 if (slewEncoder(AXIS_RA, GetAxis1Park()) && slewEncoder(AXIS_DE, GetAxis2Park()))
721 {
723 LOG_INFO("Parking is in progress...");
724 return true;
725 }
726
727 return false;
728}
729
734{
735 SetParked(false);
736 return true;
737}
738
742bool AstroTrac::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
743{
744 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
745 {
746 // Process alignment properties
747 ProcessAlignmentTextProperties(this, name, texts, names, n);
748 }
749
750 return INDI::Telescope::ISNewText(dev, name, texts, names, n);
751}
752
756bool AstroTrac::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
757{
758 // Check guider interface
759 if (GI::processNumber(dev, name, values, names, n))
760 return true;
761
762 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
763 {
764 // Guide Rate
765 if (GuideRateNP.isNameMatch(name))
766 {
767 GuideRateNP.update(values, names, n);
768 GuideRateNP.setState(IPS_OK);
769 GuideRateNP.apply();
770 return true;
771 }
772
773 // Acceleration
774 if (AccelerationNP.isNameMatch(name))
775 {
776 AccelerationNP.update(values, names, n);
777
778 if (setAcceleration(AXIS_RA, AccelerationNP[AXIS_RA].getValue())
779 && setAcceleration(AXIS_DE, AccelerationNP[AXIS_DE].getValue()))
780 AccelerationNP.setState(IPS_OK);
781 else
782 AccelerationNP.setState(IPS_ALERT);
783
784 AccelerationNP.apply();
785 return true;
786 }
787
788 // Encoders
789 if (EncoderNP.isNameMatch(name))
790 {
791 if (slewEncoder(AXIS_RA, values[0]) && slewEncoder(AXIS_DE, values[1]))
792 {
794 EncoderNP.setState(IPS_OK);
795 }
796 else
797 EncoderNP.setState(IPS_ALERT);
798
799 EncoderNP.apply();
800 return true;
801 }
802
803 // Process alignment properties
804 ProcessAlignmentNumberProperties(this, name, values, names, n);
805 }
806
807 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
808}
809
813bool AstroTrac::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
814{
815 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
816 {
817 // Process alignment properties
818 ProcessAlignmentSwitchProperties(this, name, states, names, n);
819 }
820
821 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
822}
823
827bool AstroTrac::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
828 char *formats[], char *names[], int n)
829{
830 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
831 {
832 // Process alignment properties
833 ProcessAlignmentBLOBProperties(this, name, sizes, blobsizes, blobs, formats, names, n);
834 }
835 // Pass it up the chain
836 return INDI::Telescope::ISNewBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
837}
838
843{
844 bool rc1 = setVelocity(AXIS_RA, 0) && stopMotion(AXIS_RA);
845 bool rc2 = setVelocity(AXIS_DE, 0) && stopMotion(AXIS_DE);
846
847 return rc1 && rc2;
848}
849
854{
856 {
857 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
858 return false;
859 }
860
861 if (command == MOTION_START)
862 {
863 double velocity = SLEW_SPEEDS[SlewRateSP.findOnSwitchIndex()] * TRACKRATE_SIDEREAL
864 * (dir == DIRECTION_NORTH ? 1 : -1);
865 setVelocity(AXIS_DE, velocity);
866 }
867 else
868 {
869 // reset tracking
871 stopMotion(AXIS_DE);
872 }
873
874 return true;
875}
876
881{
883 {
884 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
885 return false;
886 }
887
888 if (command == MOTION_START)
889 {
890 double velocity = SLEW_SPEEDS[SlewRateSP.findOnSwitchIndex()] * TRACKRATE_SIDEREAL
891 * (dir == DIRECTION_WEST ? 1 : -1);
892 setVelocity(AXIS_RA, velocity);
893 }
894 else
895 {
896 // reset tracking
898 stopMotion(AXIS_RA);
899 }
900
901 return true;
902}
903
908{
909 if (type == MOUNT_ALTAZ)
910 {
911 LOG_ERROR("AstroTrac supports GEM and single arm (Fork) setups only.");
912 return false;
913 }
914 return true;
915}
916
920bool AstroTrac::updateLocation(double latitude, double longitude, double elevation)
921{
923 // Set this according to mount type
925 return true;
926}
927
931bool AstroTrac::updateTime(ln_date *utc, double utc_offset)
932{
933 INDI_UNUSED(utc);
934 INDI_UNUSED(utc_offset);
935 return true;
936}
937
942{
943 SetAxis1Park(EncoderNP[AXIS_RA].getValue());
944 SetAxis2Park(EncoderNP[AXIS_DE].getValue());
945
946 return true;
947}
948
953{
954 SetAxis1Park(0);
955 SetAxis2Park(0);
956
957 return true;
958}
959
964{
965 // do nothing if idle
967 {
968 GuideNSNP[AXIS_RA].setValue(0);
969 GuideNSNP[AXIS_DE].setValue(0);
970 GuideNSNP.setState(IPS_OK);
971 GuideNSNP.apply();
972
973 LOG_INFO("Please start tracking to set guide pulse");
974
975 return IPS_IDLE;
976 }
977
978 // get the current velocity
979 double lastRARate(0), lastDERate(0);
980 getVelocity(AXIS_RA, lastRARate);
981 getVelocity(AXIS_DE, lastDERate);
982
983 // if current DEC velocity is zero, try RA otherwise assume sidereal
984 lastRARate = std::fabs(lastRARate);
985 double rate = std::fabs(lastDERate) > 0 ? lastDERate : (lastRARate > 0 ? lastRARate : TRACKRATE_SIDEREAL);
986
987 // absolute movement in arcseconds
988 double dDE = std::fabs(GuideRateNP.at(AXIS_DE)->getValue() * rate * ms / 1000.0);
989
990 // final velocity guiding north is rate + dDE
991 setVelocity(AXIS_DE, rate + dDE);
992 INDI::Timer::singleShot(ms, [this]()
993 {
994 // reset tracking
996 GuideNSNP[AXIS_RA].setValue(0);
997 GuideNSNP[AXIS_DE].setValue(0);
998 GuideNSNP.setState(IPS_OK);
999 GuideNSNP.apply();
1000 });
1001 return IPS_BUSY;
1002}
1003
1008{
1009 // do nothing if idle
1011 {
1012 GuideNSNP[AXIS_RA].setValue(0);
1013 GuideNSNP[AXIS_DE].setValue(0);
1014 GuideNSNP.setState(IPS_OK);
1015 GuideNSNP.apply();
1016
1017 LOG_INFO("Please start tracking to set guide pulse");
1018
1019 return IPS_IDLE;
1020 }
1021
1022 // get the current velocity
1023 double lastRARate(0), lastDERate(0);
1024 getVelocity(AXIS_RA, lastRARate);
1025 getVelocity(AXIS_DE, lastDERate);
1026
1027 // if current DEC velocity is zero, try RA otherwise assume sidereal
1028 lastRARate = std::fabs(lastRARate);
1029 double rate = std::fabs(lastDERate) > 0 ? lastDERate : (lastRARate > 0 ? -lastRARate : -TRACKRATE_SIDEREAL);
1030
1031 // absolute movement in arcseconds
1032 double dDE = std::fabs(GuideRateNP.at(AXIS_DE)->getValue() * rate * ms / 1000.0);
1033
1034 // final velocity guiding south is rate - dDE
1035 setVelocity(AXIS_DE, rate - dDE);
1036 INDI::Timer::singleShot(ms, [this]()
1037 {
1038 // reset tracking
1040 GuideNSNP[AXIS_RA].setValue(0);
1041 GuideNSNP[AXIS_DE].setValue(0);
1042 GuideNSNP.setState(IPS_OK);
1043 GuideNSNP.apply();
1044 });
1045 return IPS_BUSY;
1046}
1047
1052{
1053 // do nothing if idle
1055 {
1056 GuideWENP[AXIS_RA].setValue(0);
1057 GuideWENP[AXIS_DE].setValue(0);
1058 GuideWENP.setState(IPS_OK);
1059 GuideWENP.apply();
1060
1061 LOG_INFO("Please start tracking to set guide pulse");
1062
1063 return IPS_IDLE;
1064 }
1065
1066 // get the current velocity
1067 double lastRARate(0);
1068 getVelocity(AXIS_RA, lastRARate);
1069
1070 // if the current RA rate is zero, which is a valid custom tracking rate, just assume sidereal
1071 double rate = std::fabs(lastRARate) > 0 ? lastRARate : TRACKRATE_SIDEREAL;
1072
1073 // absolute movement in arcseconds
1074 double dRA = std::fabs(GuideRateNP.at(AXIS_RA)->getValue() * rate * ms / 1000.0);
1075
1076 // not sure if this logic belongs here or the calling function
1077 // // compensate RA velocity for declination
1078 // TelescopeDirectionVector TDV;
1079 // TDV = TelescopeDirectionVectorFromEquatorialCoordinates(m_MountInternalCoordinates);
1080 // double skyRA = 0, skyDE = 0;
1081 // if (TransformTelescopeToCelestial(TDV, skyRA, skyDE))
1082 // {
1083 // dRA *= std::cos(M_PI / 180 * skyDE);
1084 // }
1085
1086 // final velocity guiding east is rate + dRA, i.e the guide star will appear to move east
1087 setVelocity(AXIS_RA, rate + dRA);
1088 INDI::Timer::singleShot(ms, [this]()
1089 {
1090 // reset the tracking mode
1092 GuideWENP[AXIS_RA].setValue(0);
1093 GuideWENP[AXIS_DE].setValue(0);
1094 GuideWENP.setState(IPS_OK);
1095 GuideWENP.apply();
1096 });
1097
1098 return IPS_BUSY;
1099}
1100
1105{
1106 // do nothing if idle
1108 {
1109 GuideWENP[AXIS_RA].setValue(0);
1110 GuideWENP[AXIS_DE].setValue(0);
1111 GuideWENP.setState(IPS_OK);
1112 GuideWENP.apply();
1113
1114 LOG_INFO("Please start tracking to set guide pulse");
1115
1116 return IPS_IDLE;
1117 }
1118
1119 // get the current velocity
1120 double lastRARate(0);
1121 getVelocity(AXIS_RA, lastRARate);
1122
1123 // if the current RA rate is zero, which is a valid custom tracking rate, just assume sidereal
1124 double rate = std::fabs(lastRARate) > 0 ? lastRARate : TRACKRATE_SIDEREAL;
1125
1126 // absolute movement in arcseconds
1127 double dRA = std::fabs(GuideRateNP.at(AXIS_RA)->getValue() * rate * ms / 1000.0);
1128
1129 // not sure if this logic belongs here or the calling function
1130 // // compensate RA velocity for declination
1131 // TelescopeDirectionVector TDV;
1132 // TDV = TelescopeDirectionVectorFromEquatorialCoordinates(m_MountInternalCoordinates);
1133 // double skyRA = 0, skyDE = 0;
1134 // if (TransformTelescopeToCelestial(TDV, skyRA, skyDE))
1135 // {
1136 // dRA *= std::cos(M_PI / 180 * skyDE);
1137 // }
1138
1139 // final velocity guiding west is rate - dRA, i.e the guide star will appear to move west
1140 setVelocity(AXIS_RA, rate - dRA);
1141 INDI::Timer::singleShot(ms, [this]()
1142 {
1143 // reset the tracking mode
1145 GuideWENP[AXIS_RA].setValue(0);
1146 GuideWENP[AXIS_DE].setValue(0);
1147 GuideWENP.setState(IPS_OK);
1148 GuideWENP.apply();
1149 });
1150 return IPS_BUSY;
1151}
1152
1156bool AstroTrac::SetTrackRate(double raRate, double deRate)
1157{
1158 return setVelocity(AXIS_RA, raRate) && setVelocity(AXIS_DE, deRate);
1159}
1160
1164bool AstroTrac::SetTrackMode(uint8_t mode)
1165{
1166 double dRA = 0, dDE = 0;
1167 if (mode == TRACK_SIDEREAL)
1168 dRA = TRACKRATE_SIDEREAL;
1169 else if (mode == TRACK_SOLAR)
1170 dRA = TRACKRATE_SOLAR;
1171 else if (mode == TRACK_LUNAR)
1172 dRA = TRACKRATE_LUNAR;
1173 else if (mode == TRACK_CUSTOM)
1174 {
1175 dRA = TrackRateNP[AXIS_RA].getValue();
1176 dDE = TrackRateNP[AXIS_DE].getValue();
1177 }
1178
1179 return setVelocity(AXIS_RA, dRA) && setVelocity(AXIS_DE, dDE);
1180}
1181
1186{
1187 // On engaging track, we simply set the current track mode and it will take care of the rest including custom track rates.
1188 if (enabled)
1189 return SetTrackMode(TrackModeSP.findOnSwitchIndex());
1190 // Disable tracking
1191 else
1192 {
1193 setVelocity(AXIS_RA, 0);
1194 setVelocity(AXIS_DE, 0);
1195 }
1196 return true;
1197}
1198
1203{
1206 return true;
1207}
1208
1212void AstroTrac::simulateMount()
1213{
1214 // milliseconds elapsed
1215 uint32_t elapsed = m_SimulationTimer.elapsed();
1216
1217 // If too much time elapsed, restart the timer.
1218 if (elapsed > 5000)
1219 {
1220 m_SimulationTimer.restart();
1221 return;
1222 }
1223
1224 if (MovementWESP.getState() == IPS_BUSY || MovementNSSP.getState() == IPS_BUSY)
1225 {
1226 double haVelocity = SLEW_SPEEDS[SlewRateSP.findOnSwitchIndex()] * TRACKRATE_SIDEREAL *
1227 (MovementWESP.findOnSwitchIndex() == DIRECTION_NORTH ? 1 : -1) * (m_Location.latitude >= 0 ? 1 : -1);
1228 double deVelocity = SLEW_SPEEDS[SlewRateSP.findOnSwitchIndex()] * TRACKRATE_SIDEREAL *
1229 (MovementNSSP.findOnSwitchIndex() == DIRECTION_NORTH ? 1 : -1) * (m_Location.latitude >= 0 ? 1 : -1);
1230
1231 haVelocity *= MovementWESP.getState() == IPS_BUSY ? 1 : 0;
1232 deVelocity *= MovementNSSP.getState() == IPS_BUSY ? 1 : 0;
1233
1234 // In degrees
1235 double elapsedDistanceHA = (elapsed / 1000.0 * haVelocity) / 3600.0;
1236 double elapsedDistanceDE = (elapsed / 1000.0 * deVelocity) / 3600.0;
1237
1238 // Hour Angle
1239 SimData.currentMechanicalHA += elapsedDistanceHA;
1240 if (SimData.currentMechanicalHA > 180)
1241 SimData.currentMechanicalHA -= 360;
1242 else if (SimData.currentMechanicalHA < -180)
1243 SimData.currentMechanicalHA += 360;
1244
1245 SimData.currentMechanicalDE += elapsedDistanceDE;
1246 if (SimData.currentMechanicalDE > 180)
1247 SimData.currentMechanicalDE -= 360;
1248 else if (SimData.currentMechanicalDE < -180)
1249 SimData.currentMechanicalDE += 360;
1250 }
1251 else
1252 {
1253 switch (TrackState)
1254 {
1255 case SCOPE_IDLE:
1256 case SCOPE_PARKED:
1257 break;
1258
1259 case SCOPE_SLEWING:
1260 case SCOPE_PARKING:
1261 {
1262 // In degrees
1263 double elapsedDistance = (elapsed / 1000.0 * MAX_SLEW_VELOCITY) / 3600.0;
1264
1265 // Hour Angle
1266 double dHA = SimData.targetMechanicalHA - SimData.currentMechanicalHA;
1267 if (std::abs(dHA) <= elapsedDistance)
1268 SimData.currentMechanicalHA = SimData.targetMechanicalHA;
1269 else if (dHA > 0)
1270 SimData.currentMechanicalHA += elapsedDistance;
1271 else
1272 SimData.currentMechanicalHA -= elapsedDistance;
1273
1274 // Declination
1275 double dDE = SimData.targetMechanicalDE - SimData.currentMechanicalDE;
1276 if (std::abs(dDE) <= elapsedDistance)
1277 SimData.currentMechanicalDE = SimData.targetMechanicalDE;
1278 else if (dDE > 0)
1279 SimData.currentMechanicalDE += elapsedDistance;
1280 else
1281 SimData.currentMechanicalDE -= elapsedDistance;
1282 }
1283 break;
1284
1285 case SCOPE_TRACKING:
1286 {
1287 // Increase HA axis at selected tracking rate (arcsec/s).
1288 SimData.currentMechanicalHA += (elapsed / 1000.0 * TrackRateNP[AXIS_RA].getValue()) / 3600.0;
1289 if (SimData.currentMechanicalHA > 180)
1290 SimData.currentMechanicalHA = 180;
1291 else if (SimData.currentMechanicalHA < -180)
1292 SimData.currentMechanicalHA = -180;
1293 }
1294 break;
1295 }
1296 }
1297
1298 m_SimulationTimer.restart();
1299}
1300
1305{
1306 if (enable)
1307 m_SimulationTimer.start();
1308}
1309
1313bool AstroTrac::handleSimulationCommand(const char *cmd, char *res, int cmd_len, int res_len)
1314{
1315 INDI_UNUSED(cmd_len);
1316
1317 // Get version
1318 if (strstr(cmd, "zv?"))
1319 {
1320 snprintf(res, res_len, "<%czvSIMU>", cmd[1]);
1321 }
1322 // Get Encoder Position
1323 else if (strstr(cmd, "p?"))
1324 {
1325 snprintf(res, res_len, "<%cp%.6f>", cmd[1], cmd[1] == '1' ? SimData.currentMechanicalHA : SimData.currentMechanicalDE);
1326 }
1327 // Set Encoder Position
1328 else if (strstr(cmd, "p"))
1329 {
1330 double value = 0;
1331 sscanf(cmd, "<%*cp%lf", &value);
1332 if (cmd[1] == '1')
1333 SimData.targetMechanicalHA = value;
1334 else
1335 SimData.targetMechanicalDE = value;
1336 snprintf(res, res_len, "<%cp#>", cmd[1]);
1337 }
1338 // Get Acceleration
1339 else if (strstr(cmd, "a?"))
1340 {
1341 snprintf(res, res_len, "<%ca%u>", cmd[1], SimData.acceleration[cmd[1] - '1']);
1342 }
1343 // Set Acceleration
1344 else if (strstr(cmd, "a"))
1345 {
1346 uint32_t value = 0;
1347 sscanf(cmd, "<%*ca%u", &value);
1348 SimData.acceleration[cmd[1] - '1'] = value;
1349 snprintf(res, res_len, "<%ca#>", cmd[1]);
1350 }
1351 // Get Velocity
1352 else if (strstr(cmd, "v?"))
1353 {
1354 snprintf(res, res_len, "<%cv%.6f>", cmd[1], SimData.velocity[cmd[1] - '1']);
1355 }
1356 // Set Velocity using encoders
1357 else if (strstr(cmd, "ve"))
1358 {
1359 double value = 0;
1360 sscanf(cmd, "<%*cve%lf", &value);
1361 SimData.velocity[cmd[1] - '1'] = value;
1362 snprintf(res, res_len, "<%cve#>", cmd[1]);
1363 }
1364 // Get Slew status
1365 else if (strstr(cmd, "t"))
1366 {
1367 char result = '0';
1368 if (cmd[1] == '1')
1369 result = std::abs(SimData.currentMechanicalHA - SimData.targetMechanicalHA) <= DIFF_THRESHOLD ? '0' : '1';
1370 else
1371 result = std::abs(SimData.currentMechanicalDE - SimData.targetMechanicalDE) <= DIFF_THRESHOLD ? '0' : '1';
1372 snprintf(res, res_len, "<%ct%c#>", cmd[1], result);
1373 }
1374 // Abort
1375 else if (strstr(cmd, "x"))
1376 {
1377 snprintf(res, res_len, "<%cx#>", cmd[1]);
1378 }
1379
1380 return true;
1381}
1382
1386bool AstroTrac::sendCommand(const char *cmd, char *res, int cmd_len, int res_len)
1387{
1388 int nbytes_written = 0, nbytes_read = 0, rc = -1;
1389
1390 if (isSimulation())
1391 return handleSimulationCommand(cmd, res, cmd_len, res_len);
1392
1393 tcflush(PortFD, TCIOFLUSH);
1394
1395 if (cmd_len > 0)
1396 {
1397 char hex_cmd[DRIVER_LEN * 3] = {0};
1398 hexDump(hex_cmd, cmd, cmd_len);
1399 LOGF_DEBUG("CMD <%s>", hex_cmd);
1400 rc = tty_write(PortFD, cmd, cmd_len, &nbytes_written);
1401 }
1402 else
1403 {
1404 LOGF_DEBUG("CMD <%s>", cmd);
1405 rc = tty_write_string(PortFD, cmd, &nbytes_written);
1406 }
1407
1408 if (rc != TTY_OK)
1409 {
1410 char errstr[MAXRBUF] = {0};
1411 tty_error_msg(rc, errstr, MAXRBUF);
1412 LOGF_ERROR("Serial write error: %s.", errstr);
1413 return false;
1414 }
1415
1416 if (res == nullptr)
1417 {
1418 tcdrain(PortFD);
1419 return true;
1420 }
1421
1422 if (res_len > 0)
1423 rc = tty_read(PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
1424 else
1425 rc = tty_nread_section(PortFD, res, DRIVER_LEN, DRIVER_STOP_CHAR, DRIVER_TIMEOUT, &nbytes_read);
1426
1427 if (rc != TTY_OK)
1428 {
1429 char errstr[MAXRBUF] = {0};
1430 tty_error_msg(rc, errstr, MAXRBUF);
1431 LOGF_ERROR("Serial read error: %s.", errstr);
1432 return false;
1433 }
1434
1435 if (res_len > 0)
1436 {
1437 char hex_res[DRIVER_LEN * 3] = {0};
1438 hexDump(hex_res, res, res_len);
1439 LOGF_DEBUG("RES <%s>", hex_res);
1440 }
1441 else
1442 {
1443 LOGF_DEBUG("RES <%s>", res);
1444 }
1445
1446 tcflush(PortFD, TCIOFLUSH);
1447
1448 return true;
1449}
1450
1454void AstroTrac::hexDump(char *buf, const char *data, int size)
1455{
1456 for (int i = 0; i < size; i++)
1457 sprintf(buf + 3 * i, "%02X ", static_cast<uint8_t>(data[i]));
1458
1459 if (size > 0)
1460 buf[3 * size - 1] = '\0';
1461}
1462
1466std::vector<std::string> AstroTrac::split(const std::string &input, const std::string &regex)
1467{
1468 // passing -1 as the submatch index parameter performs splitting
1469 std::regex re(regex);
1470 std::sregex_token_iterator
1471 first{input.begin(), input.end(), re, -1},
1472 last;
1473 return {first, last};
1474}
std::unique_ptr< AstroTrac > AstroTrac_mount(new AstroTrac())
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual const char * getDefaultName() override
Definition astrotrac.cpp:55
double velocity[2]
Definition astrotrac.h:176
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
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 void simulationTriggered(bool enable) override
Handle Simulation Trigger.
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 SetMountType(TelescopeMountType type) override
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
virtual bool saveConfigItems(FILE *fp) override
Config Items.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
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 MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool Park() override
Park the telescope to its home position.
uint32_t acceleration[2]
Definition astrotrac.h:178
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition astrotrac.cpp:63
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
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.
void SetApproximateMountAlignmentFromMountType(MountType_t Type)
Call this function to set the ApproximateMountAlignment property of the current Math Plugin....
void EquatorialCoordinatesFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, INDI::IEquatorialCoordinates &EquatorialCoordinates)
Calculates equatorial coordinates from the supplied telescope direction vector and declination.
const TelescopeDirectionVector TelescopeDirectionVectorFromEquatorialCoordinates(INDI::IEquatorialCoordinates EquatorialCoordinates)
Calculates a telescope direction vector from the supplied equatorial coordinates.
bool isConnected() const
INDI::PropertySwitch getSwitch(const char *name) const
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.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
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.
int64_t elapsed() const
Returns the number of milliseconds since this ElapsedTimer was last started.
int64_t restart()
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
INDI::PropertyNumber GuideNSNP
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....
TelescopeMountType getMountType() const
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 bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
double GetAxis1Park() const
void setTelescopeConnection(const uint8_t &value)
setTelescopeConnection Set telescope connection mode. Child class should call this in the constructor...
double GetAxis2Park() const
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
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
TelescopeMountType
Mount geometry reported in the standard TELESCOPE_MOUNT_TYPE property. The values are the indices of ...
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.
void setPierSide(TelescopePierSide side)
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.
static void singleShot(int msec, const std::function< void()> &callback)
This static function calls a the given function after a given time interval.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch MovementNSSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MountTypeSP
Standard TELESCOPE_MOUNT_TYPE property, indexed by TelescopeMountType. Writable if the driver sets TE...
INDI::PropertySwitch MovementWESP
INDI::PropertyNumber LocationNP
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
INDI_EQ_AXIS
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_WEST
INDI_DIR_NS
@ DIRECTION_NORTH
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition indicom.c:418
double rangeHA(double r)
rangeHA Limits the hour angle value to be between -12 ---> 12
Definition indicom.c:1301
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition indicom.c:1311
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
Definition indicom.c:473
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition indicom.c:1243
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
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:759
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sidereal time given longitude and system clock.
#define INDI_UNUSED(x)
Definition indidevapi.h:132
#define MAXRBUF
Definition indidriver.c:52
int IUGetConfigOnSwitchIndex(const char *dev, const char *property, int *index)
IUGetConfigOnSwitchIndex Opens configuration file and reads single switch property to find ON switch ...
Definition indidriver.c:719
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 LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#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...
uint16_t type
Definition pwc-ioctl.h:0
uint8_t cmd[4]
Definition pwc-ioctl.h:2
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