Instrument Neutral Distributed Interface INDI 2.2.5
telescope_simulator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7 .
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 .
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include "telescope_simulator.h"
20#include "scopesim_helper.h"
21
22#include "indicom.h"
23#include "lilxml.h"
24
25#include <libnova/julian_day.h>
26
27using namespace INDI::AlignmentSubsystem;
28
29#include <algorithm>
30#include <cmath>
31#include <cstring>
32#include <memory>
33
34// We declare an auto pointer to ScopeSim.
35static std::unique_ptr<ScopeSim> telescope_sim(new ScopeSim());
36
37#define RA_AXIS 0
38#define DEC_AXIS 1
39#define GUIDE_NORTH 0
40#define GUIDE_SOUTH 1
41#define GUIDE_WEST 0
42#define GUIDE_EAST 1
43
45{
46 DBG_SCOPE = static_cast<uint32_t>(INDI::Logger::getInstance().addDebugLevel("Scope Verbose", "SCOPE"));
47
52 4
53 );
54
55 /* initialize random seed: */
56 srand(static_cast<uint32_t>(time(nullptr)));
57
58 // Initialize axes to a safe default (EQ pointing at NCP, counterweight down).
59 // updateMountAndPierSide() sets mount-type-dependent rates when config is loaded.
60 axisPrimary.setDegrees(0.0);
61 axisPrimary.TrackRate(Axis::SIDEREAL);
62 axisSecondary.setDegrees(90.0);
63 axisSecondary.TrackRate(Axis::OFF);
64}
65
67{
68 return "Telescope Simulator";
69}
70
72{
73 /* Make sure to init parent properties first */
75
76#ifdef USE_SIM_TAB
77 // alignment properties, these are in the Simulation tab
78
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",
82 "Simulation", IP_WO, ISR_1OFMANY, 60, IPS_IDLE);
83
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",
91 "Simulation", IP_RW, 0, IPS_IDLE);
92
93 flipHourAngleNP[0].fill("FLIP_HA", "Hour Angle (deg)", "%g", -20, 20, 0.1, 0);
94 flipHourAngleNP.fill(getDeviceName(), "FLIP_HA", "Flip Posn.",
95 "Simulation", IP_WO, 0, IPS_IDLE);
96
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);
99 mountAxisNP.fill(getDeviceName(), "MOUNT_AXES", "Mount Axes",
100 "Simulation", IP_RO, 0, IPS_IDLE);
101
102 // Bad guiding: backlash is pulse time lost after a direction reversal, rate is the
103 // actual axis motion relative to the guide rate, jitter randomly changes each pulse
104 // duration by up to +/- that percentage and drop is the chance a pulse is ignored.
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",
114 "Simulation", IP_RW, 0, IPS_IDLE);
115
116 PACDeviceTP[0].fill("PAC_DEVICE", "Alignment Corrector", "Alignment Correction Simulator");
117 PACDeviceTP.fill(getDeviceName(), "ACTIVE_PAC", "Polar Alignment Corrector", "Simulation", IP_RW, 60, IPS_IDLE);
118 PACDeviceTP.load();
119
120 const char *pacDevice = PACDeviceTP[0].getText();
121 if (pacDevice && strlen(pacDevice) > 0)
122 {
123 IDSnoopDevice(pacDevice, "PAC_MANUAL_ADJUSTMENT");
124 IDSnoopDevice(pacDevice, "CORRECTION_GAIN");
125 }
126
127#endif
128
129 /* How fast do we guide compared to sidereal rate */
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);
132 GuideRateNP.fill(getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RW, 0,
133 IPS_IDLE);
134
135 SlewRateSP[SLEW_GUIDE].fill("SLEW_GUIDE", "Guide", ISS_OFF);
136 SlewRateSP[SLEW_CENTERING].fill("SLEW_CENTERING", "Centering", ISS_OFF);
137 SlewRateSP[SLEW_FIND].fill("SLEW_FIND", "Find", ISS_OFF);
138 SlewRateSP[SLEW_MAX].fill("SLEW_MAX", "Max", ISS_ON);
139 SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB,
141
142 // Add Tracking Modes, the order must match the order of the TelescopeTrackMode enum
143 AddTrackMode("TRACK_SIDEREAL", "Sidereal", true);
144 AddTrackMode("TRACK_SOLAR", "Solar");
145 AddTrackMode("TRACK_LUNAR", "Lunar");
146 AddTrackMode("TRACK_CUSTOM", "Custom");
147
148 // Park data type is set in updateMountAndPierSide() based on the mount type.
149
151
152 /* Add debug controls so we may debug driver if necessary */
154
156
158
160
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);
163 EqPENP.fill(getDeviceName(), "EQUATORIAL_PE", "True Pointing", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE);
164
165 return true;
166}
167
168void ScopeSim::ISGetProperties(const char *dev)
169{
170 /* First we let our parent populate */
172
173#ifdef USE_SIM_TAB
174 // Load mount type settings and apply immediately so axis track rates and
175 // alignment.mountType are correct before the first ReadScopeStatus tick.
176 MountTypeSP.load();
177 MountTypeSP.apply();
178 defineProperty(simPierSideSP);
179 simPierSideSP.load();
180 updateMountAndPierSide();
181 defineProperty(mountModelNP);
182 mountModelNP.load();
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);
186 defineProperty(mountAxisNP);
187 defineProperty(flipHourAngleNP);
188 flipHourAngleNP.load();
189 defineProperty(guideErrorsNP);
190 guideErrorsNP.load();
191 defineProperty(PACDeviceTP);
192 PACDeviceTP.load();
193#endif
194 m_currentAz = axisPrimary.position.Degrees();
195 m_currentAlt = axisSecondary.position.Degrees();
196}
197
199{
200 updateMountAndPierSide();
201
203
204 if (isConnected())
205 {
206 defineProperty(GuideRateNP);
207 GuideRateNP.load();
208 // Always set lat/lon before axis init so instrumentHaDecToMount uses the right location.
209 // updateLocation() is called later by the framework; this ensures it's set now from config.
210 alignment.latitude = Angle(LocationNP[LOCATION_LATITUDE].getValue());
211 alignment.longitude = Angle(LocationNP[LOCATION_LONGITUDE].getValue());
212
213 if (InitPark())
214 {
215 if (isParked())
216 {
217 // at this point there is a valid ParkData.xml available.
218 // For ALTAZ, Axis1=Az (degrees), Axis2=Alt (degrees).
219 // For EQ, Axis1=HA (hours), Axis2=Dec (degrees).
220 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
221 {
222 // Convert stored INDI Az/Alt park position to instrument RA/Dec.
223 Angle instHA, instDec;
224 alignment.mountToInstrumentHaDec(
225 Angle(ParkPositionNP[AXIS_RA].getValue()),
226 Angle(ParkPositionNP[AXIS_DE].getValue()),
227 &instHA, &instDec);
228 m_currentRA = (alignment.lst() - instHA).Hours();
229 m_currentDEC = instDec.Degrees();
230 }
231 else
232 {
233 m_currentRA = (alignment.lst() - Angle(ParkPositionNP[AXIS_RA].getValue(), Angle::ANGLE_UNITS::HOURS)).Hours();
234 m_currentDEC = ParkPositionNP[AXIS_DE].getValue();
235 }
236 }
237 // If loading parking data is successful, we just set the default parking values.
238 // ALTAZ: Az=0 (North horizon), Alt=0. EQ: HA=-6h (counterweight down), Dec=0.
239 double defaultAxis1 = (m_MountType == Alignment::MOUNT_TYPE::ALTAZ) ? 0. : -6.;
240 SetAxis1ParkDefault(defaultAxis1);
242 }
243 else
244 {
245 // Otherwise, we set all parking data to default in case no parking data is found.
246 double defaultAxis1 = (m_MountType == Alignment::MOUNT_TYPE::ALTAZ) ? 0. : -6.;
247 SetAxis1Park(defaultAxis1);
248 SetAxis2Park(0.);
249 SetAxis1ParkDefault(defaultAxis1);
251 }
252
253 // Initialize axis positions from the current RA/Dec (park position if parked,
254 // last known position otherwise) using naive (no Wallace) conversion.
255 // Do NOT call Sync() here — it would add a spurious identity entry to the INDI
256 // alignment database that conflicts with real sync points.
257 // Also seed m_targetRA/Dec so the ALTAZ tracking servo has a valid target from the start.
258 {
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;
268 }
269
270 // A new connection starts from the system clock until the client sets TIME_UTC
271 alignment.clockOffsetDays = 0;
273
274#ifdef USE_SIM_TAB
275 const char *pacDevice = PACDeviceTP[0].getText();
276 if (pacDevice && strlen(pacDevice) > 0)
277 {
278 IDSnoopDevice(pacDevice, "PAC_MANUAL_ADJUSTMENT");
279 IDSnoopDevice(pacDevice, "CORRECTION_GAIN");
280 }
281#endif
282
283 defineProperty(EqPENP);
285 }
286 else
287 {
288 deleteProperty(EqPENP);
289 deleteProperty(GuideRateNP);
290 }
291
293
294 return true;
295}
296
298{
299 LOG_INFO("Telescope simulator is online.");
301
302 return true;
303}
304
306{
307 LOG_INFO("Telescope simulator is offline.");
308 return true;
309}
310
311
312void ScopeSim::updateCurrentCoordsFromAxes()
313{
314 Angle instHA, instDec;
315 alignment.mountToInstrumentHaDec(axisPrimary.position, axisSecondary.position, &instHA, &instDec);
316 m_currentRA = (alignment.lst() - instHA).Hours();
317 m_currentDEC = instDec.Degrees();
318
319 if (GetAlignmentDatabase().size() >= 1)
320 {
321 double corrRA, corrDec;
322 bool corrected = false;
323 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
324 {
325 corrected = TelescopeAltAzToSky(axisSecondary.position.Degrees(),
326 axisPrimary.position.Degrees(), corrRA, corrDec);
327 }
328 else
329 {
330 // Encode the current encoder RA (= LST − HA), not HA, so the TDV
331 // fed into TransformTelescopeToCelestial uses the same time-stable
332 // coordinate that Sync() now stores in the alignment database.
333 double encoderRA = (alignment.lst() - instHA).Hours();
334 INDI::IEquatorialCoordinates raCoords{ encoderRA, instDec.Degrees() };
335 TelescopeDirectionVector tdv =
337 corrected = TransformTelescopeToCelestialJD(tdv, corrRA, corrDec, alignment.julianDate());
338 }
339 if (corrected)
340 {
341 m_currentRA = corrRA;
342 m_currentDEC = corrDec;
343 }
344 }
345}
346
347void ScopeSim::setTargetFromAxisPosition(Angle primary, Angle secondary)
348{
349 Angle instHA, instDec;
350 alignment.mountToInstrumentHaDec(primary, secondary, &instHA, &instDec);
351 m_targetRA = (alignment.lst() - instHA).Hours();
352 m_targetDEC = instDec.Degrees();
353}
354
356{
357 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ && TrackState == SCOPE_TRACKING &&
358 TrackModeSP.findOnSwitchIndex() != TRACK_CUSTOM)
359 {
360 double dt = getCurrentPollingPeriod() / 1000.0;
361 double JDnow = alignment.julianDate();
362 double JDoffset = dt / 86400.0;
363
364 // RA drift rate relative to sidereal for the selected track mode, in hours/sec.
365 // Nudging RA at each parabola sample by the non-sidereal offset makes the
366 // derived Az/Alt rates correct for the track mode without changing the meaning
367 // of m_targetRA/Dec. Mirrors EQ behaviour: RA is corrected, Dec is not.
368 int trackMode = TrackModeSP.findOnSwitchIndex();
369 double raDriftHrsPerSec = 0;
370 if (trackMode == TRACK_SOLAR)
371 raDriftHrsPerSec = (TRACKRATE_SIDEREAL - TRACKRATE_SOLAR) / 3600.0 / 15.0;
372 else if (trackMode == TRACK_LUNAR)
373 raDriftHrsPerSec = (TRACKRATE_SIDEREAL - TRACKRATE_LUNAR) / 3600.0 / 15.0;
374
375 auto getAltAz = [&](double JD, INDI::IHorizontalCoordinates & coords)
376 {
377 double dtFromNow = (JD - JDnow) * 86400.0;
378 INDI::IEquatorialCoordinates eq { m_targetRA + raDriftHrsPerSec * dtFromNow, m_targetDEC };
380 };
381
382 bool targetChanged = std::abs(m_LastTrackingRA - m_targetRA) > 1e-6 ||
383 std::abs(m_LastTrackingDec - m_targetDEC) > 1e-6;
384
385 if (!m_IsPipelinePrimed || targetChanged)
386 {
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;
393 }
394 else
395 {
396 m_TrackingWindowCoords[0] = m_TrackingWindowCoords[1];
397 m_TrackingWindowCoords[1] = m_TrackingWindowCoords[2];
398 getAltAz(JDnow + JDoffset, m_TrackingWindowCoords[2]);
399 }
400
401 // Unwrap azimuth around the center point to avoid 360/0 discontinuity
402 // Angle(x).Degrees() normalizes x to (-180, +180], same as the private Angle::range()
403 auto range180 = [](double x)
404 {
405 return Angle(x).Degrees();
406 };
407 double pAz[3] = { m_TrackingWindowCoords[0].azimuth,
408 m_TrackingWindowCoords[1].azimuth,
409 m_TrackingWindowCoords[2].azimuth
410 };
411 pAz[0] = pAz[1] + range180(pAz[0] - pAz[1]);
412 pAz[2] = pAz[1] + range180(pAz[2] - pAz[1]);
413
414 // Parabolic coefficients (t in normalized units; points at t = -1, 0, +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;
420
421 // Predicted position at next tick (t = +1 normalized = +dt seconds from now)
422 double targetAzNext = az_a + az_b + pAz[1];
423 double targetAltNext = alt_a + alt_b + m_TrackingWindowCoords[1].altitude;
424
425 // Rate to close the gap in exactly dt seconds, converted to arcsec/s for SetTrackRate
426 double azRate = range180(targetAzNext - m_currentAz) / dt * 3600.0;
427 double altRate = (targetAltNext - m_currentAlt) / dt * 3600.0;
428
429 SetTrackRate(azRate, altRate);
430 }
431
432 // new mechanical angle calculation
433 axisPrimary.update();
434 axisSecondary.update();
435
436 publishTruePointing();
437
438 // Raw encoder position: what the mount "reports" without knowing its own errors.
439 // This is what EQUATORIAL_EOD_COORD carries and what the INDI alignment module uses.
440 // Apply INDI alignment correction if sync points exist.
441 updateCurrentCoordsFromAxes();
442
443 // Az/Alt for the ALTAZ tracking servo. The servo (top of ReadScopeStatus) drives the
444 // axis motors; it must compare axis-space positions against axis-space targets. Using
445 // Wallace-corrected (true) Az/Alt here would inject the Wallace error as a permanent
446 // position offset, causing the servo to oscillate every tick. Use raw axis positions.
447 // axisPrimary stores INDI Az (0=North through East), same convention as m_currentAz.
448 m_currentAz = axisPrimary.position.Degrees();
449 m_currentAlt = axisSecondary.position.Degrees();
450
451 // update properties from the axis
452 if (alignment.mountType == Alignment::MOUNT_TYPE::EQ_GEM)
453 {
454 setPierSide(fabs(axisSecondary.position.Degrees()) > 90 ? PIER_WEST : PIER_EAST);
455 }
456
457 bool slewing = axisPrimary.isSlewing || axisSecondary.isSlewing;
458 switch (TrackState)
459 {
460 case SCOPE_PARKING:
461 if (!slewing)
462 {
463 SetParked(true);
464 EqNP.setState(IPS_IDLE);
465 LOG_INFO("Telescope slew is complete. Parked");
466 }
467 break;
468 case SCOPE_SLEWING:
469 if (!slewing)
470 {
471 // It seems to be required that tracking is enabled when a slew finishes but is it correct?
472 // if the mount was not tracking before the slew should it remain not tracking?
474 SetTrackEnabled(true);
475 EqNP.setState(IPS_IDLE);
476
477 if (HomeSP.getState() == IPS_BUSY)
478 {
479 HomeSP.reset();
480 HomeSP.setState(IPS_OK);
481 HomeSP.apply();
482 LOG_INFO("Home position reached.");
483 }
484 else
485 LOG_INFO("Telescope slew is complete. Tracking...");
486
487 // Check slew accuracy in axis space so the result is frame-independent:
488 // m_targetRA/Dec are instrument-frame; m_currentRA/Dec may be alignment-corrected.
489 {
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);
496 }
497
498 }
499 break;
500 case SCOPE_PARKED:
501 return true;
502 default:
503 break;
504 }
505
506 if (guidingEW && !axisPrimary.IsGuiding())
507 {
508 GuideWENP[0].setValue(0);
509 GuideWENP[1].setValue(0);
511 guidingEW = false;
512 }
513
514 if (guidingNS && !axisSecondary.IsGuiding())
515 {
516 GuideNSNP[0].setValue(0);
517 GuideNSNP[1].setValue(0);
519 guidingNS = false;
520 }
521
522#ifdef USE_SIM_TAB
523 double PrimaryAngle = axisPrimary.position.Degrees();
524 double SecondaryAngle = axisSecondary.position.Degrees();
525 // No need to spam log until we have some actual changes.
526 if (std::fabs(mountAxisNP[PRIMARY].getValue() - PrimaryAngle) > 0.0001 ||
527 std::fabs(mountAxisNP[SECONDARY].getValue() - SecondaryAngle) > 0.0001)
528 {
529 mountAxisNP[PRIMARY].setValue(PrimaryAngle);
530 mountAxisNP[SECONDARY].setValue(SecondaryAngle);
531
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());
534
535 mountAxisNP.apply();
536 }
537#endif
538
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);
543
544 NewRaDec(m_currentRA, m_currentDEC);
545
546 return true;
547}
548
549bool ScopeSim::Goto(double r, double d)
550{
551 // When the INDI alignment subsystem has learned sync points, transform the celestial
552 // target through the alignment database so the mount ends up at the right sky position
553 // despite the injected mount errors.
554 //
555 // ALTAZ mounts: the math plugin uses Az/Alt encoding. Decode via SkyToTelescopeAltAz
556 // and set axis slew targets directly in Az/Alt space.
557 //
558 // EQ mounts: the math plugin uses RA/Dec encoding. Decode via
559 // EquatorialCoordinatesFromTelescopeDirectionVector to obtain encoder RA directly,
560 // then pass it to StartSlew which converts it to HA for the axis motor.
561 if (GetAlignmentDatabase().size() >= 1 && m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
562 {
563 double instrumentAlt, instrumentAz_INDI;
564 if (SkyToTelescopeAltAz(r, d, instrumentAlt, instrumentAz_INDI))
565 {
566 axisPrimary.StartSlew(Angle(instrumentAz_INDI));
567 axisSecondary.StartSlew(Angle(instrumentAlt));
568
569 // m_targetRA/Dec must be the instrument position (not celestial) so the ALTAZ
570 // tracking servo's getAltAz() computes instrument Az/Alt rates, not celestial.
571 setTargetFromAxisPosition(Angle(instrumentAz_INDI), Angle(instrumentAlt));
572
574 EqNP.setState(IPS_BUSY);
575 LOGF_INFO("Slewing to RA: %.4f Dec: %.4f", m_targetRA, m_targetDEC);
576 return true;
577 }
578 }
579
580 double targetRA = r, targetDec = d;
581 if (GetAlignmentDatabase().size() >= 1)
582 {
584 if (TransformCelestialToTelescopeJD(r, d, alignment.julianDate(), tdv))
585 {
586 // The TDV now encodes encoder RA (time-stable), so decode with
587 // EquatorialCoordinatesFromTelescopeDirectionVector — no LST conversion needed.
590 targetRA = raCoords.rightascension;
591 targetDec = raCoords.declination;
592 LOGF_INFO("EQ Goto: alignment corrected RA %.4fh Dec %.4f -> RA %.4fh Dec %.4f",
593 r, d, targetRA, targetDec);
594 }
595 else
596 {
597 LOG_WARN("EQ Goto: TransformCelestialToTelescope FAILED, using raw coordinates");
598 }
599 }
600
601 StartSlew(targetRA, targetDec, SCOPE_SLEWING);
602 return true;
603}
604
605bool ScopeSim::Sync(double ra, double dec)
606{
607 // The INDI alignment math plugins encode telescope directions as:
608 // - ALTAZ (ZENITH) mounts: Az/Alt via TelescopeDirectionVectorFromAltitudeAzimuth
609 // - EQ mounts: RA/Dec via TelescopeDirectionVectorFromEquatorialCoordinates
610 // Using encoder RA (= LST − HA, time-stable during sidereal tracking) ensures the
611 // stored offset sky_RA − encoder_RA remains constant across iterations, so successive
612 // sync+goto cycles converge rather than diverging.
613
615 entry.ObservationJulianDate = alignment.julianDate();
616 entry.RightAscension = ra;
617 entry.Declination = dec;
618 entry.PrivateDataSize = 0;
619
620 const bool altAz = (m_MountType == Alignment::MOUNT_TYPE::ALTAZ);
621 const double indi_az = axisPrimary.position.Degrees();
622 const double indi_alt = axisSecondary.position.Degrees();
623 if (altAz)
624 {
625 INDI::IHorizontalCoordinates altAzCoords { indi_az, indi_alt };
627 }
628 else
629 {
630 // EQ mounts: encode the raw encoder RA/Dec as the telescope direction.
631 // Use RA (= LST − HA), not HA, so the stored offset is time-stable.
632 // HA changes at the sidereal rate even during tracking; encoder RA does not.
633 // Storing HA causes the correction to drift by ~15 arcsec/s, accumulating
634 // error over successive alignment iterations.
635 Angle instHA, instDec;
636 alignment.mountToInstrumentHaDec(axisPrimary.position, axisSecondary.position,
637 &instHA, &instDec);
638
639 double encoderRA = (alignment.lst() - instHA).Hours();
640 INDI::IEquatorialCoordinates raCoords{ encoderRA, instDec.Degrees() };
642 }
643
644 // A new sync supersedes older sync points at (nearly) the same place: the latest plate solve is the
645 // better measurement. Previously the new point was silently dropped as a duplicate while this function
646 // still reported success, so re-syncing near an existing point had no effect on the pointing model.
647 // ALTAZ entries need the geographic reference position (see AddAlignmentEntryAltAz); without it
648 // nothing is stored and the existing points are kept.
649 INDI::IGeographicCoordinates referencePosition;
650 if (altAz && !GetDatabaseReferencePosition(referencePosition))
651 {
652 LOG_WARN("Sync not stored in the alignment database: geographic location is not known yet.");
653 }
654 else
655 {
656 const size_t before = GetAlignmentDatabase().size();
657 RemoveSyncPoint(entry);
658 const int replaced = static_cast<int>(before - GetAlignmentDatabase().size());
659
660 if (altAz)
661 AddAlignmentEntryAltAz(ra, dec, indi_alt, indi_az); // handles DB + Initialise
662 else
663 {
664 GetAlignmentDatabase().push_back(entry);
665 UpdateSize();
666 Initialise(this);
667 }
668
669 if (replaced > 0)
670 LOGF_INFO("Sync replaced %d older alignment point(s) at the same position.", replaced);
671 }
672
673 // Keep the ALTAZ tracking servo on the current instrument position after sync.
674 setTargetFromAxisPosition(axisPrimary.position, axisSecondary.position);
675
676 LOGF_DEBUG("Sync at RA %f Dec %f m_targetRA %f m_targetDEC %f",
677 ra, dec, m_targetRA, m_targetDEC);
678
679 LOG_INFO("Sync is successful.");
680
681 EqNP.setState(IPS_OK);
682 NewRaDec(m_currentRA, m_currentDEC);
683
684 return true;
685}
686
688{
689 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
690 {
691 // For ALTAZ, park position is stored as INDI Az (degrees) / Alt (degrees).
692 // Convert directly to axis positions and slew; do not go through StartSlew's
693 // HA/Dec path which treats Axis1 as hours.
694 Angle indi_az = Angle(GetAxis1Park());
695 Angle alt = Angle(GetAxis2Park());
696 axisPrimary.StartSlew(indi_az);
697 axisSecondary.StartSlew(alt);
698 setTargetFromAxisPosition(indi_az, alt);
700 EqNP.setState(IPS_BUSY);
701 LOG_INFO("Parking...");
702 }
703 else
704 {
705 double ra = (alignment.lst() - Angle(GetAxis1Park() * 15.)).Degrees() / 15.;
706 StartSlew(ra, GetAxis2Park(), SCOPE_PARKING);
707 }
708 return true;
709}
710
711// common code for GoTo and park
712void ScopeSim::StartSlew(double ra, double dec, TelescopeStatus status)
713{
714 // Naive axis conversion: no Wallace corrections. The mount slews to where its
715 // encoders say, unaware of its own IH/ID/etc. errors — just like a real mount.
716 Angle ha = alignment.lst() - Angle(ra * 15.0);
717 Angle primary, secondary;
718 alignment.instrumentHaDecToMount(ha, Angle(dec), &primary, &secondary);
719
720 axisPrimary.StartSlew(primary);
721 axisSecondary.StartSlew(secondary);
722
723 // Store instrument-frame RA/Dec so the ALTAZ tracking servo always works
724 // in a consistent coordinate frame, regardless of how StartSlew was called.
725 setTargetFromAxisPosition(primary, secondary);
726 char RAStr[64], DecStr[64];
727
728 fs_sexa(RAStr, m_targetRA, 2, 3600);
729 fs_sexa(DecStr, m_targetDEC, 2, 3600);
730
731 const char * statusStr;
732 switch (status)
733 {
734 case SCOPE_PARKING:
735 statusStr = "Parking";
736 break;
737 case SCOPE_SLEWING:
738 statusStr = "Slewing";
739 break;
740 default:
741 statusStr = "unknown";
742 }
743 TrackState = status;
744
745 LOGF_INFO("%s to RA: %s - DEC: %s", statusStr, RAStr, DecStr);
746}
747
749{
750 SetParked(false);
751 return true;
752}
753
754bool ScopeSim::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
755{
756 // Check guider interface
757 if (GI::processNumber(dev, name, values, names, n))
758 return true;
759
760 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
761 {
762 if (strcmp(name, "GUIDE_RATE") == 0)
763 {
764 GuideRateNP.update(values, names, n);
765 GuideRateNP.setState(IPS_OK);
766 GuideRateNP.apply();
767 return true;
768 }
769
770#ifdef USE_SIM_TAB
771 if (mountModelNP.isNameMatch(name))
772 {
773 if (mountModelNP.isUpdated(values, names, n))
774 {
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);
779 saveConfig(mountModelNP);
780 }
781 mountModelNP.setState(IPS_OK);
782 mountModelNP.apply();
783 return true;
784 }
785
786 if (flipHourAngleNP.isNameMatch(name))
787 {
788 flipHourAngleNP.update(values, names, n);
789 flipHourAngleNP.setState(IPS_OK);
790 flipHourAngleNP.apply();
791 alignment.setFlipHourAngle(flipHourAngleNP[0].getValue());
792 return true;
793 }
794 if (guideErrorsNP.isNameMatch(name))
795 {
796 guideErrorsNP.update(values, names, n);
797 guideErrorsNP.setState(IPS_OK);
798 guideErrorsNP.apply();
799 saveConfig(guideErrorsNP);
800 return true;
801 }
802#endif
803 }
804
805 ProcessAlignmentNumberProperties(this, name, values, names, n);
806
807 // if we didn't process it, continue up the chain, let somebody else
808 // give it a shot
809 return INDI::Telescope::ISNewNumber(dev, name, values, names, n);
810}
811
812bool ScopeSim::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
813{
814 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
815 {
816#ifdef USE_SIM_TAB
817 if (simPierSideSP.isNameMatch(name))
818 {
819 if (!simPierSideSP.update(states, names, n))
820 return false;
821
822 simPierSideSP.setState(IPS_OK);
823 simPierSideSP.apply();
824 updateMountAndPierSide();
825 return true;
826 }
827#endif \
828 // Slew mode
829 if (SlewRateSP.isNameMatch(name))
830 {
831 if (SlewRateSP.update( states, names, n) == false)
832 return false;
833
834 SlewRateSP.setState(IPS_OK);
835 SlewRateSP.apply();
836 return true;
837 }
838 }
839
840 ProcessAlignmentSwitchProperties(this, name, states, names, n);
841
842 // Persist alignment plugin and active state immediately when changed.
843 // Use a full saveConfig() — the selective form (saveConfig(true, name)) only
844 // patches the named property in the existing XML and skips CURRENT_MATH_PLUGIN.
845 if (strcmp(name, "ALIGNMENT_SUBSYSTEM_MATH_PLUGINS") == 0 ||
846 strcmp(name, "ALIGNMENT_SUBSYSTEM_ACTIVE") == 0)
847 saveConfig();
848
849 // Nobody has claimed this, so pass it over
850 return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
851}
852
853bool ScopeSim::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
854{
855#ifdef USE_SIM_TAB
856 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
857 {
858 if (PACDeviceTP.isNameMatch(name))
859 {
860 PACDeviceTP.setState(IPS_OK);
861 PACDeviceTP.update(texts, names, n);
862 PACDeviceTP.apply();
863
864 // A PAC without CORRECTION_GAIN makes the full move
865 m_snoopedGain = 1.0;
866 m_PACMoveActive = false;
867
868 const char *pacDevice = PACDeviceTP[0].getText();
869 if (pacDevice && strlen(pacDevice) > 0)
870 {
871 IDSnoopDevice(pacDevice, "PAC_MANUAL_ADJUSTMENT");
872 IDSnoopDevice(pacDevice, "CORRECTION_GAIN");
873 }
874
875 saveConfig(PACDeviceTP);
876 return true;
877 }
878 }
879#endif
880 ProcessAlignmentTextProperties(this, name, texts, names, n);
881 return INDI::Telescope::ISNewText(dev, name, texts, names, n);
882}
883
884#ifdef USE_SIM_TAB
885void ScopeSim::applyPACCorrection()
886{
887 // The steps move the polar axis like a real PAC: a positive azimuth step moves it East, a positive altitude
888 // step raises it. MM_MA > 0 means the axis is west of the pole and MM_ME > 0 that it is too low, so a move
889 // East or up reduces them. Clients send the correction, i.e. the negative of the measured error.
890 // The azimuth step is in degrees of azimuth. Near the pole a degree of azimuth spans cos(latitude) degrees
891 // on the sky, which is what MM_MA measures. The gain simulates a PAC that moves less than requested.
892 const double cosLat = std::cos(alignment.latitude.radians());
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;
897
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);
903
904 mountModelNP.setState(IPS_OK);
905 mountModelNP.apply();
906
907 LOGF_INFO("Applied PAC correction: MA %.4f -> %.4f, ME %.4f -> %.4f (arcmin, gain %.0f%%)",
908 oldMA, newMA, oldME, newME, m_snoopedGain * 100);
909
910 // Publish the new true pointing right away instead of at the next ReadScopeStatus,
911 // so the CCD simulator has it long before the PAC reports the move complete.
912 publishTruePointing();
913 updateCurrentCoordsFromAxes();
914 NewRaDec(m_currentRA, m_currentDEC);
915}
916#endif
917
918void ScopeSim::publishTruePointing()
919{
920 // True pointing: apply Wallace error injection to get where the scope physically points.
921 // Published as EQUATORIAL_PE so the CCD simulator generates star fields at this position.
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());
926 EqPENP.setState(IPS_OK);
927 EqPENP.apply();
928}
929
931{
932#ifdef USE_SIM_TAB
933 const char *propName = findXMLAttValu(root, "name");
934 const char *deviceName = findXMLAttValu(root, "device");
935 const char *pacDevice = PACDeviceTP[0].getText();
936
937 if (pacDevice && strlen(pacDevice) > 0 && deviceName && strcmp(deviceName, pacDevice) == 0)
938 {
939 if (!strcmp(propName, "PAC_MANUAL_ADJUSTMENT"))
940 {
941 // Capture the step values (AZ and ALT) whenever the property is updated.
942 // PAC_MANUAL_ADJUSTMENT[MANUAL_AZ_STEP] > 0 → East, < 0 → West
943 // PAC_MANUAL_ADJUSTMENT[MANUAL_ALT_STEP] > 0 → North, < 0 → South
944 XMLEle *ep = nullptr;
945 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
946 {
947 const char *elemName = findXMLAttValu(ep, "name");
948 if (!strcmp(elemName, "MANUAL_AZ_STEP"))
949 m_snoopedAzError = atof(pcdataXMLEle(ep));
950 else if (!strcmp(elemName, "MANUAL_ALT_STEP"))
951 m_snoopedAltError = atof(pcdataXMLEle(ep));
952 }
953
954 // Apply each move once, when the PAC starts it (state = Busy). A client takes its next frame as
955 // soon as it sees the move complete (state = Ok), and the CCD simulator renders a frame when the
956 // exposure starts. Applying the move on Ok raced with that frame, which then showed the old position.
957 // A move the driver completes at once (e.g. 0/0) reports Ok without Busy and moves nothing.
958 const char *stateStr = findXMLAttValu(root, "state");
959 const bool busy = stateStr && !strcmp(stateStr, "Busy");
960 if (busy && !m_PACMoveActive)
961 applyPACCorrection();
962 m_PACMoveActive = busy;
963 return true;
964 }
965
966 if (!strcmp(propName, "CORRECTION_GAIN"))
967 {
968 for (XMLEle *ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
969 {
970 if (!strcmp(findXMLAttValu(ep, "name"), "GAIN"))
971 m_snoopedGain = atof(pcdataXMLEle(ep)) / 100.0;
972 }
973 return true;
974 }
975 }
976#endif
978}
979
981{
982 axisPrimary.Abort();
983 axisSecondary.Abort();
986 return true;
987}
988
990{
992 {
993 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
994 return false;
995 }
996 mcRate = static_cast<int>(SlewRateSP.findOnSwitchIndex()) + 1;
997 mcRate = std::max(1, std::min(4, mcRate));
998
999 int rate = (dir == INDI_DIR_NS::DIRECTION_NORTH) ? mcRate : -mcRate;
1000 if (HasPierSide() && (currentPierSide == PIER_WEST)) // see scopesim_helper.cpp: alignment
1001 rate = -rate;
1002 LOGF_DEBUG("MoveNS dir %s, motion %s, rate %d", dir == DIRECTION_NORTH ? "N" : "S", command == 0 ? "start" : "stop", rate);
1003
1004 axisSecondary.mcRate = command == MOTION_START ? rate : 0;
1005
1006 return true;
1007}
1008
1010{
1011 if (TrackState == SCOPE_PARKED)
1012 {
1013 LOG_ERROR("Please unpark the mount before issuing any motion commands.");
1014 return false;
1015 }
1016
1017 mcRate = static_cast<int>(SlewRateSP.findOnSwitchIndex()) + 1;
1018 mcRate = std::max(1, std::min(4, mcRate));
1019
1020 int rate = (dir == INDI_DIR_WE::DIRECTION_EAST) ? -mcRate : mcRate;
1021 LOGF_DEBUG("MoveWE dir %d, motion %s, rate %d", dir == DIRECTION_EAST ? "E" : "W", command == 0 ? "start" : "stop", rate);
1022
1023 axisPrimary.mcRate = command == MOTION_START ? rate : 0;
1024 return true;
1025}
1026
1027uint32_t ScopeSim::applyGuideErrors(int axis, double &rate, uint32_t ms)
1028{
1029 const char *axisName = (axis == RA_AXIS) ? "RA" : "DEC";
1030 std::uniform_real_distribution<double> uniform(0.0, 1.0);
1031
1032 // A dropped pulse never reaches the motor, so it leaves the backlash state alone.
1033 if (uniform(m_GuideRng) * 100 < guideErrorsNP[GE_DROP_RA + axis].getValue())
1034 {
1035 LOGF_DEBUG("%s guide pulse of %u ms dropped.", axisName, ms);
1036 return 0;
1037 }
1038
1039 const double jitter = guideErrorsNP[GE_JITTER_RA + axis].getValue();
1040 if (jitter > 0)
1041 {
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);
1045 }
1046
1047 // In milliseconds. Doesn't depend on guide rate.
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])
1052 {
1053 if (remaining == 0)
1054 remaining = backlash;
1055 else if (remaining >= backlash)
1056 remaining = 0;
1057 else
1058 remaining = backlash - remaining;
1059 }
1060 m_GuideLastPositive[axis] = positive;
1061
1062 const uint32_t taken = std::min(remaining, ms);
1063 if (taken > 0)
1064 {
1065 remaining -= taken;
1066 ms -= taken;
1067 LOGF_DEBUG("%s backlash took %u ms of the guide pulse, %u ms left to clear.", axisName, taken, remaining);
1068 }
1069
1070 rate *= guideErrorsNP[GE_RATE_RA + axis].getValue() / 100.0;
1071 return ms;
1072}
1073
1074void ScopeSim::guideAltAzDecomposed(double dNS, double dEW, uint32_t ms)
1075{
1076 // Decompose a celestial N/S/E/W guide pulse into Az/Alt axis components using
1077 // the parallactic angle q. sinQ = sin(q)/cos(alt), cosQ = cos(q)/cos(alt).
1078 // The azimuth rate for celestial North is -sin(q)/cos(alt); since sinQ already
1079 // carries one 1/cos(alt), dAz_N = -sinQ/cosAlt gives -sin(q)/cos^2(alt), which
1080 // is the correct field rotation formula.
1081 //
1082 // Celestial North in Az/Alt: dAlt = cos(q), dAz = -sin(q)/cos(alt)
1083 // Celestial East in Az/Alt: dAlt = sin(q), dAz = cos(q)/cos(alt)
1084
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);
1090
1091 if (std::abs(cosAlt) > 1e-4)
1092 {
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);
1096
1097 double dAlt_N = cosQ;
1098 double dAz_N = -sinQ / cosAlt;
1099 double dAlt_E = sinQ;
1100 double dAz_E = cosQ / cosAlt;
1101
1102 axisPrimary.StartGuide(dNS * dAz_N + dEW * dAz_E, ms);
1103 axisSecondary.StartGuide(dNS * dAlt_N + dEW * dAlt_E, ms);
1104 }
1105 else
1106 {
1107 // Near zenith: Az is degenerate; fall back to direct axis motion.
1108 axisPrimary.StartGuide(dEW, ms);
1109 axisSecondary.StartGuide(dNS, ms);
1110 }
1111}
1112
1114{
1115 double rate = GuideRateNP[DEC_AXIS].getValue();
1116 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
1117 {
1118 ms = applyGuideErrors(DEC_AXIS, rate, ms);
1119 guideAltAzDecomposed(rate, 0.0, ms);
1120 }
1121 else
1122 {
1123 if (HasPierSide() && (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
1124 rate = -rate;
1125 ms = applyGuideErrors(DEC_AXIS, rate, ms);
1126 axisSecondary.StartGuide(rate, ms);
1127 }
1128 guidingNS = true;
1129 return IPS_BUSY;
1130}
1131
1133{
1134 double rate = -GuideRateNP[DEC_AXIS].getValue();
1135 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
1136 {
1137 ms = applyGuideErrors(DEC_AXIS, rate, ms);
1138 guideAltAzDecomposed(rate, 0.0, ms);
1139 }
1140 else
1141 {
1142 if (HasPierSide() && (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
1143 rate = -rate;
1144 ms = applyGuideErrors(DEC_AXIS, rate, ms);
1145 axisSecondary.StartGuide(rate, ms);
1146 }
1147 guidingNS = true;
1148 return IPS_BUSY;
1149}
1150
1152{
1153 double rate = -GuideRateNP[RA_AXIS].getValue();
1154 ms = applyGuideErrors(RA_AXIS, rate, ms);
1155 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
1156 guideAltAzDecomposed(0.0, rate, ms);
1157 else
1158 axisPrimary.StartGuide(rate, ms);
1159 guidingEW = true;
1160 return IPS_BUSY;
1161}
1162
1164{
1165 double rate = GuideRateNP[RA_AXIS].getValue();
1166 ms = applyGuideErrors(RA_AXIS, rate, ms);
1167 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
1168 guideAltAzDecomposed(0.0, rate, ms);
1169 else
1170 axisPrimary.StartGuide(rate, ms);
1171 guidingEW = true;
1172 return IPS_BUSY;
1173}
1174
1176{
1177 if (m_MountType == Alignment::MOUNT_TYPE::ALTAZ)
1178 {
1179 // Store INDI Az (0=North) and Alt in degrees.
1180 SetAxis1Park(m_currentAz);
1181 SetAxis2Park(m_currentAlt);
1182 }
1183 else
1184 {
1185 double ha = (alignment.lst() - Angle(m_currentRA, Angle::ANGLE_UNITS::HOURS)).Hours();
1186 SetAxis1Park(ha);
1187 SetAxis2Park(m_currentDEC);
1188 }
1189 return true;
1190}
1191
1193{
1194 // mount points to East (counterweights down) at the horizon
1195 // works for both hemispheres
1196 SetAxis1Park(-6.);
1197 SetAxis2Park(0.);
1198
1199 return true;
1200}
1201
1202bool ScopeSim::SetTrackMode(uint8_t mode)
1203{
1204 switch (static_cast<TelescopeTrackMode>(mode))
1205 {
1206 case TRACK_SIDEREAL:
1207 axisPrimary.TrackRate(Axis::SIDEREAL);
1208 if (m_MountType != Alignment::MOUNT_TYPE::ALTAZ)
1209 axisSecondary.TrackRate(Axis::OFF);
1210 return true;
1211 case TRACK_SOLAR:
1212 axisPrimary.TrackRate(Axis::SOLAR);
1213 if (m_MountType != Alignment::MOUNT_TYPE::ALTAZ)
1214 axisSecondary.TrackRate(Axis::OFF);
1215 return true;
1216 case TRACK_LUNAR:
1217 axisPrimary.TrackRate(Axis::LUNAR);
1218 if (m_MountType != Alignment::MOUNT_TYPE::ALTAZ)
1219 axisSecondary.TrackRate(Axis::OFF);
1220 return true;
1221 case TRACK_CUSTOM:
1222 SetTrackRate(TrackRateNP[AXIS_RA].getValue(), TrackRateNP[AXIS_DE].getValue());
1223 return true;
1224 }
1225 return false;
1226}
1227
1229{
1230 if (enabled)
1231 m_IsPipelinePrimed = false;
1232 axisPrimary.Tracking(enabled);
1233 axisSecondary.Tracking(enabled);
1234 return true;
1235}
1236
1237bool ScopeSim::SetTrackRate(double raRate, double deRate)
1238{
1239 axisPrimary.TrackingRateDegSec = Angle(raRate / 3600.0);
1240 axisSecondary.TrackingRateDegSec = Angle(deRate / 3600.0);
1241 return true;
1242}
1243
1245{
1247
1249
1250#ifdef USE_SIM_TAB
1251 GuideRateNP.save(fp);
1252 simPierSideSP.save(fp);
1253 mountModelNP.save(fp);
1254 flipHourAngleNP.save(fp);
1255 guideErrorsNP.save(fp);
1256 PACDeviceTP.save(fp);
1257
1258#endif
1259 return true;
1260}
1261
1262bool ScopeSim::updateLocation(double latitude, double longitude, double elevation)
1263{
1264 LOGF_DEBUG("Update location %8.3f, %8.3f, %4.0f", latitude, longitude, elevation);
1265
1266 alignment.latitude = Angle(latitude);
1267 alignment.longitude = Angle(longitude);
1268
1269 UpdateLocation(latitude, longitude, elevation);
1270 return true;
1271}
1272
1273bool ScopeSim::updateTime(ln_date *utc, double utc_offset)
1274{
1275 INDI_UNUSED(utc_offset);
1276
1277 // Follow the client's clock: the sky (LST, hour angle, pier side) moves on from the time the client set,
1278 // so it agrees with the client instead of the system clock
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);
1281 // The ALTAZ tracking servo predicts from Az/Alt samples taken at the old time; sample again
1282 m_IsPipelinePrimed = false;
1283 return true;
1284}
1285
1287{
1289 // Telescope has already selected the requested type in MountTypeSP.
1290 return updateMountAndPierSide();
1291}
1292
1293bool ScopeSim::updateMountAndPierSide()
1294{
1295#ifdef USE_SIM_TAB
1296 int mountType = MountTypeSP.findOnSwitchIndex();
1297 int pierSide = simPierSideSP.findOnSwitchIndex();
1298 if (mountType < 0 || pierSide < 0)
1299 return false;
1300
1301 // If nothing changed, return
1302 if (mountType == m_MountType && pierSide == m_PierSide)
1303 return true;
1304
1305 const int previousMountType = m_MountType;
1306 m_MountType = mountType;
1307 m_PierSide = pierSide;
1308
1309 LOGF_INFO("update mount and pier side: Pier Side %s, mount type %d", pierSide == 0 ? "Off" : "On", mountType);
1310#else
1311 int mountType = static_cast<int>(Alignment::MOUNT_TYPE::EQ_GEM);
1312 int pierSide = PS_ON;
1313#endif
1314 if ( mountType == Alignment::MOUNT_TYPE::ALTAZ)
1315 {
1316 LOG_INFO("AltAz mount type experimental");
1317 // return false;
1318 }
1319
1320 alignment.mountType = static_cast<Alignment::MOUNT_TYPE>(mountType);
1321
1322 // Tell the INDI alignment subsystem whether this is an equatorial or ALTAZ mount.
1323 // Without this, the math plugin always fits an ALTAZ model regardless of mount type.
1325 alignment.mountType == Alignment::MOUNT_TYPE::ALTAZ
1328
1329#ifdef USE_SIM_TAB
1330 // Sync points store the telescope direction in the encoding of the mount geometry that was active
1331 // when they were taken: Az/Alt for ALTAZ, encoder RA/Dec for the equatorial types (see Sync()).
1332 // After switching between ALTAZ and an equatorial type, those entries are decoded with the wrong
1333 // encoding and every GoTo lands at an unrelated sky position. They cannot be re-encoded reliably,
1334 // so drop them. EQ_GEM <-> EQ_FORK share the RA/Dec encoding and keep their sync points.
1335 // previousMountType is -1 during initial config load, so a restored database is never discarded.
1336 const bool wasAltAz = (previousMountType == Alignment::MOUNT_TYPE::ALTAZ);
1337 const bool isAltAz = (mountType == Alignment::MOUNT_TYPE::ALTAZ);
1338 if (previousMountType >= 0 && wasAltAz != isAltAz && !GetAlignmentDatabase().empty())
1339 {
1340 LOGF_WARN("Mount type changed between ALTAZ and equatorial: clearing %d alignment sync point(s) "
1341 "recorded for the previous mount geometry.", static_cast<int>(GetAlignmentDatabase().size()));
1342 GetAlignmentDatabase().clear();
1343 UpdateSize();
1344 Initialise(this);
1345 }
1346#endif
1347
1348 // Set the park data type appropriate for the mount geometry.
1349 if (mountType == static_cast<int>(Alignment::MOUNT_TYPE::ALTAZ))
1351 else
1353
1354 // Reinitialize the secondary axis track rate for the selected mount type.
1355 // ALTAZ: both axes need sidereal rate (overridden each tick by parabolic tracking).
1356 // EQ: primary tracks sidereal, secondary (Dec) is driven only when slewing.
1357 if (mountType == Alignment::MOUNT_TYPE::ALTAZ)
1358 axisSecondary.TrackRate(Axis::SIDEREAL);
1359 else
1360 axisSecondary.TrackRate(Axis::OFF);
1361
1362 // update the pier side capability depending on the mount type
1363 uint32_t cap = GetTelescopeCapability();
1364 if (pierSide == PS_ON && mountType == static_cast<int>(Alignment::MOUNT_TYPE::EQ_GEM))
1365 {
1367 }
1368 else
1369 {
1370 cap &= ~static_cast<uint32_t>(TELESCOPE_HAS_PIER_SIDE);
1371 }
1372 SetTelescopeCapability(cap, 4);
1373
1374 return true;
1375}
1376
1377
1379{
1380 switch (action)
1381 {
1382 case HOME_FIND:
1383 LOG_INFO("Finding home position...");
1384 m_Home[AXIS_RA] = alignment.lst().Hours();
1385 m_Home[AXIS_DE] = LocationNP[LOCATION_LATITUDE].getValue() > 0 ? 90 : -90;
1386 Goto(m_Home[AXIS_RA], m_Home[AXIS_DE]);
1387 return IPS_BUSY;
1388
1389 case HOME_SET:
1390 m_Home[AXIS_RA] = (alignment.lst() - Angle(EqNP[AXIS_RA].getValue(), Angle::HOURS)).HoursHa();
1391 m_Home[AXIS_DE] = EqNP[AXIS_DE].getValue();
1392 LOG_INFO("Setting home position to current position.");
1393 return IPS_OK;
1394
1395 case HOME_GO:
1396 {
1397 LOG_INFO("Going to home position.");
1398 if (m_Home[AXIS_RA] == 0)
1399 {
1400 m_Home[AXIS_RA] = 0;
1401 m_Home[AXIS_DE] = LocationNP[LOCATION_LATITUDE].getValue() > 0 ? 90 : -90;
1402 }
1403
1404 // Home HA to home RA
1405 auto ra = (alignment.lst() - Angle(m_Home[AXIS_RA], Angle::HOURS)).Hours();
1406 Goto(ra, m_Home[AXIS_DE]);
1407 return IPS_BUSY;
1408 }
1409
1410 default:
1411 return IPS_ALERT;
1412 }
1413 return IPS_ALERT;
1414}
1415
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 ...
double radians()
radians
double Hours()
Hours.
double Degrees()
Degrees.
void StartSlew(Angle angle)
Angle position
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.
bool isConnected() const
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
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.
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.
#define M_PI
Definition dsp.h:52
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...
INDI::PropertyNumber LocationNP
INDI::PropertyNumber ParkPositionNP
double ra
double dec
#define RA_AXIS
#define DEC_AXIS
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
@ IP_WO
Definition indiapi.h:183
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
@ ISR_1OFMANY
Definition indiapi.h:171
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
@ DIRECTION_EAST
INDI_DIR_NS
@ DIRECTION_NORTH
double range180(double r)
range180 Limits an angle to be between -180 to +180 degrees
Definition indicom.c:1331
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.
#define INDI_UNUSED(x)
Definition indidevapi.h:132
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...
Definition indidriver.c:143
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_WARN(fmt,...)
Definition indilogger.h:81
#define LOG_WARN(txt)
Definition indilogger.h:73
#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 LOG_INFO(txt)
Definition indilogger.h:74
#define LOGF_EXTRA1(fmt,...)
Definition indilogger.h:84
#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
INumber eq[]
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
Definition lilxml.cpp:644
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
Definition lilxml.cpp:555
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Definition lilxml.cpp:606
A little DOM-style library to handle parsing and processing an XML file.
struct xml_ele_ XMLEle
Definition lilxml.h:81
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
uint16_t type
Definition pwc-ioctl.h:0
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