Skip to content

Commit ae63abc

Browse files
authored
Z probing will be done using the retract amount plus 20% to avoid soft limits (#2720)
1 parent ec7511b commit ae63abc

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeService.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public class ProbeService implements UGSEventListener {
4848
private static final Logger logger = Logger.getLogger(ProbeService.class.getName());
4949
private static final String WCS_PATTERN = "G10 L20 P%d %s";
5050

51+
/**
52+
* The amount of the retract amount to add to the second probe
53+
*/
54+
public static final double SECOND_PROBE_DISTANCE_PERCENT = 1.2;
55+
5156
private final BackendAPI backend;
5257
private final List<Position> probePositions = new ArrayList<>();
5358
private ProbeOperation currentOperation = ProbeOperation.NONE;
@@ -123,6 +128,7 @@ private void performZProbeInternal(int stepNumber) throws IllegalStateException
123128
String unit = GcodeUtils.unitCommand(params.units);
124129

125130
continuation = () -> performZProbeInternal(stepNumber + 1);
131+
double retractDistance = retractDistance(params.zSpacing, params.retractAmount);
126132
try {
127133
switch (stepNumber) {
128134
case 0: {
@@ -133,10 +139,10 @@ private void performZProbeInternal(int stepNumber) throws IllegalStateException
133139
break;
134140
}
135141
case 1: {
136-
gcode("G91 " + unit + " G0 Z" + retractDistance(params.zSpacing, params.retractAmount));
142+
gcode("G91 " + unit + " G0 Z" + Utils.formatter.format(retractDistance));
137143
sendRetractPause();
138-
// TODO If probing a large distance this could cause soft limit alarm here, use the retract amount on the second probe
139-
probe('Z', params.feedRateSlow, params.zSpacing, params.units);
144+
// Do a second probe with 20% + the retract amount
145+
probe('Z', params.feedRateSlow, -(SECOND_PROBE_DISTANCE_PERCENT * retractDistance), params.units);
140146
break;
141147
}
142148
case 2: {
@@ -276,9 +282,10 @@ private void performXYZProbeInternal(int stepNumber) throws IllegalStateExceptio
276282
break;
277283
}
278284
case 1: {
279-
gcode(g0Rel + " Z" + retractDistance(params.zSpacing, params.retractAmount));
285+
double zRetractAmount = retractDistance(params.zSpacing, params.retractAmount);
286+
gcode(g0Rel + " Z" + zRetractAmount);
280287
sendRetractPause();
281-
probe('Z', params.feedRateSlow, params.zSpacing, params.units);
288+
probe('Z', params.feedRateSlow, -(SECOND_PROBE_DISTANCE_PERCENT * zRetractAmount), params.units);
282289
break;
283290
}
284291
case 2: {

ugs-platform/ProbeModule/src/test/java/com/willwinder/ugs/platform/probe/ProbeServiceTest.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ This file is part of Universal Gcode Sender (UGS).
1818
*/
1919
package com.willwinder.ugs.platform.probe;
2020

21-
import com.willwinder.universalgcodesender.Utils;
21+
import static com.willwinder.ugs.platform.probe.ProbeService.retractDistance;
22+
import static com.willwinder.universalgcodesender.Utils.formatter;
2223
import com.willwinder.universalgcodesender.listeners.ControllerState;
2324
import com.willwinder.universalgcodesender.model.BackendAPI;
2425
import com.willwinder.universalgcodesender.model.Position;
2526
import com.willwinder.universalgcodesender.model.UnitUtils.Units;
27+
import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G54;
28+
import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G55;
2629
import com.willwinder.universalgcodesender.model.events.ControllerStateEvent;
2730
import com.willwinder.universalgcodesender.model.events.ProbeEvent;
2831
import org.junit.Test;
2932
import org.mockito.InOrder;
3033
import org.mockito.Mockito;
31-
32-
import static com.willwinder.ugs.platform.probe.ProbeService.retractDistance;
33-
import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G54;
34-
import static com.willwinder.universalgcodesender.model.WorkCoordinateSystem.G55;
35-
import static org.mockito.Mockito.*;
34+
import static org.mockito.Mockito.doReturn;
35+
import static org.mockito.Mockito.inOrder;
36+
import static org.mockito.Mockito.times;
3637

3738
/**
3839
*
@@ -66,19 +67,20 @@ private void testZProbe(ProbeParameters pc) throws Exception {
6667
InOrder order = inOrder(backend);
6768

6869
order.verify(backend, times(1)).probe("Z", pc.feedRate, pc.zSpacing, pc.units);
70+
double retractDistance = retractDistance(pc.zSpacing, pc.retractAmount);
6971
order.verify(backend, times(1))
70-
.sendGcodeCommand(true, "G91 G20 G0 Z" + retractDistance(pc.zSpacing, pc.retractAmount));
72+
.sendGcodeCommand(true, "G91 G20 G0 Z" + formatter.format(retractDistance));
7173
order.verify(backend, times(1))
7274
.sendGcodeCommand(true, "G4 P" + pc.delayAfterRetract);
73-
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, pc.zSpacing, pc.units);
75+
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, -(retractDistance * 1.2), pc.units);
7476
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G20 G0 Z0.0");
7577

7678
double zDir = Math.signum(pc.zSpacing) * -1;
7779
double zProbedOffset = zDir * pc.zOffset;
7880
Position startPositionInUnits = pc.startPosition.getPositionIn(pc.units);
7981
double zPosition = startPositionInUnits.z - probeZ.getPositionIn(pc.units).z + zProbedOffset;
8082

81-
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P1 Z" + Utils.formatter.format(zPosition));
83+
order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P1 Z" + formatter.format(zPosition));
8284
}
8385

8486
@Test
@@ -133,7 +135,7 @@ public void testProbeServiceOutside() throws Exception {
133135
double yProbeOffset = pc.startPosition.y - probeY.y + yDir * (radius + Math.abs(pc.yOffset));
134136

135137
order.verify(backend, times(1)).sendGcodeCommand(true,
136-
"G10 L20 P2 X" + Utils.formatter.format(xProbeOffset) + "Y" + Utils.formatter.format(yProbeOffset));
138+
"G10 L20 P2 X" + formatter.format(xProbeOffset) + "Y" + formatter.format(yProbeOffset));
137139
}
138140

139141
@Test
@@ -163,11 +165,12 @@ public void testProbeServiceXYZ() throws Exception {
163165

164166
// Probe Z axis
165167
order.verify(backend, times(1)).probe("Z", pc.feedRate, pc.zSpacing, pc.units);
168+
double retractDistance = retractDistance(pc.zSpacing, pc.retractAmount);
166169
order.verify(backend, times(1))
167-
.sendGcodeCommand(true, "G91 G21 G0 Z" + retractDistance(pc.zSpacing, pc.retractAmount));
170+
.sendGcodeCommand(true, "G91 G21 G0 Z" + retractDistance);
168171
order.verify(backend, times(1))
169172
.sendGcodeCommand(true, "G4 P" + pc.delayAfterRetract);
170-
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, pc.zSpacing, pc.units);
173+
order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, -(retractDistance * 1.2), pc.units);
171174
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z0.0");
172175
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + -pc.xSpacing);
173176
order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z" + pc.zSpacing);
@@ -203,9 +206,9 @@ public void testProbeServiceXYZ() throws Exception {
203206
double zProbeOffset = pc.startPosition.z - probeZ.z;
204207

205208
order.verify(backend, times(1)).sendGcodeCommand(true,
206-
"G10 L20 P2 X" + Utils.formatter.format(xProbeOffset)
207-
+ "Y" + Utils.formatter.format(yProbeOffset)
208-
+ "Z" + Utils.formatter.format(zProbeOffset));
209+
"G10 L20 P2 X" + formatter.format(xProbeOffset)
210+
+ "Y" + formatter.format(yProbeOffset)
211+
+ "Z" + formatter.format(zProbeOffset));
209212
}
210213

211214
@Test

0 commit comments

Comments
 (0)