25#include <libnova/julian_day.h>
35static std::unique_ptr<ScopeSim> telescope_sim(
new ScopeSim());
56 srand(
static_cast<uint32_t
>(time(
nullptr)));
60 axisPrimary.setDegrees(0.0);
62 axisSecondary.setDegrees(90.0);
68 return "Telescope Simulator";
79 simPierSideSP[PS_OFF].fill(
"PS_OFF",
"Off",
ISS_OFF);
80 simPierSideSP[PS_ON].fill(
"PS_ON",
"On",
ISS_ON);
81 simPierSideSP.fill(
getDeviceName(),
"SIM_PIER_SIDE",
"Sim Pier Side",
84 mountModelNP[MM_IH].fill(
"MM_IH",
"Ha Zero (IH) '",
"%.1f", -10800, 10800, 0.1, 0);
85 mountModelNP[MM_ID].fill(
"MM_ID",
"Dec Zero (ID) '",
"%.1f", -10800, 10800, 0.1, 0);
86 mountModelNP[MM_CH].fill(
"MM_CH",
"Cone (CH) '",
"%.1f", -300, 300, 0.1, 0);
87 mountModelNP[MM_NP].fill(
"MM_NP",
"Ha/Dec (NP) '",
"%.1f", -300, 300, 0.1, 0);
88 mountModelNP[MM_MA].fill(
"MM_MA",
"Pole Azm (MA) '",
"%.1f", -300, 300, 0.1, 0);
89 mountModelNP[MM_ME].fill(
"MM_ME",
"Pole elev (ME) '",
"%.1f", -300, 300, 0.1, 0);
90 mountModelNP.fill(
getDeviceName(),
"MOUNT_MODEL",
"Mount Model",
93 flipHourAngleNP[0].fill(
"FLIP_HA",
"Hour Angle (deg)",
"%g", -20, 20, 0.1, 0);
94 flipHourAngleNP.fill(
getDeviceName(),
"FLIP_HA",
"Flip Posn.",
97 mountAxisNP[PRIMARY].fill(
"PRIMARY",
"Primary (Ha)",
"%g", -180, 180, 0.01, 0);
98 mountAxisNP[SECONDARY].fill(
"SECONDARY",
"Secondary (Dec)",
"%g", -180, 180, 0.01, 0);
105 guideErrorsNP[GE_BACKLASH_RA +
RA_AXIS].fill(
"RA_BACKLASH",
"RA Backlash (ms)",
"%.0f", 0, 5000, 0, 0);
106 guideErrorsNP[GE_BACKLASH_RA +
DEC_AXIS].fill(
"DEC_BACKLASH",
"DEC Backlash (ms)",
"%.0f", 0, 5000, 0, 0);
107 guideErrorsNP[GE_RATE_RA +
RA_AXIS].fill(
"RA_RATE",
"RA Rate (%)",
"%.0f", 0, 300, 0, 100);
108 guideErrorsNP[GE_RATE_RA +
DEC_AXIS].fill(
"DEC_RATE",
"DEC Rate (%)",
"%.0f", 0, 300, 0, 100);
109 guideErrorsNP[GE_JITTER_RA +
RA_AXIS].fill(
"RA_JITTER",
"RA Jitter (%)",
"%.0f", 0, 100, 0, 0);
110 guideErrorsNP[GE_JITTER_RA +
DEC_AXIS].fill(
"DEC_JITTER",
"DEC Jitter (%)",
"%.0f", 0, 100, 0, 0);
111 guideErrorsNP[GE_DROP_RA +
RA_AXIS].fill(
"RA_DROP",
"RA Dropped (%)",
"%.0f", 0, 100, 0, 0);
112 guideErrorsNP[GE_DROP_RA +
DEC_AXIS].fill(
"DEC_DROP",
"DEC Dropped (%)",
"%.0f", 0, 100, 0, 0);
113 guideErrorsNP.fill(
getDeviceName(),
"GUIDE_ERRORS",
"Guide Errors",
116 PACDeviceTP[0].fill(
"PAC_DEVICE",
"Alignment Corrector",
"Alignment Correction Simulator");
120 const char *pacDevice = PACDeviceTP[0].getText();
121 if (pacDevice && strlen(pacDevice) > 0)
130 GuideRateNP[
RA_AXIS].fill(
"GUIDE_RATE_WE",
"W/E Rate",
"%g", 0, 1, 0.1, 0.5);
131 GuideRateNP[
DEC_AXIS].fill(
"GUIDE_RATE_NS",
"N/S Rate",
"%g", 0, 1, 0.1, 0.5);
161 EqPENP[PE_RA].fill(
"RA_PE",
"RA (hh:mm:ss)",
"%010.6m", 0, 24, 0, 0);
162 EqPENP[PE_DEC].fill(
"DEC_PE",
"DEC (dd:mm:ss)",
"%010.6m", -90, 90, 0, 0);
179 simPierSideSP.load();
180 updateMountAndPierSide();
183 alignment.setCorrections(mountModelNP[MM_IH].getValue() / 60.0, mountModelNP[MM_ID].getValue() / 60.0,
184 mountModelNP[MM_CH].getValue() / 60.0, mountModelNP[MM_NP].getValue() / 60.0,
185 mountModelNP[MM_MA].getValue() / 60.0, mountModelNP[MM_ME].getValue() / 60.0);
188 flipHourAngleNP.load();
190 guideErrorsNP.load();
194 m_currentAz = axisPrimary.position.Degrees();
195 m_currentAlt = axisSecondary.position.Degrees();
200 updateMountAndPierSide();
223 Angle instHA, instDec;
224 alignment.mountToInstrumentHaDec(
228 m_currentRA = (alignment.lst() - instHA).
Hours();
229 m_currentDEC = instDec.
Degrees();
259 Angle ha = alignment.lst() -
Angle(m_currentRA * 15.0);
260 Angle primary, secondary;
261 alignment.instrumentHaDecToMount(ha,
Angle(m_currentDEC), &primary, &secondary);
262 axisPrimary.position = primary;
263 axisSecondary.position = secondary;
264 m_currentAz = axisPrimary.position.
Degrees();
265 m_currentAlt = axisSecondary.position.Degrees();
266 m_targetRA = m_currentRA;
267 m_targetDEC = m_currentDEC;
271 alignment.clockOffsetDays = 0;
275 const char *pacDevice = PACDeviceTP[0].getText();
276 if (pacDevice && strlen(pacDevice) > 0)
299 LOG_INFO(
"Telescope simulator is online.");
307 LOG_INFO(
"Telescope simulator is offline.");
312void ScopeSim::updateCurrentCoordsFromAxes()
314 Angle instHA, instDec;
316 m_currentRA = (alignment.
lst() - instHA).Hours();
317 m_currentDEC = instDec.
Degrees();
321 double corrRA, corrDec;
322 bool corrected =
false;
333 double encoderRA = (alignment.lst() - instHA).Hours();
334 INDI::IEquatorialCoordinates raCoords{ encoderRA, instDec.
Degrees() };
335 TelescopeDirectionVector tdv =
341 m_currentRA = corrRA;
342 m_currentDEC = corrDec;
347void ScopeSim::setTargetFromAxisPosition(
Angle primary,
Angle secondary)
349 Angle instHA, instDec;
350 alignment.mountToInstrumentHaDec(primary, secondary, &instHA, &instDec);
351 m_targetRA = (alignment.lst() - instHA).
Hours();
352 m_targetDEC = instDec.
Degrees();
361 double JDnow = alignment.julianDate();
362 double JDoffset = dt / 86400.0;
369 double raDriftHrsPerSec = 0;
377 double dtFromNow = (JD - JDnow) * 86400.0;
382 bool targetChanged = std::abs(m_LastTrackingRA - m_targetRA) > 1e-6 ||
383 std::abs(m_LastTrackingDec - m_targetDEC) > 1e-6;
385 if (!m_IsPipelinePrimed || targetChanged)
387 getAltAz(JDnow - JDoffset, m_TrackingWindowCoords[0]);
388 getAltAz(JDnow, m_TrackingWindowCoords[1]);
389 getAltAz(JDnow + JDoffset, m_TrackingWindowCoords[2]);
390 m_IsPipelinePrimed =
true;
391 m_LastTrackingRA = m_targetRA;
392 m_LastTrackingDec = m_targetDEC;
396 m_TrackingWindowCoords[0] = m_TrackingWindowCoords[1];
397 m_TrackingWindowCoords[1] = m_TrackingWindowCoords[2];
398 getAltAz(JDnow + JDoffset, m_TrackingWindowCoords[2]);
407 double pAz[3] = { m_TrackingWindowCoords[0].azimuth,
408 m_TrackingWindowCoords[1].azimuth,
409 m_TrackingWindowCoords[2].azimuth
411 pAz[0] = pAz[1] +
range180(pAz[0] - pAz[1]);
412 pAz[2] = pAz[1] +
range180(pAz[2] - pAz[1]);
415 double az_a = (pAz[2] + pAz[0] - 2.0 * pAz[1]) / 2.0;
416 double az_b = (pAz[2] - pAz[0]) / 2.0;
417 double alt_a = (m_TrackingWindowCoords[2].altitude + m_TrackingWindowCoords[0].altitude
418 - 2.0 * m_TrackingWindowCoords[1].altitude) / 2.0;
419 double alt_b = (m_TrackingWindowCoords[2].altitude - m_TrackingWindowCoords[0].altitude) / 2.0;
422 double targetAzNext = az_a + az_b + pAz[1];
423 double targetAltNext = alt_a + alt_b + m_TrackingWindowCoords[1].altitude;
426 double azRate =
range180(targetAzNext - m_currentAz) / dt * 3600.0;
427 double altRate = (targetAltNext - m_currentAlt) / dt * 3600.0;
433 axisPrimary.update();
434 axisSecondary.update();
436 publishTruePointing();
441 updateCurrentCoordsFromAxes();
448 m_currentAz = axisPrimary.position.Degrees();
449 m_currentAlt = axisSecondary.position.Degrees();
457 bool slewing = axisPrimary.isSlewing || axisSecondary.isSlewing;
465 LOG_INFO(
"Telescope slew is complete. Parked");
485 LOG_INFO(
"Telescope slew is complete. Tracking...");
490 Angle targetHa = alignment.lst() -
Angle(m_targetRA * 15.0);
491 Angle tPrimary, tSecondary;
492 alignment.instrumentHaDecToMount(targetHa,
Angle(m_targetDEC), &tPrimary, &tSecondary);
493 double dPri = (axisPrimary.position - tPrimary).Degrees();
494 double dSec = (axisSecondary.position - tSecondary).Degrees();
495 LOGF_DEBUG(
"slew accuracy pri %f arcsec, sec %f arcsec", dPri * 3600, dSec * 3600);
506 if (guidingEW && !axisPrimary.IsGuiding())
514 if (guidingNS && !axisSecondary.IsGuiding())
523 double PrimaryAngle = axisPrimary.position.Degrees();
524 double SecondaryAngle = axisSecondary.position.Degrees();
526 if (std::fabs(mountAxisNP[PRIMARY].getValue() - PrimaryAngle) > 0.0001 ||
527 std::fabs(mountAxisNP[SECONDARY].getValue() - SecondaryAngle) > 0.0001)
529 mountAxisNP[PRIMARY].setValue(PrimaryAngle);
530 mountAxisNP[SECONDARY].setValue(SecondaryAngle);
532 LOGF_EXTRA1(
"new %s: %f, ra %f", axisPrimary.axisName, PrimaryAngle, EqPENP[PE_RA].getValue());
533 LOGF_EXTRA1(
"new %s: %f, dec %f", axisSecondary.axisName, SecondaryAngle, EqPENP[PE_DEC].getValue());
539 char RAStr[64], DecStr[64];
540 fs_sexa(RAStr, m_currentRA, 2, 3600);
541 fs_sexa(DecStr, m_currentDEC, 2, 3600);
542 DEBUGF(DBG_SCOPE,
"Current RA: %s Current DEC: %s", RAStr, DecStr);
544 NewRaDec(m_currentRA, m_currentDEC);
563 double instrumentAlt, instrumentAz_INDI;
566 axisPrimary.StartSlew(
Angle(instrumentAz_INDI));
567 axisSecondary.StartSlew(
Angle(instrumentAlt));
571 setTargetFromAxisPosition(
Angle(instrumentAz_INDI),
Angle(instrumentAlt));
575 LOGF_INFO(
"Slewing to RA: %.4f Dec: %.4f", m_targetRA, m_targetDEC);
580 double targetRA = r, targetDec = d;
592 LOGF_INFO(
"EQ Goto: alignment corrected RA %.4fh Dec %.4f -> RA %.4fh Dec %.4f",
593 r, d, targetRA, targetDec);
597 LOG_WARN(
"EQ Goto: TransformCelestialToTelescope FAILED, using raw coordinates");
621 const double indi_az = axisPrimary.position.Degrees();
622 const double indi_alt = axisSecondary.position.Degrees();
635 Angle instHA, instDec;
636 alignment.mountToInstrumentHaDec(axisPrimary.position, axisSecondary.position,
639 double encoderRA = (alignment.lst() - instHA).
Hours();
652 LOG_WARN(
"Sync not stored in the alignment database: geographic location is not known yet.");
670 LOGF_INFO(
"Sync replaced %d older alignment point(s) at the same position.", replaced);
674 setTargetFromAxisPosition(axisPrimary.position, axisSecondary.position);
676 LOGF_DEBUG(
"Sync at RA %f Dec %f m_targetRA %f m_targetDEC %f",
677 ra,
dec, m_targetRA, m_targetDEC);
682 NewRaDec(m_currentRA, m_currentDEC);
696 axisPrimary.StartSlew(indi_az);
697 axisSecondary.StartSlew(alt);
698 setTargetFromAxisPosition(indi_az, alt);
712void ScopeSim::StartSlew(
double ra,
double dec, TelescopeStatus status)
717 Angle primary, secondary;
725 setTargetFromAxisPosition(primary, secondary);
726 char RAStr[64], DecStr[64];
728 fs_sexa(RAStr, m_targetRA, 2, 3600);
729 fs_sexa(DecStr, m_targetDEC, 2, 3600);
731 const char * statusStr;
735 statusStr =
"Parking";
738 statusStr =
"Slewing";
741 statusStr =
"unknown";
745 LOGF_INFO(
"%s to RA: %s - DEC: %s", statusStr, RAStr, DecStr);
762 if (strcmp(name,
"GUIDE_RATE") == 0)
764 GuideRateNP.update(values, names,
n);
765 GuideRateNP.setState(
IPS_OK);
771 if (mountModelNP.isNameMatch(name))
773 if (mountModelNP.isUpdated(values, names,
n))
775 mountModelNP.update(values, names,
n);
776 alignment.setCorrections(mountModelNP[MM_IH].getValue() / 60.0, mountModelNP[MM_ID].getValue() / 60.0,
777 mountModelNP[MM_CH].getValue() / 60.0, mountModelNP[MM_NP].getValue() / 60.0,
778 mountModelNP[MM_MA].getValue() / 60.0, mountModelNP[MM_ME].getValue() / 60.0);
781 mountModelNP.setState(
IPS_OK);
782 mountModelNP.apply();
786 if (flipHourAngleNP.isNameMatch(name))
788 flipHourAngleNP.update(values, names,
n);
789 flipHourAngleNP.setState(
IPS_OK);
790 flipHourAngleNP.apply();
791 alignment.setFlipHourAngle(flipHourAngleNP[0].getValue());
794 if (guideErrorsNP.isNameMatch(name))
796 guideErrorsNP.update(values, names,
n);
797 guideErrorsNP.setState(
IPS_OK);
798 guideErrorsNP.apply();
817 if (simPierSideSP.isNameMatch(name))
819 if (!simPierSideSP.update(states, names,
n))
822 simPierSideSP.setState(
IPS_OK);
823 simPierSideSP.apply();
824 updateMountAndPierSide();
845 if (strcmp(name,
"ALIGNMENT_SUBSYSTEM_MATH_PLUGINS") == 0 ||
846 strcmp(name,
"ALIGNMENT_SUBSYSTEM_ACTIVE") == 0)
858 if (PACDeviceTP.isNameMatch(name))
860 PACDeviceTP.setState(
IPS_OK);
861 PACDeviceTP.update(texts, names,
n);
866 m_PACMoveActive =
false;
868 const char *pacDevice = PACDeviceTP[0].getText();
869 if (pacDevice && strlen(pacDevice) > 0)
885void ScopeSim::applyPACCorrection()
893 const double oldMA = mountModelNP[MM_MA].getValue();
894 const double oldME = mountModelNP[MM_ME].getValue();
895 const double newMA = oldMA - m_snoopedAzError * 60.0 * cosLat * m_snoopedGain;
896 const double newME = oldME - m_snoopedAltError * 60.0 * m_snoopedGain;
898 mountModelNP[MM_MA].setValue(newMA);
899 mountModelNP[MM_ME].setValue(newME);
900 alignment.
setCorrections(mountModelNP[MM_IH].getValue() / 60.0, mountModelNP[MM_ID].getValue() / 60.0,
901 mountModelNP[MM_CH].getValue() / 60.0, mountModelNP[MM_NP].getValue() / 60.0,
902 mountModelNP[MM_MA].getValue() / 60.0, mountModelNP[MM_ME].getValue() / 60.0);
905 mountModelNP.
apply();
907 LOGF_INFO(
"Applied PAC correction: MA %.4f -> %.4f, ME %.4f -> %.4f (arcmin, gain %.0f%%)",
908 oldMA, newMA, oldME, newME, m_snoopedGain * 100);
912 publishTruePointing();
913 updateCurrentCoordsFromAxes();
914 NewRaDec(m_currentRA, m_currentDEC);
918void ScopeSim::publishTruePointing()
922 Angle trueRa, trueDec;
923 alignment.mountToApparentRaDec(axisPrimary.position, axisSecondary.position, &trueRa, &trueDec);
924 EqPENP[PE_RA].setValue(trueRa.
Hours());
925 EqPENP[PE_DEC].setValue(trueDec.
Degrees());
935 const char *pacDevice = PACDeviceTP[0].getText();
937 if (pacDevice && strlen(pacDevice) > 0 && deviceName && strcmp(deviceName, pacDevice) == 0)
939 if (!strcmp(propName,
"PAC_MANUAL_ADJUSTMENT"))
948 if (!strcmp(elemName,
"MANUAL_AZ_STEP"))
950 else if (!strcmp(elemName,
"MANUAL_ALT_STEP"))
959 const bool busy = stateStr && !strcmp(stateStr,
"Busy");
960 if (busy && !m_PACMoveActive)
961 applyPACCorrection();
962 m_PACMoveActive = busy;
966 if (!strcmp(propName,
"CORRECTION_GAIN"))
983 axisSecondary.Abort();
993 LOG_ERROR(
"Please unpark the mount before issuing any motion commands.");
996 mcRate =
static_cast<int>(
SlewRateSP.findOnSwitchIndex()) + 1;
997 mcRate = std::max(1, std::min(4, mcRate));
1002 LOGF_DEBUG(
"MoveNS dir %s, motion %s, rate %d", dir ==
DIRECTION_NORTH ?
"N" :
"S", command == 0 ?
"start" :
"stop", rate);
1004 axisSecondary.mcRate = command ==
MOTION_START ? rate : 0;
1013 LOG_ERROR(
"Please unpark the mount before issuing any motion commands.");
1017 mcRate =
static_cast<int>(
SlewRateSP.findOnSwitchIndex()) + 1;
1018 mcRate = std::max(1, std::min(4, mcRate));
1021 LOGF_DEBUG(
"MoveWE dir %d, motion %s, rate %d", dir ==
DIRECTION_EAST ?
"E" :
"W", command == 0 ?
"start" :
"stop", rate);
1023 axisPrimary.mcRate = command ==
MOTION_START ? rate : 0;
1027uint32_t ScopeSim::applyGuideErrors(
int axis,
double &rate, uint32_t ms)
1029 const char *axisName = (axis ==
RA_AXIS) ?
"RA" :
"DEC";
1030 std::uniform_real_distribution<double> uniform(0.0, 1.0);
1033 if (uniform(m_GuideRng) * 100 < guideErrorsNP[GE_DROP_RA + axis].getValue())
1035 LOGF_DEBUG(
"%s guide pulse of %u ms dropped.", axisName, ms);
1039 const double jitter = guideErrorsNP[GE_JITTER_RA + axis].getValue();
1042 const uint32_t requested = ms;
1043 ms =
static_cast<uint32_t
>(std::lround(ms * (1 + (2 * uniform(m_GuideRng) - 1) * jitter / 100)));
1044 LOGF_DEBUG(
"%s guide pulse jitter: %u ms => %u ms", axisName, requested, ms);
1048 const uint32_t backlash =
static_cast<uint32_t
>(guideErrorsNP[GE_BACKLASH_RA + axis].getValue());
1049 uint32_t &remaining = m_GuideRemainingBacklash[axis];
1050 const bool positive = rate >= 0;
1051 if (positive != m_GuideLastPositive[axis])
1054 remaining = backlash;
1055 else if (remaining >= backlash)
1058 remaining = backlash - remaining;
1060 m_GuideLastPositive[axis] = positive;
1062 const uint32_t taken = std::min(remaining, ms);
1067 LOGF_DEBUG(
"%s backlash took %u ms of the guide pulse, %u ms left to clear.", axisName, taken, remaining);
1070 rate *= guideErrorsNP[GE_RATE_RA + axis].getValue() / 100.0;
1074void ScopeSim::guideAltAzDecomposed(
double dNS,
double dEW, uint32_t ms)
1085 double H = (alignment.lst() - Angle(m_currentRA * 15.0)).radians();
1086 double dec = Angle(m_currentDEC).radians();
1087 double lat = alignment.latitude.radians();
1088 double alt = m_currentAlt *
M_PI / 180.0;
1089 double cosAlt = std::cos(alt);
1091 if (std::abs(cosAlt) > 1e-4)
1093 double sinQ = std::sin(H) * std::cos(lat) / cosAlt;
1094 double cosQ = (std::sin(lat) - std::sin(
dec) * std::sin(alt))
1095 / (std::cos(
dec) * cosAlt);
1097 double dAlt_N = cosQ;
1098 double dAz_N = -sinQ / cosAlt;
1099 double dAlt_E = sinQ;
1100 double dAz_E = cosQ / cosAlt;
1102 axisPrimary.StartGuide(dNS * dAz_N + dEW * dAz_E, ms);
1103 axisSecondary.StartGuide(dNS * dAlt_N + dEW * dAlt_E, ms);
1108 axisPrimary.StartGuide(dEW, ms);
1109 axisSecondary.StartGuide(dNS, ms);
1115 double rate = GuideRateNP[
DEC_AXIS].getValue();
1118 ms = applyGuideErrors(
DEC_AXIS, rate, ms);
1119 guideAltAzDecomposed(rate, 0.0, ms);
1125 ms = applyGuideErrors(
DEC_AXIS, rate, ms);
1126 axisSecondary.StartGuide(rate, ms);
1134 double rate = -GuideRateNP[
DEC_AXIS].getValue();
1137 ms = applyGuideErrors(
DEC_AXIS, rate, ms);
1138 guideAltAzDecomposed(rate, 0.0, ms);
1144 ms = applyGuideErrors(
DEC_AXIS, rate, ms);
1145 axisSecondary.StartGuide(rate, ms);
1153 double rate = -GuideRateNP[
RA_AXIS].getValue();
1154 ms = applyGuideErrors(
RA_AXIS, rate, ms);
1156 guideAltAzDecomposed(0.0, rate, ms);
1158 axisPrimary.StartGuide(rate, ms);
1165 double rate = GuideRateNP[
RA_AXIS].getValue();
1166 ms = applyGuideErrors(
RA_AXIS, rate, ms);
1168 guideAltAzDecomposed(0.0, rate, ms);
1170 axisPrimary.StartGuide(rate, ms);
1231 m_IsPipelinePrimed =
false;
1232 axisPrimary.Tracking(enabled);
1233 axisSecondary.Tracking(enabled);
1239 axisPrimary.TrackingRateDegSec =
Angle(raRate / 3600.0);
1240 axisSecondary.TrackingRateDegSec =
Angle(deRate / 3600.0);
1251 GuideRateNP.save(fp);
1252 simPierSideSP.save(fp);
1253 mountModelNP.save(fp);
1254 flipHourAngleNP.save(fp);
1255 guideErrorsNP.save(fp);
1256 PACDeviceTP.save(fp);
1264 LOGF_DEBUG(
"Update location %8.3f, %8.3f, %4.0f", latitude, longitude, elevation);
1266 alignment.latitude =
Angle(latitude);
1267 alignment.longitude =
Angle(longitude);
1279 alignment.clockOffsetDays = ln_get_julian_day(utc) - ln_get_julian_from_sys();
1280 LOGF_DEBUG(
"Simulated clock is %.3f s from the system clock", alignment.clockOffsetDays * 86400);
1282 m_IsPipelinePrimed =
false;
1290 return updateMountAndPierSide();
1293bool ScopeSim::updateMountAndPierSide()
1298 if (mountType < 0 || pierSide < 0)
1302 if (mountType == m_MountType && pierSide == m_PierSide)
1305 const int previousMountType = m_MountType;
1306 m_MountType = mountType;
1307 m_PierSide = pierSide;
1309 LOGF_INFO(
"update mount and pier side: Pier Side %s, mount type %d", pierSide == 0 ?
"Off" :
"On", mountType);
1312 int pierSide = PS_ON;
1316 LOG_INFO(
"AltAz mount type experimental");
1340 LOGF_WARN(
"Mount type changed between ALTAZ and equatorial: clearing %d alignment sync point(s) "
1383 LOG_INFO(
"Finding home position...");
1384 m_Home[
AXIS_RA] = alignment.lst().Hours();
1392 LOG_INFO(
"Setting home position to current position.");
1397 LOG_INFO(
"Going to home position.");
void setCorrections(double ih, double id, double ch, double np, double ma, double me)
setCorrections set the values of the six corrections
void instrumentHaDecToMount(Angle instrumentHa, Angle instrumentDec, Angle *primary, Angle *secondary)
void mountToInstrumentHaDec(Angle primary, Angle secondary, Angle *instrumentHa, Angle *instrumentDec)
mountToInstrumentHaDec: convert mount axis positions to instrument (encoder) HA/Dec without applying ...
The Angle class This class implements an angle type. This holds an angle that is always in the range ...
void StartSlew(Angle angle)
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...
bool SkyToTelescopeAltAz(double actualRA, double actualDec, double &mountAlt, double &mountAz, double JD=ln_get_julian_from_sys())
Converts an actual sky location to coordinates to send to the mount, usually called in Goto.
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...
bool TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRA, double &actualDec, double JD=ln_get_julian_from_sys())
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
bool AddAlignmentEntryAltAz(double actualRA, double actualDec, double mountAlt, double mountAz, double JD=ln_get_julian_from_sys())
Adds an alignment point to the model database, usually called from Sync.
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 ...
void RemoveSyncPoint(const AlignmentDatabaseEntry &CandidateEntry, double Tolerance=0.1)
Remove a sync point that falls within the tolerance of a candidate point.
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
bool GetDatabaseReferencePosition(IGeographicCoordinates &Position)
Get the database reference position.
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 SetAlignmentSubsystemActive(bool enable)
SetAlignmentSubsystemActive Enable or Disable alignment subsystem.
void SetApproximateMountAlignmentFromMountType(MountType_t Type)
Call this function to set the ApproximateMountAlignment property of the current Math Plugin....
const TelescopeDirectionVector TelescopeDirectionVectorFromAltitudeAzimuth(INDI::IHorizontalCoordinates HorizontalCoordinates)
Calculates a normalised direction vector from the supplied altitude and azimuth.
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.
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
uint32_t getDriverInterface() const
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
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....
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
int findOnSwitchIndex() const
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 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.
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....
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.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
IGeographicCoordinates m_Location
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
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....
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.
@ TELESCOPE_CAN_HOME_FIND
@ TELESCOPE_HAS_TRACK_RATE
@ TELESCOPE_HAS_PIER_SIDE
@ TELESCOPE_CAN_SET_MOUNT_TYPE
@ TELESCOPE_HAS_TRACK_MODE
@ TELESCOPE_CAN_CONTROL_TRACK
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
The ScopeSim class provides a simple mount simulator of an equatorial mount.
virtual bool ReadScopeStatus() override
Read telescope status.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Execute a homing action.
virtual const char * getDefaultName() override
virtual bool Disconnect() override
Disconnect from device.
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 updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
virtual bool Goto(double, double) override
Move the scope to the supplied RA and DEC coordinates.
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 ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool Park() override
Park the telescope to its home position.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope 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 updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool SetMountType(TelescopeMountType type) override
SetMountType Called when the user selects a different mount type in TELESCOPE_MOUNT_TYPE....
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
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.
TelescopePierSide currentPierSide
INDI::PropertyNumber TrackRateNP
INDI::PropertyNumber EqNP
INDI::PropertySwitch HomeSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertySwitch MountTypeSP
Standard TELESCOPE_MOUNT_TYPE property, indexed by TelescopeMountType. Writable if the driver sets TE...
void sendTimeFromSystem()
INDI::PropertyNumber LocationNP
INDI::PropertyNumber ParkPositionNP
double range180(double r)
range180 Limits an angle to be between -180 to +180 degrees
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[].
Implementations for common driver routines.
void IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_EXTRA1(fmt,...)
#define DEBUGF(priority, msg,...)
#define TRACKRATE_SIDEREAL
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
A little DOM-style library to handle parsing and processing an XML file.
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.
Entry in the in memory alignment database.
double RightAscension
Right ascension in decimal hours. N.B. libnova works in decimal degrees so conversion is always neede...
double ObservationJulianDate
TelescopeDirectionVector TelescopeDirection
Normalised vector giving telescope pointing direction. This is referred to elsewhere as the "apparent...
double Declination
Declination in decimal degrees.
int PrivateDataSize
This size in bytes of any private data.
Holds a normalised direction vector (direction cosines).