; Circular pocket - clears a round pocket using spiral toolpath ; Params: #1=x, #2=y, #3=diameter, #4=ztop, #5=zbot, #6=finishcut, #7=mode ; Mode bitmask: bit0=conventional, bit1=bothways, bit2=plunge(vs helix), bit3=outside o sub ; o call [x][y] [diameter] [ztop][zbot] [finishcut] [mode] # = [FIX[#7/1] MOD 2 EQ 1] # = [FIX[#7/2] MOD 2 EQ 1] # = [FIX[#7/4] MOD 2 EQ 1] # = [FIX[#7/8] MOD 2 EQ 1] # = [FIX[#7/1] MOD 2 EQ 0] # = [FIX[#7/2] MOD 2 EQ 0] # = [FIX[#7/4] MOD 2 EQ 0] # = [FIX[#7/8] MOD 2 EQ 0] G90 ; absolute x,y,z G90.1 ; absolute i,j,k M101 ; enable Z-axis (M102 disables) G17 ; select XY plane for arcs # = [#<_td>] # = [#/2] o1 if [EXISTS[#<_z_clearance>]] # = #<_z_clearance> o1 else # = #4 o1 endif o2 if [EXISTS[#<_rampang>]] # = #<_rampang> o2 else # = 5 ; degrees o2 endif o3 if [EXISTS[#<_stepover>]] # = #<_stepover> o3 else # = [#*0.4] o3 endif o4 if [# GT #3] ; tool bigger than pocket, bail out o5 return o4 endif # = 0 # = 0 o100 if [#] ; helical plunge # = [#*0.3] ; helix radius = 30% of tool diameter o115 if [[[#3-#]/2-ABS[#6]] LE #] ; shrink if helix would exceed pocket wall # = [[[#3-#]/2-ABS[#6]]*0.8] o115 endif # = [#*2*3.14*TAN[#]] G0 Z# G0 X[#1+#] Y[#2] G0 Z#4 ; helical plunge # = [#4-#] o101 while [# GT #5] o102 if [#] G3 X[#1+#] Y[#2] I[#1] J[#2] Z[#] P1 o102 else G2 X[#1+#] Y[#2] I[#1] J[#2] Z[#] P1 o102 endif # = [# - #] o101 endwhile ; finish the helical plunge # = [[#-#5]/[#4-#5]*360] ; TODO: what the heck is the denominator here doing? o103 if [#] G3 X[#1+COS[#]*#] Y[#2+SIN[#]*#] I[#1] J[#2] Z[#5] G3 X[#1+COS[#]*#] Y[#2+SIN[#]*#] I[#1] J[#2] Z[#5] o103 else G2 X[#1+COS[#]*#] Y[#2-SIN[#]*#] I[#1] J[#2] Z[#5] G2 X[#1+COS[#]*#] Y[#2-SIN[#]*#] I[#1] J[#2] Z[#5] o103 endif o100 elseif [#] ; straight plunge G0 Z# G0 X[#1] Y[#2] G0 Z[#4] G1 Z[#5] o100 endif ; spiral outward from center to clear pocket, stopping short by finishcut amount # = # # = # o105 while [# LT [[#3-#]/2-ABS[#6]]] o106 if [#] G1 X[#1+COS[#]*#] Y[#2+SIN[#]*#] o106 else G1 X[#1+COS[#]*#] Y[#2-SIN[#]*#] o106 endif # = [#+1] ; advance 1 degree per step # = [#+[#-#]/360*#] ; radius grows by stepover each revolution o105 endwhile ; pre-finish cut: full circle at pocket wall minus finishcut allowance # = [[#3-#]/2-ABS[#6]] o107 if [#] G1 X[#1+COS[#]*#] Y[#2+SIN[#]*#] G3 X[#1+COS[#]*#] Y[#2+SIN[#]*#] I[#1] J[#2] o107 else G1 X[#1+COS[#]*#] Y[#2-SIN[#]*#] G2 X[#1+COS[#]*#] Y[#2-SIN[#]*#] I[#1] J[#2] o107 endif ; finish cut: full circle at final pocket wall radius o104 if [ABS[#6] GT 0.0] # = [[#3-#]/2] o108 if [#] G1 X[#1+COS[#]*#] Y[#2+SIN[#]*#] G3 X[#1+COS[#]*#] Y[#2+SIN[#]*#] I[#1] J[#2] # = [[#3-#]/2*0.9] ; retract slightly inward before rapid out G1 X[#1+COS[#]*#] Y[#2+SIN[#]*#] o108 else G1 X[#1+COS[#]*#] Y[#2-SIN[#]*#] G2 X[#1+COS[#]*#] Y[#2-SIN[#]*#] I[#1] J[#2] # = [[#3-#]/2*0.9] ; retract slightly inward before rapid out G1 X[#1+COS[#]*#] Y[#2-SIN[#]*#] o108 endif o104 endif G0 Z# o endsub M2