1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*******************************************************************************
Copyright(c) 2020 Rick Bassham. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/
#include <gtest/gtest.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstdlib>
#include <cstring>
#include <stdio.h>
#include <indilogger.h>
#include "alignment_scope.h"
double round(double value, int decimal_places)
{
const double multiplier = std::pow(10.0, decimal_places);
return std::round(value * multiplier) / multiplier;
}
TEST(ALIGNMENT_TEST, Test_TDVRoundTripEquatorial)
{
Scope s(INDI::AlignmentSubsystem::MathPluginManagement::EQUATORIAL);
ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
s.Handshake();
// Vega
double ra = 18.6156, dec = 38.78361;
INDI::IEquatorialCoordinates RaDec {ra, rangeDec(dec)};
TelescopeDirectionVector TDV = s.TelescopeDirectionVectorFromEquatorialCoordinates(RaDec);
INDI::IEquatorialCoordinates RaDecResult;
s.EquatorialCoordinatesFromTelescopeDirectionVector(TDV, RaDecResult);
RaDecResult.rightascension = range24(RaDecResult.rightascension);
RaDecResult.declination = rangeDec(RaDecResult.declination);
ASSERT_DOUBLE_EQ(RaDec.rightascension, RaDecResult.rightascension);
ASSERT_DOUBLE_EQ(RaDec.declination, RaDecResult.declination);
}
TEST(ALIGNMENT_TEST, Test_TDVRoundTripAltAz)
{
Scope s(INDI::AlignmentSubsystem::MathPluginManagement::ALTAZ);
ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
s.Handshake();
double alt = 35.7, az = 80.0;
INDI::IHorizontalCoordinates AltAz;
AltAz.altitude = range360(alt);
AltAz.azimuth = range360(az);
TelescopeDirectionVector TDV = s.TelescopeDirectionVectorFromAltitudeAzimuth(AltAz);
INDI::IHorizontalCoordinates AltAzResult;
s.AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAzResult);
AltAzResult.altitude = range360(AltAzResult.altitude);
AltAzResult.azimuth = range360(AltAzResult.azimuth);
ASSERT_DOUBLE_EQ(AltAz.altitude, AltAzResult.altitude);
ASSERT_DOUBLE_EQ(AltAz.azimuth, AltAzResult.azimuth);
}
TEST(ALIGNMENT_TEST, Test_ThreeSyncPointsEquatorial)
{
Scope s(INDI::AlignmentSubsystem::MathPluginManagement::EQUATORIAL);
ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
s.Handshake();
double VegaJ2000RA = 18.6156972;
double VegaJ2000Dec = 38.7856944;
double ArcturusJ2000RA = 14.2612083;
double ArcturusJ2000Dec = 19.1872694;
double MizarJ2000RA = 13.3988500;
double MizarJ2000Dec = 54.9254167;
// The test scope will do a "perfect" sync with whatever we send it.
s.Sync(VegaJ2000RA, VegaJ2000Dec);
s.Sync(ArcturusJ2000RA, ArcturusJ2000Dec);
s.Sync(MizarJ2000RA, MizarJ2000Dec);
double VegaSkyRA, VegaSkyDec;
s.TelescopeEquatorialToSky(VegaJ2000RA, VegaJ2000Dec, VegaSkyRA, VegaSkyDec);
// I would expect these to be closer than 1 decimal apart, but it seems to work
ASSERT_DOUBLE_EQ(round(VegaJ2000RA, 1), round(VegaSkyRA, 1));
ASSERT_DOUBLE_EQ(round(VegaJ2000Dec, 3), round(VegaSkyDec, 3));
double VegaMountRA, VegaMountDec;
s.SkyToTelescopeEquatorial(VegaSkyRA, VegaSkyDec, VegaMountRA, VegaMountDec);
ASSERT_DOUBLE_EQ(round(VegaJ2000RA, 1), round(VegaMountRA, 1));
ASSERT_DOUBLE_EQ(round(VegaJ2000Dec, 3), round(VegaMountDec, 3));
}
TEST(ALIGNMENT_TEST, Test_ThreeSyncPointsAltAz)
{
Scope s(INDI::AlignmentSubsystem::MathPluginManagement::ALTAZ);
ASSERT_TRUE(s.updateLocation(29.05, 48.15, 0));
s.Handshake();
double VegaJ2000RA = 18.6156972;
double VegaJ2000Dec = 38.7856944;
double ArcturusJ2000RA = 14.2612083;
double ArcturusJ2000Dec = 19.1872694;
double MizarJ2000RA = 13.3988500;
double MizarJ2000Dec = 54.9254167;
// The test scope will do a "perfect" sync with whatever we send it.
ASSERT_TRUE(s.Sync(VegaJ2000RA, VegaJ2000Dec));
ASSERT_TRUE(s.Sync(ArcturusJ2000RA, ArcturusJ2000Dec));
ASSERT_TRUE(s.Sync(MizarJ2000RA, MizarJ2000Dec));
double testPointAlt = 35.123456, testPointAz = 80.123456;
double skyRA, skyDec;
ASSERT_TRUE(s.TelescopeAltAzToSky(testPointAlt, testPointAz, skyRA, skyDec));
// convert the ra/dec we received to alt/az to compare
INDI::IGeographicCoordinates location;
s.GetDatabaseReferencePosition(location);
INDI::IEquatorialCoordinates raDec {skyRA, skyDec};
INDI::IHorizontalCoordinates altAz;
INDI::EquatorialToHorizontal(&raDec, &location, ln_get_julian_from_sys(), &altAz);
// I would expect these to be closer than 1 decimal apart, but it seems to work
ASSERT_DOUBLE_EQ(round(testPointAlt, 1), round(altAz.altitude, 1));
ASSERT_DOUBLE_EQ(round(testPointAz, 1), round(altAz.azimuth, 1));
double roundTripAlt, roundTripAz;
s.SkyToTelescopeAltAz(skyRA, skyDec, roundTripAlt, roundTripAz);
ASSERT_DOUBLE_EQ(round(testPointAlt, 1), round(roundTripAlt, 1));
ASSERT_DOUBLE_EQ(round(testPointAz, 1), round(roundTripAz, 1));
}
int main(int argc, char **argv)
{
INDI::Logger::getInstance().configure("", INDI::Logger::file_off,
INDI::Logger::DBG_ERROR, INDI::Logger::DBG_ERROR);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|