Instrument Neutral Distributed Interface INDI  1.9.5
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 }
INDI::AlignmentSubsystem::TelescopeDirectionVectorSupportFunctions::EquatorialCoordinatesFromTelescopeDirectionVector
void EquatorialCoordinatesFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, INDI::IEquatorialCoordinates &EquatorialCoordinates)
Calculates equatorial coordinates from the supplied telescope direction vector and declination.
Definition: TelescopeDirectionVectorSupportFunctions.h:85
Scope::updateLocation
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
Definition: alignment_scope.h:87
INDI::AlignmentSubsystem::InMemoryDatabase::GetDatabaseReferencePosition
bool GetDatabaseReferencePosition(IGeographicCoordinates &Position)
Get the database reference position.
Definition: InMemoryDatabase.cpp:43
INDI::Logger::getInstance
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
Definition: indilogger.cpp:354
INDI::IHorizontalCoordinates::azimuth
double azimuth
Definition: libastro.h:58
INDI::IEquatorialCoordinates::declination
double declination
Definition: libastro.h:51
Scope::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: alignment_scope.h:69
INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers::TelescopeEquatorialToSky
bool TelescopeEquatorialToSky(double mountRA, double mountDec, double &actualRA, double &actualDec)
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
Definition: AlignmentSubsystemForDrivers.cpp:131
INDI::AlignmentSubsystem::TelescopeDirectionVectorSupportFunctions::AltitudeAzimuthFromTelescopeDirectionVector
void AltitudeAzimuthFromTelescopeDirectionVector(const TelescopeDirectionVector TelescopeDirectionVector, INDI::IHorizontalCoordinates &HorizontalCoordinates)
Calculates an altitude and azimuth from the supplied normalised direction vector and declination.
Definition: TelescopeDirectionVectorSupportFunctions.h:68
INDI::Logger::DBG_ERROR
@ DBG_ERROR
Definition: indilogger.h:192
round
double round(double value, int decimal_places)
Definition: test_alignment.cpp:32
INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers::SkyToTelescopeEquatorial
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.
Definition: AlignmentSubsystemForDrivers.cpp:100
INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers::TelescopeAltAzToSky
bool TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRA, double &actualDec)
Converts a mount location to actual sky coordinates, usually called in ReadScopeStatus.
Definition: AlignmentSubsystemForDrivers.cpp:217
range24
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1485
Scope
Definition: alignment_scope.h:12
range360
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1495
Pulsar2Commands::AltAz
@ AltAz
Definition: lx200pulsar2.cpp:396
indilogger.h
INDI::Logger::file_off
static const loggerConf file_off
Definition: indilogger.h:219
INDI::IEquatorialCoordinates::rightascension
double rightascension
Definition: libastro.h:50
Scope::Sync
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Definition: alignment_scope.h:146
ra
double ra
Definition: ieqprolegacydriver.cpp:43
INDI::Logger::configure
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:298
INDI::EquatorialToHorizontal
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition: libastro.cpp:140
INDI::IHorizontalCoordinates::altitude
double altitude
Definition: libastro.h:59
INDI::AlignmentSubsystem::MathPluginManagement::EQUATORIAL
@ EQUATORIAL
Definition: MathPluginManagement.h:40
dec
double dec
Definition: ieqprolegacydriver.cpp:44
INDI::IGeographicCoordinates
Definition: libastro.h:64
main
int main(int argc, char **argv)
Definition: test_alignment.cpp:154
rangeDec
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1505
INDI::AlignmentSubsystem::MathPluginManagement::ALTAZ
@ ALTAZ
Definition: MathPluginManagement.h:40
INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers::SkyToTelescopeAltAz
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.
Definition: AlignmentSubsystemForDrivers.cpp:192
INDI::IHorizontalCoordinates
Definition: libastro.h:56
INDI::IEquatorialCoordinates
Definition: libastro.h:48
TEST
TEST(ALIGNMENT_TEST, Test_TDVRoundTripEquatorial)
Definition: test_alignment.cpp:38
alignment_scope.h
INDI::AlignmentSubsystem::TelescopeDirectionVectorSupportFunctions::TelescopeDirectionVectorFromEquatorialCoordinates
const TelescopeDirectionVector TelescopeDirectionVectorFromEquatorialCoordinates(INDI::IEquatorialCoordinates EquatorialCoordinates)
Calculates a telescope direction vector from the supplied equatorial coordinates.
Definition: TelescopeDirectionVectorSupportFunctions.h:146
INDI::AlignmentSubsystem::TelescopeDirectionVector
Holds a nomalised direction vector (direction cosines)
Definition: Common.h:68
INDI::AlignmentSubsystem::TelescopeDirectionVectorSupportFunctions::TelescopeDirectionVectorFromAltitudeAzimuth
const TelescopeDirectionVector TelescopeDirectionVectorFromAltitudeAzimuth(INDI::IHorizontalCoordinates HorizontalCoordinates)
Calculates a normalised direction vector from the supplied altitude and azimuth.
Definition: TelescopeDirectionVectorSupportFunctions.h:132