Skip to content

Commit

Permalink
Lower the precision requirement of the reported probed XY position. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed Sep 4, 2024
1 parent 113577e commit f3f65ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f3f65ab

Please sign in to comment.