From 6601fa62056c546fa8c2c3a3aad60ad8caf6e46d Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 11 Dec 2019 23:53:37 +0000 Subject: [PATCH 1/2] Added a check to ensure that pulse guide commands fail when the scope is slewing or already being moved on the same axes. --- .../TelescopeUnitTests.cs | 34 +++++++++++++ Meade.net.Telescope/Telescope.cs | 48 ++++++++++++------- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index df3637c..25f49a3 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1322,6 +1322,40 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Verify( x => x.WaitForMilliseconds(duration), Times.Once); } + [TestCase(GuideDirections.guideEast)] + [TestCase(GuideDirections.guideWest)] + [TestCase(GuideDirections.guideNorth)] + [TestCase(GuideDirections.guideSouth)] + public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) + { + _sharedResourcesWrapperMock.Setup(x => x.SendString("#:D#")).Returns("|"); + + var duration = 0; + ConnectTelescope(); + + var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + + Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target.")); + } + + [TestCase(GuideDirections.guideEast, TelescopeAxes.axisPrimary)] + [TestCase(GuideDirections.guideWest, TelescopeAxes.axisPrimary)] + [TestCase(GuideDirections.guideNorth, TelescopeAxes.axisSecondary)] + [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] + public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) + { + _sharedResourcesWrapperMock.Setup(x => x.SendString("#:D#")).Returns(""); + + var duration = 0; + ConnectTelescope(); + + _telescope.MoveAxis(axes, 1); + + var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + + Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide while moving same axis.")); + } + [TestCase(GuideDirections.guideEast)] [TestCase(GuideDirections.guideWest)] [TestCase(GuideDirections.guideNorth)] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 96173de..f1d55f0 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1415,6 +1415,15 @@ namespace ASCOM.Meade.net LogMessage("PulseGuide", $"pulse guide direction {direction} duration {duration}"); CheckConnected("PulseGuide"); + if (IsSlewingToTarget()) + throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); + + if (_movingPrimary && (direction == GuideDirections.guideEast || direction == GuideDirections.guideWest)) + throw new InvalidOperationException("Unable to PulseGuide while moving same axis."); + + if (_movingSecondary && (direction == GuideDirections.guideNorth || direction == GuideDirections.guideSouth)) + throw new InvalidOperationException("Unable to PulseGuide while moving same axis."); + var coordinatesBeforeMove = GetTelescopeRaAndDec(); if (_userNewerPulseGuiding && duration < 10000) @@ -1928,26 +1937,31 @@ namespace ASCOM.Meade.net if (MovingAxis()) return true; - CheckConnected("Slewing Get"); - - var result = _sharedResourcesWrapper.SendString("#:D#"); - //:D# Requests a string of bars indicating the distance to the current target location. - //Returns: - //LX200's – a string of bar characters indicating the distance. - //Autostars and Autostar II – a string containing one bar until a slew is complete, then a null string is returned. - - if (result == null) - { - return false; - } - - bool isSlewing = result != string.Empty; - - LogMessage("Slewing Get", $"Result = {isSlewing}"); - return isSlewing; + return IsSlewingToTarget(); } } + private bool IsSlewingToTarget() + { + CheckConnected("Slewing Get"); + + var result = _sharedResourcesWrapper.SendString("#:D#"); + //:D# Requests a string of bars indicating the distance to the current target location. + //Returns: + //LX200's – a string of bar characters indicating the distance. + //Autostars and Autostar II – a string containing one bar until a slew is complete, then a null string is returned. + + if (result == null) + { + return false; + } + + bool isSlewing = result != string.Empty; + + LogMessage("Slewing Get", $"Result = {isSlewing}"); + return isSlewing; + } + public void SyncToAltAz(double azimuth, double altitude) { LogMessage("SyncToAltAz", "Not implemented"); From c7f1a4272f3826f677b63b843dc13ad50411595a Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 20 Feb 2020 21:31:09 +0000 Subject: [PATCH 2/2] Slewing now reports false when performing a guide command using the old guiding method. --- .../TelescopeUnitTests.cs | 23 ++++++++ Meade.net.Telescope/Telescope.cs | 59 ++++++++++++------- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 25f49a3..1bd772b 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1356,6 +1356,29 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide while moving same axis.")); } + [TestCase(GuideDirections.guideEast)] + [TestCase(GuideDirections.guideWest)] + [TestCase(GuideDirections.guideNorth)] + [TestCase(GuideDirections.guideSouth)] + public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenIsSlewingRespondsFalse(GuideDirections direction) + { + var duration = 0; + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); + + var isSlewing = true; + _utilMock.Setup(x => x.WaitForMilliseconds(duration)).Callback(() => + { + isSlewing = _telescope.Slewing; + }); + + _telescope.Connected = true; + + _telescope.PulseGuide(direction, duration); + + Assert.That(isSlewing, Is.False); + } + [TestCase(GuideDirections.guideEast)] [TestCase(GuideDirections.guideWest)] [TestCase(GuideDirections.guideNorth)] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index f1d55f0..8a41f33 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -134,7 +134,8 @@ namespace ASCOM.Meade.net } private double _guideRate; - + private bool _isGuiding = false; + private void Initialise() { //todo move the TraceLogger out to a factory class. @@ -1459,28 +1460,36 @@ namespace ASCOM.Meade.net } else { - switch (direction) + _isGuiding = true; + try { - case GuideDirections.guideEast: - MoveAxis(TelescopeAxes.axisPrimary, 1); - _utilities.WaitForMilliseconds(duration); - MoveAxis(TelescopeAxes.axisPrimary, 0); - break; - case GuideDirections.guideNorth: - MoveAxis(TelescopeAxes.axisSecondary, 1); - _utilities.WaitForMilliseconds(duration); - MoveAxis(TelescopeAxes.axisSecondary, 0); - break; - case GuideDirections.guideSouth: - MoveAxis(TelescopeAxes.axisSecondary, -1); - _utilities.WaitForMilliseconds(duration); - MoveAxis(TelescopeAxes.axisSecondary, 0); - break; - case GuideDirections.guideWest: - MoveAxis(TelescopeAxes.axisPrimary, -1); - _utilities.WaitForMilliseconds(duration); - MoveAxis(TelescopeAxes.axisPrimary, 0); - break; + switch (direction) + { + case GuideDirections.guideEast: + MoveAxis(TelescopeAxes.axisPrimary, 1); + _utilities.WaitForMilliseconds(duration); + MoveAxis(TelescopeAxes.axisPrimary, 0); + break; + case GuideDirections.guideNorth: + MoveAxis(TelescopeAxes.axisSecondary, 1); + _utilities.WaitForMilliseconds(duration); + MoveAxis(TelescopeAxes.axisSecondary, 0); + break; + case GuideDirections.guideSouth: + MoveAxis(TelescopeAxes.axisSecondary, -1); + _utilities.WaitForMilliseconds(duration); + MoveAxis(TelescopeAxes.axisSecondary, 0); + break; + case GuideDirections.guideWest: + MoveAxis(TelescopeAxes.axisPrimary, -1); + _utilities.WaitForMilliseconds(duration); + MoveAxis(TelescopeAxes.axisPrimary, 0); + break; + } + } + finally + { + _isGuiding = false; } } @@ -1924,6 +1933,9 @@ namespace ASCOM.Meade.net private bool MovingAxis() { + if (_isGuiding) + return false; + return _movingPrimary || _movingSecondary; } @@ -1945,6 +1957,9 @@ namespace ASCOM.Meade.net { CheckConnected("Slewing Get"); + if (_isGuiding) + return false; + var result = _sharedResourcesWrapper.SendString("#:D#"); //:D# Requests a string of bars indicating the distance to the current target location. //Returns: