Added support for MoveAxis

This commit is contained in:
2019-05-07 17:51:08 +01:00
parent cc5eabdfab
commit 5d16edee2e
5 changed files with 341 additions and 198 deletions
@@ -30,5 +30,6 @@ namespace ASCOM.MeadeAutostar497.Controller
void SyncToTarget();
void SlewToTarget();
void SlewToTargetAsync();
void MoveAxis(TelescopeAxes axis, double rate);
}
}
@@ -129,6 +129,10 @@ namespace ASCOM.MeadeAutostar497.Controller
{
if (!Connected) return false;
if (movingAxis())
return true;
var result = SerialPort.CommandTerminated(":D#", "#");
return result != string.Empty;
}
@@ -651,6 +655,107 @@ namespace ASCOM.MeadeAutostar497.Controller
DoSlewAsync(true);
}
private bool movingAxis()
{
return _movingPrimary || _movingSecondary;
}
private bool _movingPrimary;
private bool _movingSecondary;
public void MoveAxis(TelescopeAxes axis, double rate)
{
var absrate = Math.Abs(rate);
switch(absrate)
{
case 0:
//do nothing, it's ok this time as we're halting the slew.
break;
case 1:
SerialPort.Command(":RG#");
//:RG# Set Slew rate to Guiding Rate (slowest)
//Returns: Nothing
break;
case 2:
SerialPort.Command(":RC#");
//:RC# Set Slew rate to Centering rate (2nd slowest)
//Returns: Nothing
break;
case 3:
SerialPort.Command(":RM#");
//:RM# Set Slew rate to Find Rate (2nd Fastest)
//Returns: Nothing
break;
case 4:
SerialPort.Command(":RS#");
//:RS# Set Slew rate to max (fastest)
//Returns: Nothing
break;
default:
throw new ASCOM.InvalidValueException($"Rate {rate} not supported");
}
switch (axis)
{
case TelescopeAxes.axisPrimary:
if (rate == 0)
{
_movingPrimary = false;
SerialPort.Command(":Qe#");
//:Qe# Halt eastward Slews
//Returns: Nothing
SerialPort.Command(":Qw#");
//:Qw# Halt westward Slews
//Returns: Nothing
}
else if (rate > 0)
{
SerialPort.Command(":Me#");
//:Me# Move Telescope East at current slew rate
//Returns: Nothing
_movingPrimary = true;
}
else
{
SerialPort.Command(":Mw#");
//:Mw# Move Telescope West at current slew rate
//Returns: Nothing
_movingPrimary = true;
}
break;
case TelescopeAxes.axisSecondary:
if (rate == 0)
{
_movingSecondary = false;
SerialPort.Command(":Qn#");
//:Qn# Halt northward Slews
//Returns: Nothing
SerialPort.Command(":Qs#");
//:Qs# Halt southward Slews
//Returns: Nothing
}
else if (rate > 0)
{
SerialPort.Command(":Mn#");
//:Mn# Move Telescope North at current slew rate
//Returns: Nothing
_movingSecondary = true;
}
else
{
SerialPort.Command(":Ms#");
//:Ms# Move Telescope South at current slew rate
//Returns: Nothing
_movingSecondary = true;
}
break;
default:
throw new ASCOM.MethodNotImplementedException("Can not move this axis.");
}
}
//todo remove the polar parameter and split method into two.
private void DoSlewAsync( bool polar)
{