Xcarve + UGS:How to prevent full Z axis retraction at the beginning of the carve

I’ve been running into a problem accurately zeroing the Z axis when I use UGS. Before issuing the gcode I home the machine (standard limit switches, no noise eliminating mods), then I lower the Z down to the surface of the stock and hit “reset zero”, and then issue the start. When I issue, the bit initially raises all the way to the Z limit, instead of the retract height established in the code, moves to the position of the first cut and goes to work. For the rest of the job the retract height that I define in Fusion is used and everything is good. The problem is that the initial full retraction adds anywhere from 1/16" to 1/8" of error in the Z position, so my first cut ends up being too deep or not cutting at all (leading to too shallow a final cut). I think the error is coming from the switch, and if I could modify the Gcode to make that very first retraction stop at a specific point rather than hitting the limit switch it should solve the problem - but I dont know which command is responsible for the retraction. Alternatively maybe I could set a “soft limit” but it’s not clear to me on the Z if the soft limit is intended to limit downward movement or the retraction height (what I’ve read makes it seem like people use them on Z to keep the bit from cutting in to the backer)?

Here’s what the first chunk of gcode looks like:

(T1  D=0.125 CR=0 - ZMIN=-0.5625 - flat end mill)
G90 G94
G28 G91 Z0

(Main Contour)
T1 M6
S1504 M3
G0 X12.5137 Y8.9451
G1 Z0.0994 F50.1
Z-0.0475 F10.1
Y8.9454 Z-0.0503
X12.5138 Y8.9464 Z-0.0529
X12.5139 Y8.9478 Z-0.0553
X12.514 Y8.9498 Z-0.0573
X12.5142 Y8.9522 Z-0.0588
X12.5144 Y8.9548 Z-0.0597
X12.5146 Y8.9576 Z-0.06
X12.5156 Y8.9701 F50.1
G3 X12.5041 Y8.9835 I-0.0125 J0.001
G1 X12.4898 Y8.9846 F70.1
X12.3642 Y8.9933
X12.2358 Y9.0012
X12.1048 Y9.0082
X11.9711 Y9.0145
X11.835 Y9.02
X11.6965 Y9.0247
X11.5555 Y9.0285
X11.4124 Y9.0317
X11.267 Y9.034
X11.1197 Y9.0356
X10.9703 Y9.0363
X10.6663 Y9.0354
X10.5118 Y9.0338
X10.3558 Y9.0312
X10.1985 Y9.0278
X10.04 Y9.0236

One thing you need to do is remove the T1 M6 command as grbl can do strange things when it sees that…it is not supported by grbl.

What is this command doing for you?

G28 G91 Z0

Ill be sure to start removing the T1 M6.

As for the G28 G91 Z0, your guess is as good as mine - Fusion360 has decided to add that when post processing for their default grbl settings.

It is the offending line…it is taking the machine to your limit switch.

This says go to the pre-defined Machine co-ordinates that were set by G28.1
Set incremental programming (relative moves)

If he homed his machine just prior (which he did), I believe it takes it up to the limit of the Z-Axis.

If he has never set G28.1 then the movement is random. If he cleared the EEPROM before loading in the grbl code then it would be Machine 0,0,0 G28 is independent of homing.

Well not quite, as homing sets Machine Zero.

So…is this command: G28 G91 Z0 the one giving him problems?

I think so.


Just because of the way that G-code reads I would guess that the G28 line is being inserted by his post processor. If so, it should be removed from the post processor or he will have mysterious problems from time to time which will be very difficult to track down.

The Z0 ending doesn’t make any sense.

G28 Z0 G91 would make more sense, but is definitely not what he wants as that says go to the G28 position passing through Machine position Z = 0.

[Edit] ********* correction -> passing through Work position Z = 0

I would remove both the following from his post processor:

G28 G91 Z0
T1 M6

and the M9 and M8

unless he needs to turn his coolant off then on.

what i do is home he machine, reset all the axis’s, he jog to the surface of the material at my origin (X0,Y0) and write the number down. Then I load it in the program as the work offset with the G10 command.
Pretty consistent so far, with no strange moves.
With generic post processors, you always have to edit the g code. I see a lot of things that you can remove ( M6, M8, etc.) and you can do it by hand -editing the text, or dice in to the post and tweak it, once and for all.

Thanks everybody, sounds like this will do the trick.

I love this forum!

1 Like

There is no need to edit the code by hand every time. In the post processor options (comes up when you press ‘post process’) you can tell 360 to not use the g28 command.

You can also tell it to not send tool change commands somewhere too I think. I use chillipeppr to send the code to the x carve and it has an option to not pause on tool changes so I’ve never had to set it up in 360.

If you have limit switches though, why not set up the g28 location using the G28.1 command? You can set the location to be somewhere at the back of the machine so the work surface will always be clear for you when not carving.