Equatorial HorizontalToEquatorial( const Horizontal & horizontal, double localSiderealTime, Angle geographicLatitude ) { return HorizontalToEquatorial( horizontal, Angle( localSiderealTime, Angle::Cycle ), geographicLatitude ); }
void GetTel(double *telra, double *teldec, int pmodel) { /* Packet preset to request HA/Azimuth counts */ char sendstr[] = { 0x50, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x03 }; char returnstr[32]; int azcount = 0; int altcount = 0; double encoderaz = 0.; double encoderalt = 0.; double telha0 = 0.; double teldec0 = 0.; double telra0 = 0.; double telra1 = 0.; double teldec1 = 0.; int numRead = 0; static int count0, count1, count2; /* Packet to request RA/Azimuth */ sendstr[2] = 0x10; /* Flush the input buffer */ tcflush(TelPortFD,TCIOFLUSH); /* Send the request */ writen(TelPortFD,sendstr,8); numRead=readn(TelPortFD,returnstr,4,2); if (numRead == 4) { count0 = (unsigned char) returnstr[0]; count1 = (unsigned char) returnstr[1]; count2 = (unsigned char) returnstr[2]; azcount = 256*256*count0 + 256*count1 + count2; if (azcount > 8388608) { azcount = -(16777217 - azcount); } encoderaz = (double) azcount; } /* Packet to request Dec/Altitude */ sendstr[2] = 0x11; /* Flush the input buffer */ tcflush(TelPortFD,TCIOFLUSH); /* Send the request */ writen(TelPortFD,sendstr,8); numRead=readn(TelPortFD,returnstr,4,2); if (numRead == 4) { count0 = (unsigned char) returnstr[0]; count1 = (unsigned char) returnstr[1]; count2 = (unsigned char) returnstr[2]; altcount = 256*256*count0 + 256*count1 + count2; if (altcount > 8388608) { altcount = -(16777217 - altcount); } encoderalt = (double) altcount; } /* Convert counts to degrees for both azimuth and altitude encoders */ encoderaz = encoderaz / azcountperdeg; encoderalt = encoderalt / altcountperdeg; /* Transform encoder readings to mount ha, ra and dec */ /* GEM encoders zero for OTA over pier pointed at pole */ if (telmount == GEM) { if ( encoderaz == 0. ) { if ( encoderalt < 0.) { telha0 = -6.; teldec0 = 90. + encoderalt; } else { telha0 = +6.; teldec0 = 90. - encoderalt; } } else if ( encoderaz == -90. ) { if ( encoderalt < 0.) { telha0 = 0.; teldec0 = 90. + encoderalt; } else { telha0 = -12.; teldec0 = 90. - encoderalt; } } else if ( encoderaz == 90. ) { if ( encoderalt > 0.) { telha0 = 0.; teldec0 = 90. - encoderalt; } else { telha0 = -12.; teldec0 = 90. + encoderalt; } } else if ((encoderaz > -180. ) && (encoderaz < -90.)) { teldec0 = 90. - encoderalt; telha0 = Map12(6. + encoderaz/15.); } else if ((encoderaz > -90. ) && (encoderaz < 0.)) { teldec0 = 90. - encoderalt; telha0 = Map12(6. + encoderaz/15.); } else if ((encoderaz > 0. ) && (encoderaz < 90.)) { teldec0 = 90. + encoderalt; telha0 = Map12(-6. + encoderaz/15.); } else if ((encoderaz > 90. ) && (encoderaz < 180.)) { teldec0 = 90. + encoderalt; telha0 = Map12(-6. + encoderaz/15.); } else { fprintf(stderr,"German equatorial ha encoder out of range\n"); teldec0 = 0.; telha0 = 0.; } /* Flip signs for the southern sky */ if (SiteLatitude < 0.) { teldec0 = -1.*teldec0; telha0 = -1.*telha0; } telra0 = Map24(LSTNow() - telha0); } else if (telmount == EQFORK) { teldec0 = encoderalt; telha0 = Map12(encoderaz/15.); /* Flip signs for the southern sky */ if (SiteLatitude < 0.) { teldec0 = -1.*teldec0; telha0 = -1.*telha0; } telra0 = Map24(LSTNow() - telha0); } else if (telmount == ALTAZ) { HorizontalToEquatorial(encoderaz, encoderalt, &telha0, & teldec0); telha0 = Map12(telha0); telra0 = Map24(LSTNow() - telha0); } else { fprintf(stderr,"Unknown mounting type\n"); *telra=0.; *teldec=0.; telencoderaz = 0.; telencoderalt = 0.; return; } /* Handle special case if not already treated where dec is beyond a pole */ if (teldec0 > 90.) { teldec0 = 180. - teldec0; telra0 = Map24(telra0 + 12.); } else if (teldec0 < -90.) { teldec0 = -180. - teldec0; telra0 = Map24(telra0 + 12.); } /* Apply pointing model to the coordinates that are reported by the telescope */ PointingFromTel(&telra1, &teldec1, telra0, teldec0, pmodel); /* Return corrected values */ *telra=telra1; *teldec=teldec1; /* Update global encoder reading */ telencoderaz = encoderaz; telencoderalt = encoderalt; return; }
bool TestAstroCoordTransformations( ) { bool ok = true; cout << "Testing AstroCoordTransformations" << endl; int h = 7; int m = 45; double s = 18.946; cout << "raPollux: AngleHMS( " << h << ", " << m << ", " << s << " )" << endl; Angle raPollux( AngleHMS( h, m, s ) ); int d = 28; m = 1; s = 34.26; cout << "decPollux: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle decPollux( AngleDMS( d, m, s ) ); Equatorial equatPollux( raPollux, decPollux ); TESTCHECKF( equatPollux.RightAscension().Degrees(), 116.328942, &ok ); TESTCHECKF( equatPollux.Declination().Degrees(), 28.026183, &ok ); TESTCHECKF( equatPollux.Distance(), 1., &ok ); double obl = 23.4392911; cout << "obliquity: " << obl << endl; Angle obliquity( obl, Angle::Degree ); cout << "EquatorialToEcliptical( equatPollux, " << obl << " )" << endl; Ecliptical ecliptPollux = EquatorialToEcliptical( equatPollux, obliquity ); TESTCHECKF( ecliptPollux.Longitude().Degrees(), 113.21562958, &ok ); TESTCHECKF( ecliptPollux.Latitude().Degrees(), 6.6841698, &ok ); TESTCHECKF( ecliptPollux.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Point3D equatPolluxV = equatPollux.Rectangular(); Matrix3D equat2eclipt = EquatorialToEclipticalMatrix( obliquity ); Point3D ecliptPolluxV = equat2eclipt * equatPolluxV; ecliptPollux.Set( ecliptPolluxV ); TESTCHECKF( ecliptPollux.Longitude().Degrees(), 113.215630, &ok ); TESTCHECKF( ecliptPollux.Latitude().Degrees(), 6.684170, &ok ); TESTCHECKF( ecliptPollux.Distance(), 1., &ok ); TESTCHECKF( EclipticalLongitude( equatPolluxV, obliquity ).Degrees(), 113.215630, &ok ); cout << "EclipticalToEquatorial( ecliptPollux, " << obl << " )" << endl; equatPollux = EclipticalToEquatorial( ecliptPollux, obliquity ); TESTCHECKF( equatPollux.RightAscension().Degrees(), 116.328942, &ok ); TESTCHECKF( equatPollux.Declination().Degrees(), 28.026183, &ok ); TESTCHECKF( equatPollux.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Matrix3D eclipt2equat = EclipticalToEquatorialMatrix( obliquity ); equatPolluxV = eclipt2equat * ecliptPolluxV; equatPollux.Set( equatPolluxV ); TESTCHECKF( equatPollux.RightAscension().Degrees(), 116.328942, &ok ); TESTCHECKF( equatPollux.Declination().Degrees(), 28.026183, &ok ); TESTCHECKF( equatPollux.Distance(), 1., &ok ); h = 23; m = 9; s = 16.641; cout << "raVenus: AngleHMS( " << h << ", " << m << ", " << s << " )" << endl; Angle raVenus( AngleHMS( h, m, s ) ); d = -6; m = 43; s = 11.61; cout << "decVenus: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle decVenus( AngleDMS( d, m, s ) ); Equatorial equatVenus( raVenus, decVenus ); TESTCHECKF( equatVenus.RightAscension().Degrees(), 347.3193375, &ok ); TESTCHECKF( equatVenus.Declination().Degrees(), -6.71988889, &ok ); TESTCHECKF( equatVenus.Distance(), 1., &ok ); h = 3; m = 26; s = 41.153; cout << "local sidereal time: " << h << "h" << m << "m" << s << "s" << endl; AngleHMS lstHMS( h, m, s ); Angle lst( lstHMS ); d = 38; m = 55; s = 17; cout << "lat U.S.N.O.: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle latUSNO( AngleDMS( d, m, s ) ); cout << "EquatorialToHorizontal( equatVenus, lst, latUSNO )" << endl; Horizontal horizVenus = EquatorialToHorizontal( equatVenus, lst, latUSNO ); TESTCHECKF( horizVenus.Azimuth().Degrees(), 248.03369608, &ok ); TESTCHECKF( horizVenus.Altitude().Degrees(), 15.12487568, &ok ); TESTCHECKF( horizVenus.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Point3D equatVenusV = equatVenus.Rectangular(); Matrix3D equat2horiz = EquatorialToHorizontalMatrix( lst, latUSNO ); Point3D horizVenusV = equat2horiz * equatVenusV; horizVenus.Set( horizVenusV ); TESTCHECKF( horizVenus.Azimuth().Degrees(), 248.03369608, &ok ); TESTCHECKF( horizVenus.Altitude().Degrees(), 15.12487568, &ok ); TESTCHECKF( horizVenus.Distance(), 1., &ok ); cout << "HorizontalToEquatorial( horizVenus, lst, latUSNO )" << endl; equatVenus = HorizontalToEquatorial( horizVenus, lst, latUSNO ); TESTCHECKF( equatVenus.RightAscension().Degrees(), 347.3193375, &ok ); TESTCHECKF( equatVenus.Declination().Degrees(), -6.71988889, &ok ); TESTCHECKF( equatVenus.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; horizVenusV = horizVenus.Rectangular(); Matrix3D horiz2equat = HorizontalToEquatorialMatrix( lst, latUSNO ); equatVenusV = horiz2equat * horizVenusV; equatVenus.Set( equatVenusV ); TESTCHECKF( equatVenus.RightAscension().Degrees(), 347.3193375, &ok ); TESTCHECKF( equatVenus.Declination().Degrees(), -6.71988889, &ok ); TESTCHECKF( equatVenus.Distance(), 1., &ok ); h = 17; m = 48; s = 59.74; cout << "raNovaSer: AngleHMS( " << h << ", " << m << ", " << s << " )" << endl; Angle raNovaSer( AngleHMS( h, m, s ) ); d = -14; m = 43; s = 8.2; cout << "decNovaSer: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle decNovaSer( AngleDMS( d, m, s ) ); Equatorial equatNovaSer( raNovaSer, decNovaSer ); TESTCHECKF( equatNovaSer.RightAscension().Degrees(), 267.248917, &ok ); TESTCHECKF( equatNovaSer.Declination().Degrees(), -14.7189444, &ok ); cout << "EquatorialToGalactic( equatNovaSer )" << endl; Galactic galNovaSer = EquatorialToGalactic( equatNovaSer ); TESTCHECKF( galNovaSer.Longitude().Degrees(), 12.95925004, &ok ); TESTCHECKF( galNovaSer.Latitude().Degrees(), 6.0462985, &ok ); TESTCHECKF( galNovaSer.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Point3D equatNovaSerV = equatNovaSer.Rectangular(); Matrix3D equat2gal = EquatorialToGalacticMatrix( ); Point3D galNovaSerV = equat2gal * equatNovaSerV; galNovaSer.Set( galNovaSerV ); TESTCHECKF( galNovaSer.Longitude().Degrees(), 12.95925004, &ok ); TESTCHECKF( galNovaSer.Latitude().Degrees(), 6.0462985, &ok ); TESTCHECKF( galNovaSer.Distance(), 1., &ok ); cout << "GalacticToEquatorial( galNovaSer )" << endl; equatNovaSer = GalacticToEquatorial( galNovaSer ); TESTCHECKF( equatNovaSer.RightAscension().Degrees(), 267.248917, &ok ); TESTCHECKF( equatNovaSer.Declination().Degrees(), -14.7189444, &ok ); TESTCHECKF( equatNovaSer.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; galNovaSerV = galNovaSer.Rectangular(); Matrix3D gal2equat = GalacticToEquatorialMatrix( ); equatNovaSerV = gal2equat * galNovaSerV; equatNovaSer.Set( equatNovaSerV ); TESTCHECKF( equatNovaSer.RightAscension().Degrees(), 267.248917, &ok ); TESTCHECKF( equatNovaSer.Declination().Degrees(), -14.7189444, &ok ); TESTCHECKF( equatNovaSer.Distance(), 1., &ok ); h = 16; m = 26; s = 29.19; cout << "raTest1: AngleHMS( " << h << ", " << m << ", " << s << " )" << endl; Angle raTest1( AngleHMS( h, m, s ) ); d = -21; m = 13; s = 38.68; cout << "decTest1: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle decTest1( AngleDMS( d, m, s ) ); Equatorial equatTest1( raTest1, decTest1 ); h = 1; m = 14; s = 45.2959; cout << "local sidereal time: " << h << "h" << m << "m" << s << "s" << endl; lstHMS.Set( h, m, s ); lst.Set( lstHMS ); d = 35; m = 43; s = 59; cout << "lat: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle latTest1( AngleDMS( d, m, s ) ); cout << "EquatorialToHorizontal( equatTest1, lst, latTest1 )" << endl; Horizontal horizTest1 = EquatorialToHorizontal( equatTest1, lst, latTest1 ); AngleDMS dmsTest1Az( horizTest1.Azimuth() ); TESTCHECK( dmsTest1Az.Positive(), true, &ok ); TESTCHECK( dmsTest1Az.Degrees(), 275, &ok ); TESTCHECK( dmsTest1Az.Minutes(), 50, &ok ); TESTCHECKFE( dmsTest1Az.Seconds(), 38.9193, &ok, 1e-3 ); AngleDMS dmsTest1Alt( horizTest1.Altitude() ); TESTCHECK( dmsTest1Alt.Positive(), false, &ok ); TESTCHECK( dmsTest1Alt.Degrees(), 45, &ok ); TESTCHECK( dmsTest1Alt.Minutes(), 55, &ok ); TESTCHECKFE( dmsTest1Alt.Seconds(), 27.7358, &ok, 1e-3 ); TESTCHECKF( horizTest1.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Point3D equatTest1V = equatTest1.Rectangular(); equat2horiz = EquatorialToHorizontalMatrix( lst, latTest1 ); Point3D horizTest1V = equat2horiz * equatTest1V; horizTest1.Set( horizTest1V ); dmsTest1Az.Set( horizTest1.Azimuth() ); TESTCHECK( dmsTest1Az.Positive(), true, &ok ); TESTCHECK( dmsTest1Az.Degrees(), 275, &ok ); TESTCHECK( dmsTest1Az.Minutes(), 50, &ok ); TESTCHECKFE( dmsTest1Az.Seconds(), 38.9193, &ok, 1e-3 ); dmsTest1Alt.Set( horizTest1.Altitude() ); TESTCHECK( dmsTest1Alt.Positive(), false, &ok ); TESTCHECK( dmsTest1Alt.Degrees(), 45, &ok ); TESTCHECK( dmsTest1Alt.Minutes(), 55, &ok ); TESTCHECKFE( dmsTest1Alt.Seconds(), 27.7358, &ok, 1e-3 ); TESTCHECKF( horizTest1.Distance(), 1., &ok ); cout << "HorizontalToEquatorial( horizTest1, lst, latTest1 )" << endl; equatTest1 = HorizontalToEquatorial( horizTest1, lst, latTest1 ); AngleHMS hmsTest1RA( equatTest1.RightAscension() ); TESTCHECK( hmsTest1RA.Hours(), 16, &ok ); TESTCHECK( hmsTest1RA.Minutes(), 26, &ok ); TESTCHECKFE( hmsTest1RA.Seconds(), 29.19, &ok, 1e-3 ); AngleDMS dmsTest1Dec( equatTest1.Declination() ); TESTCHECK( dmsTest1Dec.Positive(), false, &ok ); TESTCHECK( dmsTest1Dec.Degrees(), 21, &ok ); TESTCHECK( dmsTest1Dec.Minutes(), 13, &ok ); TESTCHECKFE( dmsTest1Dec.Seconds(), 38.68, &ok, 1e-3 ); TESTCHECKF( equatTest1.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; horizTest1V = horizTest1.Rectangular(); horiz2equat = HorizontalToEquatorialMatrix( lst, latTest1 ); equatTest1V = horiz2equat * horizTest1V; equatTest1.Set( equatTest1V ); hmsTest1RA.Set( equatTest1.RightAscension() ); TESTCHECK( hmsTest1RA.Hours(), 16, &ok ); TESTCHECK( hmsTest1RA.Minutes(), 26, &ok ); TESTCHECKFE( hmsTest1RA.Seconds(), 29.19, &ok, 1e-3 ); dmsTest1Dec.Set( equatTest1.Declination() ); TESTCHECK( dmsTest1Dec.Positive(), false, &ok ); TESTCHECK( dmsTest1Dec.Degrees(), 21, &ok ); TESTCHECK( dmsTest1Dec.Minutes(), 13, &ok ); TESTCHECKF( dmsTest1Dec.Seconds(), 38.68, &ok ); TESTCHECKFE( equatTest1.Distance(), 1., &ok, 1e-3 ); h = 16; m = 26; s = 29.399; cout << "raTest2: AngleHMS( " << h << ", " << m << ", " << s << " )" << endl; Angle raTest2( AngleHMS( h, m, s ) ); d = -21; m = 13; s = 38.39; cout << "decTest2: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; Angle decTest2( AngleDMS( d, m, s ) ); Equatorial equatTest2( raTest2, decTest2 ); d = 23; m = 26; s = 15.791; cout << "obliquity: AngleDMS( " << d << ", " << m << ", " << s << " )" << endl; obliquity.Set( AngleDMS( d, m, s ) ); cout << "EquatorialToEcliptical( equatTest2, obliquity )" << endl; Ecliptical ecliptTest2 = EquatorialToEcliptical( equatTest2, obliquity ); AngleDMS dmsTest2Long( ecliptTest2.Longitude() ); TESTCHECK( dmsTest2Long.Positive(), true, &ok ); TESTCHECK( dmsTest2Long.Degrees(), 248, &ok ); TESTCHECK( dmsTest2Long.Minutes(), 17, &ok ); TESTCHECKFE( dmsTest2Long.Seconds(), 30.82, &ok, 1e-3 ); AngleDMS dmsTest2Lat( ecliptTest2.Latitude() ); TESTCHECK( dmsTest2Lat.Positive(), true, &ok ); TESTCHECK( dmsTest2Lat.Degrees(), 0, &ok ); TESTCHECK( dmsTest2Lat.Minutes(), 27, &ok ); TESTCHECKFE( dmsTest2Lat.Seconds(), 57.59, &ok, 1e-3 ); TESTCHECKF( ecliptTest2.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; Point3D equatTest2V = equatTest2.Rectangular(); equat2eclipt = EquatorialToEclipticalMatrix( obliquity ); Point3D ecliptTest2V = equat2eclipt * equatTest2V; ecliptTest2.Set( ecliptTest2V ); dmsTest2Long.Set( ecliptTest2.Longitude() ); TESTCHECK( dmsTest2Long.Positive(), true, &ok ); TESTCHECK( dmsTest2Long.Degrees(), 248, &ok ); TESTCHECK( dmsTest2Long.Minutes(), 17, &ok ); TESTCHECKFE( dmsTest2Long.Seconds(), 30.82, &ok, 1e-3 ); dmsTest2Lat.Set( ecliptTest2.Latitude() ); TESTCHECK( dmsTest2Lat.Positive(), true, &ok ); TESTCHECK( dmsTest2Lat.Degrees(), 0, &ok ); TESTCHECK( dmsTest2Lat.Minutes(), 27, &ok ); TESTCHECKFE( dmsTest2Lat.Seconds(), 57.59, &ok, 1e-3 ); TESTCHECKF( ecliptTest2.Distance(), 1., &ok ); cout << "EclipticalToEquatorial( ecliptTest2, obliquity )" << endl; equatTest2 = EclipticalToEquatorial( ecliptTest2, obliquity ); AngleHMS hmsTest2RA( equatTest2.RightAscension() ); TESTCHECK( hmsTest2RA.Hours(), 16, &ok ); TESTCHECK( hmsTest2RA.Minutes(), 26, &ok ); TESTCHECKFE( hmsTest2RA.Seconds(), 29.399, &ok, 1e-3 ); AngleDMS dmsTest2Dec( equatTest2.Declination() ); TESTCHECK( dmsTest2Dec.Positive(), false, &ok ); TESTCHECK( dmsTest2Dec.Degrees(), 21, &ok ); TESTCHECK( dmsTest2Dec.Minutes(), 13, &ok ); TESTCHECKFE( dmsTest2Dec.Seconds(), 38.39, &ok, 1e-3 ); TESTCHECKF( equatTest2.Distance(), 1., &ok ); cout << "Same test, using points and matrices" << endl; ecliptTest2V = ecliptTest2.Rectangular(); eclipt2equat = EclipticalToEquatorialMatrix( obliquity ); equatTest2V = eclipt2equat * ecliptTest2V; equatTest2.Set( equatTest2V ); hmsTest2RA.Set( equatTest2.RightAscension() ); TESTCHECK( hmsTest2RA.Hours(), 16, &ok ); TESTCHECK( hmsTest2RA.Minutes(), 26, &ok ); TESTCHECKFE( hmsTest2RA.Seconds(), 29.399, &ok, 1e-3 ); dmsTest2Dec.Set( equatTest2.Declination() ); TESTCHECK( dmsTest2Dec.Positive(), false, &ok ); TESTCHECK( dmsTest2Dec.Degrees(), 21, &ok ); TESTCHECK( dmsTest2Dec.Minutes(), 13, &ok ); TESTCHECKF( dmsTest2Dec.Seconds(), 38.39, &ok ); TESTCHECKFE( equatTest2.Distance(), 1., &ok, 1e-3 ); if ( ok ) cout << "AstroCoordTransformations PASSED." << endl << endl; else cout << "AstroCoordTransformations FAILED." << endl << endl; return ok; }