Instrument Neutral Distributed Interface INDI  2.0.0
test_alignment.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2020 Rick Bassham. All rights reserved.
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Library General Public
5  License version 2 as published by the Free Software Foundation.
6  .
7  This library is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  Library General Public License for more details.
11  .
12  You should have received a copy of the GNU Library General Public License
13  along with this library; see the file COPYING.LIB. If not, write to
14  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
15  Boston, MA 02110-1301, USA.
16 *******************************************************************************/
17 
18 #include <gtest/gtest.h>
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <cstdlib>
25 #include <cstring>
26 #include <stdio.h>
27 
28 #include <indilogger.h>
29 
30 #include "alignment_scope.h"
31 
32 double round(double value, int decimal_places)
33 {
34  const double multiplier = std::pow(10.0, decimal_places);
35  return std::round(value * multiplier) / multiplier;
36 }
37 
38 TEST(ALIGNMENT_TEST, Test_TDVRoundTripEquatorial)
39 {
41  ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
42  s.Handshake();
43 
44  // Vega
45  double ra = 18.6156, dec = 38.78361;
46 
49  INDI::IEquatorialCoordinates RaDecResult;
51 
52  RaDecResult.rightascension = range24(RaDecResult.rightascension);
53  RaDecResult.declination = rangeDec(RaDecResult.declination);
54 
55  ASSERT_DOUBLE_EQ(RaDec.rightascension, RaDecResult.rightascension);
56  ASSERT_DOUBLE_EQ(RaDec.declination, RaDecResult.declination);
57 }
58 
59 TEST(ALIGNMENT_TEST, Test_TDVRoundTripAltAz)
60 {
62  ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
63  s.Handshake();
64 
65  double alt = 35.7, az = 80.0;
67  AltAz.altitude = range360(alt);
68  AltAz.azimuth = range360(az);
70  INDI::IHorizontalCoordinates AltAzResult;
72 
73  AltAzResult.altitude = range360(AltAzResult.altitude);
74  AltAzResult.azimuth = range360(AltAzResult.azimuth);
75 
76  ASSERT_DOUBLE_EQ(AltAz.altitude, AltAzResult.altitude);
77  ASSERT_DOUBLE_EQ(AltAz.azimuth, AltAzResult.azimuth);
78 }
79 
80 TEST(ALIGNMENT_TEST, Test_ThreeSyncPointsEquatorial)
81 {
83  ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
84  s.Handshake();
85 
86  double VegaJ2000RA = 18.6156972;
87  double VegaJ2000Dec = 38.7856944;
88 
89  double ArcturusJ2000RA = 14.2612083;
90  double ArcturusJ2000Dec = 19.1872694;
91 
92  double MizarJ2000RA = 13.3988500;
93  double MizarJ2000Dec = 54.9254167;
94 
95  // The test scope will do a "perfect" sync with whatever we send it.
96  s.Sync(VegaJ2000RA, VegaJ2000Dec);
97  s.Sync(ArcturusJ2000RA, ArcturusJ2000Dec);
98  s.Sync(MizarJ2000RA, MizarJ2000Dec);
99 
100  double VegaSkyRA, VegaSkyDec;
101  s.TelescopeEquatorialToSky(VegaJ2000RA, VegaJ2000Dec, VegaSkyRA, VegaSkyDec);
102 
103  // I would expect these to be closer than 1 decimal apart, but it seems to work
104  ASSERT_DOUBLE_EQ(round(VegaJ2000RA, 1), round(VegaSkyRA, 1));
105  ASSERT_DOUBLE_EQ(round(VegaJ2000Dec, 3), round(VegaSkyDec, 3));
106 
107  double VegaMountRA, VegaMountDec;
108  s.SkyToTelescopeEquatorial(VegaSkyRA, VegaSkyDec, VegaMountRA, VegaMountDec);
109  ASSERT_DOUBLE_EQ(round(VegaJ2000RA, 1), round(VegaMountRA, 1));
110  ASSERT_DOUBLE_EQ(round(VegaJ2000Dec, 3), round(VegaMountDec, 3));
111 }
112 
113 TEST(ALIGNMENT_TEST, Test_ThreeSyncPointsAltAz)
114 {
116  ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
117  s.Handshake();
118 
119  double VegaJ2000RA = 18.6156972;
120  double VegaJ2000Dec = 38.7856944;
121 
122  double ArcturusJ2000RA = 14.2612083;
123  double ArcturusJ2000Dec = 19.1872694;
124 
125  double MizarJ2000RA = 13.3988500;
126  double MizarJ2000Dec = 54.9254167;
127 
128  // The test scope will do a "perfect" sync with whatever we send it.
129  ASSERT_TRUE(s.Sync(VegaJ2000RA, VegaJ2000Dec));
130  ASSERT_TRUE(s.Sync(ArcturusJ2000RA, ArcturusJ2000Dec));
131  ASSERT_TRUE(s.Sync(MizarJ2000RA, MizarJ2000Dec));
132 
133  double testPointAlt = 35.123456, testPointAz = 80.123456;
134  double skyRA, skyDec;
135  ASSERT_TRUE(s.TelescopeAltAzToSky(testPointAlt, testPointAz, skyRA, skyDec));
136 
137  // convert the ra/dec we received to alt/az to compare
139  s.GetDatabaseReferencePosition(location);
140  INDI::IEquatorialCoordinates raDec {skyRA, skyDec};
142  INDI::EquatorialToHorizontal(&raDec, &location, ln_get_julian_from_sys(), &altAz);
143  // I would expect these to be closer than 1 decimal apart, but it seems to work
144  ASSERT_DOUBLE_EQ(round(testPointAlt, 1), round(altAz.altitude, 1));
145  ASSERT_DOUBLE_EQ(round(testPointAz, 1), round(altAz.azimuth, 1));
146 
147  double roundTripAlt, roundTripAz;
148  s.SkyToTelescopeAltAz(skyRA, skyDec, roundTripAlt, roundTripAz);
149 
150  ASSERT_DOUBLE_EQ(round(testPointAlt, 1), round(roundTripAlt, 1));
151  ASSERT_DOUBLE_EQ(round(testPointAz, 1), round(roundTripAz, 1));
152 }
153 
154 int main(int argc, char **argv)
155 {
158 
159  ::testing::InitGoogleTest(&argc, argv);
160 
161  return RUN_ALL_TESTS();
162 }
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.
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.
bool GetDatabaseReferencePosition(IGeographicCoordinates &Position)
Get the database reference position.
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.
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 Handshake() override
perform handshake with device to check communication
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
double ra
double dec
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1235
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1245
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1255
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition: libastro.cpp:140
Holds a nomalised direction vector (direction cosines)
Definition: Common.h:69
static const loggerConf file_off
Definition: indilogger.h:219
void configure(const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier,...
Definition: indilogger.cpp:283
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
Definition: indilogger.cpp:339
TEST(ALIGNMENT_TEST, Test_TDVRoundTripEquatorial)
int main(int argc, char **argv)
double round(double value, int decimal_places)