Skip to content

Commit

Permalink
Clear ABC axes when probing (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Jan 17, 2025
1 parent 8bb7c49 commit bf4ba7c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ public Builder setC(Double c) {
}
return this;
}

public Builder clearABC() {
this.a = null;
this.b = null;
this.c = null;
return this;
}
}

public String getFormattedGCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,17 @@ private void moveToSafeStartPoint(Position currentPosition) {
}

// Move to the XY start position
PartialPosition startPos = PartialPosition.builder(minXYZ).clearZ().build();
PartialPosition startPos = PartialPosition.builder(minXYZ)
.clearZ()
.clearABC()
.build();

String cmd = GcodeUtils.generateMoveCommand(
"G90G0", getProbeScanFeedRate(), startPos);
logger.log(Level.INFO, "Move to start position {0}", new Object[]{startPos});
backend.sendGcodeCommand(true, cmd);

// Move to the Y start position
// Move to the Z start position
PartialPosition startHeight = PartialPosition.builder(maxXYZ.getUnits()).setZ(maxXYZ.getZ()).build();
cmd = GcodeUtils.generateMoveCommand(
"G90G0", getProbeScanFeedRate(), startHeight);
Expand All @@ -226,7 +230,11 @@ private void probeNextPoint(Double zBackoff) {
Position p = this.pendingPositions.peek();

// Position over next probe position
PartialPosition startPos = PartialPosition.builder(p).clearZ().build();
PartialPosition startPos = PartialPosition.builder(p)
.clearZ()
.clearABC()
.build();

String cmd = GcodeUtils.generateMoveCommand(
"G90G0", getProbeScanFeedRate(), startPos);
logger.log(Level.INFO, "MoveTo {0} {1}", new Object[]{startPos, cmd});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.willwinder.universalgcodesender.model.BackendAPI;
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;
import com.willwinder.universalgcodesender.utils.AutoLevelSettings;
import com.willwinder.universalgcodesender.utils.Settings;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.anyBoolean;
import org.mockito.Mock;
import static org.mockito.Mockito.doNothing;
import org.mockito.MockitoAnnotations;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -149,6 +153,33 @@ public void probeEventShouldProgressTheScanForEachProbeEventInInches() {
assertEquals(25.4, surfaceScanner.getProbePositionGrid()[1][1].getZ(), 0.1);
}

@Test
public void scanShouldMoveToSafe() throws Exception {
Settings settings = new Settings();
settings.setSafetyHeight(6);

AutoLevelSettings autoLevelSettings = settings.getAutoLevelSettings();
autoLevelSettings.setMin(new Position(0,0,0, UnitUtils.Units.MM));
autoLevelSettings.setMax(new Position(0,0,0, UnitUtils.Units.MM));
autoLevelSettings.setProbeScanFeedRate(500);

when(backendAPI.getSettings()).thenReturn(settings);
when(backendAPI.getWorkPosition()).thenReturn(new Position(0,0,0 ,UnitUtils.Units.MM));
when(backendAPI.getMachinePosition()).thenReturn(new Position(0,0,0, UnitUtils.Units.MM));

ArgumentCaptor<String> sentGcodeCommandCaptor = ArgumentCaptor.forClass(String.class);
doNothing().when(backendAPI).sendGcodeCommand(anyBoolean(), sentGcodeCommandCaptor.capture());

SurfaceScanner surfaceScanner = new SurfaceScanner(backendAPI);
surfaceScanner.reset();
surfaceScanner.scan();

assertEquals(4, sentGcodeCommandCaptor.getAllValues().size());
assertEquals("G21G90G0Z6F500", sentGcodeCommandCaptor.getAllValues().get(0));
assertEquals("G21G90G0X0Y0F500", sentGcodeCommandCaptor.getAllValues().get(1));
assertEquals("G21G90G0Z0F500", sentGcodeCommandCaptor.getAllValues().get(2));
assertEquals("G21G90G0X0Y0F500", sentGcodeCommandCaptor.getAllValues().get(3));
}

private static Position createProbePoint(Position position, UnitUtils.Units units, double z) {
Position probePoint = new Position(position.getPositionIn(units));
Expand Down

0 comments on commit bf4ba7c

Please sign in to comment.