From 18ea52c9721ebcf27dff4ca7d089a1a02ce9962e Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sat, 24 Apr 2021 20:52:21 +0100 Subject: [PATCH] Impemented the code changes to return co-ordinated when the telescope is parked. Also added loads of checks for if the telescope is parked. --- .../AstroMath.UnitTests.csproj | 4 + .../Meade.net.Telescope.csproj | 1 - Meade.net.Telescope/Telescope.cs | 95 +++++++++++++++---- .../AstroMaths/HorizonCoordinates.cs | 0 Meade.net/Meade.net.csproj | 2 + Meade.net/MeadeTelescopeBase.cs | 20 ++-- 6 files changed, 97 insertions(+), 25 deletions(-) rename {Meade.net.Telescope => Meade.net}/AstroMaths/HorizonCoordinates.cs (100%) diff --git a/AstroMath.UnitTests/AstroMath.UnitTests.csproj b/AstroMath.UnitTests/AstroMath.UnitTests.csproj index 9457f57..cffc483 100644 --- a/AstroMath.UnitTests/AstroMath.UnitTests.csproj +++ b/AstroMath.UnitTests/AstroMath.UnitTests.csproj @@ -90,6 +90,10 @@ {64308775-bd4a-469c-bcab-3ed830b811af} Meade.net.Telescope + + {3689a2cb-94c5-4012-a5cf-7e7d1dd27143} + Meade.net + diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index cfae8a4..92ec7b9 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -122,7 +122,6 @@ - diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 3c891ef..2d33ae8 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -878,6 +878,7 @@ namespace ASCOM.Meade.net public void AbortSlew() { CheckConnected("AbortSlew"); + CheckParked(); LogMessage("AbortSlew", "Aborting slew"); SharedResourcesWrapper.SendBlind(":Q#"); @@ -889,6 +890,12 @@ namespace ASCOM.Meade.net SetSlewingMinEndTime(); } + private void CheckParked() + { + if (AtPark) + throw new ParkedException("Telescope is parked"); + } + public AlignmentModes AlignmentMode { get @@ -974,7 +981,7 @@ namespace ASCOM.Meade.net get { CheckConnected("Altitude Get"); - + var altAz = CalcAltAzFromTelescopeEqData(); LogMessage("Altitude", $"{altAz.Altitude}"); return altAz.Altitude; @@ -1247,21 +1254,41 @@ namespace ASCOM.Meade.net } } + private double _lastGoodDeclination; + public double Declination { get { CheckConnected("Declination Get"); + try + { + CheckParked(); - var result = SharedResourcesWrapper.SendString(":GD#"); - //:GD# Get Telescope Declination. - //Returns: sDD*MM# or sDD*MM’SS# - //Depending upon the current precision setting for the telescope. + var result = SharedResourcesWrapper.SendString(":GD#"); + //:GD# Get Telescope Declination. + //Returns: sDD*MM# or sDD*MM’SS# + //Depending upon the current precision setting for the telescope. - double declination = _utilities.DMSToDegrees(result); + double declination = _utilities.DMSToDegrees(result); - LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); - return declination; + LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); + _lastGoodDeclination = declination; + return declination; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.LastGoodPosition: + return _lastGoodDeclination; + case ParkedBehaviour.ReportCoordinates: + var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); + return raDec.Declination; + default: + throw; + } + } } } @@ -1413,6 +1440,7 @@ namespace ASCOM.Meade.net { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); CheckConnected("MoveAxis"); + CheckParked(); var absRate = Math.Abs(rate); @@ -1535,6 +1563,7 @@ namespace ASCOM.Meade.net try { CheckConnected("PulseGuide"); + CheckParked(); if (IsSlewingToTarget()) throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); @@ -1644,21 +1673,43 @@ namespace ASCOM.Meade.net var hms = $"{token[0]}:{seconds}"; return _utilities.HMSToHours(hms); } + + double _lastGoodRightAsension; public double RightAscension { get { CheckConnected("RightAscension Get"); - var result = SharedResourcesWrapper.SendString(":GR#"); - //:GR# Get Telescope RA - //Returns: HH:MM.T# or HH:MM:SS# - //Depending which precision is set for the telescope + try + { + CheckParked(); - double rightAscension = HmToHours(result); + var result = SharedResourcesWrapper.SendString(":GR#"); + //:GR# Get Telescope RA + //Returns: HH:MM.T# or HH:MM:SS# + //Depending which precision is set for the telescope - LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); - return rightAscension; + double rightAscension = HmToHours(result); + + LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); + _lastGoodRightAsension = rightAscension; + return rightAscension; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.LastGoodPosition: + return _lastGoodRightAsension; + case ParkedBehaviour.ReportCoordinates: + var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); + return raDec.RightAscension; + default: + throw; + } + } + } } @@ -1870,6 +1921,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); CheckConnected("SlewToAltAz"); + CheckParked(); SlewToAltAzAsync(azimuth, altitude); @@ -1882,6 +1934,7 @@ namespace ASCOM.Meade.net public void SlewToAltAzAsync(double azimuth, double altitude) { CheckConnected("SlewToAltAzAsync"); + CheckParked(); if (altitude > 90) throw new InvalidValueException("Altitude cannot be greater than 90."); @@ -1922,6 +1975,7 @@ namespace ASCOM.Meade.net private void DoSlewAsync(bool polar) { CheckConnected("DoSlewAsync"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -1986,6 +2040,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); CheckConnected("SlewToCoordinates"); + CheckParked(); SlewToCoordinatesAsync(rightAscension, declination); @@ -2001,6 +2056,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); CheckConnected("SlewToCoordinatesAsync"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -2016,6 +2072,7 @@ namespace ASCOM.Meade.net { LogMessage("SlewToTarget", "Executing"); CheckConnected("SlewToTarget"); + CheckParked(); SlewToTargetAsync(); while (Slewing) @@ -2029,6 +2086,7 @@ namespace ASCOM.Meade.net public void SlewToTargetAsync() { CheckConnected("SlewToTargetAsync"); + CheckParked(); if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter)) throw new InvalidOperationException("No target selected to slew to."); @@ -2167,6 +2225,7 @@ namespace ASCOM.Meade.net LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}"); CheckConnected("SyncToCoordinates"); + CheckParked(); SharedResourcesWrapper.Lock(() => { @@ -2181,7 +2240,8 @@ namespace ASCOM.Meade.net { LogMessage("SyncToTarget", "Executing"); CheckConnected("SyncToTarget"); - + CheckParked(); + var result = SharedResourcesWrapper.SendString(":CM#"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: @@ -2234,6 +2294,7 @@ namespace ASCOM.Meade.net LogMessage("TargetDeclination Set", $"{value}"); CheckConnected("TargetDeclination Set"); + CheckParked(); if (value > 90) throw new InvalidValueException("Declination cannot be greater than 90."); @@ -2289,6 +2350,7 @@ namespace ASCOM.Meade.net { LogMessage("TargetRightAscension Set", $"{value}"); CheckConnected("TargetRightAscension Set"); + CheckParked(); if (value < 0) throw new InvalidValueException("Right ascension value cannot be below 0"); @@ -2357,6 +2419,7 @@ namespace ASCOM.Meade.net { LogMessage("TrackingRate Set", $"{value}"); CheckConnected("TrackingRate Set"); + CheckParked(); switch (value) { diff --git a/Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs b/Meade.net/AstroMaths/HorizonCoordinates.cs similarity index 100% rename from Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs rename to Meade.net/AstroMaths/HorizonCoordinates.cs diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index 366e8e0..c30849a 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -137,6 +137,7 @@ frmMain.cs + @@ -201,6 +202,7 @@ true +