' This version is for Lathe use - Roger Caffin  13/08/2016' It is a total rewrite of the original Mach3 version' In essence, the g83 instruction in Mach3 calls this macro' It must be in the folder Mach3/macros/machturn'' G83 X (ignored)  Z (required) Q (required) R (required)' It is ASSUMED that X=0 for a lathe: there is NO X movement here' Entry will be with Z = Zstart above the material surface' Z is the target depth for the instruction' Q is the maximum peck distance per cycle; actual peck may be less' R is the 'Retract' distance: where the drill retracts to each on cycle' Note that FeedHold does not seem to interrupt this instruction: use Stop'' Normally R will be above the surface of the material so that a cyclic'  retraction to R will clear the drill bit right out of the hole.' However, the tip of the drill can score the bore on subsequent'  re-entries, which may be undesirable.' There are two versions of this instruction:' g83 (C=0) does a full slow retract to R on each cycle' g83.1 (C=1) does a fast retract just to the start of the last cycle' The g83(.1) instruction may be preceeded by a g98 or g99 instruction.' g98 (ExitMode=0) causes the cycle to exit with Z = R' g99 (ExitMode=1) causes the cycle to exit with Z = Zstart' Note that g98 may leave the drill in an unfortunate position.Test = false		' Debug flagZStart = tZStart()	' Starting Z height - OKZEnd = tEndZ()		' this is the Z in the G83 call - OKQ = Abs(tInFeed())	' Q value, REQUIRED, OKR = tZClear()		' R value, REQUIRED, OKC = tTaper()		' g83/g83.1 flag - OKExitMode= RetractMode()	' g98/g99 flag - OKXPos = tEndX()		' this is the X in the G83 call - WRONGIf Zend>= R Then	' Sanity check on target Z'  MsgBox("Target Z > Retract value!", 16, "Sanity Check")  MsgBox("Target Z > Retract value!")  stopEnd IfIf Test = True Then	' Debug log file  If c=0 Then    G83="G83 (slow)"  Else    G83="G83.1 (fast)"  End If  If ExitMode=0 Then    EMode="G98 (to R)"  Else    EMode="G99 (to ZStart)"  End If      LogFile="LogFile.tap"	' Found in mach3/gcode  MyErr=openteachfile(LogFile)  If MyErr=0 Then    MsgBox("Couldn't open Log File")  Else'    MsgBox("Opened Log File")    Code "(ZStart = " & ZStart & ")"    Code "(Zend = " & Zend &")"    Code "(PeckQ = " & Q &")"    Code "(Retract = " & R &")"    Code "(Slow/Fast = " & g83 & ")"    code "(ExitMode = " & EMode & ")"    Code "(EndX = " & XPos &")"  End IfEnd If' Z clearance parameterIf GetLED (2) Then  ZClear=0.2	' mm if metricelse  ZClear=0.01	' " if imperialEnd If' Extra feature for R below surface to keep drill tip engagedIf R < ZStart Then  code "g1 z" & R	' Drill slowly down to first R value  ZLast=R		' Last Z positionelse  ZLast=ZStart		' No movement as already thereend if'Cycle controlZTravel=ZLast-ZEnd		' Takes into account R<ZStartZCycles=int(ZTravel/Q)+1	' Number of cyclesZIncr=ZTravel/Zcycles		' Actual Z increment to be used'Cycle sanity checkif ZCycles> 300 then'  MsgBox("More than 300 cycles",16,"Sanity Check")  MsgBox("More than 300 cycles")  stopend ifFor I = 1 to ZCycles  ZTemp=ZLast+ZClear		' Just above contact  Code "G00 Z" & Ztemp		' Rapid to start  ZNext=ZLast-ZIncr		' Next peck down  Code "G01 Z" & ZNext		' Drill next peck distance  If C = 1 Then			' Select retraction mode    Code "G00 Z" & ZLast	' G83.1 for fast/partial extract  Else    Code "G00 Z" & R		' G83 for full retract  End If  ZLast = ZNext			'Log new Z positionNext IIf ExitMode = 1 Then		' And where does ExitMode come from ????  Code "G00 Z" & ZStartelse  Code "G00 Z" & REnd IfIf Test = True Then  CloseTeachFile()End If 