Exemplo n.º 1
0
        private async Task calibrateAndRetry(IGridMotorMover mover, int previousPos, int desiredGridPos)
        {
            bool magnetWasOn = magnet.IsOn;

            if (magnetWasOn)
            {
                magnet.TurnOff();
            }
            await mover.CalibrateAsync(desiredGridPos > previousPos?MoveDirection.Backward : MoveDirection.Forward);

            try
            {
                await mover.GoToPositionAsync(previousPos);
            }
            catch (CalibrationException)
            {
                System.Diagnostics.Debug.WriteLine("Threw another CalibrationException on move despite recalibrating.");
            }

            if (magnetWasOn)
            {
                magnet.TurnOn();
            }
            try
            {
                await mover.GoToPositionAsync(desiredGridPos);
            }
            catch (CalibrationException)
            {
                System.Diagnostics.Debug.WriteLine("Threw another CalibrationException on move despite recalibrating.");
            }
        }
Exemplo n.º 2
0
        private async Task tryToMoveAsync(IGridMotorMover mover, int desiredGridPosition)
        {
            var previousPosition = mover.GridPosition;

            try
            {
                await mover.GoToPositionAsync(desiredGridPosition);
            }
            catch (CalibrationException)
            {
                await calibrateAndRetry(mover, previousPosition, desiredGridPosition);
            }
        }