Instrument Neutral Distributed Interface INDI 2.2.5
MathPlugin.cpp
Go to the documentation of this file.
1
9#include "MathPlugin.h"
10
11#include <indicom.h>
12#include <libnova/julian_day.h>
13
14#include <cmath>
15
16namespace INDI
17{
18namespace AlignmentSubsystem
19{
20bool MathPlugin::TransformCelestialToTelescopeJD(double RightAscension, double Declination,
21 double JulianDate, TelescopeDirectionVector &ApparentTelescopeDirectionVector)
22{
23 return TransformCelestialToTelescope(RightAscension, Declination,
24 JulianDate - ln_get_julian_from_sys(), ApparentTelescopeDirectionVector);
25}
26
27bool MathPlugin::TransformTelescopeToCelestialJD(const TelescopeDirectionVector &ApparentTelescopeDirectionVector,
28 double &RightAscension, double &Declination, double JulianDate)
29{
30 return TransformTelescopeToCelestial(ApparentTelescopeDirectionVector, RightAscension, Declination,
31 JulianDate - ln_get_julian_from_sys());
32}
33
40
42{
43 if (!pDb) return;
44
45 // Threshold in degrees for celestial Dec (EQ) or encoder El (altaz).
46 // For EQ, 88 deg catches the truly degenerate zone where cos(Dec)->0
47 // while leaving multi-point models that include near-pole coverage intact.
48 static constexpr double kPolarThresholdDeg = 88.0;
49 // Shift degenerate entries so that celestial Dec (EQ) or encoder El
50 // (altaz) ends up at this value, well within the conditioned region.
51 static constexpr double kTargetPitchDeg = 80.0;
52
53 auto &db = pDb->GetAlignmentDatabase();
55 bool haveLoc = pDb->GetDatabaseReferencePosition(location);
56
58
59 for (auto &entry : db)
60 {
61 if (mountAlignment == ZENITH)
62 {
63 // Altaz: degeneracy at the zenith -- check encoder El via TDV.z
64 double sinThresh = std::sin(DEG_TO_RAD(kPolarThresholdDeg));
65 if (std::abs(entry.TelescopeDirection.z) < sinThresh)
66 continue;
67
68 if (!haveLoc) continue;
69
70 double currentPitchDeg = RAD_TO_DEG(std::asin(entry.TelescopeDirection.z));
71 double targetPitch = (currentPitchDeg >= 0) ? kTargetPitchDeg : -kTargetPitchDeg;
72 double deltaDeg = currentPitchDeg - targetPitch;
73
74 INDI::IEquatorialCoordinates celEq { entry.RightAscension, entry.Declination };
76 EquatorialToHorizontal(&celEq, &location,
77 entry.ObservationJulianDate, &hor);
78
79 double newEl = hor.altitude - deltaDeg;
80 if (newEl < 20.0) newEl = 20.0;
81 if (newEl > kPolarThresholdDeg) newEl = kPolarThresholdDeg;
82
83 INDI::IHorizontalCoordinates newHor { hor.azimuth, newEl };
84 entry.TelescopeDirection = sf.TelescopeDirectionVectorFromAltitudeAzimuth(newHor);
85 entry.Declination -= (hor.altitude - newEl);
86 }
87 else
88 {
89 // EQ: degeneracy at the celestial pole -- cos(Dec)->0 makes the
90 // roll-index (IH) term unobservable. Check celestial Dec.
91 if (std::abs(entry.Declination) < kPolarThresholdDeg)
92 continue;
93
94 double encoderPitchDeg = RAD_TO_DEG(std::asin(entry.TelescopeDirection.z));
95 double celDec = entry.Declination;
96 double targetCelDec = (celDec >= 0) ? kTargetPitchDeg : -kTargetPitchDeg;
97 double deltaDeg = celDec - targetCelDec;
98
99 // Shift encoder pitch by the same delta to preserve the correction
100 double newEncoderPitch = encoderPitchDeg - deltaDeg;
101
102 // Rebuild TDV using celestial RA (assumes zero roll-index error
103 // at the pole -- the only safe assumption when unobservable).
104 // RA-based encoding matches the BuiltIn/SVD/Nearest convention.
105 INDI::IEquatorialCoordinates raCoords { entry.RightAscension, newEncoderPitch };
106 entry.TelescopeDirection = sf.TelescopeDirectionVectorFromEquatorialCoordinates(raCoords);
107 entry.Declination = targetCelDec;
108 }
109 }
110}
111
112} // namespace AlignmentSubsystem
113} // namespace INDI
This class provides the driver side API to the in memory alignment database.
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
bool GetDatabaseReferencePosition(IGeographicCoordinates &Position)
Get the database reference position.
virtual bool TransformCelestialToTelescope(const double RightAscension, const double Declination, double JulianOffset, TelescopeDirectionVector &ApparentTelescopeDirectionVector)=0
Get the alignment corrected telescope pointing direction for the supplied celestial coordinates.
virtual bool Initialise(InMemoryDatabase *pInMemoryDatabase)
Initialise or re-initialise the math plugin. Re-reading the in memory database as necessary.
virtual bool TransformTelescopeToCelestialJD(const TelescopeDirectionVector &ApparentTelescopeDirectionVector, double &RightAscension, double &Declination, double JulianDate)
Get the true celestial coordinates for the supplied telescope pointing direction.
static void SanitizePolarEntries(InMemoryDatabase *pInMemoryDatabase, MountAlignment_t mountAlignment)
Sanitize alignment database entries that are near the pole (EQ) or zenith (altaz)....
virtual bool TransformTelescopeToCelestial(const TelescopeDirectionVector &ApparentTelescopeDirectionVector, double &RightAscension, double &Declination, double JulianOffset=0)=0
Get the true celestial coordinates for the supplied telescope pointing direction.
MountAlignment_t ApproximateMountAlignment
Describe the approximate alignment of the mount. This information is normally used in a one star alig...
Definition MathPlugin.h:128
virtual bool TransformCelestialToTelescopeJD(double RightAscension, double Declination, double JulianDate, TelescopeDirectionVector &ApparentTelescopeDirectionVector)
Get the alignment corrected telescope pointing direction for the supplied celestial coordinates.
These functions are used to convert different coordinate systems to and from the telescope direction ...
const TelescopeDirectionVector TelescopeDirectionVectorFromAltitudeAzimuth(INDI::IHorizontalCoordinates HorizontalCoordinates)
Calculates a normalised direction vector from the supplied altitude and azimuth.
const TelescopeDirectionVector TelescopeDirectionVectorFromEquatorialCoordinates(INDI::IEquatorialCoordinates EquatorialCoordinates)
Calculates a telescope direction vector from the supplied equatorial coordinates.
Implementations for common driver routines.
#define RAD_TO_DEG(r)
Definition indimacros.h:131
#define DEG_TO_RAD(d)
Definition indimacros.h:128
enum INDI::AlignmentSubsystem::MountAlignment MountAlignment_t
Namespace to encapsulate INDI client, drivers, and mediator classes.
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
Holds a normalised direction vector (direction cosines)
Definition Common.h:69