bool ScopeSim::Goto(double ra,double dec) { DEBUGF(DBG_SIMULATOR, "Goto - Celestial reference frame target right ascension %lf(%lf) declination %lf", ra * 360.0 / 24.0, ra, dec); if (ISS_ON == IUFindSwitch(&CoordSP,"TRACK")->s) { char RAStr[32], DecStr[32]; fs_sexa(RAStr, ra, 2, 3600); fs_sexa(DecStr, dec, 2, 3600); CurrentTrackingTarget.ra = ra; CurrentTrackingTarget.dec = dec; DEBUG(DBG_SIMULATOR, "Goto - tracking requested"); } // Call the alignment subsystem to translate the celestial reference frame coordinate // into a telescope reference frame coordinate TelescopeDirectionVector TDV; ln_hrz_posn AltAz; if (TransformCelestialToTelescope(ra, dec, 0.0, TDV)) { // The alignment subsystem has successfully transformed my coordinate AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } else { // The alignment subsystem cannot transform the coordinate. // Try some simple rotations using the stored observatory position if any bool HavePosition = false; ln_lnlat_posn Position; if ((NULL != IUFindNumber(&LocationNP, "LAT")) && ( 0 != IUFindNumber(&LocationNP, "LAT")->value) && (NULL != IUFindNumber(&LocationNP, "LONG")) && ( 0 != IUFindNumber(&LocationNP, "LONG")->value)) { // I assume that being on the equator and exactly on the prime meridian is unlikely Position.lat = IUFindNumber(&LocationNP, "LAT")->value; Position.lng = IUFindNumber(&LocationNP, "LONG")->value; HavePosition = true; } struct ln_equ_posn EquatorialCoordinates; // libnova works in decimal degrees EquatorialCoordinates.ra = ra * 360.0 / 24.0; EquatorialCoordinates.dec = dec; if (HavePosition) { ln_get_hrz_from_equ(&EquatorialCoordinates, &Position, ln_get_julian_from_sys(), &AltAz); TDV = TelescopeDirectionVectorFromAltitudeAzimuth(AltAz); switch (GetApproximateMountAlignment()) { case ZENITH: break; case NORTH_CELESTIAL_POLE: // Rotate the TDV coordinate system clockwise (negative) around the y axis by 90 minus // the (positive)observatory latitude. The vector itself is rotated anticlockwise TDV.RotateAroundY(Position.lat - 90.0); break; case SOUTH_CELESTIAL_POLE: // Rotate the TDV coordinate system anticlockwise (positive) around the y axis by 90 plus // the (negative)observatory latitude. The vector itself is rotated clockwise TDV.RotateAroundY(Position.lat + 90.0); break; } AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } else { // The best I can do is just do a direct conversion to Alt/Az TDV = TelescopeDirectionVectorFromEquatorialCoordinates(EquatorialCoordinates); AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } } // My altitude encoder runs -90 to +90 if ((AltAz.alt > 90.0) || (AltAz.alt < -90.0)) { DEBUG(DBG_SIMULATOR, "Goto - Altitude out of range"); // This should not happen return false; } // My polar encoder runs 0 to +360 if ((AltAz.az > 360.0) || (AltAz.az < -360.0)) { DEBUG(DBG_SIMULATOR, "Goto - Azimuth out of range"); // This should not happen return false; } if (AltAz.az < 0.0) { DEBUG(DBG_SIMULATOR, "Goto - Azimuth negative"); AltAz.az = 360.0 + AltAz.az; } DEBUGF(DBG_SIMULATOR, "Goto - Scope reference frame target altitude %lf azimuth %lf", AltAz.alt, AltAz.az); GotoTargetMicrostepsDEC = int(AltAz.alt * MICROSTEPS_PER_DEGREE); if (GotoTargetMicrostepsDEC == CurrentEncoderMicrostepsDEC) AxisStatusDEC = STOPPED; else { if (GotoTargetMicrostepsDEC > CurrentEncoderMicrostepsDEC) AxisDirectionDEC = FORWARD; else AxisDirectionDEC = REVERSE; AxisStatusDEC = SLEWING_TO; } GotoTargetMicrostepsRA = int(AltAz.az * MICROSTEPS_PER_DEGREE); if (GotoTargetMicrostepsRA == CurrentEncoderMicrostepsRA) AxisStatusRA = STOPPED; else { if (GotoTargetMicrostepsRA > CurrentEncoderMicrostepsRA) AxisDirectionRA = (GotoTargetMicrostepsRA - CurrentEncoderMicrostepsRA) < MICROSTEPS_PER_REVOLUTION / 2.0 ? FORWARD : REVERSE; else AxisDirectionRA = (CurrentEncoderMicrostepsRA - GotoTargetMicrostepsRA) < MICROSTEPS_PER_REVOLUTION / 2.0 ? REVERSE : FORWARD; AxisStatusRA = SLEWING_TO; } TrackState = SCOPE_SLEWING; EqNP.s = IPS_BUSY; return true; }
ln_hrz_posn NexStarEvo::AltAzFromRaDec(double ra, double dec, double ts) { // Call the alignment subsystem to translate the celestial reference frame coordinate // into a telescope reference frame coordinate TelescopeDirectionVector TDV; ln_hrz_posn AltAz; if (TransformCelestialToTelescope(ra, dec, ts, TDV)) { // The alignment subsystem has successfully transformed my coordinate AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } else { // The alignment subsystem cannot transform the coordinate. // Try some simple rotations using the stored observatory position if any bool HavePosition = false; ln_lnlat_posn Position; if ((NULL != IUFindNumber(&LocationNP, "LAT")) && (0 != IUFindNumber(&LocationNP, "LAT")->value) && (NULL != IUFindNumber(&LocationNP, "LONG")) && (0 != IUFindNumber(&LocationNP, "LONG")->value)) { // I assume that being on the equator and exactly on the prime meridian is unlikely Position.lat = IUFindNumber(&LocationNP, "LAT")->value; Position.lng = IUFindNumber(&LocationNP, "LONG")->value; HavePosition = true; } struct ln_equ_posn EquatorialCoordinates; // libnova works in decimal degrees EquatorialCoordinates.ra = ra * 360.0 / 24.0; EquatorialCoordinates.dec = dec; if (HavePosition) { ln_get_hrz_from_equ(&EquatorialCoordinates, &Position, ln_get_julian_from_sys() + ts, &AltAz); TDV = TelescopeDirectionVectorFromAltitudeAzimuth(AltAz); switch (GetApproximateMountAlignment()) { case ZENITH: break; case NORTH_CELESTIAL_POLE: // Rotate the TDV coordinate system clockwise (negative) around the y axis by 90 minus // the (positive)observatory latitude. The vector itself is rotated anticlockwise TDV.RotateAroundY(Position.lat - 90.0); break; case SOUTH_CELESTIAL_POLE: // Rotate the TDV coordinate system anticlockwise (positive) around the y axis by 90 plus // the (negative)observatory latitude. The vector itself is rotated clockwise TDV.RotateAroundY(Position.lat + 90.0); break; } AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } else { // The best I can do is just do a direct conversion to Alt/Az TDV = TelescopeDirectionVectorFromEquatorialCoordinates(EquatorialCoordinates); AltitudeAzimuthFromTelescopeDirectionVector(TDV, AltAz); } } return AltAz; }