From f3f65ab401b739d76bc0f992fdc71742505985f4 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Wed, 4 Sep 2024 20:58:18 +0200 Subject: [PATCH] Lower the precision requirement of the reported probed XY position. (#2601) --- .../surfacescanner/SurfaceScanner.java | 5 ++--- .../surfacescanner/SurfaceScannerTest.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java index c61e77f9d..6397a83de 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java @@ -27,6 +27,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.model.UnitUtils.Units; import com.willwinder.universalgcodesender.model.events.ProbeEvent; import com.willwinder.universalgcodesender.utils.AutoLevelSettings; +import static com.willwinder.universalgcodesender.utils.MathUtils.isEqual; import java.util.Deque; import java.util.LinkedList; @@ -38,8 +39,6 @@ This file is part of Universal Gcode Sender (UGS). import java.util.logging.Level; import java.util.logging.Logger; -import static com.willwinder.universalgcodesender.utils.MathUtils.isEqual; - /** * @author wwinder */ @@ -167,7 +166,7 @@ public void probeEvent(final Position p) { // The position reported from the controller might lack some precision on the X/Y position. // We therefore need to lower the precision when checking the probed X/Y axes - double delta = expectedProbePosition.getUnits() == Units.MM ? 0.01 : 0.001; + double delta = 0.1; if (!isEqual(probedPosition.getX(), expectedProbePosition.getX(), delta) || !isEqual(probedPosition.getY(), expectedProbePosition.getY(), delta)) { reset(); throw new RuntimeException(String.format("Unexpected probe location, expected %s to be %s", probedPosition, expectedProbePosition)); diff --git a/ugs-platform/ugs-platform-surfacescanner/src/test/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScannerTest.java b/ugs-platform/ugs-platform-surfacescanner/src/test/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScannerTest.java index a37e166d3..4c10f7e50 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/test/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScannerTest.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/test/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScannerTest.java @@ -69,6 +69,28 @@ public void probeEventShouldProgressTheScanForEachProbeEventInMillimeters() { assertEquals(1, surfaceScanner.getProbePositionGrid()[1][1].getZ(), 0.1); } + @Test + public void probeEventShouldAllowForSomePrecisionErrorsFromController() { + Settings settings = new Settings(); + when(backendAPI.getSettings()).thenReturn(settings); + + SurfaceScanner surfaceScanner = new SurfaceScanner(backendAPI); + surfaceScanner.reset(); + + Position first = new Position(surfaceScanner.getNextProbePoint().get()); + first.setX(first.getX() - 0.1); + surfaceScanner.probeEvent(createProbePoint(first, UnitUtils.Units.MM, 1)); + + Position second = new Position(surfaceScanner.getNextProbePoint().get()); + first.setY(first.getY() + 0.1); + surfaceScanner.probeEvent(createProbePoint(second, UnitUtils.Units.MM, 2)); + + Position third = new Position(surfaceScanner.getNextProbePoint().get()); + third.setY(third.getY() + 0.11); + assertThrows(RuntimeException.class, () -> surfaceScanner.probeEvent(createProbePoint(third, UnitUtils.Units.MM, 1))); + } + + @Test public void probeEventShouldProgressTheScanForEachProbeEventInInches() { Settings settings = new Settings();