Instrument Neutral Distributed Interface INDI 2.2.5
AlignmentSubsystemForDrivers.cpp
Go to the documentation of this file.
1
8
10
11namespace INDI
12{
13namespace AlignmentSubsystem
14{
16{
17 // Set up the in memory database pointer for math plugins
19 // Tell the built in math plugin about it
20 Initialise(this);
21 // Fix up the database load callback
22 SetLoadDatabaseCallback(&MyDatabaseLoadCallback, this);
23}
24
25// Public methods
26
32
33void AlignmentSubsystemForDrivers::ProcessAlignmentBLOBProperties(Telescope *pTelescope, const char *name, int sizes[],
34 int blobsizes[], char *blobs[], char *formats[],
35 char *names[], int n)
36{
37 MapPropertiesToInMemoryDatabase::ProcessBlobProperties(pTelescope, name, sizes, blobsizes, blobs, formats, names,
38 n);
39}
40
42 double values[], char *names[], int n)
43{
44 MapPropertiesToInMemoryDatabase::ProcessNumberProperties(pTelescope, name, values, names, n);
45}
46
48 ISState *states, char *names[], int n)
49{
50 MapPropertiesToInMemoryDatabase::ProcessSwitchProperties(pTelescope, name, states, names, n);
51 MathPluginManagement::ProcessSwitchProperties(pTelescope, name, states, names, n);
52}
53
55 char *texts[], char *names[], int n)
56{
57 MathPluginManagement::ProcessTextProperties(pTelescope, name, texts, names, n);
58}
59
64
65// Helper methods
66
67bool AlignmentSubsystemForDrivers::AddAlignmentEntryEquatorial(double actualRA, double actualDec, double mountRA,
68 double mountDec, double JD)
69{
71 if (!GetDatabaseReferencePosition(location))
72 {
73 return false;
74 }
75
76 INDI::IEquatorialCoordinates RaDec {mountRA, mountDec};
79
80 NewEntry.ObservationJulianDate = JD;
81 NewEntry.RightAscension = actualRA;
82 NewEntry.Declination = actualDec;
83 NewEntry.TelescopeDirection = TDV;
84 NewEntry.PrivateDataSize = 0;
85
86 if (!CheckForDuplicateSyncPoint(NewEntry))
87 {
88 GetAlignmentDatabase().push_back(NewEntry);
89 UpdateSize();
90
91 // tell the math plugin about the new alignment point
92 Initialise(this);
93
94 return true;
95 }
96
97 return false;
98}
99
100bool AlignmentSubsystemForDrivers::SkyToTelescopeEquatorial(double actualRA, double actualDec, double &mountRA,
101 double &mountDec, double JD)
102{
105 IGeographicCoordinates location;
106
107 // by default, just return what we were given
108 mountRA = actualRA;
109 mountDec = actualDec;
110
111 if (!GetDatabaseReferencePosition(location))
112 {
113 return false;
114 }
115
116 if (GetAlignmentDatabase().size() >= 1)
117 {
118 if (TransformCelestialToTelescopeJD(actualRA, actualDec, JD, TDV))
119 {
121 // and now we have to convert from lha back to RA
122 mountRA = eq.rightascension;
123 mountDec = eq.declination;
124 return true;
125 }
126 }
127
128 return false;
129}
130
131bool AlignmentSubsystemForDrivers::TelescopeEquatorialToSky(double mountRA, double mountDec, double &actualRA,
132 double &actualDec, double JD)
133{
135 IGeographicCoordinates location;
136
137 // by default, just return what we were given
138 actualRA = mountRA;
139 actualDec = mountDec;
140
141 if (!GetDatabaseReferencePosition(location))
142 {
143 return false;
144 }
145
146 if (GetAlignmentDatabase().size() >= 1)
147 {
149 eq.rightascension = mountRA;
150 eq.declination = mountDec;
151
153 return TransformTelescopeToCelestialJD(TDV, actualRA, actualDec, JD);
154 }
155
156 return false;
157}
158
159bool AlignmentSubsystemForDrivers::AddAlignmentEntryAltAz(double actualRA, double actualDec, double mountAlt,
160 double mountAz, double JD)
161{
162 IGeographicCoordinates location;
163 if (!GetDatabaseReferencePosition(location))
164 {
165 return false;
166 }
167
168 INDI::IHorizontalCoordinates AltAz {range360(mountAz), range360(mountAlt)};
169 AlignmentDatabaseEntry NewEntry;
171
172 NewEntry.ObservationJulianDate = JD;
173 NewEntry.RightAscension = actualRA;
174 NewEntry.Declination = actualDec;
175 NewEntry.TelescopeDirection = TDV;
176 NewEntry.PrivateDataSize = 0;
177
178 if (!CheckForDuplicateSyncPoint(NewEntry))
179 {
180 GetAlignmentDatabase().push_back(NewEntry);
181 UpdateSize();
182
183 // tell the math plugin about the new alignment point
184 Initialise(this);
185
186 return true;
187 }
188
189 return false;
190}
191
192bool AlignmentSubsystemForDrivers::SkyToTelescopeAltAz(double actualRA, double actualDec, double &mountAlt,
193 double &mountAz, double JD)
194{
197 IGeographicCoordinates location;
198
199 if (!GetDatabaseReferencePosition(location))
200 {
201 return false;
202 }
203
204 if (GetAlignmentDatabase().size() >= 1)
205 {
206 if (TransformCelestialToTelescopeJD(actualRA, actualDec, JD, TDV))
207 {
209 mountAz = range360(altAz.azimuth);
210 mountAlt = range360(altAz.altitude);
211 return true;
212 }
213 }
214
215 return false;
216}
217
218bool AlignmentSubsystemForDrivers::TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRa,
219 double &actualDec, double JD)
220{
222 IGeographicCoordinates location;
223
224 if (!GetDatabaseReferencePosition(location))
225 {
226 return false;
227 }
228
229 if (GetAlignmentDatabase().size() >= 1)
230 {
232 altaz.azimuth = range360(mountAz);
233 altaz.altitude = range360(mountAlt);
235 return TransformTelescopeToCelestialJD(TDV, actualRa, actualDec, JD);
236 }
237
238 return false;
239}
240
241// Private methods
242
243void AlignmentSubsystemForDrivers::MyDatabaseLoadCallback(void *ThisPointer)
244{
245 ((AlignmentSubsystemForDrivers *)ThisPointer)->Initialise((AlignmentSubsystemForDrivers *)ThisPointer);
246}
247
248} // namespace AlignmentSubsystem
249} // namespace INDI
This class encapsulates all the alignment subsystem classes that are useful to driver implementations...
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 AddAlignmentEntryEquatorial(double actualRA, double actualDec, double mountRA, double mountDec, double JD=ln_get_julian_from_sys())
Adds an alignment point to the model database, usually called from Sync.
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...
bool SkyToTelescopeEquatorial(double actualRA, double actualDec, double &mountRA, double &mountDec, double JD=ln_get_julian_from_sys())
Converts an actual sky location to coordinates to send to the mount, usually called in Goto.
bool TelescopeEquatorialToSky(double mountRA, double mountDec, double &actualRA, double &actualDec, double JD=ln_get_julian_from_sys())
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
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.
void ProcessAlignmentBLOBProperties(Telescope *pTelescope, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Call this function from within the ISNewBlob processing path. The function will handle any alignment ...
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 SetLoadDatabaseCallback(LoadDatabaseCallbackPointer_t CallbackPointer, void *ThisPointer)
Set the function to be called when the database is loaded or reloaded.
bool CheckForDuplicateSyncPoint(const AlignmentDatabaseEntry &CandidateEntry, double Tolerance=0.1) const
Check if a entry already exists in the database.
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
bool GetDatabaseReferencePosition(IGeographicCoordinates &Position)
Get the database reference position.
void ProcessNumberProperties(Telescope *, const char *name, double values[], char *names[], int n)
Call this function from within the ISNewNumber processing path. The function will handle any alignmen...
void InitProperties(Telescope *pTelescope)
Initialize alignment database properties. It is recommended to call this function within initProperti...
void UpdateSize()
Call this function when the number of entries in the database changes.
void ProcessBlobProperties(Telescope *pTelescope, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Call this function from within the ISNewBLOB processing path. The function will handle any alignment ...
void ProcessSwitchProperties(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 ProcessSwitchProperties(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 math plu...
void InitProperties(Telescope *pTelescope)
Initialize alignment math plugin properties. It is recommended to call this function within initPrope...
void SaveConfigProperties(FILE *fp)
Call this function to save persistent math plugin properties. This function should be called from wit...
bool TransformTelescopeToCelestialJD(const TelescopeDirectionVector &ApparentTelescopeDirectionVector, double &RightAscension, double &Declination, double JulianDate)
TransformTelescopeToCelestialJD Transforms Mount Coords to Celestial (Sky) Coordinates.
void SetCurrentInMemoryDatabase(InMemoryDatabase *pDatabase)
Set the current in memory database.
bool TransformCelestialToTelescopeJD(double RightAscension, double Declination, double JulianDate, TelescopeDirectionVector &ApparentTelescopeDirectionVector)
TransformCelestialToTelescopeJD Transforms Celestial (Sky) Coords to Mount Coordinates.
void ProcessTextProperties(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 math plugi...
bool Initialise(InMemoryDatabase *pInMemoryDatabase)
Initialise or re-initialise the math plugin. Re-reading the in memory database as necessary.
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.
void AltitudeAzimuthFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, INDI::IHorizontalCoordinates &HorizontalCoordinates)
Calculates an altitude and azimuth from the supplied normalised direction vector and declination.
ISState
Switch state.
Definition indiapi.h:148
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition indicom.c:1321
*brief user defined string literal for JSON values *sa std::size_t n
INumber eq[]
Namespace to encapsulate the INDI Alignment Subsystem classes. For more information see "INDI Alignme...
Namespace to encapsulate INDI client, drivers, and mediator classes.
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