@@ -18,21 +18,22 @@ This file is part of Universal Gcode Sender (UGS).
1818 */
1919package 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 ;
2223import com .willwinder .universalgcodesender .listeners .ControllerState ;
2324import com .willwinder .universalgcodesender .model .BackendAPI ;
2425import com .willwinder .universalgcodesender .model .Position ;
2526import com .willwinder .universalgcodesender .model .UnitUtils .Units ;
27+ import static com .willwinder .universalgcodesender .model .WorkCoordinateSystem .G54 ;
28+ import static com .willwinder .universalgcodesender .model .WorkCoordinateSystem .G55 ;
2629import com .willwinder .universalgcodesender .model .events .ControllerStateEvent ;
2730import com .willwinder .universalgcodesender .model .events .ProbeEvent ;
2831import org .junit .Test ;
2932import org .mockito .InOrder ;
3033import 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