In your method you do not need the X call after you make your prestage move BUT the G83 DOES require the Ycall (polar index value). Mach tracks the Offset value of X but does not store the polar index value.
I am very conscious that my knowledge of g-code programming is limited, and I had completely forgotten about the L option in g83. Thank you for reminding me. However, it does not solve all the problems - at least as far as I can see.
What g83 does do is peck drilling with a retract to the defined R position at the end. If I loop that with the L option, the traverse to the next hole is done with the drill tip at the R height. But sometimes I need to retract the drill tip another 20 mm up before doing the traverse, to clear things. I could put R=20 , but that then wastes a lot of time for every hole and for every peck move. It wastes a lot of time doing the slow feed from +20 mm down to the surface in multiple peck cycles before it starts drilling, and it also wastes a lot of time doing the retract/return over the extra 20 mm on each peck cycle after that. What I would love would be two more parameters:
Z: where to drill to (existing)
R: where to retract to for clearing swarf (existing)
T: where to retract to for the next traverse
S: where to rapid feed to before starting the drilling
This is unlikely to happen!
Fortunately I can achieve all of this with a full subroutine call. All I have to do is to over-ride the bug in the mach3 implementation of the g83 code by directly specifying the current XY position inside the g83 command.
To explain what is happening in the code: specifying the XY values in the g83 command over-rides the default fetching of a stored previous XY position. The bug is that it fetches from the wrong data structure - it fetches from the 'final cartesian' data structure rather than from the 'last program-specified data structure'.
In more detail, what then happens is that the g83 command assumes the 'final cartesian' XY values it has fetched are polar values and converts them into cartesian values because it knows it is in polar mode. Specifying the current XY position in the g83 command over-rides the default fetch and passes genuine polar values to the code.
But I must remember the L parameter in future. It will be useful somewhere, I am quite sure. Thanks.
Cheers
Roger