Example #1
0
        public void TestMotorStall()
        {
            constructMotorMover();
            ((MotorMover)motorMover).Dispose();
            motorMover = new MotorMover(0, positionSignaler, motorLocator, mockMotor);

            int targetPos = 400;
            var moveTask  = motorMover.GoToPositionAsync(targetPos);

            Task.Delay(60).Wait();
            mockMotor.HandleMotorDirectionChanged(MoveDirection.Stopped);
            while (mockMotor.Information.Direction != MoveDirection.Stopped)
            {
                Task.Delay(30).Wait();
            }
            Task.Delay(30).Wait();
            int finalPos = moveTask.Result;

            Assert.IsTrue(finalPos < targetPos, "Counted all the way to the target position instead of stalling.");
            Assert.AreEqual(motorLocator.Position, finalPos, "MotorLocator position did not match finalPos");
            Assert.AreEqual(MoveDirection.Stopped, mockMotor.Direction, "Motor was not stopped after move stalled.");
            Assert.AreEqual(0, motorMover.EstimatedOvershoot, "EstimatedOvershoot shouldn't be updated with a stall.");
        }
Example #2
0
        public void TestMotorMoverCancel()
        {
            constructMotorMover();
            ((MotorMover)motorMover).Dispose();
            motorMover = new MotorMover(0, positionSignaler, motorLocator, mockMotor);

            int targetPos = 300;
            var moveTask  = motorMover.GoToPositionAsync(targetPos);

            Task.Delay(30).Wait();
            motorMover.CancelMove();
            while (mockMotor.Information.Direction != MoveDirection.Stopped)
            {
                Task.Delay(30).Wait();
            }
            Task.Delay(60).Wait();
            Assert.IsTrue(moveTask.IsCompleted, "Move task did not end after cancellation.");
            int finalPos = moveTask.Result;

            Assert.AreEqual(motorLocator.Position, finalPos, $"Motor mover result {finalPos} does not match motorLocator position {motorLocator.Position}");
            Assert.IsTrue(finalPos < targetPos, $"Motor final position {finalPos} did not make sense with target {targetPos}.");
            Assert.AreEqual(0, motorMover.EstimatedOvershoot, "EstimatedOvershoot should not update if a move is canceled.");
        }