Refactored the backlash compensation so that less move commands are issued.

This commit is contained in:
2020-09-03 17:06:16 +01:00
parent b9f1dd9d61
commit 1dc7d7142a
2 changed files with 34 additions and 35 deletions
+10 -11
View File
@@ -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(_profileProperties.BacklashCompensation)), Times.Never);
_utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once());
_utilMock.Verify(x => x.WaitForMilliseconds(1000), Times.Once());
}
[TestCase(200, 3, 3)]
[TestCase(-200, 1, 0)]
public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuserWithBacklashCompensation(int position, int hundredMsWaitCount, int backlashCompensaionCount)
[TestCase(200)]
[TestCase(-200)]
public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuserWithBacklashCompensation(int position)
{
_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.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
{
_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);
_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]
+24 -24
View File
@@ -342,8 +342,6 @@ namespace ASCOM.Meade.net
_tl.LogMessage("Move", position.ToString());
CheckConnected("Move");
//todo implement dynamic braking
if (position < -MaxIncrement || position > MaxIncrement)
{
throw new InvalidValueException($"position out of range {-MaxIncrement} < {position} < {MaxIncrement}");
@@ -358,28 +356,32 @@ namespace ASCOM.Meade.net
_sharedResourcesWrapper.Lock(() =>
{
MoveFocuser(direction, Math.Abs(position));
ApplyBacklashCompensation(direction);
//This gives the focuser time to physically stop.
_utilities.WaitForMilliseconds(1000);
//backlash compensation.
var backlashCompensationSteps = direction ? Math.Abs(_backlashCompensation) : 0;
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)
{
//_sharedResourcesWrapper.SendBlind("#:FF#");
@@ -393,9 +395,7 @@ namespace ASCOM.Meade.net
//Returns: Nothing
//All others Not Supported
_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-#");
//:F+# Start Focuser moving inward (toward objective)
//Returns: None