public SkyAtlasVM(IProfileService profileService, ITelescopeMediator telescopeMediator) : base(profileService) { // Not required to register to the mediator, as we don't need updates this.telescopeMediator = telescopeMediator; ResetFilters(null); SearchCommand = new AsyncCommand <bool>(() => Search()); CancelSearchCommand = new RelayCommand(CancelSearch); ResetFiltersCommand = new RelayCommand(ResetFilters); SetSequenceCoordinatesCommand = new AsyncCommand <bool>(() => SetSequenceCoordinates()); SlewToCoordinatesCommand = new AsyncCommand <bool>(async() => { return(await telescopeMediator.SlewToCoordinatesAsync(SearchResult.SelectedItem.Coordinates)); }); SetFramingAssistantCoordinatesCommand = new AsyncCommand <bool>(() => SetFramingAssistantCoordinates()); InitializeFilters(); PageSize = 50; profileService.LocationChanged += (object sender, EventArgs e) => { _nightDuration = null; //Clear cache InitializeElevationFilters(); ResetRiseAndSetTimes(); }; profileService.LocaleChanged += (object sender, EventArgs e) => { InitializeFilters(); }; Ticker = new Ticker(TimeSpan.FromSeconds(30)); }
public FocusTargetsVM(IProfileService profileService, ITelescopeMediator telescopeMediator, IApplicationResourceDictionary resourceDictionary) : base(profileService) { Title = "LblManualFocusTargets"; ImageGeometry = (System.Windows.Media.GeometryGroup)resourceDictionary["FocusTargetsSVG"]; this.telescopeMediator = telescopeMediator; telescopeMediator.RegisterConsumer(this); AsyncContext.Run(LoadFocusTargets); updateTimer = new Timer(TimeSpan.FromMinutes(1).TotalMilliseconds) { AutoReset = true }; updateTimer.Elapsed += (sender, args) => CalculateVisibleStars(); if (IsVisible) { updateTimer.Start(); } SlewToCoordinatesCommand = new AsyncCommand <bool>(async() => await telescopeMediator.SlewToCoordinatesAsync(SelectedFocusTarget.Coordinates)); }
public async Task <PlateSolveResult> Center(CaptureSequence seq, CenterSolveParameter parameter, IProgress <PlateSolveProgress> solveProgress, IProgress <ApplicationStatus> progress, CancellationToken ct) { if (parameter?.Coordinates == null) { throw new ArgumentException(nameof(CenterSolveParameter.Coordinates)); } if (parameter?.Threshold <= 0) { throw new ArgumentException(nameof(CenterSolveParameter.Threshold)); } var centered = false; PlateSolveResult result; Separation offset = new Separation(); do { result = await CaptureSolver.Solve(seq, parameter, solveProgress, progress, ct); if (result.Success == false) { //Solving failed. Give up. break; } var position = (telescopeMediator.GetCurrentPosition() - offset).Transform(result.Coordinates.Epoch); result.Separation = result.DetermineSeparation(position); Logger.Debug($"Centering Solver - Scope Position: {position}; Centering Coordinates: {parameter.Coordinates}; Solve Result: {result.Coordinates}; Separation {result.Separation}"); solveProgress?.Report(new PlateSolveProgress() { PlateSolveResult = result }); if (Math.Abs(result.Separation.Distance.ArcMinutes) > parameter.Threshold) { progress?.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblPlateSolveNotInsideToleranceSyncing"] }); if (parameter.NoSync || !await telescopeMediator.Sync(result.Coordinates)) { offset = result.DetermineSeparation(position + offset); Logger.Debug($"Sync failed - calculating offset instead to compensate. Original: {position.Transform(result.Coordinates.Epoch)}; Solved: {result.Coordinates}; Offset: {offset}"); progress?.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblPlateSolveSyncViaTargetOffset"] }); } else { var positionAfterSync = telescopeMediator.GetCurrentPosition().Transform(result.Coordinates.Epoch); if (Astrometry.DegreeToArcsec(Math.Abs(positionAfterSync.RADegrees - result.Coordinates.RADegrees)) > 1 || Astrometry.DegreeToArcsec(Math.Abs(positionAfterSync.Dec - result.Coordinates.Dec)) > 1) { offset = result.DetermineSeparation(positionAfterSync); Logger.Debug($"Sync failed silently - calculating offset instead to compensate. Original: {positionAfterSync}; Solved: {result.Coordinates}; Offset: {offset}"); } else { // Sync worked - reset offset Logger.Debug("Synced sucessfully"); offset = new Separation(); } } Logger.Trace($"Slewing to target after sync. Target coordinates RA: {parameter.Coordinates.RAString} Dec: {parameter.Coordinates.DecString} Epoch: {parameter.Coordinates.Epoch}"); progress?.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblPlateSolveNotInsideToleranceReslew"] }); await telescopeMediator.SlewToCoordinatesAsync(parameter.Coordinates + offset); progress?.Report(new ApplicationStatus() { Status = Locale.Loc.Instance["LblPlateSolveNotInsideToleranceRepeating"] }); } else { centered = true; } } while (!centered); return(result); }
public FramingAssistantVM(IProfileService profileService, ICameraMediator cameraMediator, ITelescopeMediator telescopeMediator, IApplicationStatusMediator applicationStatusMediator) : base(profileService) { this.cameraMediator = cameraMediator; this.cameraMediator.RegisterConsumer(this); this.telescopeMediator = telescopeMediator; this.applicationStatusMediator = applicationStatusMediator; Opacity = 0.2; SkyMapAnnotator = new SkyMapAnnotator(telescopeMediator); var defaultCoordinates = new Coordinates(0, 0, Epoch.J2000, Coordinates.RAType.Degrees); DSO = new DeepSkyObject(string.Empty, defaultCoordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); FramingAssistantSource = profileService.ActiveProfile.FramingAssistantSettings.LastSelectedImageSource; CameraPixelSize = profileService.ActiveProfile.CameraSettings.PixelSize; FocalLength = profileService.ActiveProfile.TelescopeSettings.FocalLength; _statusUpdate = new Progress <ApplicationStatus>(p => Status = p); LoadImageCommand = new AsyncCommand <bool>(async() => { return(await LoadImage()); }); CancelLoadImageFromFileCommand = new RelayCommand((object o) => { CancelLoadImage(); }); _progress = new Progress <int>((p) => DownloadProgressValue = p); CancelLoadImageCommand = new RelayCommand((object o) => { CancelLoadImage(); }); DragStartCommand = new RelayCommand(DragStart); DragStopCommand = new RelayCommand(DragStop); DragMoveCommand = new RelayCommand(DragMove); ClearCacheCommand = new RelayCommand(ClearCache, (object o) => Cache != null); RefreshSkyMapAnnotationCommand = new RelayCommand((object o) => SkyMapAnnotator.UpdateSkyMap(), (object o) => SkyMapAnnotator.Initialized); MouseWheelCommand = new RelayCommand(MouseWheel); CoordsFromPlanetariumCommand = new AsyncCommand <bool>(() => Task.Run(CoordsFromPlanetarium)); DeepSkyObjectSearchVM = new DeepSkyObjectSearchVM(); DeepSkyObjectSearchVM.PropertyChanged += DeepSkyObjectSearchVM_PropertyChanged; SetSequenceCoordinatesCommand = new AsyncCommand <bool>(async(object parameter) => { var vm = (ApplicationVM)Application.Current.Resources["AppVM"]; vm.ChangeTab(ApplicationTab.SEQUENCE); var deepSkyObjects = new List <DeepSkyObject>(); foreach (var rect in CameraRectangles) { var name = rect.Id > 0 ? DSO?.Name + string.Format(" {0} ", Locale.Loc.Instance["LblPanel"]) + rect.Id : DSO?.Name; var dso = new DeepSkyObject(name, rect.Coordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); dso.Rotation = Rectangle.DisplayedRotation; deepSkyObjects.Add(dso); } bool msgResult = false; if (parameter.ToString() == "Replace") { msgResult = await vm.SeqVM.SetSequenceCoordiantes(deepSkyObjects); } else if (parameter.ToString() == "Add") { msgResult = await vm.SeqVM.SetSequenceCoordiantes(deepSkyObjects, false); } ImageParameter = null; GC.Collect(); GC.WaitForPendingFinalizers(); return(msgResult); }, (object o) => Rectangle?.Coordinates != null); RecenterCommand = new AsyncCommand <bool>(async() => { DSO.Coordinates = Rectangle.Coordinates; await LoadImageCommand.ExecuteAsync(null); return(true); }, (object o) => Rectangle?.Coordinates != null); SlewToCoordinatesCommand = new AsyncCommand <bool>(async() => { return(await telescopeMediator.SlewToCoordinatesAsync(Rectangle.Coordinates)); }, (object o) => Rectangle?.Coordinates != null); var appSettings = profileService.ActiveProfile.ApplicationSettings; appSettings.PropertyChanged += ApplicationSettings_PropertyChanged; profileService.ProfileChanged += (object sender, EventArgs e) => { appSettings.PropertyChanged -= ApplicationSettings_PropertyChanged; this.FocalLength = profileService.ActiveProfile.TelescopeSettings.FocalLength; this.CameraPixelSize = profileService.ActiveProfile.CameraSettings.PixelSize; RaisePropertyChanged(nameof(CameraPixelSize)); RaisePropertyChanged(nameof(FocalLength)); RaisePropertyChanged(nameof(FieldOfView)); RaisePropertyChanged(nameof(CameraWidth)); RaisePropertyChanged(nameof(CameraHeight)); appSettings = profileService.ActiveProfile.ApplicationSettings; appSettings.PropertyChanged += ApplicationSettings_PropertyChanged; ApplicationSettings_PropertyChanged(null, null); }; resizeTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, _dispatcher); resizeTimer.Interval = TimeSpan.FromMilliseconds(500); resizeTimer.Tick += ResizeTimer_Tick; ScrollViewerSizeChangedCommand = new RelayCommand((parameter) => { resizeTimer.Stop(); if (ImageParameter != null && FramingAssistantSource == SkySurveySource.SKYATLAS) { resizeTimer.Start(); } }); profileService.LocationChanged += (object sender, EventArgs e) => { DSO = new DeepSkyObject(DSO.Name, DSO.Coordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); }; InitializeCache(); }
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); }