... [RS274NGC] ... # REMAPPING REMAP=g74 modalgroup=1 argspec=xzk py=g740 ... [PYTHON] TOPLEVEL = python/toplevel.py PATH_PREPEND = python ...
#!/usr/bin/python import remap
#!/usr/bin/python import sys from interpreter import INTERP_OK import math def g740(self, **words): # G74 is typically called like so: # G74 x ? z ? k ? (x = diameter, usually 0; z = hole endpoint; k = peck length) # get position if (self.params['_lathe_diameter_mode']): # if is_lathe_mode x_mode = 2 else: x_mode = 1 x_start = self.params[5420] * x_mode z_start = self.params[5422] if 'x' in words: x_end = words['x'] * x_mode else: x_end = x_start * x_mode if 'z' in words: z_end = words['z'] else: z_end = z_start if 'k' in words: peck_length = words['k'] else: peck_length = 0 z_range = z_end - z_start if peck_length > 0: num_pecks = int(math.fabs(z_range / peck_length)) else: num_pecks = 0 if (self.params['_metric']): # if is_metric backoff_length = 0.50 # mm rounding_fudge = 0.0001 else: backoff_length = 0.020 # inch rounding_fudge = 0.00001 z_list = [] for i in range(num_pecks + 1): z_list.append(z_start - (i * peck_length)) z_list.append(z_end) #print "--kaw - z_list =", z_list if math.fabs(x_end - x_start) > rounding_fudge: # We're groove'n for i in range(num_pecks + 1): self.execute("G0 Z %s" % z_list[i]) self.execute("G1 Z %s" % z_list[i + 1]) self.execute("G1 X %s" % x_end) self.execute("G1 Z %s" % (z_list[i] + backoff_length)) self.execute("G0 X %s" % x_start) else: # We're drilling for i in range(num_pecks + 1): self.execute("G1 Z %s" % z_list[i + 1]) self.execute("G0 Z %s" % (z_list[i + 1] + backoff_length)) return INTERP_OK
The G74 routine above relies on an initial move to a starting position. This position is captured and used for x_start and z_start. The x and z words in the G74 command are used for x_end and z_end. If x_start and x_end are equal, this invokes a plunge with chip break routine, otherwise a grooving routine is invoked. Since Python can round off floating point numbers, a "close enough" algorithm is use to test x_start and x_end equality. A check for peck_length > 0 is used to prevent a divide by zero error in the num_pecks calculation. Apparently, the x position parameter 5420 does not follow the lathe diameter mode, so we need to check for it and adjust x values. This needs testing, so beware. I need to add checks for valid x, z, and k values, such as, the z parameter value must be less than the z start position, k can not be negative. Remap has a feature that flags whether a parameter is optional or required, which I have not addressed yet.
Peter Smid's book "CNC Programming Handbook, 3rd Edition" Page 222, covering G74 was used as a reference: https://books.google.com/books?id=w7-jBgAAQBAJ&pg=PA222
... [RS274NGC] ... # REMAPPING REMAP=g74 modalgroup=1 argspec=xzk ngc=g740 ...
o<g740>sub (Peck Drill) (capture start position) #<x_start> = #5420 (Current X Location) #<z_start> = #5422 (Current Z Location) #<z_end> = #<z> #<peck> = #<k> #<z_range> = [ABS[#<z_end> - #<z_start>]] #<num_pecks> = [#<z_range> / #<peck>] o10 if [#<peck> GT 0] #<num_pecks> = [#<z_range> / #<peck>] o10 else #<num_pecks> = 0 o10 endif o20 if [#<_metric>] #<back_off> = 0.500 (mm) o20 else #<back_off> = 0.0200 (inch) o20 endif #<pass> = 1 o30 repeat [#<num_pecks>] #<z_target> = [#<z_start> - [#<pass> * #<peck>]] G1 Z #<z_target> G0 Z [#<z_target> + #<back_off>] #<pass> = [#<pass> + 1] o30 endrepeat G1 Z #<z_end> G0 Z #<z_start> o<g740> endsub M2
#!/usr/bin/python import sys import linuxcnc from interpreter import INTERP_OK import math import emccanon def g740(self, **words): # G74 is typically called like so: # G74 x ? z ? k ? (x = diameter, usually 0; z = hole endpoint; k = peck length) # get machine G30 position in current G20/21 units x_start = self.params[5420] z_start = self.params[5422] if 'z' in words: z_end = words['z'] else: z_end = z_start if 'k' in words: peck_length = words['k'] else: peck_length = 0 z_range = z_end - z_start if peck_length > 0: num_pecks = int(math.fabs(z_range / peck_length)) else: num_pecks = 0 if (self.params['_metric']): # if is_metric backoff_length = 0.50 # mm else: backoff_length = 0.020 # inch for i in range(num_pecks): #""" z_target = z_start - ((i + 1) * peck_length) line = i * 2 emccanon.STRAIGHT_FEED(line,x_start,0,z_target,0,0,0,0,0,0) emccanon.STRAIGHT_TRAVERSE(line + 1,x_start,0,(z_target + backoff_length),0,0,0,0,0,0) emccanon.STRAIGHT_FEED(line + 1,x_start,0,z_end,0,0,0,0,0,0) emccanon.STRAIGHT_TRAVERSE(line + 2,x_start,0,(z_start),0,0,0,0,0,0) #""" """ z_target = z_start - ((i + 1) * peck_length) self.execute("G1 Z %s" % z_target) z_backoff = z_target + backoff_length self.execute("G0 Z %s" % z_backoff) self.execute("G1 Z %s" % z_end) self.execute("G0 Z %s" % z_start) #""" return INTERP_OK