(info: Quadrilateral pocketing using cutter radius compensation) ; Use with care, test in simulator first. ; Notes: ; Defaults herein are inch based ; Uses tool diameter from tool table for cutter radius compensation ; Supports conventional or climb milling ; Ramps to depth for each z increment ; Mirror about x axis for negative scale ; too small diameter tools and/or small stepovers may exceed outlinepasslimit ; too large diameter tools may case gouging errors ; Works for most rectangles and parallelograms but may require some care ; for specifying: ; point ordering (see entry move notes below) ; tool diameter (in tool table) ; stepover ; Entry moves: ; Input point ordering Requested Direction Entry line ; -------------------- ------------------------ ------------------ ; 1234 == CW 2 == CW == Conventional point1 --> point2 ; 1234 == CW 3 == CCW == Climb point1 --> point4 ; 1234 == CCW 2 == CW == Conventional point1 --> point4 ; 1234 == CCW 3 == CCW == Climb point1 --> point2 ; To accomodate the widest range of tool diameters, order the point sequence ; (1234) so that the entry move is not directed towards an acute angle. ; Scaling, rotations, and offsets are supported. ; Scaling is applied first. ; Rotation is then applied (with respect to origin). It is often simplest ; to specify the feature so that it is centered at the origin. ; Offsets are applied last. ;---------------------------------------------------------------------- ; Copyright: 2012,2014 ; Author: Dewey Garrett ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;---------------------------------------------------------------------- o sub # = #1 (=1) # = #2 (=1000) # = #3 (=2 2conv|3climb) ; conventional=cw, climb=ccw # = #4 (=10) # = #5 (=0.1) # = #6 (=0.02) # = #7 (=0.2) # = #8 (=0) # = #9 # = #10 # = #11 # = #12 # = #13 # = #14 # = #15 # = #16 # = #17 (=1) ; use neg value for mirroring # = #18 (=0) ; angle in degrees # = #19 (=0) # = #20 (=0) # = #21 (=0.5) ; tooldiameter fraction # = #22 (=0.002) # = #23 (=1) ; 1 == prompt user # = #24 (=1) # = #25 (=0) # = #26 (=0) # = 100 ; outer loop # = 100 ; inner loop # = 0.01 ; small increment to tool diameter # = [0 - #] # = [0 - #] g40 ; make sure cutter radius compensation off at start g64 p # ; path tolerance o if [# EQ 0] (print, qpocket: zero scale # - EXITING) (debug, qpocket: zero scale # - EXITING) (AXIS,notify, qpocket: zero scale - EXITING) m2 o endif o if [# LT 0] (print, qpocket: MIRROR about x axis for negative scale #) (debug, qpocket: MIRROR about x axis for negative scale #) (AXIS,notify, qpocket: MIRROR about x axis for negative scale) o endif # = [# * #] # = [# * #] # = [# * #] # = [# * #] # = [ABS[#]] # = [# * #] # = [# * #] # = [# * #] # = [# * #] # = 1 o if [[# GT 1] OR [# LE 0]] (print, qpocket: invalid stepover=# - EXITING) (debug, qpocket: invalid stepover=# - EXITING) (AXIS,notify, qpocket: invalid stepover - EXITING) m2 o endif o if [[# NE 2] AND [# NE 3]] (print, qpocket:bad dir=# - EXITING) (debug, qpocket:bad dir=# - EXITING) (AXIS,notify, qpocket:bad dir - EXITING) m2 o endif ;compute direction eg 2==cw,3==ccw for points as ordered: o call [4][#][#][#][#][#][#][#][#] # = #<_dir:> ; direction of input points 2==cw # = #<_dir:cx> ; centroid # = #<_dir:cy> ; centroid o if [# LE 0] ; failed to get direction -- pathological case (print, failed to compute direction - EXITING) (debug, failed to compute direction - EXITING) (AXIS,notify, failed to compute direction - EXITING) m2 o endif ; Get data for x,y points # = 4 o call [#] [#][#][#][#] # = #<_pointsdata:ctr> # = [#<_pointsdata:min> - #] # = [#<_pointsdata:max> - #] o call [#] [#][#][#][#] # = #<_pointsdata:ctr> # = [#<_pointsdata:min> - #] # = [#<_pointsdata:max> - #] ; Respecify input points about the x,y centroid o if [# GT 0] (debug, centroid: # #) o endif # = [# - #] # = [# - #] # = [# - #] # = [# - #] # = [# - #] # = [# - #] # = [# - #] # = [# - #] ; make order of points agree with input direction request o if [# NE #] o if [# GT 0] (debug, reversing input point sequence: 1-4-3-2) o endif ; swap points ordering: 1234 --> 1432 # = # # = # # = # # = # # = # # = # o endif ; determine min size for first outline pass o if [[#-#] GT [#-#]] # = [ABS[#-#]/2] o else # = [ABS[#-#]/2] o endif ; load tool and establish scaling for first outline pass o call [#][#][#][#] # = #5410 # = [#5410 + #] # = [# / 2] # = [# / #] # = [# * #] o if [# GE #] (print, qpocket: tooldiam is too big # - EXITING) (debug, qpocket: tooldiam is too big # - EXITING) (AXIS,notify, qpocket: tooldiam is too big - EXITING) m2 o endif ; scale the centered feature and translate to original position o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> ; xni,yni are the initial points at the smallest scaling ; apply input rotation and offset o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> ;get angles for connecting lines o call [#][#][#][#] # = #<_line:cos> # = #<_line:sin> o call [#][#][#][#] # = #<_line:cos> # = #<_line:sin> o call [#][#][#][#] # = #<_line:cos> # = #<_line:sin> o call [#][#][#][#] # = #<_line:cos> # = #<_line:sin> ;compute angles at line interesctions: o call [#][#][#][#][#][#] # = #<_dot:ang> o call [#][#][#][#][#][#] # = #<_dot:ang> o call [#][#][#][#][#][#] # = #<_dot:ang> o call [#][#][#][#][#][#] # = #<_dot:ang> f # s # m3 ;spindle cw o if [# GT 0] o call [#] ; optionally prompt user o endif g0 z# ; depth loop (outer) # = # # = 1 o while [# GT #] # = # # = [# + #] o if [# LT #] # = # o endif o if [# GT #] (print, qpocket: depthpasslimit exceeded # - EXITING) (debug, qpocket: depthpasslimit exceeded # - EXITING) (AXIS,notify, qpocket: depthpasslimit exceeded - EXITING) m2 o endif o if [# EQ 1] ;entry point: ;go along the 1-->2 line to enter at a point where tool will fit # = [ # / [TAN[#/2]]] # = [# / #] ;(print, entry 12 k=# elen12=# angle=#) # = [# + # * #] # = [# + # * #] ;compute pre-entry points: o if [# EQ 2] ; dir EQ 2 CW (conventional) # = [# + # * # - # * #] # = [# - # * # - # * #] # = [# + # * #] # = [# + # * #] # = [ # * #] # = [ # * #] o else ;dir EQ 3 CCW (climb) # = [# - # * # - # * #] # = [# + # * # - # * #] # = [# + # * #] # = [# + # * #] # = [ # * #] # = [ # * #] o endif g0 x # y # ;preentry 1 g0 x # y # ;preentry 2 o if [# EQ 2] ; CW / g42 ;cutter radius comp right of path g2 x # y # i # j # ;arc entry o else ;dir EQ 3 CCW / g41 ;cutter radius comp left of path g3 x # y # i # j # ;arc entry o endif g1 z # ;plunge to start height from zsafe o else ; depthpass GT 1: return to interior entry point g1 x # y # z# ; use zlast o endif ; outline loop (inner) # = 1 # = # # = # o do o if [# GT #] (print, qpocket: outlinepasslimit exceeded # - EXITING) (debug, qpocket: outlinepasslimit exceeded # - EXITING) (AXIS,notify,qpocket: outlinepasslimit exceeded - EXITING) m2 o endif # = [# mod 4] o if [# EQ 1] ; move through smallest interior outline o if [# EQ 1] g1 x # y # z# ;ramp down to zcurrent g1 x # y # g1 x # y # g1 x # y # g1 x # y # o endif o if [# EQ 2] g1 x # y # z# ;ramp down to zcurrent g1 x # y # g1 x # y # g1 x # y # g1 x # y # o endif o if [# EQ 3] g1 x # y # z# ;ramp down to zcurrent g1 x # y # g1 x # y # g1 x # y # g1 x # y # o endif o if [# EQ 0] g1 x # y # z# ;ramp down to zcurrent g1 x # y # g1 x # y # g1 x # y # g1 x # y # o endif # = [# + 1] o else ; increasingly larger outlines # = [# + # * #] # = [# * #] # = [# + 1] o if [# GE #] # = # # = 0 ;terminate after this pass o endif ; scale the centered feature and translate to original position o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][0][#][#][#] # = #<_move:x> # = #<_move:y> ; apply input rotation and offset o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> o call [#][#][#][1][#][#] # = #<_move:x> # = #<_move:y> ; move through scaled interior outline o if [# EQ 0] g1 x # y # z # x # y # x # y # x # y # x # y # o endif o if [# EQ 1] g1 x # y # z # x # y # x # y # x # y # x # y # o endif o if [# EQ 2] g1 x # y # z # x # y # x # y # x # y # x # y # o endif o if [# EQ 3] g1 x # y # z # x # y # x # y # x # y # x # y # o endif o endif o while [# GT 0] # = [# + 1] o endwhile ; after finishing at input scale, need to turn corner ; and go along the next line enough to turn off compensation o if [# EQ 0] ;end at pt 1 # = # # = # # = [# / [TAN[#/2]]] # = [# + # * #] # = [# + # * #] o endif o if [# EQ 1] ;end at pt 2 # = # # = # # = [# / [TAN[#/2]]] # = [# + # * #] # = [# + # * #] o endif o if [# EQ 2] ;end at pt 3 # = # # = # # = [# / [TAN[#/2]]] # = [# + # * #] # = [# + # * #] o endif o if [# EQ 3] ;end at pt 4 # = # # = # # = [# / [TAN[#/2]]] # = [# + # * #] # = [# + # * #] o endif g1 x # y # g1 x # y # g0 z # g40 ;cutter radius compensation off o endsub