From 3dc5efee9abc16733d31354fd39dd5faa4c38553 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 14 May 2019 00:20:49 +0100 Subject: [PATCH] Basic implementation of the IFocusserV3 --- MeadeAutostar497/AscomClasses/Telescope.cs | 20 +++-- .../Controller/ITelescopeController.cs | 3 + .../Controller/TelescopeController.cs | 74 +++++++++++++++++++ 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/MeadeAutostar497/AscomClasses/Telescope.cs b/MeadeAutostar497/AscomClasses/Telescope.cs index d17efa0..b9acd64 100644 --- a/MeadeAutostar497/AscomClasses/Telescope.cs +++ b/MeadeAutostar497/AscomClasses/Telescope.cs @@ -949,8 +949,8 @@ namespace ASCOM.MeadeAutostar497 #region IFocuser Implementation - private int focuserPosition = 0; // Class level variable to hold the current focuser position - private const int focuserSteps = 10000; + //private int focuserPosition = 0; // Class level variable to hold the current focuser position + //private const int focuserSteps = 10000; public bool Absolute { @@ -994,8 +994,9 @@ namespace ASCOM.MeadeAutostar497 { get { - tl.LogMessage("MaxIncrement Get", focuserSteps.ToString()); - return focuserSteps; // Maximum change in one move + var maxIncrement = _telescopeController.FocuserMaxIncrement; + tl.LogMessage("MaxIncrement Get", maxIncrement.ToString()); + return maxIncrement; // Maximum change in one move } } @@ -1003,22 +1004,25 @@ namespace ASCOM.MeadeAutostar497 { get { - tl.LogMessage("MaxStep Get", focuserSteps.ToString()); - return focuserSteps; // Maximum extent of the focuser, so position range is 0 to 10,000 + var maxStep = _telescopeController.FocuserMaxStep; + tl.LogMessage("MaxStep Get", maxStep.ToString()); + return maxStep; } } public void Move(int Position) { tl.LogMessage("Move", Position.ToString()); - focuserPosition = Position; // Set the focuser position + _telescopeController.FocuserMove(Position); + //focuserPosition = Position; // Set the focuser position } public int Position { get { - return focuserPosition; // Return the focuser position + throw new ASCOM.PropertyNotImplementedException("Position", false); + //return focuserPosition; // Return the focuser position } } diff --git a/MeadeAutostar497/Controller/ITelescopeController.cs b/MeadeAutostar497/Controller/ITelescopeController.cs index bcc7b23..a31d9d9 100644 --- a/MeadeAutostar497/Controller/ITelescopeController.cs +++ b/MeadeAutostar497/Controller/ITelescopeController.cs @@ -21,6 +21,8 @@ namespace ASCOM.MeadeAutostar497.Controller double TargetRightAscension { get; set; } double TargetDeclination { get; set; } DriveRates TrackingRate { get; } + int FocuserMaxIncrement { get; set; } + int FocuserMaxStep { get; set; } void AbortSlew(); void PulseGuide(GuideDirections direction, int duration); void Park(); @@ -33,5 +35,6 @@ namespace ASCOM.MeadeAutostar497.Controller void SlewToTargetAsync(); void MoveAxis(TelescopeAxes axis, double rate); void FocuserHalt(); + void FocuserMove(int position); } } \ No newline at end of file diff --git a/MeadeAutostar497/Controller/TelescopeController.cs b/MeadeAutostar497/Controller/TelescopeController.cs index ca72cc1..209dd09 100644 --- a/MeadeAutostar497/Controller/TelescopeController.cs +++ b/MeadeAutostar497/Controller/TelescopeController.cs @@ -97,6 +97,7 @@ namespace ASCOM.MeadeAutostar497.Controller SerialPort.Open(); TestConnectionActive(); + SetFocuserSpeedFastest(); } catch (Exception) { @@ -520,6 +521,10 @@ namespace ASCOM.MeadeAutostar497.Controller } } + public int FocuserMaxIncrement { get; set; } = 7000; + + public int FocuserMaxStep { get; set; } = 7000; + public double Altitude { get { @@ -730,6 +735,7 @@ namespace ASCOM.MeadeAutostar497.Controller private bool _movingPrimary; private bool _movingSecondary; + public void MoveAxis(TelescopeAxes axis, double rate) { SerialPort.Lock(); @@ -840,6 +846,74 @@ namespace ASCOM.MeadeAutostar497.Controller //Returns: Nothing } + public void FocuserMove(int newPosition) + { + //todo implement backlash compensation + //todo implement direction reverse + //todo implement dynamic braking + + if (newPosition < -FocuserMaxIncrement || newPosition > FocuserMaxIncrement) + { + throw new ASCOM.InvalidValueException($"position out of range {-FocuserMaxIncrement} < {newPosition} < {FocuserMaxIncrement}"); + } + + if (newPosition == 0) + return; + + if (newPosition > 0) + { + //desired move direction is out + MoveFocuser(true, Math.Abs(newPosition)); + } + else + { + //desired move direction is in + MoveFocuser(false, Math.Abs(newPosition)); + } + } + + private void MoveFocuser(bool directionOut, int steps) + { + SerialPort.Command(directionOut ? ":F+#" : ":F-#"); + //:F+# Start Focuser moving inward (toward objective) + //Returns: None + + //:F-# Start Focuser moving outward (away from objective) + //Returns: None + + Util.WaitForMilliseconds(steps); + + FocuserHalt(); + } + + private void SetFocuserSpeedFastest() + { + SerialPort.Command(":FF#"); + //:FF# Set Focus speed to fastest setting + //Returns: Nothing + } + + private void SetFocuserSpeedSlowest() + { + SerialPort.Command(":FS#"); + //:FS# Set Focus speed to slowest setting + //Returns: Nothing + } + + private void SetFocuserSpeed( int speed) + { + if (speed < 1) + throw new ArgumentOutOfRangeException("speed is too low"); + + if (speed > 4) + throw new ArgumentOutOfRangeException("speed is too high"); + + SerialPort.Command($":F{speed}#"); + //:F# Autostar, Autostar II – set focuser speed to where is an ASCII digit 1..4 + //Returns: Nothing + //All others – Not Supported + } + //todo remove the polar parameter and split method into two. private void DoSlewAsync( bool polar) {