Example #1
0
        /// <summary>
        /// Finds a theoretical home position for the telescope to return to. It will be pointing to the Celestial Pole, but in such a way that
        /// CW bar should be nearly vertical, and there is no meridian flip involved.
        /// </summary>
        /// <param name="currentCoordinates"></param>
        /// <returns></returns>
        private Coordinates GetHomeCoordinates(Coordinates currentCoordinates)
        {
            double siderealTime = Astrometry.GetLocalSiderealTimeNow(profileService.ActiveProfile.AstrometrySettings.Longitude);

            if (siderealTime > 24)
            {
                siderealTime -= 24;
            }
            if (siderealTime < 0)
            {
                siderealTime += 24;
            }
            double      timeToMed         = currentCoordinates.RA - siderealTime;
            Coordinates returnCoordinates = new Coordinates(Angle.ByHours(0), Angle.ByDegree(0), Epoch.J2000);

            if (profileService.ActiveProfile.AstrometrySettings.HemisphereType == Hemisphere.NORTHERN)
            {
                returnCoordinates.Dec = 89;
                returnCoordinates.RA  = siderealTime + 6 * Math.Sign(timeToMed);
            }
            if (profileService.ActiveProfile.AstrometrySettings.HemisphereType == Hemisphere.SOUTHERN)
            {
                returnCoordinates.Dec = -89;
                returnCoordinates.RA  = siderealTime + 6 * Math.Sign(timeToMed);
            }
            return(returnCoordinates);
        }
Example #2
0
        private async Task <bool> MeasurePolarError(IProgress <ApplicationStatus> progress, Direction direction)
        {
            if (CameraInfo?.Connected == true)
            {
                cancelMeasureErrorToken?.Dispose();
                cancelMeasureErrorToken = new CancellationTokenSource();
                Task moveBackTask = Task.CompletedTask;
                try {
                    var siderealTime = Astrometry.GetLocalSiderealTimeNow(profileService.ActiveProfile.AstrometrySettings.Longitude);
                    var latitude     = Angle.ByDegree(profileService.ActiveProfile.AstrometrySettings.Latitude);
                    var dec          = Angle.ByDegree(TelescopeInfo.Declination);
                    var hourAngle    = Astrometry.GetHourAngle(Angle.ByHours(siderealTime), Angle.ByHours(TelescopeInfo.Coordinates.RA));
                    var altitude     = Astrometry.GetAltitude(hourAngle, latitude, dec);
                    var azimuth      = Astrometry.GetAzimuth(hourAngle, altitude, latitude, dec);
                    var altitudeSide = azimuth.Degree < 180 ? AltitudeSite.EAST : AltitudeSite.WEST;

                    Coordinates startPosition = telescopeMediator.GetCurrentPosition();
                    double      poleErr       = await CalculatePoleError(startPosition, progress, cancelMeasureErrorToken.Token);

                    moveBackTask = telescopeMediator.SlewToCoordinatesAsync(startPosition);

                    string poleErrString = Deg2str(Math.Abs(poleErr), 4);
                    cancelMeasureErrorToken.Token.ThrowIfCancellationRequested();
                    if (double.IsNaN(poleErr))
                    {
                        /* something went wrong */
                        progress.Report(new ApplicationStatus()
                        {
                            Status = string.Empty
                        });
                        return(false);
                    }

                    string msg = "";

                    if (direction == Direction.ALTITUDE)
                    {
                        if (profileService.ActiveProfile.AstrometrySettings.HemisphereType == Hemisphere.NORTHERN)
                        {
                            if (altitudeSide == AltitudeSite.EAST)
                            {
                                if (poleErr < 0)
                                {
                                    msg = poleErrString + " too low";
                                }
                                else
                                {
                                    msg = poleErrString + " too high";
                                }
                            }
                            else
                            {
                                if (poleErr < 0)
                                {
                                    msg = poleErrString + " too high";
                                }
                                else
                                {
                                    msg = poleErrString + " too low";
                                }
                            }
                        }
                        else
                        {
                            if (altitudeSide == AltitudeSite.EAST)
                            {
                                if (poleErr < 0)
                                {
                                    msg = poleErrString + " too high";
                                }
                                else
                                {
                                    msg = poleErrString + " too low";
                                }
                            }
                            else
                            {
                                if (poleErr < 0)
                                {
                                    msg = poleErrString + " too low";
                                }
                                else
                                {
                                    msg = poleErrString + " too high";
                                }
                            }
                        }
                    }
                    else if (direction == Direction.AZIMUTH)
                    {
                        //if northern
                        if (profileService.ActiveProfile.AstrometrySettings.HemisphereType == Hemisphere.NORTHERN)
                        {
                            if (poleErr < 0)
                            {
                                msg = poleErrString + " too east";
                            }
                            else
                            {
                                msg = poleErrString + " too west";
                            }
                        }
                        else
                        {
                            if (poleErr < 0)
                            {
                                msg = poleErrString + " too west";
                            }
                            else
                            {
                                msg = poleErrString + " too east";
                            }
                        }
                    }

                    progress.Report(new ApplicationStatus()
                    {
                        Status = msg
                    });
                } catch (OperationCanceledException) {
                } finally {
                    await moveBackTask;
                }

                /*  Altitude
                 *      Northern
                 *          East side
                 *              poleError < 0 -> too low
                 *              poleError > 0 -> too high
                 *  Azimuth
                 *      Northern
                 *          South side
                 *              poleError < 0 -> too east
                 *              poleError > 0 -> too west
                 */
            }
            else
            {
                Notification.ShowWarning(Locale.Loc.Instance["LblNoCameraConnected"]);
            }

            return(true);
        }