Refactored the backlash compensation so that less move commands are issued.
This commit is contained in:
@@ -416,12 +416,11 @@ namespace Meade.net.Focuser.UnitTests
|
|||||||
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
|
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
|
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once());
|
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once());
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(1000), Times.Once());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(200, 3, 3)]
|
[TestCase(200)]
|
||||||
[TestCase(-200, 1, 0)]
|
[TestCase(-200)]
|
||||||
public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuserWithBacklashCompensation(int position, int hundredMsWaitCount, int backlashCompensaionCount)
|
public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuserWithBacklashCompensation(int position)
|
||||||
{
|
{
|
||||||
_profileProperties.BacklashCompensation = 3000;
|
_profileProperties.BacklashCompensation = 3000;
|
||||||
|
|
||||||
@@ -433,20 +432,20 @@ namespace Meade.net.Focuser.UnitTests
|
|||||||
{
|
{
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F-#"), Times.Once);
|
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F-#"), Times.Once);
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F+#"), Times.Never);
|
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F+#"), Times.Never);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F-#"), Times.Once);
|
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F-#"), Times.Once);
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F+#"), Times.Exactly(2));
|
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:F+#"), Times.Once);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once);
|
||||||
|
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
_sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny<Action>()), Times.Once);
|
_sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny<Action>()), Times.Once);
|
||||||
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once);
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Exactly(backlashCompensaionCount));
|
|
||||||
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(hundredMsWaitCount));
|
|
||||||
_utilMock.Verify(x => x.WaitForMilliseconds(1000), Times.Once);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -342,8 +342,6 @@ namespace ASCOM.Meade.net
|
|||||||
_tl.LogMessage("Move", position.ToString());
|
_tl.LogMessage("Move", position.ToString());
|
||||||
CheckConnected("Move");
|
CheckConnected("Move");
|
||||||
|
|
||||||
//todo implement dynamic braking
|
|
||||||
|
|
||||||
if (position < -MaxIncrement || position > MaxIncrement)
|
if (position < -MaxIncrement || position > MaxIncrement)
|
||||||
{
|
{
|
||||||
throw new InvalidValueException($"position out of range {-MaxIncrement} < {position} < {MaxIncrement}");
|
throw new InvalidValueException($"position out of range {-MaxIncrement} < {position} < {MaxIncrement}");
|
||||||
@@ -358,28 +356,32 @@ namespace ASCOM.Meade.net
|
|||||||
|
|
||||||
_sharedResourcesWrapper.Lock(() =>
|
_sharedResourcesWrapper.Lock(() =>
|
||||||
{
|
{
|
||||||
MoveFocuser(direction, Math.Abs(position));
|
//backlash compensation.
|
||||||
ApplyBacklashCompensation(direction);
|
var backlashCompensationSteps = direction ? Math.Abs(_backlashCompensation) : 0;
|
||||||
//This gives the focuser time to physically stop.
|
|
||||||
_utilities.WaitForMilliseconds(1000);
|
var steps = Math.Abs(position) + backlashCompensationSteps;
|
||||||
|
|
||||||
|
|
||||||
|
MoveFocuser(direction, steps);
|
||||||
|
|
||||||
|
|
||||||
|
//todo refactor the backlash compensation to combine the commands into as few moves as practicle.
|
||||||
|
//ApplyBacklashCompensation(direction);
|
||||||
|
if (direction & backlashCompensationSteps != 0)
|
||||||
|
{
|
||||||
|
_tl.LogMessage("Move", "Applying backlash compensation");
|
||||||
|
MoveFocuser(!direction, backlashCompensationSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
//This gives the focuser time to physically stop. Not sure if this is really needed.
|
||||||
|
//_utilities.WaitForMilliseconds(1000);
|
||||||
|
|
||||||
|
|
||||||
|
//todo implement dynamic braking
|
||||||
|
//dynamic breaking is sending the command to move in the opposite direction immediatly followed by the command to stop.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyBacklashCompensation(bool directionOut)
|
|
||||||
{
|
|
||||||
if (_backlashCompensation == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_tl.LogMessage("Move", "Applying backlash compensation");
|
|
||||||
|
|
||||||
if (directionOut)
|
|
||||||
{
|
|
||||||
MoveFocuser(directionOut, Math.Abs(_backlashCompensation));
|
|
||||||
_utilities.WaitForMilliseconds(Math.Abs(_backlashCompensation));
|
|
||||||
MoveFocuser(!directionOut, Math.Abs(_backlashCompensation));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MoveFocuser(bool directionOut, int steps)
|
private void MoveFocuser(bool directionOut, int steps)
|
||||||
{
|
{
|
||||||
//_sharedResourcesWrapper.SendBlind("#:FF#");
|
//_sharedResourcesWrapper.SendBlind("#:FF#");
|
||||||
@@ -394,8 +396,6 @@ namespace ASCOM.Meade.net
|
|||||||
//All others – Not Supported
|
//All others – Not Supported
|
||||||
_utilities.WaitForMilliseconds(100);
|
_utilities.WaitForMilliseconds(100);
|
||||||
|
|
||||||
//Todo fix this issue. A Single focus command sometimes gets lost on the #909, so sending lots of them solves the issue.
|
|
||||||
|
|
||||||
_sharedResourcesWrapper.SendBlind(directionOut ? "#:F+#" : "#:F-#");
|
_sharedResourcesWrapper.SendBlind(directionOut ? "#:F+#" : "#:F-#");
|
||||||
//:F+# Start Focuser moving inward (toward objective)
|
//:F+# Start Focuser moving inward (toward objective)
|
||||||
//Returns: None
|
//Returns: None
|
||||||
|
|||||||
Reference in New Issue
Block a user