Instrument Neutral Distributed Interface INDI  2.0.2
AlignmentSubsystemForDrivers.cpp
Go to the documentation of this file.
1 
10 
11 namespace INDI
12 {
13 namespace 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 
28 {
31 }
32 
33 void 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 
61 {
63 }
64 
65 // Helper methods
66 
67 bool AlignmentSubsystemForDrivers::AddAlignmentEntryEquatorial(double actualRA, double actualDec, double mountRA,
68  double mountDec)
69 {
70  IGeographicCoordinates location;
71  if (!GetDatabaseReferencePosition(location))
72  {
73  return false;
74  }
75 
76  INDI::IEquatorialCoordinates RaDec {mountRA, mountDec};
77  AlignmentDatabaseEntry NewEntry;
79 
80  NewEntry.ObservationJulianDate = ln_get_julian_from_sys();
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 
100 bool AlignmentSubsystemForDrivers::SkyToTelescopeEquatorial(double actualRA, double actualDec, double &mountRA,
101  double &mountDec)
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 (TransformCelestialToTelescope(actualRA, actualDec, 0.0, 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 
131 bool AlignmentSubsystemForDrivers::TelescopeEquatorialToSky(double mountRA, double mountDec, double &actualRA,
132  double &actualDec)
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 TransformTelescopeToCelestial(TDV, actualRA, actualDec);
154  }
155 
156  return false;
157 }
158 
159 bool AlignmentSubsystemForDrivers::AddAlignmentEntryAltAz(double actualRA, double actualDec, double mountAlt,
160  double mountAz)
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 = ln_get_julian_from_sys();
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 
192 bool AlignmentSubsystemForDrivers::SkyToTelescopeAltAz(double actualRA, double actualDec, double &mountAlt, double &mountAz)
193 {
194  INDI::IHorizontalCoordinates altAz{0, 0};
196  IGeographicCoordinates location;
197 
198  if (!GetDatabaseReferencePosition(location))
199  {
200  return false;
201  }
202 
203  if (GetAlignmentDatabase().size() > 1)
204  {
205  if (TransformCelestialToTelescope(actualRA, actualDec, 0.0, TDV))
206  {
208  mountAz = range360(altAz.azimuth);
209  mountAlt = range360(altAz.altitude);
210  return true;
211  }
212  }
213 
214  return false;
215 }
216 
217 bool AlignmentSubsystemForDrivers::TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRa, double &actualDec)
218 {
219  INDI::IHorizontalCoordinates altaz{0, 0};
220  IGeographicCoordinates location;
221 
222  if (!GetDatabaseReferencePosition(location))
223  {
224  return false;
225  }
226 
227  if (GetAlignmentDatabase().size() > 1)
228  {
230  altaz.azimuth = range360(mountAz);
231  altaz.altitude = range360(mountAlt);
233  return TransformTelescopeToCelestial(TDV, actualRa, actualDec);
234  }
235 
236  return false;
237 }
238 
239 // Private methods
240 
241 void AlignmentSubsystemForDrivers::MyDatabaseLoadCallback(void *ThisPointer)
242 {
243  ((AlignmentSubsystemForDrivers *)ThisPointer)->Initialise((AlignmentSubsystemForDrivers *)ThisPointer);
244 }
245 
246 } // namespace AlignmentSubsystem
247 } // namespace INDI
This class encapsulates all the alignment subsystem classes that are useful to driver implementations...
bool SkyToTelescopeEquatorial(double actualRA, double actualDec, double &mountRA, double &mountDec)
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)
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
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 AddAlignmentEntryAltAz(double actualRA, double actualDec, double mountAlt, double mountAz)
Adds an alignment point to the model database, usually called from Sync.
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 TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRA, double &actualDec)
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
bool SkyToTelescopeAltAz(double actualRA, double actualDec, double &mountAlt, double &mountAz)
Converts an actual sky location to coordinates to send to the mount, usually called in Goto.
void InitAlignmentProperties(Telescope *pTelescope)
Initilize alignment subsystem properties. It is recommended to call this function within initProperti...
void ProcessAlignmentBLOBProperties(Telescope *pTelescope, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Call this function from within the ISNewBlob processing path. The function will handle any alignment ...
void SaveAlignmentConfigProperties(FILE *fp)
Call this function to save persistent alignment related properties. This function should be called fr...
void ProcessAlignmentTextProperties(Telescope *pTelescope, const char *name, char *texts[], char *names[], int n)
Call this function from within the ISNewText processing path. The function will handle any alignment ...
bool AddAlignmentEntryEquatorial(double actualRA, double actualDec, double mountRA, double mountDec)
Adds an alignment point to the model database, usually called from Sync.
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
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.
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...
bool TransformTelescopeToCelestial(const TelescopeDirectionVector &ApparentTelescopeDirectionVector, double &RightAscension, double &Declination)
TransformTelescopeToCelestial Transforms Mount Coords to Celestial (Sky) Coordinates.
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...
void SetCurrentInMemoryDatabase(InMemoryDatabase *pDatabase)
Set the current in memory database.
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 TransformCelestialToTelescope(const double RightAscension, const double Declination, double JulianOffset, TelescopeDirectionVector &ApparentTelescopeDirectionVector)
TransformCelestialToTelescope 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.
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:150
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1245
INumber eq[]
Definition: intelliscope.c:54
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 nomalised direction vector (direction cosines)
Definition: Common.h:69