From 9e9cd3438fda07dd92038f217d91894b8d91c018 Mon Sep 17 00:00:00 2001 From: SpectralVectors Date: Thu, 21 Mar 2024 08:36:34 -0400 Subject: [PATCH] Autopep8 format, author & version update Ran Autopep8 on all files in repo, they are otherwise untouched with one exception: In the __init__ file, I had to manually rearrange the import statements to avoid triggering a circular import error. This will be addressed in a future commit. Updated authors in bl_info to: 'Vilem Novak & Contributors' - this can be changed as required Updated version to: 1.0.5 --- scripts/addons/cam/nc/anilam_crusader_m.py | 43 +- .../addons/cam/nc/anilam_crusader_m_read.py | 1 + scripts/addons/cam/nc/attach.py | 36 +- scripts/addons/cam/nc/cad_iso_read.py | 95 +- scripts/addons/cam/nc/cad_nc_read.py | 53 +- scripts/addons/cam/nc/cad_read.py | 142 +- scripts/addons/cam/nc/centroid1.py | 41 +- scripts/addons/cam/nc/centroid1_read.py | 1 + scripts/addons/cam/nc/drag_knife.py | 24 +- scripts/addons/cam/nc/emc2.py | 337 +- scripts/addons/cam/nc/emc2_read.py | 1 + scripts/addons/cam/nc/emc2b.py | 17 +- scripts/addons/cam/nc/emc2b_crc.py | 3 + scripts/addons/cam/nc/emc2b_crc_read.py | 2 + scripts/addons/cam/nc/emc2b_read.py | 2 + scripts/addons/cam/nc/emc2tap.py | 40 +- scripts/addons/cam/nc/emc2tap_read.py | 2 + scripts/addons/cam/nc/fadal.py | 100 +- scripts/addons/cam/nc/format.py | 30 +- scripts/addons/cam/nc/gantry_router.py | 18 +- scripts/addons/cam/nc/gantry_router_read.py | 2 + scripts/addons/cam/nc/gravos.py | 98 +- scripts/addons/cam/nc/grbl.py | 72 +- scripts/addons/cam/nc/heiden.py | 2347 +++++++------- scripts/addons/cam/nc/heiden530.py | 30 +- scripts/addons/cam/nc/heiden_read.py | 24 +- scripts/addons/cam/nc/hm50.py | 21 +- scripts/addons/cam/nc/hm50_read.py | 2 + scripts/addons/cam/nc/hpgl2d.py | 19 +- scripts/addons/cam/nc/hpgl2d_read.py | 29 +- scripts/addons/cam/nc/hpgl2dv.py | 6 +- scripts/addons/cam/nc/hpgl2dv_read.py | 1 + scripts/addons/cam/nc/hpgl3d.py | 10 +- scripts/addons/cam/nc/hpgl3d_read.py | 11 +- scripts/addons/cam/nc/hxml_writer.py | 88 +- scripts/addons/cam/nc/iso.py | 2714 +++++++++-------- scripts/addons/cam/nc/iso_codes.py | 3 +- scripts/addons/cam/nc/iso_crc.py | 3 + scripts/addons/cam/nc/iso_crc_read.py | 2 + scripts/addons/cam/nc/iso_modal.py | 3 + scripts/addons/cam/nc/iso_modal_read.py | 2 + scripts/addons/cam/nc/iso_read.py | 61 +- scripts/addons/cam/nc/lathe1.py | 149 +- scripts/addons/cam/nc/lathe1_read.py | 80 +- scripts/addons/cam/nc/lynx_otter_o.py | 63 +- scripts/addons/cam/nc/mach3.py | 22 +- scripts/addons/cam/nc/mach3_read.py | 2 + scripts/addons/cam/nc/makerbotHBP.py | 107 +- scripts/addons/cam/nc/makerbotHBP_read.py | 2 + scripts/addons/cam/nc/makerbot_codes.py | 229 +- scripts/addons/cam/nc/nc.py | 973 +++--- scripts/addons/cam/nc/nc_read.py | 62 +- scripts/addons/cam/nc/nclathe_read.py | 136 +- scripts/addons/cam/nc/num_reader.py | 4 +- scripts/addons/cam/nc/printbot3d.py | 7 +- scripts/addons/cam/nc/printbot3d_read.py | 1 + scripts/addons/cam/nc/recreator.py | 80 +- scripts/addons/cam/nc/rez2.py | 555 ++-- scripts/addons/cam/nc/rez2_read.py | 366 +-- scripts/addons/cam/nc/series1.py | 5 +- scripts/addons/cam/nc/series1_read.py | 1 + scripts/addons/cam/nc/shopbot_mtc.py | 395 ++- scripts/addons/cam/nc/siegkx1.py | 2 + scripts/addons/cam/nc/siegkx1_read.py | 2 + scripts/addons/cam/nc/tnc151.py | 9 +- scripts/addons/cam/nc/tnc151_read.py | 2 + scripts/addons/cam/nc/winpc.py | 42 +- 67 files changed, 5218 insertions(+), 4614 deletions(-) diff --git a/scripts/addons/cam/nc/anilam_crusader_m.py b/scripts/addons/cam/nc/anilam_crusader_m.py index 89cee5532..994d64ed0 100644 --- a/scripts/addons/cam/nc/anilam_crusader_m.py +++ b/scripts/addons/cam/nc/anilam_crusader_m.py @@ -5,6 +5,7 @@ from . import nc from . import iso + class Creator(iso.Creator): def __init__(self): iso.Creator.__init__(self) @@ -16,10 +17,10 @@ def SPACE_STR(self): return(' ') # This version of COMMENT removes comments from the resultant GCode # Note: The Anilam hates comments when importing code. - def COMMENT(self,comment): return('') + def COMMENT(self, comment): return('') def program_begin(self, id, comment): - self.write('%\n'); # Start of file token that Anilam Crusader M likes + self.write('%\n') # Start of file token that Anilam Crusader M likes # No Comments for the Anilam crusaher M, please...... #self.write( ('(' + comment + ')' + '\n') ) @@ -28,41 +29,41 @@ def program_end(self): self.write('%\n') # EOF signal for Anilam Crusader M ############################################################################ - ## Settings + # Settings def imperial(self): - self.write( self.IMPERIAL() + '\n') + self.write(self.IMPERIAL() + '\n') self.fmt.number_of_decimal_places = 4 def metric(self): - self.write( self.METRIC() + '\n' ) + self.write(self.METRIC() + '\n') self.fmt.number_of_decimal_places = 3 def absolute(self): - self.write( self.ABSOLUTE() + '\n') + self.write(self.ABSOLUTE() + '\n') def incremental(self): - self.write( self.INCREMENTAL() + '\n' ) + self.write(self.INCREMENTAL() + '\n') def polar(self, on=True): - if (on) : - self.write(self.POLAR_ON() + '\n' ) - else : - self.write(self.POLAR_OFF() + '\n' ) + if (on): + self.write(self.POLAR_ON() + '\n') + else: + self.write(self.POLAR_OFF() + '\n') def set_plane(self, plane): - if (plane == 0) : + if (plane == 0): self.write('G17\n') - elif (plane == 1) : + elif (plane == 1): self.write('G18\n') - elif (plane == 2) : + elif (plane == 2): self.write('G19\n') def comment(self, text): - pass + pass ############################################################################ - ## Tools + # Tools def tool_change(self, id): self.write(('T%i' % id) + '\n') @@ -83,11 +84,13 @@ def tool_defn(self, id, name='', params=None): # These are selected by values from 1 to 9 inclusive. def workplane(self, id): if ((id >= 1) and (id <= 6)): - self.write( (self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\n') + self.write((self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\n') if ((id >= 7) and (id <= 9)): - self.write( ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\n') + self.write(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\n') + + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + self.write( + '(Canned drill cycle ops are not yet supported here on this Anilam Crusader M postprocessor)') - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance = None): - self.write('(Canned drill cycle ops are not yet supported here on this Anilam Crusader M postprocessor)') nc.creator = Creator() diff --git a/scripts/addons/cam/nc/anilam_crusader_m_read.py b/scripts/addons/cam/nc/anilam_crusader_m_read.py index 8e03a13c8..d8a688a5b 100644 --- a/scripts/addons/cam/nc/anilam_crusader_m_read.py +++ b/scripts/addons/cam/nc/anilam_crusader_m_read.py @@ -7,6 +7,7 @@ # Override some iso parser methods to interpret arc centers as relative to origin, not relative to start of arc. + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/attach.py b/scripts/addons/cam/nc/attach.py index 27c2d0c86..2da4f263a 100644 --- a/scripts/addons/cam/nc/attach.py +++ b/scripts/addons/cam/nc/attach.py @@ -16,6 +16,8 @@ units = 1.0 ################################################################################ + + class Creator(recreator.Redirector): def __init__(self, original): @@ -44,10 +46,11 @@ def z2(self, z): # use a line with no length path.append(ocl.Line(ocl.Point(self.x, self.y, self.z), ocl.Point(self.x, self.y, self.z))) self.setPdcfIfNotSet() - if (self.z>self.minz): - self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?) + if (self.z > self.minz): + # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?) + self.pdcf.setZ(self.z) else: - self.pdcf.setZ(self.minz/units) # Else use minz + self.pdcf.setZ(self.minz/units) # Else use minz self.pdcf.setPath(path) self.pdcf.run() plist = self.pdcf.getCLPoints() @@ -55,13 +58,15 @@ def z2(self, z): return p.z + self.material_allowance/units def cut_path(self): - if self.path == None: return + if self.path == None: + return self.setPdcfIfNotSet() - if (self.z>self.minz): - self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?) + if (self.z > self.minz): + # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?) + self.pdcf.setZ(self.z) else: - self.pdcf.setZ(self.minz/units) # Else use minz + self.pdcf.setZ(self.minz/units) # Else use minz # get the points on the surface self.pdcf.setPath(self.path) @@ -69,7 +74,7 @@ def cut_path(self): self.pdcf.run() plist = self.pdcf.getCLPoints() - #refine the points + # refine the points f = ocl.LineCLFilter() f.setTolerance(0.005) for p in plist: @@ -85,7 +90,7 @@ def cut_path(self): self.path = ocl.Path() - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if z != None: if z < self.z: return @@ -102,24 +107,28 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): return # add a line to the path - if self.path == None: self.path = ocl.Path() + if self.path == None: + self.path = ocl.Path() self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z))) - def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True): + def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw=True): px = self.x py = self.y pz = self.z recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw) # add an arc to the path - if self.path == None: self.path = ocl.Path() - self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z), ocl.Point(i, j, pz), ccw)) + if self.path == None: + self.path = ocl.Path() + self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point( + self.x, self.y, self.z), ocl.Point(i, j, pz), ccw)) def set_ocl_cutter(self, cutter): self.cutter = cutter ################################################################################ + def attach_begin(): global attached if attached == True: @@ -130,6 +139,7 @@ def attach_begin(): nc.creator.pdcf = None nc.creator.path = None + def attach_end(): global attached nc.creator.cut_path() diff --git a/scripts/addons/cam/nc/cad_iso_read.py b/scripts/addons/cam/nc/cad_iso_read.py index 2ca104fec..b3a2511f6 100644 --- a/scripts/addons/cam/nc/cad_iso_read.py +++ b/scripts/addons/cam/nc/cad_iso_read.py @@ -16,17 +16,18 @@ import sys ################################################################################ -class Parser(nc.Parser): +class Parser(nc.Parser): def __init__(self, writer): nc.Parser.__init__(self, writer) - self.pattern_main = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') + self.pattern_main = re.compile( + '([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') - #if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point - # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal + # if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point + # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal # add your character here > [(!;] for comments char # then look for the 'comment' function towards the end of the file and add another elif @@ -81,7 +82,7 @@ def ParseWord(self, word): self.path_col = "feed" self.col = "feed" elif (word == 'G82' or word == 'g82'): - self.drill = True; + self.drill = True self.no_move = True self.path_col = "feed" self.col = "feed" @@ -94,7 +95,8 @@ def ParseWord(self, word): self.absolute() elif (word == 'G91' or word == 'g91'): self.incremental() - elif (word[0] == 'G') : col = "prep" + elif (word[0] == 'G'): + col = "prep" elif (word[0] == 'I' or word[0] == 'i'): self.col = "axis" self.i = eval(word[1:]) @@ -107,19 +109,22 @@ def ParseWord(self, word): self.col = "axis" self.k = eval(word[1:]) self.move = True - elif (word[0] == 'M') : self.col = "misc" - elif (word[0] == 'N') : self.col = "blocknum" - elif (word[0] == 'O') : self.col = "program" + elif (word[0] == 'M'): + self.col = "misc" + elif (word[0] == 'N'): + self.col = "blocknum" + elif (word[0] == 'O'): + self.col = "program" elif (word[0] == 'P' or word[0] == 'p'): - if (self.no_move != True): - self.col = "axis" - self.p = eval(word[1:]) - self.move = True + if (self.no_move != True): + self.col = "axis" + self.p = eval(word[1:]) + self.move = True elif (word[0] == 'Q' or word[0] == 'q'): - if (self.no_move != True): - self.col = "axis" - self.q = eval(word[1:]) - self.move = True + if (self.no_move != True): + self.col = "axis" + self.q = eval(word[1:]) + self.move = True elif (word[0] == 'R' or word[0] == 'r'): self.col = "axis" self.r = eval(word[1:]) @@ -128,9 +133,9 @@ def ParseWord(self, word): self.col = "axis" self.s = eval(word[1:]) self.move = True - elif (word[0] == 'T') : + elif (word[0] == 'T'): self.col = "tool" - self.set_tool( eval(word[1:]) ) + self.set_tool(eval(word[1:])) elif (word[0] == 'X' or word[0] == 'x'): self.col = "axis" self.x = eval(word[1:]) @@ -143,21 +148,27 @@ def ParseWord(self, word): self.col = "axis" self.z = eval(word[1:]) self.move = True - elif (word[0] == '(') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == '!') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == ';') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == '#') : self.col = "variable" - elif (word[0] == ':') : self.col = "blocknum" - elif (ord(word[0]) <= 32) : self.cdata = True + elif (word[0] == '('): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == '!'): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == ';'): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == '#'): + self.col = "variable" + elif (word[0] == ':'): + self.col = "blocknum" + elif (ord(word[0]) <= 32): + self.cdata = True def Parse(self, name, oname=None): - self.files_open(name,oname) + self.files_open(name, oname) - #self.begin_ncblock() - #self.begin_path(None) - #self.add_line(z=500) - #self.end_path() - #self.end_ncblock() + # self.begin_ncblock() + # self.begin_path(None) + # self.add_line(z=500) + # self.end_path() + # self.end_ncblock() self.path_col = None self.f = None @@ -179,7 +190,7 @@ def Parse(self, name, oname=None): self.y = None self.z = None - #self.begin_ncblock() + # self.begin_ncblock() self.move = False self.drill = False @@ -207,12 +218,15 @@ def Parse(self, name, oname=None): else: if (self.move and not self.no_move): self.begin_path(self.path_col) - if (self.arc==-1): - self.add_arc(self.x, self.y, self.z, self.i, self.j, self.k, self.r, self.arc) - elif (self.arc==1): - #self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one - self.add_arc(self.x, self.y, self.z, self.i, self.j, self.k, self.r, self.arc) - else : self.add_line(self.x, self.y, self.z, self.a, self.b, self.c) + if (self.arc == -1): + self.add_arc(self.x, self.y, self.z, self.i, + self.j, self.k, self.r, self.arc) + elif (self.arc == 1): + # self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one + self.add_arc(self.x, self.y, self.z, self.i, + self.j, self.k, self.r, self.arc) + else: + self.add_line(self.x, self.y, self.z, self.a, self.b, self.c) self.end_path() self.end_ncblock() @@ -221,9 +235,10 @@ def Parse(self, name, oname=None): ################################################################################ + if __name__ == '__main__': parser = ParserIso() - if len(sys.argv)>2: - parser.Parse(sys.argv[1],sys.argv[2]) + if len(sys.argv) > 2: + parser.Parse(sys.argv[1], sys.argv[2]) else: parser.Parse(sys.argv[1]) diff --git a/scripts/addons/cam/nc/cad_nc_read.py b/scripts/addons/cam/nc/cad_nc_read.py index 15ef23ece..4203fcdb3 100644 --- a/scripts/addons/cam/nc/cad_nc_read.py +++ b/scripts/addons/cam/nc/cad_nc_read.py @@ -12,14 +12,14 @@ def __init__(self): self.currentx = -1.0 self.currenty = 0.0 self.currentz = 0.0 - x,y,z = 0.0,0.0,0.0 + x, y, z = 0.0, 0.0, 0.0 self.absolute_flag = True ############################################################################ - ## Internals + # Internals def files_open(self, name, oname=None): - if (oname == None ): + if (oname == None): oname = (name+'.scr') self.file_in = open(name, 'r') self.file_out = open(oname, 'w') @@ -60,52 +60,61 @@ def begin_path(self, col=None): if (col != None): if col == 'rapid': self.file_out.write('-color Red\n') - #self.file_out.write('') + # self.file_out.write('') self.file_out.write('-linetype set dashed\n') self.file_out.write('\n') else: self.file_out.write('-color Green\n') - #self.file_out.write('') + # self.file_out.write('') self.file_out.write('-linetype set continuous\n') self.file_out.write('\n') - else : self.file_out.write('\n') + else: + self.file_out.write('\n') def end_path(self): self.file_out.write('\n') def add_line(self, x=None, y=None, z=None, a=None, b=None, c=None): - if (x == None and y == None and z == None and a == None and b == None and c == None) : return + if (x == None and y == None and z == None and a == None and b == None and c == None): + return #self.file_out.write('line %s,%s %s,%s' %(self.currentx,self.currenty,x,y)) - if (x == None) : x = self.currentx - if (y == None) : y = self.currenty - if (z == None) : z = self.currentz - self.file_out.write('line %s,%s,%s %s,%s,%s\n' %(self.currentx,self.currenty,self.currentz,x,y,z)) + if (x == None): + x = self.currentx + if (y == None): + y = self.currenty + if (z == None): + z = self.currentz + self.file_out.write('line %s,%s,%s %s,%s,%s\n' % + (self.currentx, self.currenty, self.currentz, x, y, z)) self.currentx = x self.currenty = y self.currentz = z def add_arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, d=None): - if (x == None and y == None and z == None and i == None and j == None and k == None and r == None and d == None) : return + if (x == None and y == None and z == None and i == None and j == None and k == None and r == None and d == None): + return z = self.currentz - if (x == None) : x = self.currentx - if (y == None) : y = self.currenty - if (z == None) : z = self.currentz + if (x == None): + x = self.currentx + if (y == None): + y = self.currenty + if (z == None): + z = self.currentz if (d == 1): - self.file_out.write('arc %s,%s,%s\n' %(self.currentx,self.currenty,self.currentz)) + self.file_out.write('arc %s,%s,%s\n' % (self.currentx, self.currenty, self.currentz)) self.file_out.write('c\n') - self.file_out.write('%s,%s,%s\n' %(self.currentx+i,self.currenty+j,self.currentz)) - self.file_out.write('%s,%s,%s' %(x,y,z)) + self.file_out.write('%s,%s,%s\n' % (self.currentx+i, self.currenty+j, self.currentz)) + self.file_out.write('%s,%s,%s' % (x, y, z)) else: - self.file_out.write('arc %s,%s,%s\n' %(x,y,z)) + self.file_out.write('arc %s,%s,%s\n' % (x, y, z)) self.file_out.write('c\n') - self.file_out.write('%s,%s,%s\n' %(self.currentx+i,self.currenty+j,self.currentz)) - self.file_out.write('%s,%s,%s' %(self.currentx,self.currenty,self.currentz)) + self.file_out.write('%s,%s,%s\n' % (self.currentx+i, self.currenty+j, self.currentz)) + self.file_out.write('%s,%s,%s' % (self.currentx, self.currenty, self.currentz)) self.currentx = x self.currenty = y self.currentz = z - def incremental(self): self.absolute_flag = False diff --git a/scripts/addons/cam/nc/cad_read.py b/scripts/addons/cam/nc/cad_read.py index 40efded39..faf31bbe8 100644 --- a/scripts/addons/cam/nc/cad_read.py +++ b/scripts/addons/cam/nc/cad_read.py @@ -12,12 +12,11 @@ import sys - # Override some iso parser methods to interpret arc centers as relative to origin, not relative to start of arc. -#def write_layer(name,number): - #FILE.write('-LAYER New %s%s \n' %(name,number)) - #FILE.write('-LAYER Set %s%s \n' %(name,number)) +# def write_layer(name,number): +#FILE.write('-LAYER New %s%s \n' %(name,number)) +#FILE.write('-LAYER Set %s%s \n' %(name,number)) class CAD_backplot(iso.Parser): @@ -26,13 +25,13 @@ def __init__(self): iso.Parser.__init__(self) def Parse(self, name, oname=None): - self.files_open(name,oname) + self.files_open(name, oname) - #self.begin_ncblock() - #self.begin_path(None) - #self.add_line(z=500) - #self.end_path() - #self.end_ncblock() + # self.begin_ncblock() + # self.begin_path(None) + # self.add_line(z=500) + # self.end_path() + # self.end_ncblock() path_col = None f = None @@ -45,7 +44,7 @@ def Parse(self, name, oname=None): oldz = 0.0 movelist = [] while (self.readline()): - # self.readline returns false if the line is empty - the parsing stops if the line is empty. + # self.readline returns false if the line is empty - the parsing stops if the line is empty. a = None b = None c = None @@ -64,7 +63,7 @@ def Parse(self, name, oname=None): jout = None kout = None tool = 0 - #self.begin_ncblock() + # self.begin_ncblock() move = False #arc = 0 @@ -129,7 +128,7 @@ def Parse(self, name, oname=None): path_col = "feed" col = "feed" elif (word == 'G82' or word == 'g82'): - drill = True; + drill = True no_move = True path_col = "feed" col = "feed" @@ -138,7 +137,8 @@ def Parse(self, name, oname=None): no_move = True path_col = "feed" col = "feed" - elif (word[0] == 'G') : col = "prep" + elif (word[0] == 'G'): + col = "prep" elif (word[0] == 'I' or word[0] == 'i'): col = "axis" i = eval(word[1:]) @@ -151,9 +151,12 @@ def Parse(self, name, oname=None): col = "axis" k = eval(word[1:]) move = True - elif (word[0] == 'M') : col = "misc" - elif (word[0] == 'N') : col = "blocknum" - elif (word[0] == 'O') : col = "program" + elif (word[0] == 'M'): + col = "misc" + elif (word[0] == 'N'): + col = "blocknum" + elif (word[0] == 'O'): + col = "program" elif (word[0] == 'P' or word[0] == 'p'): col = "axis" p = eval(word[1:]) @@ -170,10 +173,10 @@ def Parse(self, name, oname=None): col = "axis" s = eval(word[1:]) move = True - elif (word[0] == 'T') : + elif (word[0] == 'T'): col = "tool" - self.set_tool( eval(word[1:]) ) - tool = eval(word[1:]) + self.set_tool(eval(word[1:])) + tool = eval(word[1:]) elif (word[0] == 'X' or word[0] == 'x'): col = "axis" @@ -187,12 +190,18 @@ def Parse(self, name, oname=None): col = "axis" z = eval(word[1:]) move = True - elif (word[0] == '(') : (col, cdata) = ("comment", True) - elif (word[0] == '!') : (col, cdata) = ("comment", True) - elif (word[0] == ';') : (col, cdata) = ("comment", True) - elif (word[0] == '#') : col = "variable" - elif (word[0] == ':') : col = "blocknum" - elif (ord(word[0]) <= 32) : cdata = True + elif (word[0] == '('): + (col, cdata) = ("comment", True) + elif (word[0] == '!'): + (col, cdata) = ("comment", True) + elif (word[0] == ';'): + (col, cdata) = ("comment", True) + elif (word[0] == '#'): + col = "variable" + elif (word[0] == ':'): + col = "blocknum" + elif (ord(word[0]) <= 32): + cdata = True #self.add_text(word, col, cdata) if (drill): @@ -207,55 +216,63 @@ def Parse(self, name, oname=None): self.begin_path("feed") self.add_line(x, y, r) self.end_path() - #elif (tool): - #write_layer('T',tool) - + # elif (tool): + # write_layer('T',tool) else: if (move and not no_move): self.begin_path(path_col) - #use absolute arc centers for IJK params. + # use absolute arc centers for IJK params. # Subtract old XYZ off to get relative centers as expected: - #if path_col == 'rapid': - #FILE.write('-color Red\n') - #else: - #FILE.write('-color Green\n') + # if path_col == 'rapid': + #FILE.write('-color Red\n') + # else: + #FILE.write('-color Green\n') - if (arc) : + if (arc): z = oldz - if (x != None) and (oldx != None) and (i != None): iout = i - if (y != None) and (oldy != None) and (j != None): jout = j - if (z != None) and (oldz != None) and (k != None): kout = k + if (x != None) and (oldx != None) and (i != None): + iout = i + if (y != None) and (oldy != None) and (j != None): + jout = j + if (z != None) and (oldz != None) and (k != None): + kout = k self.add_arc(x, y, z, iout, jout, kout, r, arc) - #if (arc == -1): - ##FILE.write('arc %s,%s,%s\n' %(x,y,z)) - ##FILE.write('c\n') - ##FILE.write('%s,%s,%s\n' %(oldx+i,oldy+j,oldz)) - ##FILE.write('%s,%s,%s\n' %(oldx,oldy,z)) - - #else: - ##FILE.write('arc %s,%s,%s\n' %(oldx,oldy,z)) - ##FILE.write('c\n') - ##FILE.write('%s,%s,%s\n' %(oldx+i,oldy+j,oldz)) - ##FILE.write('%s,%s,%s\n' %(x,y,z)) + # if (arc == -1): + ##FILE.write('arc %s,%s,%s\n' %(x,y,z)) + # FILE.write('c\n') + ##FILE.write('%s,%s,%s\n' %(oldx+i,oldy+j,oldz)) + ##FILE.write('%s,%s,%s\n' %(oldx,oldy,z)) + + # else: + ##FILE.write('arc %s,%s,%s\n' %(oldx,oldy,z)) + # FILE.write('c\n') + ##FILE.write('%s,%s,%s\n' %(oldx+i,oldy+j,oldz)) + ##FILE.write('%s,%s,%s\n' %(x,y,z)) else: self.add_line(x, y, z, a, b, c) - if (x == None) : x = oldx - if (y == None) : y = oldy - if (z == None) : z = oldz - scr_line = ('line %s,%s,%s %s,%s,%s \n' %(oldx,oldy,oldz,x,y,z)) - #print scr_line + if (x == None): + x = oldx + if (y == None): + y = oldy + if (z == None): + z = oldz + scr_line = ('line %s,%s,%s %s,%s,%s \n' % (oldx, oldy, oldz, x, y, z)) + # print scr_line - ##FILE.write(scr_line) + # FILE.write(scr_line) self.end_path() - if (x != None) : oldx = x - if (y != None) : oldy = y - if (z != None) : oldz = z + if (x != None): + oldx = x + if (y != None): + oldy = y + if (z != None): + oldz = z #oldx = x #oldy = y @@ -263,13 +280,14 @@ def Parse(self, name, oname=None): self.end_ncblock() self.files_close() - #FILE.write('\n') - #FILE.close() + # FILE.write('\n') + # FILE.close() + ################################################################################ if __name__ == '__main__': parser = CAD_backplot() - if len(sys.argv)>2: - parser.Parse(sys.argv[1],sys.argv[2]) + if len(sys.argv) > 2: + parser.Parse(sys.argv[1], sys.argv[2]) else: parser.Parse(sys.argv[1]) diff --git a/scripts/addons/cam/nc/centroid1.py b/scripts/addons/cam/nc/centroid1.py index 214d01254..9fb899a22 100644 --- a/scripts/addons/cam/nc/centroid1.py +++ b/scripts/addons/cam/nc/centroid1.py @@ -15,7 +15,6 @@ now = datetime.datetime.now() - ################################################################################ class Creator(iso_modal.Creator): @@ -26,23 +25,25 @@ def __init__(self): self.useCrcCenterline = True self.absolute_flag = True self.prev_g91 = '' - self.safe_z =None + self.safe_z = None + def SPINDLE(self, format, speed): return(self.SPACE() + 'S' + (format % speed)) ################################################################################ -#cutter comp +# cutter comp - #def crc_on(self): + # def crc_on(self): # self.useCrc = True # self.useCrcCenterline = True - #def crc_off(self): + # def crc_off(self): # self.useCrc = False ################################################################################ # general def comment(self, text): - self.write(';' + text +'\n') + self.write(';' + text + '\n') + def write_blocknum(self): pass @@ -69,7 +70,6 @@ def program_begin(self, id, name=''): self.write(';time:'+str(now)+'\n') self.write('G17 G20 G80 G40 G90\n') - def program_end(self): self.write('M05\n') self.write('M25\n') @@ -79,9 +79,9 @@ def program_end(self): def program_stop(self, optional=False): self.write_blocknum() - if (optional) : + if (optional): self.write(self.STOP_OPTIONAL() + '\n') - else : + else: self.write('M05\n') self.write('M25\n') self.write(self.STOP() + '\n') @@ -94,16 +94,18 @@ def workplane(self, id): if ((id >= 1) and (id <= 6)): self.g_list.append(self.WORKPLANE() % (id + self.WORKPLANE_BASE())) if ((id >= 7) and (id <= 9)): - self.g_list.append(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) + self.g_list.append( + ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) self.prev_g0123 = '' ################################################################################ # clearance plane - def clearanceplane(self,z=None): + def clearanceplane(self, z=None): self.safe_z = z ################################################################################ # return to home + def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): """Rapid relative to home position""" self.write('M05\n') @@ -121,14 +123,13 @@ def tool_change(self, id): self.t = id self.write('M25\n') if self.safe_z == None: - self.write('G43 H'+ str(id) + ' Z') + self.write('G43 H' + str(id) + ' Z') self.write('1.0') - self.write ('\n') + self.write('\n') else: - self.write('G43 H'+ str(id) + ' Z') + self.write('G43 H' + str(id) + ' Z') self.write(str(self.safe_z)) - self.write ('\n') - + self.write('\n') def tool_defn(self, id, name='', params=None): #self.write('G43 \n') @@ -137,7 +138,6 @@ def tool_defn(self, id, name='', params=None): def write_spindle(self): pass - def spindle(self, s, clockwise): if s < 0: clockwise = not clockwise @@ -146,12 +146,12 @@ def spindle(self, s, clockwise): self.s = self.SPINDLE(self.FORMAT_ANG(), s) if clockwise: #self.s = self.SPINDLE_CW() + self.s - self.s = self.SPINDLE_CW() - self.write(self.s + '\n') + self.s = self.SPINDLE_CW() + self.write(self.s + '\n') self.write('G04 P2.0 \n') else: - self.s = self.SPINDLE_CCW() + self.s + self.s = self.SPINDLE_CCW() + self.s def end_canned_cycle(self): self.write_blocknum() @@ -165,4 +165,5 @@ def end_canned_cycle(self): self.write('M25\n') self.write('G00 X-1.0 Y1.0\n') + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/centroid1_read.py b/scripts/addons/cam/nc/centroid1_read.py index a8040bec1..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/centroid1_read.py +++ b/scripts/addons/cam/nc/centroid1_read.py @@ -3,6 +3,7 @@ # just use the iso reader + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/drag_knife.py b/scripts/addons/cam/nc/drag_knife.py index afc8da612..5288b8e3d 100644 --- a/scripts/addons/cam/nc/drag_knife.py +++ b/scripts/addons/cam/nc/drag_knife.py @@ -5,13 +5,15 @@ # # Dan Heeks 26th April 2012 +import area +import nc +from kurve_funcs import cut_curve as cut_curve from . import recreator dragging = False -from kurve_funcs import cut_curve as cut_curve -import nc -import area ################################################################################ + + class Creator(recreator.Redirector): def __init__(self, original, drag_distance): @@ -21,7 +23,8 @@ def __init__(self, original, drag_distance): self.path = None def cut_path(self): - if self.path == None: return + if self.path == None: + return print self.drag_distance self.path.OffsetForward(self.drag_distance, False) @@ -48,15 +51,19 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): return # add a line to the path - if self.path == None: self.path = area.Curve() + if self.path == None: + self.path = area.Curve() self.path.append(area.Point(self.x, self.y)) - def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True): + def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw=True): recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw) # add an arc to the path - if self.path == None: self.path = area.Curve() - self.path.append(area.Vertex(1 if ccw else -1, area.Point(self.x, self.y), area.Point(i, j))) + if self.path == None: + self.path = area.Curve() + self.path.append(area.Vertex(1 if ccw else -1, + area.Point(self.x, self.y), area.Point(i, j))) + def drag_begin(drag_distance): global dragging @@ -65,6 +72,7 @@ def drag_begin(drag_distance): nc.creator = Creator(nc.creator, drag_distance) dragging = True + def drag_end(): global dragging nc.creator.cut_path() diff --git a/scripts/addons/cam/nc/emc2.py b/scripts/addons/cam/nc/emc2.py index b9ca331c7..db3a311dc 100644 --- a/scripts/addons/cam/nc/emc2.py +++ b/scripts/addons/cam/nc/emc2.py @@ -2,230 +2,235 @@ from . import iso import math -class Creator(iso.Creator): - def __init__(self): - iso.Creator.__init__(self) - def SPACE(self): return('') - def TAP(self): return('G33.1') - def TAP_DEPTH(self, format, depth): return(self.SPACE() + 'K' + (format.string(depth))) - def BORE_FEED_OUT(self): return('G85') - def BORE_SPINDLE_STOP_RAPID_OUT(self): return('G86') - def BORE_DWELL_FEED_OUT(self, format, dwell): return('G89') + self.SPACE() + (format.string(dwell)) +class Creator(iso.Creator): + def __init__(self): + iso.Creator.__init__(self) - def program_begin(self, id, comment): - self.write( ('(' + comment + ')' + '\n') ) + def SPACE(self): return('') + def TAP(self): return('G33.1') + def TAP_DEPTH(self, format, depth): return(self.SPACE() + 'K' + (format.string(depth))) + def BORE_FEED_OUT(self): return('G85') + def BORE_SPINDLE_STOP_RAPID_OUT(self): return('G86') - ############################################################################ - ## Settings + def BORE_DWELL_FEED_OUT(self, format, dwell): return( + 'G89') + self.SPACE() + (format.string(dwell)) - def imperial(self): - self.write( self.IMPERIAL() + '\t (Imperial Values)\n') - self.fmt.number_of_decimal_places = 4 + def program_begin(self, id, comment): + self.write(('(' + comment + ')' + '\n')) - def metric(self): - self.fmt.number_of_decimal_places = 3 - self.write( self.METRIC() + '\t (Metric Values)\n' ) + ############################################################################ + # Settings - def absolute(self): - self.write( self.ABSOLUTE() + '\t (Absolute Coordinates)\n') + def imperial(self): + self.write(self.IMPERIAL() + '\t (Imperial Values)\n') + self.fmt.number_of_decimal_places = 4 - def incremental(self): - self.write( self.INCREMENTAL() + '\t (Incremental Coordinates)\n' ) + def metric(self): + self.fmt.number_of_decimal_places = 3 + self.write(self.METRIC() + '\t (Metric Values)\n') - def polar(self, on=True): - if (on) : - self.write(self.POLAR_ON() + '\t (Polar ON)\n' ) - else : - self.write(self.POLAR_OFF() + '\t (Polar OFF)\n' ) + def absolute(self): + self.write(self.ABSOLUTE() + '\t (Absolute Coordinates)\n') - def set_plane(self, plane): - if (plane == 0) : - self.write(self.PLANE_XY() + '\t (Select XY Plane)\n') - elif (plane == 1) : - self.write(self.PLANE_XZ() + '\t (Select XZ Plane)\n') - elif (plane == 2) : - self.write(self.PLANE_YZ() + '\t (Select YZ Plane)\n') + def incremental(self): + self.write(self.INCREMENTAL() + '\t (Incremental Coordinates)\n') + def polar(self, on=True): + if (on): + self.write(self.POLAR_ON() + '\t (Polar ON)\n') + else: + self.write(self.POLAR_OFF() + '\t (Polar OFF)\n') - # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 - # These are selected by values from 1 to 9 inclusive. - def workplane(self, id): - if ((id >= 1) and (id <= 6)): - self.write( (self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\t (Select Relative Coordinate System)\n') - if ((id >= 7) and (id <= 9)): - self.write( ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\t (Select Relative Coordinate System)\n') + def set_plane(self, plane): + if (plane == 0): + self.write(self.PLANE_XY() + '\t (Select XY Plane)\n') + elif (plane == 1): + self.write(self.PLANE_XZ() + '\t (Select XZ Plane)\n') + elif (plane == 2): + self.write(self.PLANE_YZ() + '\t (Select YZ Plane)\n') - def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): - if (xml_file_name != None): - self.comment('Generate an XML document describing the probed coordinates found'); - self.write('(LOGOPEN,') - self.write(xml_file_name) - self.write(')\n') + # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 + # These are selected by values from 1 to 9 inclusive. - self.write('(LOG,)\n') + def workplane(self, id): + if ((id >= 1) and (id <= 6)): + self.write((self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + + '\t (Select Relative Coordinate System)\n') + if ((id >= 7) and (id <= 9)): + self.write(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % + (id - 6))) + '\t (Select Relative Coordinate System)\n') - if ((x1 != None) or (y1 != None) or (z1 != None)): - self.write('(LOG,)\n') + def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): + if (xml_file_name != None): + self.comment('Generate an XML document describing the probed coordinates found') + self.write('(LOGOPEN,') + self.write(xml_file_name) + self.write(')\n') - if (x1 != None): - self.write('#<_value>=[' + x1 + ']\n') - self.write('(LOG,#<_value>)\n') + self.write('(LOG,)\n') - if (y1 != None): - self.write('#<_value>=[' + y1 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x1 != None) or (y1 != None) or (z1 != None)): + self.write('(LOG,)\n') - if (z1 != None): - self.write('#<_value>=[' + z1 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x1 != None): + self.write('#<_value>=[' + x1 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x1 != None) or (y1 != None) or (z1 != None)): - self.write('(LOG,)\n') + if (y1 != None): + self.write('#<_value>=[' + y1 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x2 != None) or (y2 != None) or (z2 != None)): - self.write('(LOG,)\n') + if (z1 != None): + self.write('#<_value>=[' + z1 + ']\n') + self.write('(LOG,#<_value>)\n') - if (x2 != None): - self.write('#<_value>=[' + x2 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x1 != None) or (y1 != None) or (z1 != None)): + self.write('(LOG,)\n') - if (y2 != None): - self.write('#<_value>=[' + y2 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x2 != None) or (y2 != None) or (z2 != None)): + self.write('(LOG,)\n') - if (z2 != None): - self.write('#<_value>=[' + z2 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x2 != None): + self.write('#<_value>=[' + x2 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x2 != None) or (y2 != None) or (z2 != None)): - self.write('(LOG,)\n') + if (y2 != None): + self.write('#<_value>=[' + y2 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x3 != None) or (y3 != None) or (z3 != None)): - self.write('(LOG,)\n') + if (z2 != None): + self.write('#<_value>=[' + z2 + ']\n') + self.write('(LOG,#<_value>)\n') - if (x3 != None): - self.write('#<_value>=[' + x3 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x2 != None) or (y2 != None) or (z2 != None)): + self.write('(LOG,)\n') - if (y3 != None): - self.write('#<_value>=[' + y3 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x3 != None) or (y3 != None) or (z3 != None)): + self.write('(LOG,)\n') - if (z3 != None): - self.write('#<_value>=[' + z3 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x3 != None): + self.write('#<_value>=[' + x3 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x3 != None) or (y3 != None) or (z3 != None)): - self.write('(LOG,)\n') + if (y3 != None): + self.write('#<_value>=[' + y3 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x4 != None) or (y4 != None) or (z4 != None)): - self.write('(LOG,)\n') + if (z3 != None): + self.write('#<_value>=[' + z3 + ']\n') + self.write('(LOG,#<_value>)\n') - if (x4 != None): - self.write('#<_value>=[' + x4 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x3 != None) or (y3 != None) or (z3 != None)): + self.write('(LOG,)\n') - if (y4 != None): - self.write('#<_value>=[' + y4 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x4 != None) or (y4 != None) or (z4 != None)): + self.write('(LOG,)\n') - if (z4 != None): - self.write('#<_value>=[' + z4 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x4 != None): + self.write('#<_value>=[' + x4 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x4 != None) or (y4 != None) or (z4 != None)): - self.write('(LOG,)\n') + if (y4 != None): + self.write('#<_value>=[' + y4 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x5 != None) or (y5 != None) or (z5 != None)): - self.write('(LOG,)\n') + if (z4 != None): + self.write('#<_value>=[' + z4 + ']\n') + self.write('(LOG,#<_value>)\n') - if (x5 != None): - self.write('#<_value>=[' + x5 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x4 != None) or (y4 != None) or (z4 != None)): + self.write('(LOG,)\n') - if (y5 != None): - self.write('#<_value>=[' + y5 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x5 != None) or (y5 != None) or (z5 != None)): + self.write('(LOG,)\n') - if (z5 != None): - self.write('#<_value>=[' + z5 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x5 != None): + self.write('#<_value>=[' + x5 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x5 != None) or (y5 != None) or (z5 != None)): - self.write('(LOG,)\n') + if (y5 != None): + self.write('#<_value>=[' + y5 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x6 != None) or (y6 != None) or (z6 != None)): - self.write('(LOG,)\n') + if (z5 != None): + self.write('#<_value>=[' + z5 + ']\n') + self.write('(LOG,#<_value>)\n') - if (x6 != None): - self.write('#<_value>=[' + x6 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x5 != None) or (y5 != None) or (z5 != None)): + self.write('(LOG,)\n') - if (y6 != None): - self.write('#<_value>=[' + y6 + ']\n') - self.write('(LOG,#<_value>)\n') + if ((x6 != None) or (y6 != None) or (z6 != None)): + self.write('(LOG,)\n') - if (z6 != None): - self.write('#<_value>=[' + z6 + ']\n') - self.write('(LOG,#<_value>)\n') + if (x6 != None): + self.write('#<_value>=[' + x6 + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x6 != None) or (y6 != None) or (z6 != None)): - self.write('(LOG,)\n') + if (y6 != None): + self.write('#<_value>=[' + y6 + ']\n') + self.write('(LOG,#<_value>)\n') - self.write('(LOG,)\n') + if (z6 != None): + self.write('#<_value>=[' + z6 + ']\n') + self.write('(LOG,#<_value>)\n') - if (xml_file_name != None): - self.write('(LOGCLOSE)\n') + if ((x6 != None) or (y6 != None) or (z6 != None)): + self.write('(LOG,)\n') - def open_log_file(self, xml_file_name=None ): - self.write('(LOGOPEN,') - self.write(xml_file_name) - self.write(')\n') + self.write('(LOG,)\n') - def close_log_file(self): - self.write('(LOGCLOSE)\n') + if (xml_file_name != None): + self.write('(LOGCLOSE)\n') - def log_coordinate(self, x=None, y=None, z=None): - if ((x != None) or (y != None) or (z != None)): - self.write('(LOG,)\n') + def open_log_file(self, xml_file_name=None): + self.write('(LOGOPEN,') + self.write(xml_file_name) + self.write(')\n') - if (x != None): - self.write('#<_value>=[' + x + ']\n') - self.write('(LOG,#<_value>)\n') + def close_log_file(self): + self.write('(LOGCLOSE)\n') - if (y != None): - self.write('#<_value>=[' + y + ']\n') - self.write('(LOG,#<_value>)\n') + def log_coordinate(self, x=None, y=None, z=None): + if ((x != None) or (y != None) or (z != None)): + self.write('(LOG,)\n') - if (z != None): - self.write('#<_value>=[' + z + ']\n') - self.write('(LOG,#<_value>)\n') + if (x != None): + self.write('#<_value>=[' + x + ']\n') + self.write('(LOG,#<_value>)\n') - if ((x != None) or (y != None) or (z != None)): - self.write('(LOG,)\n') + if (y != None): + self.write('#<_value>=[' + y + ']\n') + self.write('(LOG,#<_value>)\n') - def log_message(self, message=None ): - self.write('(LOG,' + message + ')\n') + if (z != None): + self.write('#<_value>=[' + z + ']\n') + self.write('(LOG,#<_value>)\n') - def start_CRC(self, left = True, radius = 0.0): - if self.t == None: - raise "No tool specified for start_CRC()" - if left: - self.write(('G41' + self.SPACE() + 'D%i') % self.t + '\t (start left cutter radius compensation)\n' ) - else: - self.write(('G42' + self.SPACE() + 'D%i') % self.t + '\t (start right cutter radius compensation)\n' ) + if ((x != None) or (y != None) or (z != None)): + self.write('(LOG,)\n') - def end_CRC(self): - self.g = 'G40' - self.write_preps() - self.write_misc() - self.write('\t (end cutter radius compensation)\n') + def log_message(self, message=None): + self.write('(LOG,' + message + ')\n') + def start_CRC(self, left=True, radius=0.0): + if self.t == None: + raise "No tool specified for start_CRC()" + if left: + self.write(('G41' + self.SPACE() + 'D%i') % + self.t + '\t (start left cutter radius compensation)\n') + else: + self.write(('G42' + self.SPACE() + 'D%i') % + self.t + '\t (start right cutter radius compensation)\n') + def end_CRC(self): + self.g = 'G40' + self.write_preps() + self.write_misc() + self.write('\t (end cutter radius compensation)\n') + def tool_defn(self, id, name='', params=None): + pass - def tool_defn(self, id, name='', params=None): - pass nc.creator = Creator() diff --git a/scripts/addons/cam/nc/emc2_read.py b/scripts/addons/cam/nc/emc2_read.py index a8040bec1..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/emc2_read.py +++ b/scripts/addons/cam/nc/emc2_read.py @@ -3,6 +3,7 @@ # just use the iso reader + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/emc2b.py b/scripts/addons/cam/nc/emc2b.py index bd82c58f0..7e7b00b84 100644 --- a/scripts/addons/cam/nc/emc2b.py +++ b/scripts/addons/cam/nc/emc2b.py @@ -6,6 +6,7 @@ now = datetime.datetime.now() + class Creator(iso_modal.Creator): def __init__(self): iso_modal.Creator.__init__(self) @@ -21,24 +22,26 @@ def SPACE(self): return ' ' def PROGRAM(self): return None + def PROGRAM_END(self): if self.output_tool_change: - return( 'T0' + self.SPACE() + 'M06' + self.SPACE() + 'M02') + return('T0' + self.SPACE() + 'M06' + self.SPACE() + 'M02') else: return('M02') def dwell(self, t): - self.write('\n') - iso_modal.Creator.dwell(self, t) + self.write('\n') + iso_modal.Creator.dwell(self, t) ############################################################################ -## Begin Program - +# Begin Program def program_begin(self, id, comment): if (self.useCrc == False): - self.write( ('(Created with emc2b post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) + self.write(('(Created with emc2b post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) else: - self.write( ('(Created with emc2b Cutter Radius Compensation post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) + self.write(('(Created with emc2b Cutter Radius Compensation post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) iso_modal.Creator.program_begin(self, id, comment) diff --git a/scripts/addons/cam/nc/emc2b_crc.py b/scripts/addons/cam/nc/emc2b_crc.py index 5a5d03784..96fbebc2e 100644 --- a/scripts/addons/cam/nc/emc2b_crc.py +++ b/scripts/addons/cam/nc/emc2b_crc.py @@ -10,6 +10,8 @@ import math ################################################################################ + + class Creator(emc2b.Creator): def __init__(self): @@ -18,4 +20,5 @@ def __init__(self): ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/emc2b_crc_read.py b/scripts/addons/cam/nc/emc2b_crc_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/emc2b_crc_read.py +++ b/scripts/addons/cam/nc/emc2b_crc_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/emc2b_read.py b/scripts/addons/cam/nc/emc2b_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/emc2b_read.py +++ b/scripts/addons/cam/nc/emc2b_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/emc2tap.py b/scripts/addons/cam/nc/emc2tap.py index dd675fe70..0c8a2f1b2 100644 --- a/scripts/addons/cam/nc/emc2tap.py +++ b/scripts/addons/cam/nc/emc2tap.py @@ -3,16 +3,15 @@ from . import emc2 - class CodesEMC2(iso_codes.Codes): def SPACE(self): return(' ') def TAP(self): return('G33.1') def TAP_DEPTH(self, format, depth): return(self.SPACE() + 'K' + (format % depth)) - # This version of COMMENT removes comments from the resultant GCode #def COMMENT(self,comment): return('') + iso_codes.codes = CodesEMC2() @@ -20,9 +19,9 @@ class CreatorEMC2tap(emc2.CreatorEMC2): def init(self): iso.CreatorEMC2.init(self) - # G33.1 tapping with EMC for now # unsynchronized (chuck) taps NIY (tap_mode = 1) + def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): # mystery parameters: # zretract=None, dwell_bottom=None,pitch=None, stoppos=None, spin_in=None, spin_out=None): @@ -32,11 +31,11 @@ def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, # This is a bad thing. All the drilling cycles need a retraction (and starting) height. return if (z == None): - return # We need a Z value as well. This input parameter represents the top of the hole + return # We need a Z value as well. This input parameter represents the top of the hole if (pitch == None): - return # We need a pitch value. + return # We need a pitch value. if (direction == None): - return # We need a direction value. + return # We need a direction value. if (tap_mode != 0): self.comment('only rigid tapping currently supported') @@ -54,32 +53,31 @@ def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, # unsure if this is needed: if self.z != retract_height: - self.rapid(z = retract_height) + self.rapid(z=retract_height) # then continue to x,y if given if (x != None) or (y != None): - self.write_blocknum() - self.write(iso_codes.codes.RAPID() ) + self.write_blocknum() + self.write(iso_codes.codes.RAPID()) - if (x != None): - self.write(iso_codes.codes.X() + (self.fmt % x)) - self.x = x + if (x != None): + self.write(iso_codes.codes.X() + (self.fmt % x)) + self.x = x - if (y != None): - self.write(iso_codes.codes.Y() + (self.fmt % y)) - self.y = y - self.write('\n') + if (y != None): + self.write(iso_codes.codes.Y() + (self.fmt % y)) + self.y = y + self.write('\n') self.write_blocknum() - self.write( iso_codes.codes.TAP() ) - self.write( iso_codes.codes.TAP_DEPTH(self.ffmt,pitch) + iso_codes.codes.SPACE() ) - self.write(iso_codes.codes.Z() + (self.fmt % (z - depth))) # This is the 'z' value for the bottom of the tap. + self.write(iso_codes.codes.TAP()) + self.write(iso_codes.codes.TAP_DEPTH(self.ffmt, pitch) + iso_codes.codes.SPACE()) + # This is the 'z' value for the bottom of the tap. + self.write(iso_codes.codes.Z() + (self.fmt % (z - depth))) self.write_misc() self.write('\n') self.z = retract_height # this cycle returns to the start position, so remember that as z value - nc.creator = CreatorEMC2tap() - diff --git a/scripts/addons/cam/nc/emc2tap_read.py b/scripts/addons/cam/nc/emc2tap_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/emc2tap_read.py +++ b/scripts/addons/cam/nc/emc2tap_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/fadal.py b/scripts/addons/cam/nc/fadal.py index 2dd8a9eb9..2fc4608cc 100644 --- a/scripts/addons/cam/nc/fadal.py +++ b/scripts/addons/cam/nc/fadal.py @@ -11,54 +11,58 @@ from . import iso from .format import Format + class Creator(iso.Creator): - def __init__(self): - iso.Creator.__init__(self) - - # internal variables - - self.fmt = Format(add_trailing_zeros = True) - - ############################################################################ - ## Codes - - def SPACE_STR(self): return ' ' - - ############################################################################ - ## Programs - - def program_begin(self, id, name=''): - if self.use_this_program_id: - id = self.use_this_program_id - if self.PROGRAM() != None: - self.write('%') - self.write('\n') - self.writem([(self.PROGRAM() % id), self.SPACE(), (self.COMMENT(name))]) - self.write('\n') - self.program_id = id - self.program_name = name - - def program_end(self): - if self.z_for_g53 != None: - self.write(self.SPACE() + self.MACHINE_COORDINATES() + self.SPACE() + 'Z' + self.fmt.string(self.z_for_g53) + '\n') - self.write(self.SPACE() + self.PROGRAM_END() + '\n') - self.write('%') - - if self.temp_file_to_append_on_close != None: - f_in = open(self.temp_file_to_append_on_close, 'r') - while (True): - line = f_in.readline() - if (len(line) == 0) : break - self.write(line) - f_in.close() - - self.file_close() - - if self.output_block_numbers: - # number every line of the file afterwards - self.number_file(self.filename) - - for f in self.subroutine_files: - self.number_file(f) + def __init__(self): + iso.Creator.__init__(self) + + # internal variables + + self.fmt = Format(add_trailing_zeros=True) + + ############################################################################ + # Codes + + def SPACE_STR(self): return ' ' + + ############################################################################ + # Programs + + def program_begin(self, id, name=''): + if self.use_this_program_id: + id = self.use_this_program_id + if self.PROGRAM() != None: + self.write('%') + self.write('\n') + self.writem([(self.PROGRAM() % id), self.SPACE(), (self.COMMENT(name))]) + self.write('\n') + self.program_id = id + self.program_name = name + + def program_end(self): + if self.z_for_g53 != None: + self.write(self.SPACE() + self.MACHINE_COORDINATES() + + self.SPACE() + 'Z' + self.fmt.string(self.z_for_g53) + '\n') + self.write(self.SPACE() + self.PROGRAM_END() + '\n') + self.write('%') + + if self.temp_file_to_append_on_close != None: + f_in = open(self.temp_file_to_append_on_close, 'r') + while (True): + line = f_in.readline() + if (len(line) == 0): + break + self.write(line) + f_in.close() + + self.file_close() + + if self.output_block_numbers: + # number every line of the file afterwards + self.number_file(self.filename) + + for f in self.subroutine_files: + self.number_file(f) + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/format.py b/scripts/addons/cam/nc/format.py index e93507f91..95d28bcee 100644 --- a/scripts/addons/cam/nc/format.py +++ b/scripts/addons/cam/nc/format.py @@ -1,10 +1,13 @@ import math + class Format: - def __init__(self, number_of_decimal_places = 3, add_leading_zeros = 1, add_trailing_zeros = False, dp_wanted = True, add_plus = False, no_minus = False, round_down = False): + def __init__(self, number_of_decimal_places=3, add_leading_zeros=1, add_trailing_zeros=False, dp_wanted=True, add_plus=False, no_minus=False, round_down=False): self.number_of_decimal_places = number_of_decimal_places - self.add_leading_zeros = add_leading_zeros # fill the start of the number with zeros, so there are at least this number of digits before the decimal point - self.add_trailing_zeros = add_trailing_zeros # fill the end of the number with zeros, as defined by "number_of_decimal_places" + # fill the start of the number with zeros, so there are at least this number of digits before the decimal point + self.add_leading_zeros = add_leading_zeros + # fill the end of the number with zeros, as defined by "number_of_decimal_places" + self.add_trailing_zeros = add_trailing_zeros self.dp_wanted = dp_wanted self.add_plus = add_plus self.no_minus = no_minus @@ -17,8 +20,10 @@ def string(self, number): s = format(f, 'f') if self.round_down == False: - if f < 0: f = f - .5 - else: f = f + .5 + if f < 0: + f = f - .5 + else: + f = f + .5 s = format(float(number), 'f') if math.fabs(f) < 1.0: @@ -52,13 +57,15 @@ def string(self, number): s += '+' s += before_dp if len(after_dp): - if self.dp_wanted: s += '.' + if self.dp_wanted: + s += '.' s += after_dp return s + class Address: - def __init__(self, text, fmt = Format(), modal = True): + def __init__(self, text, fmt=Format(), modal=True): self.text = text self.fmt = fmt self.modal = modal @@ -69,7 +76,8 @@ def set(self, number): self.str = self.text + self.fmt.string(number) def write(self, writer): - if self.str == None: return '' + if self.str == None: + return '' if self.modal: if self.str != self.previous: writer.write(writer.SPACE() + self.str) @@ -78,8 +86,9 @@ def write(self, writer): writer.write(writer.SPACE() + self.str) self.str = None + class AddressPlusMinus(Address): - def __init__(self, text, fmt = Format(), modal = True): + def __init__(self, text, fmt=Format(), modal=True): Address.__init__(self, text, fmt, modal) self.str2 = None self.previous2 = None @@ -93,7 +102,8 @@ def set(self, number, text_plus, text_minus): def write(self, writer): Address.write(self, writer) - if self.str2 == None: return '' + if self.str2 == None: + return '' if self.modal: if self.str2 != self.previous2: writer.write(writer.SPACE() + self.str2) diff --git a/scripts/addons/cam/nc/gantry_router.py b/scripts/addons/cam/nc/gantry_router.py index 80e5392db..86e1ac436 100644 --- a/scripts/addons/cam/nc/gantry_router.py +++ b/scripts/addons/cam/nc/gantry_router.py @@ -1,17 +1,19 @@ from . import nc from . import emc2 + class Creator(emc2.Creator): - def init(self): - emc2.Creator.init(self) + def init(self): + emc2.Creator.init(self) + + def program_begin(self, id, comment): + self.write(('(' + comment + ')' + '\n')) - def program_begin(self, id, comment): - self.write( ('(' + comment + ')' + '\n') ) + def tool_defn(self, id, name='', params=None): + pass - def tool_defn(self, id, name='', params=None): - pass + def spindle(self, s, clockwise): + pass - def spindle(self, s, clockwise): - pass nc.creator = Creator() diff --git a/scripts/addons/cam/nc/gantry_router_read.py b/scripts/addons/cam/nc/gantry_router_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/gantry_router_read.py +++ b/scripts/addons/cam/nc/gantry_router_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/gravos.py b/scripts/addons/cam/nc/gravos.py index 33a659f55..8dbf91f63 100644 --- a/scripts/addons/cam/nc/gravos.py +++ b/scripts/addons/cam/nc/gravos.py @@ -3,55 +3,55 @@ class Creator(iso.Creator): - def __init__(self): - iso.Creator.__init__(self) - - def SPACE_STR(self): return ' ' - def COMMENT(self, comment): return( (';%s' % comment ) ) - def PROGRAM(self): return(None) - - def program_begin(self, id, comment): - self.write( (';' + comment + '\n') ) - def TIME(self): return('X') - - def SPINDLE_OFF(self): return('M05') - # optimize - def RAPID(self): return('G0') - def FEED(self): return('G1') - - # def SPINDLE_DWELL(self,dwell): - # w='\n'+self.BLOCK() % self.n+ self.DWELL() % dwell - # return w - # - # def SPINDLE_CW(self,dwell): - # return('M03' + self.SPINDLE_DWELL(dwell) ) - # - # def SPINDLE_CCW(self,dwell): - # return('M04' + self.SPINDLE_DWELL(dwell)) - # - # def write_spindle(self): - # #self.write('\n') - # #self.write_blocknum() - # self.s.write(self) - - - def tool_change(self, id): - #print(self.SPACE()) - #print(self.TOOL()) - self.write(self.SPACE() + (self.TOOL() % id) + '\n') - #self.write('\n') - self.flush_nc() - self.t = id - - #def write_spindle(self): - # if self.s.str!=None: - # self.write(self.s.str) - # self.s.str = None - - def PROGRAM_END(self): return( 'M30') - - def program_end(self): - self.write(self.SPACE() + self.SPINDLE_OFF() + self.SPACE() + self.PROGRAM_END() + '\n') + def __init__(self): + iso.Creator.__init__(self) + + def SPACE_STR(self): return ' ' + def COMMENT(self, comment): return((';%s' % comment)) + def PROGRAM(self): return(None) + + def program_begin(self, id, comment): + self.write((';' + comment + '\n')) + + def TIME(self): return('X') + + def SPINDLE_OFF(self): return('M05') + # optimize + def RAPID(self): return('G0') + def FEED(self): return('G1') + + # def SPINDLE_DWELL(self,dwell): + # w='\n'+self.BLOCK() % self.n+ self.DWELL() % dwell + # return w + # + # def SPINDLE_CW(self,dwell): + # return('M03' + self.SPINDLE_DWELL(dwell) ) + # + # def SPINDLE_CCW(self,dwell): + # return('M04' + self.SPINDLE_DWELL(dwell)) + # + # def write_spindle(self): + # #self.write('\n') + # #self.write_blocknum() + # self.s.write(self) + + def tool_change(self, id): + # print(self.SPACE()) + # print(self.TOOL()) + self.write(self.SPACE() + (self.TOOL() % id) + '\n') + # self.write('\n') + self.flush_nc() + self.t = id + + # def write_spindle(self): + # if self.s.str!=None: + # self.write(self.s.str) + # self.s.str = None + + def PROGRAM_END(self): return('M30') + + def program_end(self): + self.write(self.SPACE() + self.SPINDLE_OFF() + self.SPACE() + self.PROGRAM_END() + '\n') nc.creator = Creator() diff --git a/scripts/addons/cam/nc/grbl.py b/scripts/addons/cam/nc/grbl.py index ff71bdd05..57d87c850 100644 --- a/scripts/addons/cam/nc/grbl.py +++ b/scripts/addons/cam/nc/grbl.py @@ -6,53 +6,57 @@ now = datetime.datetime.now() + class Creator(iso_modal.Creator): - def __init__(self): - iso_modal.Creator.__init__(self) - self.absolute_flag = True - self.prev_g91 = '' - self.useCrc = False - self.start_of_line = True - self.output_block_numbers = False - self.output_tool_definitions = False - - def PROGRAM_END(self): return ' ' - #optimize - def RAPID(self): return('G0') - def FEED(self): return('G1') + def __init__(self): + iso_modal.Creator.__init__(self) + self.absolute_flag = True + self.prev_g91 = '' + self.useCrc = False + self.start_of_line = True + self.output_block_numbers = False + self.output_tool_definitions = False + + def PROGRAM_END(self): return ' ' + # optimize + def RAPID(self): return('G0') + def FEED(self): return('G1') ############################################################################ -## Begin Program - - - def program_begin(self, id, comment): - if (self.useCrc == False): - self.write( ('(Created with grbl post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) - else: - self.write( ('(Created with grbl Cutter Radius Compensation post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) - +# Begin Program + def program_begin(self, id, comment): + if (self.useCrc == False): + self.write(('(Created with grbl post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) + else: + self.write(('(Created with grbl Cutter Radius Compensation post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) ############################################################################ -## Settings +# Settings - def tool_defn(self, id, name='', params=None): - pass + def tool_defn(self, id, name='', params=None): + pass - def tool_change(self, id): - pass + def tool_change(self, id): + pass # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 # These are selected by values from 1 to 9 inclusive. - def workplane(self, id): - if ((id >= 1) and (id <= 6)): - self.write_blocknum() - self.write( (self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\t (Select Relative Coordinate System)\n') - if ((id >= 7) and (id <= 9)): - self.write_blocknum() - self.write( ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\t (Select Relative Coordinate System)\n') + + + def workplane(self, id): + if ((id >= 1) and (id <= 6)): + self.write_blocknum() + self.write((self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + + '\t (Select Relative Coordinate System)\n') + if ((id >= 7) and (id <= 9)): + self.write_blocknum() + self.write(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % + (id - 6))) + '\t (Select Relative Coordinate System)\n') nc.creator = Creator() diff --git a/scripts/addons/cam/nc/heiden.py b/scripts/addons/cam/nc/heiden.py index bb9ff4a30..f75989f1a 100644 --- a/scripts/addons/cam/nc/heiden.py +++ b/scripts/addons/cam/nc/heiden.py @@ -1,1155 +1,1220 @@ # heiden.py, just copied from iso.py, to start with, but needs to be modified to make this sort of output -#1 BEGIN PGM 0011 MM -#2 BLK FORM 0.1 Z X-262.532 Y-262.55 Z-75.95 -#3 BLK FORM 0.2 X262.532 Y262.55 Z0.05 -#4 TOOL CALL 3 Z S3263 DL+0.0 DR+0.0 -#5 TOOL CALL 3 Z S3263 DL+0.0 DR+0.0 -#6 L X-80.644 Y-95.2 Z+100.0 R0 F237 M3 -#7 L Z-23.222 F333 -#8 L X-80.627 Y-95.208 Z-23.5 F326 -#49 L X-73.218 Y-88.104 Z-26.747 F229 -#50 L X-73.529 Y-87.795 Z-26.769 F227 -#51 L X-74.09 Y-87.326 Z-25.996 F279 -#52 M30 -#53 END PGM 0011 MM - - -from . import iso, nc,emc2 +# 1 BEGIN PGM 0011 MM +# 2 BLK FORM 0.1 Z X-262.532 Y-262.55 Z-75.95 +# 3 BLK FORM 0.2 X262.532 Y262.55 Z0.05 +# 4 TOOL CALL 3 Z S3263 DL+0.0 DR+0.0 +# 5 TOOL CALL 3 Z S3263 DL+0.0 DR+0.0 +# 6 L X-80.644 Y-95.2 Z+100.0 R0 F237 M3 +# 7 L Z-23.222 F333 +# 8 L X-80.627 Y-95.208 Z-23.5 F326 +# 49 L X-73.218 Y-88.104 Z-26.747 F229 +# 50 L X-73.529 Y-87.795 Z-26.769 F227 +# 51 L X-74.09 Y-87.326 Z-25.996 F279 +# 52 M30 +# 53 END PGM 0011 MM + + +from . import iso, nc, emc2 import math from .format import Format from .format import * ################################################################################ + + class Creator(nc.Creator): - def __init__(self): - nc.Creator.__init__(self) - - self.a = 0 - self.b = 0 - self.c = 0 - self.f = Address('F', fmt = Format(number_of_decimal_places = 2)) - self.fh = None - self.fv = None - self.fhv = False - self.g_plane = Address('G', fmt = Format(number_of_decimal_places = 0)) - self.g_list = [] - self.i = 0 - self.j = 0 - self.k = 0 - self.m = [] - self.n = 10 - self.r = 0 - self.s = AddressPlusMinus('S', fmt = Format(number_of_decimal_places = 2), modal = False) - self.t = None - self.x = 0 - self.y = 0 - self.z = 500 - self.g0123_modal = False - self.drill_modal = False - self.prev_f = '' - self.prev_g0123 = '' - self.prev_drill = '' - self.prev_retract = '' - self.prev_z = '' - self.useCrc = False - self.useCrcCenterline = False - self.gCRC = '' - self.fmt = Format() - self.absolute_flag = True - self.ffmt = Format(number_of_decimal_places = 2) - self.sfmt = Format(number_of_decimal_places = 1) - self.arc_centre_absolute = False - self.arc_centre_positive = False - self.in_quadrant_splitting = False - self.drillExpanded = False - self.can_do_helical_arcs = True - self.shift_x = 0.0 - self.shift_y = 0.0 - self.shift_z = 0.0 - ############################################################################ - ## Codes - - def SPACE(self): return('') - def FORMAT_FEEDRATE(self): return('%.2f') - def FEEDRATE(self): return((self.SPACE() + 'F')) - def FORMAT_ANG(self): return('%.1f') - def FORMAT_TIME(self): return('%.2f') - def FORMAT_DWELL(self): return('P%f') - - def BLOCK(self): return('%i') - def COMMENT(self,comment): return( ('(%s)' % comment ) ) - def VARIABLE(self): return( '#%i') - def VARIABLE_SET(self): return( '=%.3f') - - def SUBPROG_CALL(self): return( 'M98' + self.SPACE() + 'P%i') - def SUBPROG_END(self): return( 'M99') - - def STOP_OPTIONAL(self): return('M01') - def STOP(self): return('M00') - - def IMPERIAL(self): return('G20') - def METRIC(self): return('G21') - def ABSOLUTE(self): return('G90') - def INCREMENTAL(self): return('G91') - def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92') - def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1') - def POLAR_ON(self): return('G16') - def POLAR_OFF(self): return('G15') - def PLANE_XY(self): return('17') - def PLANE_XZ(self): return('18') - def PLANE_YZ(self): return('19') - - def TOOL(self): return('T%i' + self.SPACE() + 'M06') - def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1') - - def WORKPLANE(self): return('G%i') - def WORKPLANE_BASE(self): return(53) - - def SPINDLE_CW(self): return('M03') - def SPINDLE_CCW(self): return('M04') - def COOLANT_OFF(self): return('M09') - def COOLANT_MIST(self): return('M07') - def COOLANT_FLOOD(self): return('M08') - def GEAR_OFF(self): return('?') - def GEAR(self): return('M%i') - def GEAR_BASE(self): return(37) - - def RAPID(self): return('G00') - def FEED(self): return('G01') - def ARC_CW(self): return('G02') - def ARC_CCW(self): return('G03') - def DWELL(self): return('G04') - def DRILL(self): return('G81') - def DRILL_WITH_DWELL(self, format, dwell): return('G82' + self.SPACE() + (format.string(dwell))) - def PECK_DRILL(self): return('G83') - def PECK_DEPTH(self, format, depth): return(self.SPACE() + 'Q' + (format.string(depth))) - def RETRACT(self, format, height): return(self.SPACE() + 'R' + (format.string(height))) - def END_CANNED_CYCLE(self): return('G80') - def TAP(self): return('G84') - def TAP_DEPTH(self, format, depth): return(self.SPACE() + 'K' + (format.string(depth))) - - def X(self): return('X') - def Y(self): return('Y') - def Z(self): return('Z') - def A(self): return('A') - def B(self): return('B') - def C(self): return('C') - def CENTRE_X(self): return('I') - def CENTRE_Y(self): return('J') - def CENTRE_Z(self): return('K') - def RADIUS(self): return('R') - def TIME(self): return('P') - - def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2') - def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3') - def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4') - def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5') - - def MACHINE_COORDINATES(self): return('G53') - - def EXACT_PATH_MODE(self): return('G61') - def EXACT_STOP_MODE(self): return('G61.1') - - ############################################################################ - ## Internals - - def write_feedrate(self): - self.f.write(self) - - def write_preps(self): - self.g_plane.write(self) - for g in self.g_list: - self.write(self.SPACE() + g) - self.g_list = [] - - def write_misc(self): - if (len(self.m)) : self.write(self.m.pop()) - - def write_blocknum(self): - self.write(self.BLOCK() % self.n) - self.n += 1 - - def write_spindle(self): - self.s.write(self) - - ############################################################################ - ## Programs - - def program_begin(self, id, name=''): - #1 BEGIN PGM 0011 MM - self.write_blocknum() - self.program_id = id - self.write(self.SPACE() + ('BEGIN PGM %i MM' % id)) - self.write('\n') - - def program_stop(self, optional=False): - self.write_blocknum() - if (optional) : - self.write(self.SPACE() + self.STOP_OPTIONAL() + '\n') - self.prev_g0123 = '' - else : - self.write(self.STOP() + '\n') - self.prev_g0123 = '' - - - def program_end(self): - self.write_blocknum() - self.write(self.SPACE() + ('END PGM %i MM' % self.program_id) + '\n') - - def flush_nc(self): - if len(self.g_list) == 0 and len(self.m) == 0: return - self.write_blocknum() - self.write_preps() - self.write_misc() - self.write('\n') - - ############################################################################ - ## Subprograms - - def sub_begin(self, id, name=''): - self.write((self.PROGRAM() % id) + self.SPACE() + (self.COMMENT(name))) - self.write('\n') - - def sub_call(self, id): - self.write_blocknum() - self.write(self.SPACE() + (self.SUBPROG_CALL() % id) + '\n') - - def sub_end(self): - self.write_blocknum() - self.write(self.SPACE() + self.SUBPROG_END() + '\n') - - ############################################################################ - ## Settings - - def imperial(self): - self.g_list.append(self.IMPERIAL()) - self.fmt.number_of_decimal_places = 4 - - def metric(self): - self.g_list.append(self.METRIC()) - self.fmt.number_of_decimal_places = 3 - - def absolute(self): - self.g_list.append(self.ABSOLUTE()) - self.absolute_flag = True - - def incremental(self): - self.g_list.append(self.INCREMENTAL()) - self.absolute_flag = False - - def polar(self, on=True): - if (on) : self.g_list.append(self.POLAR_ON()) - else : self.g_list.append(self.POLAR_OFF()) - - def set_plane(self, plane): - if (plane == 0) : self.g_plane.set(self.PLANE_XY()) - elif (plane == 1) : self.g_plane.set(self.PLANE_XZ()) - elif (plane == 2) : self.g_plane.set(self.PLANE_YZ()) - - def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): - self.write_blocknum() - self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM())) - if (x != None): self.write( self.SPACE() + 'X ' + (self.fmt.string(x + self.shift_x)) ) - if (y != None): self.write( self.SPACE() + 'Y ' + (self.fmt.string(y + self.shift_y)) ) - if (z != None): self.write( self.SPACE() + 'Z ' + (self.fmt.string(z + self.shift_z)) ) - if (a != None): self.write( self.SPACE() + 'A ' + (self.fmt.string(a)) ) - if (b != None): self.write( self.SPACE() + 'B ' + (self.fmt.string(b)) ) - if (c != None): self.write( self.SPACE() + 'C ' + (self.fmt.string(c)) ) - self.write('\n') - - def remove_temporary_origin(self): - self.write_blocknum() - self.write(self.SPACE() + (self.REMOVE_TEMPORARY_COORDINATE_SYSTEM())) - self.write('\n') - ############################################################################ - ## new graphics origin- make a new coordinate system and snap it onto the geometry - ## the toolpath generated should be translated - def translate(self,x=None, y=None, z=None): - self.shift_x = -x - self.shift_y = -y - self.shift_z = -z - - ############################################################################ - ## Tools - - def tool_change(self, id): - self.write_blocknum() - self.write(self.SPACE() + (self.TOOL() % id) + '\n') - self.t = id - - def tool_defn(self, id, name='', params=None): - self.write_blocknum() - self.write(self.SPACE() + self.TOOL_DEFINITION()) - self.write(self.SPACE() + ('P%i' % id) + ' ') - - if (radius != None): - self.write(self.SPACE() + ('R%.3f' % (float(params['diameter'])/2))) - - if (length != None): - self.write(self.SPACE() + 'Z%.3f' % float(params['cutting edge height'])) - - self.write('\n') - - def offset_radius(self, id, radius=None): - pass - - def offset_length(self, id, length=None): - pass - - def current_tool(self): - return self.t - - ############################################################################ - ## Datums - - def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 - # These are selected by values from 1 to 9 inclusive. - def workplane(self, id): - if ((id >= 1) and (id <= 6)): - self.g_list.append(self.WORKPLANE() % (id + self.WORKPLANE_BASE())) - if ((id >= 7) and (id <= 9)): - self.g_list.append(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) - - - ############################################################################ - ## Rates + Modes - - def feedrate(self, f): - self.f.set(f) - self.fhv = False - - def feedrate_hv(self, fh, fv): - self.fh = fh - self.fv = fv - self.fhv = True - - def calc_feedrate_hv(self, h, v): - if math.fabs(v) > math.fabs(h * 2): - # some horizontal, so it should be fine to use the horizontal feed rate - self.f.set(self.fv) - else: - # not much, if any horizontal component, so use the vertical feed rate - self.f.set(self.fh) - - def spindle(self, s, clockwise): - if clockwise == True: - self.s.set(s, self.SPACE() + self.SPINDLE_CW(), self.SPACE() + self.SPINDLE_CCW()) - else: - self.s.set(s, self.SPACE() + self.SPINDLE_CCW(), self.SPACE() + self.SPINDLE_CW()) - - def coolant(self, mode=0): - if (mode <= 0) : self.m.append(self.SPACE() + self.COOLANT_OFF()) - elif (mode == 1) : self.m.append(self.SPACE() + self.COOLANT_MIST()) - elif (mode == 2) : self.m.append(self.SPACE() + self.COOLANT_FLOOD()) - - def gearrange(self, gear=0): - if (gear <= 0) : self.m.append(self.SPACE() + self.GEAR_OFF()) - elif (gear <= 4) : self.m.append(self.SPACE() + self.GEAR() % (gear + GEAR_BASE())) - - ############################################################################ - ## Moves - - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): - self.write_blocknum() - - if self.g0123_modal: - if self.prev_g0123 != self.RAPID(): - self.write(self.SPACE() + self.RAPID()) - self.prev_g0123 = self.RAPID() - else: - self.write(self.SPACE() + self.RAPID()) - self.write_preps() - if (x != None): - dx = x - self.x - if (self.absolute_flag ): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - else: - self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) - self.x = x - if (y != None): - dy = y - self.y - if (self.absolute_flag ): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - else: - self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) - - self.y = y - if (z != None): - dz = z - self.z - if (self.absolute_flag ): - self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) - - self.z = z - - if (a != None): - da = a - self.a - if (self.absolute_flag ): - self.write(self.SPACE() + self.A() + (self.fmt.string(a))) - else: - self.write(self.SPACE() + self.A() + (self.fmt.string(da))) - self.a = a - - if (b != None): - db = b - self.b - if (self.absolute_flag ): - self.write(self.SPACE() + self.B() + (self.fmt.string(b))) - else: - self.write(self.SPACE() + self.B() + (self.fmt.string(db))) - self.b = b - - if (c != None): - dc = c - self.c - if (self.absolute_flag ): - self.write(self.SPACE() + self.C() + (self.fmt.string(c))) - else: - self.write(self.SPACE() + self.C() + (self.fmt.string(dc))) - self.c = c - self.write_spindle() - self.write_misc() - self.write('\n') - - def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - if self.same_xyz(x, y, z): return - self.write_blocknum() - if self.g0123_modal: - if self.prev_g0123 != self.FEED(): - self.write(self.SPACE() + self.FEED()) - self.prev_g0123 = self.FEED() - else: - self.write(self.FEED()) - self.write_preps() - dx = dy = dz = 0 - if (x != None): - dx = x - self.x - if (self.absolute_flag ): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - else: - self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) - self.x = x - if (y != None): - dy = y - self.y - if (self.absolute_flag ): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - else: - self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) - - self.y = y - if (z != None): - dz = z - self.z - if (self.absolute_flag ): - self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) - - self.z = z - if (self.fhv) : self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - - def same_xyz(self, x=None, y=None, z=None): - if (x != None): - if (self.fmt.string(x + self.shift_x)) != (self.fmt.string(self.x)): - return False - if (y != None): - if (self.fmt.string(y + self.shift_y)) != (self.fmt.string(self.y)): - return False - if (z != None): - if (self.fmt.string(z + self.shift_z)) != (self.fmt.string(self.z)): - return False - - return True - - - def get_quadrant(self, dx, dy): - if dx < 0: - if dy < 0: - return 2 - else: - return 1 - - else: - if dy < 0: - return 3 - else: - return 0 - - def quadrant_start(self, q, i, j, rad): - while q > 3: q = q - 4 - if q == 0: - return i + rad, j - if q == 1: - return i, j + rad - if q == 2: - return i - rad, j - return i, j - rad - - def quadrant_end(self, q, i, j, rad): - return self.quadrant_start(q + 1, i, j, rad) - - def get_arc_angle(self, sdx, sdy, edx, edy, cw): - angle_s = math.atan2(sdy, sdx); - angle_e = math.atan2(edy, edx); - if cw: - if angle_s < angle_e: angle_s = angle_s + 2 * math.pi - else: - if angle_e < angle_s: angle_e = angle_e + 2 * math.pi - return angle_e - angle_s - - def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - if self.can_do_helical_arcs == False and self.in_quadrant_splitting == False and (z != None) and (math.fabs(z - self.z) > 0.000001) and (self.fmt.string(z) != self.fmt.string(self.z)): - # split the helical arc into little line feed moves - if x == None: x = self.x - if y == None: y = self.y - sdx = self.x - i - sdy = self.y - j - edx = x - i - edy = y - j - radius = math.sqrt(sdx*sdx + sdy*sdy) - arc_angle = self.get_arc_angle(sdx, sdy, edx, edy, cw) - angle_start = math.atan2(sdy, sdx); - tolerance = 0.02 - angle_step = 2.0 * math.atan( math.sqrt ( tolerance /(radius - tolerance) )) - segments = int(math.fabs(arc_angle / angle_step) + 1) - angle_step = arc_angle / segments - angle = angle_start - z_step = float(z - self.z)/segments - next_z = self.z - for p in range(0, segments): - angle = angle + angle_step - next_x = i + radius * math.cos(angle) - next_y = j + radius * math.sin(angle) - next_z = next_z + z_step - self.feed(next_x, next_y, next_z) - return - - if self.arc_centre_positive == True and self.in_quadrant_splitting == False: - # split in to quadrant arcs - self.in_quadrant_splitting = True - - if x == None: x = self.x - if y == None: y = self.y - sdx = self.x - i - sdy = self.y - j - edx = x - i - edy = y - j - - qs = self.get_quadrant(sdx, sdy) - qe = self.get_quadrant(edx, edy) - - if qs == qe: - arc_angle = math.fabs(self.get_arc_angle(sdx, sdy, edx, edy, cw)) - # arc_angle will be either less than pi/2 or greater than 3pi/2 - if arc_angle > 3.14: - if cw: - qs = qs + 4 - else: - qe = qe + 4 - - if qs == qe: - self.arc(cw, x, y, z, i, j, k, r) - else: - rad = math.sqrt(sdx * sdx + sdy * sdy) - if cw: - if qs < qe: qs = qs + 4 - else: - if qe < qs: qe = qe + 4 - - q = qs - while 1: - x1 = x - y1 = y - if q != qe: - if cw: - x1, y1 = self.quadrant_start(q, i, j, rad) - else: - x1, y1 = self.quadrant_end(q, i, j, rad) - - if ((math.fabs(x1 - self.x) > 0.000001) or (math.fabs(y1 - self.y) > 0.000001)) and ((self.fmt.string(x1) != self.fmt.string(self.x)) or (self.fmt.string(y1) != self.fmt.string(self.y))): - self.arc(cw, x1, y1, z, i, j, k, r) - if q == qe: - break - if cw: - q = q - 1 - else: - q = q + 1 - - self.in_quadrant_splitting = False - return - - #if self.same_xyz(x, y, z): return - self.write_blocknum() - arc_g_code = '' - if cw: arc_g_code = self.ARC_CW() - else: arc_g_code = self.ARC_CCW() - if self.g0123_modal: - if self.prev_g0123 != arc_g_code: - self.write(arc_g_code) - self.prev_g0123 = arc_g_code - else: - self.write(arc_g_code) - self.write_preps() - if (x != None): - dx = x - self.x - if (self.absolute_flag ): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - else: - self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) - if (y != None): - dy = y - self.y - if (self.absolute_flag ): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - else: - self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) - if (z != None): - dz = z - self.z - if (self.absolute_flag ): - self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) - if (i != None): - if self.arc_centre_absolute == False: - i = i - self.x - s = self.fmt.string(i) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_X() + s) - if (j != None): - if self.arc_centre_absolute == False: - j = j - self.y - s = self.fmt.string(j) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_Y() + s) - if (k != None): - if self.arc_centre_absolute == False: - k = k - self.z - s = self.fmt.string(k) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_Z() + s) - if (r != None): - s = self.fmt.string(r) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.RADIUS() + s) + def __init__(self): + nc.Creator.__init__(self) + + self.a = 0 + self.b = 0 + self.c = 0 + self.f = Address('F', fmt=Format(number_of_decimal_places=2)) + self.fh = None + self.fv = None + self.fhv = False + self.g_plane = Address('G', fmt=Format(number_of_decimal_places=0)) + self.g_list = [] + self.i = 0 + self.j = 0 + self.k = 0 + self.m = [] + self.n = 10 + self.r = 0 + self.s = AddressPlusMinus('S', fmt=Format(number_of_decimal_places=2), modal=False) + self.t = None + self.x = 0 + self.y = 0 + self.z = 500 + self.g0123_modal = False + self.drill_modal = False + self.prev_f = '' + self.prev_g0123 = '' + self.prev_drill = '' + self.prev_retract = '' + self.prev_z = '' + self.useCrc = False + self.useCrcCenterline = False + self.gCRC = '' + self.fmt = Format() + self.absolute_flag = True + self.ffmt = Format(number_of_decimal_places=2) + self.sfmt = Format(number_of_decimal_places=1) + self.arc_centre_absolute = False + self.arc_centre_positive = False + self.in_quadrant_splitting = False + self.drillExpanded = False + self.can_do_helical_arcs = True + self.shift_x = 0.0 + self.shift_y = 0.0 + self.shift_z = 0.0 + ############################################################################ + # Codes + + def SPACE(self): return('') + def FORMAT_FEEDRATE(self): return('%.2f') + def FEEDRATE(self): return((self.SPACE() + 'F')) + def FORMAT_ANG(self): return('%.1f') + def FORMAT_TIME(self): return('%.2f') + def FORMAT_DWELL(self): return('P%f') + + def BLOCK(self): return('%i') + def COMMENT(self, comment): return(('(%s)' % comment)) + def VARIABLE(self): return('#%i') + def VARIABLE_SET(self): return('=%.3f') + + def SUBPROG_CALL(self): return('M98' + self.SPACE() + 'P%i') + def SUBPROG_END(self): return('M99') + + def STOP_OPTIONAL(self): return('M01') + def STOP(self): return('M00') + + def IMPERIAL(self): return('G20') + def METRIC(self): return('G21') + def ABSOLUTE(self): return('G90') + def INCREMENTAL(self): return('G91') + def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92') + def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1') + def POLAR_ON(self): return('G16') + def POLAR_OFF(self): return('G15') + def PLANE_XY(self): return('17') + def PLANE_XZ(self): return('18') + def PLANE_YZ(self): return('19') + + def TOOL(self): return('T%i' + self.SPACE() + 'M06') + def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1') + + def WORKPLANE(self): return('G%i') + def WORKPLANE_BASE(self): return(53) + + def SPINDLE_CW(self): return('M03') + def SPINDLE_CCW(self): return('M04') + def COOLANT_OFF(self): return('M09') + def COOLANT_MIST(self): return('M07') + def COOLANT_FLOOD(self): return('M08') + def GEAR_OFF(self): return('?') + def GEAR(self): return('M%i') + def GEAR_BASE(self): return(37) + + def RAPID(self): return('G00') + def FEED(self): return('G01') + def ARC_CW(self): return('G02') + def ARC_CCW(self): return('G03') + def DWELL(self): return('G04') + def DRILL(self): return('G81') + def DRILL_WITH_DWELL(self, format, dwell): return('G82' + self.SPACE() + (format.string(dwell))) + def PECK_DRILL(self): return('G83') + def PECK_DEPTH(self, format, depth): return(self.SPACE() + 'Q' + (format.string(depth))) + def RETRACT(self, format, height): return(self.SPACE() + 'R' + (format.string(height))) + def END_CANNED_CYCLE(self): return('G80') + def TAP(self): return('G84') + def TAP_DEPTH(self, format, depth): return(self.SPACE() + 'K' + (format.string(depth))) + + def X(self): return('X') + def Y(self): return('Y') + def Z(self): return('Z') + def A(self): return('A') + def B(self): return('B') + def C(self): return('C') + def CENTRE_X(self): return('I') + def CENTRE_Y(self): return('J') + def CENTRE_Z(self): return('K') + def RADIUS(self): return('R') + def TIME(self): return('P') + + def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2') + def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3') + def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4') + def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5') + + def MACHINE_COORDINATES(self): return('G53') + + def EXACT_PATH_MODE(self): return('G61') + def EXACT_STOP_MODE(self): return('G61.1') + + ############################################################################ + # Internals + + def write_feedrate(self): + self.f.write(self) + + def write_preps(self): + self.g_plane.write(self) + for g in self.g_list: + self.write(self.SPACE() + g) + self.g_list = [] + + def write_misc(self): + if (len(self.m)): + self.write(self.m.pop()) + + def write_blocknum(self): + self.write(self.BLOCK() % self.n) + self.n += 1 + + def write_spindle(self): + self.s.write(self) + + ############################################################################ + # Programs + + def program_begin(self, id, name=''): + # 1 BEGIN PGM 0011 MM + self.write_blocknum() + self.program_id = id + self.write(self.SPACE() + ('BEGIN PGM %i MM' % id)) + self.write('\n') + + def program_stop(self, optional=False): + self.write_blocknum() + if (optional): + self.write(self.SPACE() + self.STOP_OPTIONAL() + '\n') + self.prev_g0123 = '' + else: + self.write(self.STOP() + '\n') + self.prev_g0123 = '' + + def program_end(self): + self.write_blocknum() + self.write(self.SPACE() + ('END PGM %i MM' % self.program_id) + '\n') + + def flush_nc(self): + if len(self.g_list) == 0 and len(self.m) == 0: + return + self.write_blocknum() + self.write_preps() + self.write_misc() + self.write('\n') + + ############################################################################ + # Subprograms + + def sub_begin(self, id, name=''): + self.write((self.PROGRAM() % id) + self.SPACE() + (self.COMMENT(name))) + self.write('\n') + + def sub_call(self, id): + self.write_blocknum() + self.write(self.SPACE() + (self.SUBPROG_CALL() % id) + '\n') + + def sub_end(self): + self.write_blocknum() + self.write(self.SPACE() + self.SUBPROG_END() + '\n') + + ############################################################################ + # Settings + + def imperial(self): + self.g_list.append(self.IMPERIAL()) + self.fmt.number_of_decimal_places = 4 + + def metric(self): + self.g_list.append(self.METRIC()) + self.fmt.number_of_decimal_places = 3 + + def absolute(self): + self.g_list.append(self.ABSOLUTE()) + self.absolute_flag = True + + def incremental(self): + self.g_list.append(self.INCREMENTAL()) + self.absolute_flag = False + + def polar(self, on=True): + if (on): + self.g_list.append(self.POLAR_ON()) + else: + self.g_list.append(self.POLAR_OFF()) + + def set_plane(self, plane): + if (plane == 0): + self.g_plane.set(self.PLANE_XY()) + elif (plane == 1): + self.g_plane.set(self.PLANE_XZ()) + elif (plane == 2): + self.g_plane.set(self.PLANE_YZ()) + + def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): + self.write_blocknum() + self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM())) + if (x != None): + self.write(self.SPACE() + 'X ' + (self.fmt.string(x + self.shift_x))) + if (y != None): + self.write(self.SPACE() + 'Y ' + (self.fmt.string(y + self.shift_y))) + if (z != None): + self.write(self.SPACE() + 'Z ' + (self.fmt.string(z + self.shift_z))) + if (a != None): + self.write(self.SPACE() + 'A ' + (self.fmt.string(a))) + if (b != None): + self.write(self.SPACE() + 'B ' + (self.fmt.string(b))) + if (c != None): + self.write(self.SPACE() + 'C ' + (self.fmt.string(c))) + self.write('\n') + + def remove_temporary_origin(self): + self.write_blocknum() + self.write(self.SPACE() + (self.REMOVE_TEMPORARY_COORDINATE_SYSTEM())) + self.write('\n') + ############################################################################ + # new graphics origin- make a new coordinate system and snap it onto the geometry + # the toolpath generated should be translated + + def translate(self, x=None, y=None, z=None): + self.shift_x = -x + self.shift_y = -y + self.shift_z = -z + + ############################################################################ + # Tools + + def tool_change(self, id): + self.write_blocknum() + self.write(self.SPACE() + (self.TOOL() % id) + '\n') + self.t = id + + def tool_defn(self, id, name='', params=None): + self.write_blocknum() + self.write(self.SPACE() + self.TOOL_DEFINITION()) + self.write(self.SPACE() + ('P%i' % id) + ' ') + + if (radius != None): + self.write(self.SPACE() + ('R%.3f' % (float(params['diameter'])/2))) + + if (length != None): + self.write(self.SPACE() + 'Z%.3f' % float(params['cutting edge height'])) + + self.write('\n') + + def offset_radius(self, id, radius=None): + pass + + def offset_length(self, id, length=None): + pass + + def current_tool(self): + return self.t + + ############################################################################ + # Datums + + def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 + # These are selected by values from 1 to 9 inclusive. + def workplane(self, id): + if ((id >= 1) and (id <= 6)): + self.g_list.append(self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + if ((id >= 7) and (id <= 9)): + self.g_list.append( + ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) + + ############################################################################ + ## Rates + Modes + + def feedrate(self, f): + self.f.set(f) + self.fhv = False + + def feedrate_hv(self, fh, fv): + self.fh = fh + self.fv = fv + self.fhv = True + + def calc_feedrate_hv(self, h, v): + if math.fabs(v) > math.fabs(h * 2): + # some horizontal, so it should be fine to use the horizontal feed rate + self.f.set(self.fv) + else: + # not much, if any horizontal component, so use the vertical feed rate + self.f.set(self.fh) + + def spindle(self, s, clockwise): + if clockwise == True: + self.s.set(s, self.SPACE() + self.SPINDLE_CW(), self.SPACE() + self.SPINDLE_CCW()) + else: + self.s.set(s, self.SPACE() + self.SPINDLE_CCW(), self.SPACE() + self.SPINDLE_CW()) + + def coolant(self, mode=0): + if (mode <= 0): + self.m.append(self.SPACE() + self.COOLANT_OFF()) + elif (mode == 1): + self.m.append(self.SPACE() + self.COOLANT_MIST()) + elif (mode == 2): + self.m.append(self.SPACE() + self.COOLANT_FLOOD()) + + def gearrange(self, gear=0): + if (gear <= 0): + self.m.append(self.SPACE() + self.GEAR_OFF()) + elif (gear <= 4): + self.m.append(self.SPACE() + self.GEAR() % (gear + GEAR_BASE())) + + ############################################################################ + # Moves + + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): + self.write_blocknum() + + if self.g0123_modal: + if self.prev_g0123 != self.RAPID(): + self.write(self.SPACE() + self.RAPID()) + self.prev_g0123 = self.RAPID() + else: + self.write(self.SPACE() + self.RAPID()) + self.write_preps() + if (x != None): + dx = x - self.x + if (self.absolute_flag): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + else: + self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) + self.x = x + if (y != None): + dy = y - self.y + if (self.absolute_flag): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + else: + self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) + + self.y = y + if (z != None): + dz = z - self.z + if (self.absolute_flag): + self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) + else: + self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) + + self.z = z + + if (a != None): + da = a - self.a + if (self.absolute_flag): + self.write(self.SPACE() + self.A() + (self.fmt.string(a))) + else: + self.write(self.SPACE() + self.A() + (self.fmt.string(da))) + self.a = a + + if (b != None): + db = b - self.b + if (self.absolute_flag): + self.write(self.SPACE() + self.B() + (self.fmt.string(b))) + else: + self.write(self.SPACE() + self.B() + (self.fmt.string(db))) + self.b = b + + if (c != None): + dc = c - self.c + if (self.absolute_flag): + self.write(self.SPACE() + self.C() + (self.fmt.string(c))) + else: + self.write(self.SPACE() + self.C() + (self.fmt.string(dc))) + self.c = c + self.write_spindle() + self.write_misc() + self.write('\n') + + def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): + if self.same_xyz(x, y, z): + return + self.write_blocknum() + if self.g0123_modal: + if self.prev_g0123 != self.FEED(): + self.write(self.SPACE() + self.FEED()) + self.prev_g0123 = self.FEED() + else: + self.write(self.FEED()) + self.write_preps() + dx = dy = dz = 0 + if (x != None): + dx = x - self.x + if (self.absolute_flag): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + else: + self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) + self.x = x + if (y != None): + dy = y - self.y + if (self.absolute_flag): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + else: + self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) + + self.y = y + if (z != None): + dz = z - self.z + if (self.absolute_flag): + self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) + else: + self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) + + self.z = z + if (self.fhv): + self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + + def same_xyz(self, x=None, y=None, z=None): + if (x != None): + if (self.fmt.string(x + self.shift_x)) != (self.fmt.string(self.x)): + return False + if (y != None): + if (self.fmt.string(y + self.shift_y)) != (self.fmt.string(self.y)): + return False + if (z != None): + if (self.fmt.string(z + self.shift_z)) != (self.fmt.string(self.z)): + return False + + return True + + def get_quadrant(self, dx, dy): + if dx < 0: + if dy < 0: + return 2 + else: + return 1 + + else: + if dy < 0: + return 3 + else: + return 0 + + def quadrant_start(self, q, i, j, rad): + while q > 3: + q = q - 4 + if q == 0: + return i + rad, j + if q == 1: + return i, j + rad + if q == 2: + return i - rad, j + return i, j - rad + + def quadrant_end(self, q, i, j, rad): + return self.quadrant_start(q + 1, i, j, rad) + + def get_arc_angle(self, sdx, sdy, edx, edy, cw): + angle_s = math.atan2(sdy, sdx) + angle_e = math.atan2(edy, edx) + if cw: + if angle_s < angle_e: + angle_s = angle_s + 2 * math.pi + else: + if angle_e < angle_s: + angle_e = angle_e + 2 * math.pi + return angle_e - angle_s + + def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + if self.can_do_helical_arcs == False and self.in_quadrant_splitting == False and (z != None) and (math.fabs(z - self.z) > 0.000001) and (self.fmt.string(z) != self.fmt.string(self.z)): + # split the helical arc into little line feed moves + if x == None: + x = self.x + if y == None: + y = self.y + sdx = self.x - i + sdy = self.y - j + edx = x - i + edy = y - j + radius = math.sqrt(sdx*sdx + sdy*sdy) + arc_angle = self.get_arc_angle(sdx, sdy, edx, edy, cw) + angle_start = math.atan2(sdy, sdx) + tolerance = 0.02 + angle_step = 2.0 * math.atan(math.sqrt(tolerance / (radius - tolerance))) + segments = int(math.fabs(arc_angle / angle_step) + 1) + angle_step = arc_angle / segments + angle = angle_start + z_step = float(z - self.z)/segments + next_z = self.z + for p in range(0, segments): + angle = angle + angle_step + next_x = i + radius * math.cos(angle) + next_y = j + radius * math.sin(angle) + next_z = next_z + z_step + self.feed(next_x, next_y, next_z) + return + + if self.arc_centre_positive == True and self.in_quadrant_splitting == False: + # split in to quadrant arcs + self.in_quadrant_splitting = True + + if x == None: + x = self.x + if y == None: + y = self.y + sdx = self.x - i + sdy = self.y - j + edx = x - i + edy = y - j + + qs = self.get_quadrant(sdx, sdy) + qe = self.get_quadrant(edx, edy) + + if qs == qe: + arc_angle = math.fabs(self.get_arc_angle(sdx, sdy, edx, edy, cw)) + # arc_angle will be either less than pi/2 or greater than 3pi/2 + if arc_angle > 3.14: + if cw: + qs = qs + 4 + else: + qe = qe + 4 + + if qs == qe: + self.arc(cw, x, y, z, i, j, k, r) + else: + rad = math.sqrt(sdx * sdx + sdy * sdy) + if cw: + if qs < qe: + qs = qs + 4 + else: + if qe < qs: + qe = qe + 4 + + q = qs + while 1: + x1 = x + y1 = y + if q != qe: + if cw: + x1, y1 = self.quadrant_start(q, i, j, rad) + else: + x1, y1 = self.quadrant_end(q, i, j, rad) + + if ((math.fabs(x1 - self.x) > 0.000001) or (math.fabs(y1 - self.y) > 0.000001)) and ((self.fmt.string(x1) != self.fmt.string(self.x)) or (self.fmt.string(y1) != self.fmt.string(self.y))): + self.arc(cw, x1, y1, z, i, j, k, r) + if q == qe: + break + if cw: + q = q - 1 + else: + q = q + 1 + + self.in_quadrant_splitting = False + return + + # if self.same_xyz(x, y, z): return + self.write_blocknum() + arc_g_code = '' + if cw: + arc_g_code = self.ARC_CW() + else: + arc_g_code = self.ARC_CCW() + if self.g0123_modal: + if self.prev_g0123 != arc_g_code: + self.write(arc_g_code) + self.prev_g0123 = arc_g_code + else: + self.write(arc_g_code) + self.write_preps() + if (x != None): + dx = x - self.x + if (self.absolute_flag): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + else: + self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) + if (y != None): + dy = y - self.y + if (self.absolute_flag): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + else: + self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) + if (z != None): + dz = z - self.z + if (self.absolute_flag): + self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) + else: + self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) + if (i != None): + if self.arc_centre_absolute == False: + i = i - self.x + s = self.fmt.string(i) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_X() + s) + if (j != None): + if self.arc_centre_absolute == False: + j = j - self.y + s = self.fmt.string(j) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_Y() + s) + if (k != None): + if self.arc_centre_absolute == False: + k = k - self.z + s = self.fmt.string(k) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_Z() + s) + if (r != None): + s = self.fmt.string(r) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.RADIUS() + s) # use horizontal feed rate - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - if (x != None): - self.x = x - if (y != None): - self.y = y - if (z != None): - self.z = z - - def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - self.arc(True, x, y, z, i, j, k, r) - - def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - self.arc(False, x, y, z, i, j, k, r) - - def dwell(self, t): - self.write_blocknum() - self.write_preps() - self.write(self.FORMAT_DWELL() % t) - self.write_misc() - self.write('\n') - - def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - def rapid_unhome(self): - pass - - def set_machine_coordinates(self): - self.write(self.SPACE() + self.MACHINE_COORDINATES()) - self.prev_g0123 = '' - - ############################################################################ - ## CRC - - def use_CRC(self): - return self.useCrc - - def CRC_nominal_path(self): - return self.useCrcCenterline - - def start_CRC(self, left = True, radius = 0.0): - # set up prep code, to be output on next line - if self.t == None: - raise "No tool specified for start_CRC()" - self.write_blocknum() - if left: - self.write(self.SPACE() + 'G41') - else: - self.write(self.SPACE() + 'G42') - self.write((self.SPACE() + 'D%i\n') % self.t) - - def end_CRC(self): - self.write_blocknum() - self.write(self.SPACE() + 'G40\n') - - ############################################################################ - ## Cycles - - def pattern(self): - pass - - def pocket(self): - pass - - def profile(self): - pass - - # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). - # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to - # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. - # Instead, this routine combines the Z value and the depth value to determine the bottom of - # the hole. - # - # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts - # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. - # - # The peck_depth value is the incremental depth (Q value) that tells the peck drilling - # cycle how deep to go on each peck until the full depth is achieved. - # - # NOTE: This routine forces the mode to absolute mode so that the values passed into - # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't - # revert it. I must set the mode so that I can be sure the values I'm passing in make - # sense to the end-machine. - # - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance = None): - if (standoff == None): - # This is a bad thing. All the drilling cycles need a retraction (and starting) height. - return - - if (z == None): - return # We need a Z value as well. This input parameter represents the top of the hole - - if self.drillExpanded: - # for machines which don't understand G81, G82 etc. - if peck_depth == None: - peck_depth = depth - current_z = z - self.rapid(x, y) - - first = True - - while True: - next_z = current_z - peck_depth - if next_z < z - depth: - next_z = z - depth - if next_z >= current_z: - break; - if first: - self.rapid(z = z + standoff) - else: - self.rapid(z = current_z) - self.feed(z = next_z) - self.rapid(z = z + standoff) - current_z = next_z - if dwell: - self.dwell(dwell) - first = False - - # we should pass clearance height into here, but my machine is on and I'm in a hurry... 22nd June 2011 danheeks - self.rapid(z = z + 5.0) - - return - - self.write_preps() - self.write_blocknum() - - if (peck_depth != 0): - # We're pecking. Let's find a tree. - if self.drill_modal: - if self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth) != self.prev_drill: - self.write(self.SPACE() + self.PECK_DRILL() + self.SPACE() + self.PECK_DEPTH(self.fmt, peck_depth)) - self.prev_drill = self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth) - else: - self.write(self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth)) - - else: - # We're either just drilling or drilling with dwell. - if (dwell == 0): - # We're just drilling. - if self.drill_modal: - if self.DRILL() != self.prev_drill: - self.write(self.SPACE() + self.DRILL()) - self.prev_drill = self.DRILL() - else: - self.write(self.SPACE() + self.DRILL()) - - else: - # We're drilling with dwell. - - if self.drill_modal: - if self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell) != self.prev_drill: - self.write(self.SPACE() + self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell)) - self.prev_drill = self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell) - else: - self.write(self.SPACE() + self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell)) - - - #self.write(self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell)) - - # Set the retraction point to the 'standoff' distance above the starting z height. - retract_height = z + standoff - if (x != None): - dx = x - self.x - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - self.x = x - - if (y != None): - dy = y - self.y - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - self.y = y - - dz = (z + standoff) - self.z # In the end, we will be standoff distance above the z value passed in. - - if self.drill_modal: - if z != self.prev_z: - self.write(self.SPACE() + self.Z() + (self.fmt.string(z - depth))) - self.prev_z=z - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(z - depth))) # This is the 'z' value for the bottom of the hole. - self.z = (z + standoff) # We want to remember where z is at the end (at the top of the hole) - - if self.drill_modal: - if self.prev_retract != self.RETRACT(self.fmt, retract_height) : - self.write(self.SPACE() + self.RETRACT(self.fmt, retract_height)) - self.prev_retract = self.RETRACT(self.fmt, retract_height) - else: - self.write(self.SPACE() + self.RETRACT(self.fmt, retract_height)) - - if (self.fhv) : - self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) - - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - - # G33.1 tapping with EMC for now - # unsynchronized (chuck) taps NIY (tap_mode = 1) - - def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): - # mystery parameters: - # zretract=None, dwell_bottom=None,pitch=None, stoppos=None, spin_in=None, spin_out=None): - # I dont see how to map these to EMC Gcode - - if (standoff == None): - # This is a bad thing. All the drilling cycles need a retraction (and starting) height. - return - if (z == None): - return # We need a Z value as well. This input parameter represents the top of the hole - if (pitch == None): - return # We need a pitch value. - if (direction == None): - return # We need a direction value. - - if (tap_mode != 0): - raise "only rigid tapping currently supported" - - self.write_preps() - self.write_blocknum() - self.write_spindle() - self.write('\n') - - # rapid to starting point; z first, then x,y iff given - - # Set the retraction point to the 'standoff' distance above the starting z height. - retract_height = z + standoff - - # unsure if this is needed: - if self.z != retract_height: - self.rapid(z = retract_height) - - # then continue to x,y if given - if (x != None) or (y != None): - self.write_blocknum() - self.write(self.RAPID() ) - - if (x != None): - self.write(self.X() + self.fmt.string(x + self.shift_x)) - self.x = x - - if (y != None): - self.write(self.Y() + self.fmt.string(y + self.shift_y)) - self.y = y - self.write('\n') - - self.write_blocknum() - self.write( self.TAP() ) - self.write( self.TAP_DEPTH(self.ffmt,pitch) + self.SPACE() ) - self.write(self.Z() + self.fmt.string(z - depth))# This is the 'z' value for the bottom of the tap. - self.write_misc() - self.write('\n') - - self.z = retract_height # this cycle returns to the start position, so remember that as z value - - def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): - pass - - def end_canned_cycle(self): - if self.drillExpanded: - return - self.write_blocknum() - self.write(self.SPACE() + self.END_CANNED_CYCLE() + '\n') - self.prev_drill = '' - self.prev_g0123 = '' - self.prev_z = '' - self.prev_f = '' - self.prev_retract = '' - ############################################################################ - ## Misc - - def comment(self, text): - self.write((self.COMMENT(text) + '\n')) - - def insert(self, text): - pass - - def block_delete(self, on=False): - pass - - def variable(self, id): - return (self.VARIABLE() % id) - - def variable_set(self, id, value): - self.write_blocknum() - self.write(self.SPACE() + (self.VARIABLE() % id) + self.SPACE() + (self.VARIABLE_SET() % value) + '\n') - - # This routine uses the G92 coordinate system offsets to establish a temporary coordinate - # system at the machine's current position. It can then use absolute coordinates relative - # to this position which makes coding easy. It then moves to the 'point along edge' which - # should be above the workpiece but still on one edge. It then backs off from the edge - # to the 'retracted point'. It then plunges down by the depth value specified. It then - # probes back towards the 'destination point'. The probed X,Y location are stored - # into the 'intersection variable' variables. Finally the machine moves back to the - # original location. This is important so that the results of multiple calls to this - # routine may be compared meaningfully. - def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None ): - self.write_blocknum() - self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) - - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write_blocknum() - self.write_feedrate() - self.write('\t(Set the feed rate for probing)\n') - - self.rapid(point_along_edge_x,point_along_edge_y) - self.rapid(retracted_point_x,retracted_point_y) - self.feed(z=depth) - - self.write_blocknum() - self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + ' Y ' + (self.fmt.string(destination_point_y)) ) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Back off the workpiece and re-probe more slowly') - self.write_blocknum() - self.write(self.SPACE() + ('#' + intersection_variable_x + '= [#5061 - [ 0.5 * ' + probe_offset_x_component + ']]\n')) - self.write_blocknum() - self.write(self.SPACE() + ('#' + intersection_variable_y + '= [#5062 - [ 0.5 * ' + probe_offset_y_component + ']]\n')) - self.write_blocknum(); - self.write(self.RAPID()) - self.write(self.SPACE() + ' X #' + intersection_variable_x + ' Y #' + intersection_variable_y + '\n') - - self.write_blocknum() - self.write(self.SPACE() + self.FEEDRATE() + self.ffmt.string(self.fh / 2.0) + '\n') - - self.write_blocknum() - self.write((self.SPACE() + self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + ' Y ' + (self.fmt.string(destination_point_y)) ) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Store the probed location somewhere we can get it again later') - self.write_blocknum() - self.write(('#' + intersection_variable_x + '=' + probe_offset_x_component + ' (Portion of probe radius that contributes to the X coordinate)\n')) - self.write_blocknum() - self.write(('#' + intersection_variable_x + '=[#' + intersection_variable_x + ' + #5061]\n')) - self.write_blocknum() - self.write(('#' + intersection_variable_y + '=' + probe_offset_y_component + ' (Portion of probe radius that contributes to the Y coordinate)\n')) - self.write_blocknum() - self.write(('#' + intersection_variable_y + '=[#' + intersection_variable_y + ' + #5062]\n')) - - self.comment('Now move back to the original location') - self.rapid(retracted_point_x,retracted_point_y) - self.rapid(z=0) - self.rapid(point_along_edge_x,point_along_edge_y) - self.rapid(x=0, y=0) - - self.write_blocknum() - self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + ('\t(Restore the previous coordinate system)\n'))) - - def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): - self.write_blocknum() - self.write((self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write_blocknum() - self.write(self.FEEDRATE() + ' [' + self.ffmt.string(self.fh) + ' / 5.0 ]') - self.write('\t(Set the feed rate for probing)\n') - - if x != None and y != None: - self.write_blocknum(); - self.write(self.RAPID()) - self.write(' X ' + x + ' Y ' + y + '\n') - - self.write_blocknum() - self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + ' Z ' + (self.fmt.string(depth)) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Store the probed location somewhere we can get it again later') - self.write_blocknum() - self.write(('#' + intersection_variable_z + '= #5063\n')) - - self.comment('Now move back to the original location') - self.rapid(z=0) - self.rapid(x=0, y=0) - - self.write_blocknum() - self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + ('\t(Restore the previous coordinate system)\n'))) - - - def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): - pass - - def open_log_file(self, xml_file_name=None ): - pass - - def log_coordinate(self, x=None, y=None, z=None): - pass - - def log_message(self, message=None): - pass - - def close_log_file(self): - pass - - # Rapid movement to the midpoint between the two points specified. - # NOTE: The points are specified either as strings representing numbers or as strings - # representing variable names. This allows the HeeksCNC module to determine which - # variable names are used in these various routines. - def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): - self.write_blocknum() - self.write(self.RAPID()) - if ((x1 != None) and (x2 != None)): - self.write((' X ' + '[[[' + x1 + ' - ' + x2 + '] / 2.0] + ' + x2 + ']')) - - if ((y1 != None) and (y2 != None)): - self.write((' Y ' + '[[[' + y1 + ' - ' + y2 + '] / 2.0] + ' + y2 + ']')) - - if ((z1 != None) and (z2 != None)): - self.write((' Z ' + '[[[' + z1 + ' - ' + z2 + '] / 2.0] + ' + z2 + ']')) - - self.write('\n') - - # Rapid movement to the intersection of two lines (in the XY plane only). This routine - # is based on information found in http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ - # written by Paul Bourke. The ua_numerator, ua_denominator, ua and ub parameters - # represent variable names (with the preceding '#' included in them) for use as temporary - # variables. They're specified here simply so that HeeksCNC can manage which variables - # are used in which GCode calculations. - # - # As per the notes on the web page, the ua_denominator and ub_denominator formulae are - # the same so we don't repeat this. If the two lines are coincident or parallel then - # no movement occurs. - # - # NOTE: The points are specified either as strings representing numbers or as strings - # representing variable names. This allows the HeeksCNC module to determine which - # variable names are used in these various routines. - def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): - self.comment('Find the intersection of the two lines made up by the four probed points') - self.write_blocknum(); - self.write(ua_numerator + '=[[[' + x4 + ' - ' + x3 + '] * [' + y1 + ' - ' + y3 + ']] - [[' + y4 + ' - ' + y3 + '] * [' + x1 + ' - ' + x3 + ']]]\n') - self.write_blocknum(); - self.write(ua_denominator + '=[[[' + y4 + ' - ' + y3 + '] * [' + x2 + ' - ' + x1 + ']] - [[' + x4 + ' - ' + x3 + '] * [' + y2 + ' - ' + y1 + ']]]\n') - self.write_blocknum(); - self.write(ub_numerator + '=[[[' + x2 + ' - ' + x1 + '] * [' + y1 + ' - ' + y3 + ']] - [[' + y2 + ' - ' + y1 + '] * [' + x1 + ' - ' + x3 + ']]]\n') - - self.comment('If they are not parallel') - self.write('O900 IF [' + ua_denominator + ' NE 0]\n') - self.comment('And if they are not coincident') - self.write('O901 IF [' + ua_numerator + ' NE 0 ]\n') - - self.write_blocknum(); - self.write(' ' + ua + '=[' + ua_numerator + ' / ' + ua_denominator + ']\n') - self.write_blocknum(); - self.write(' ' + ub + '=[' + ub_numerator + ' / ' + ua_denominator + ']\n') # NOTE: ub denominator is the same as ua denominator - self.write_blocknum(); - self.write(' ' + intersection_x + '=[' + x1 + ' + [[' + ua + ' * [' + x2 + ' - ' + x1 + ']]]]\n') - self.write_blocknum(); - self.write(' ' + intersection_y + '=[' + y1 + ' + [[' + ua + ' * [' + y2 + ' - ' + y1 + ']]]]\n') - self.write_blocknum(); - self.write(' ' + self.RAPID()) - self.write(' X ' + intersection_x + ' Y ' + intersection_y + '\n') - - self.write('O901 ENDIF\n') - self.write('O900 ENDIF\n') - - # We need to calculate the rotation angle based on the line formed by the - # x1,y1 and x2,y2 coordinate pair. With that angle, we need to move - # x_offset and y_offset distance from the current (0,0,0) position. - # - # The x1,y1,x2 and y2 parameters are all variable names that contain the actual - # values. - # The x_offset and y_offset are both numeric (floating point) values - def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): - self.comment('Rapid to rotated coordinate') - self.write_blocknum(); - self.write( '#1 = [atan[' + y2 + ' - ' + y1 + ']/[' + x2 +' - ' + x1 + ']] (nominal_angle)\n') - self.write_blocknum(); - self.write( '#2 = [atan[' + ref_y + ']/[' + ref_x + ']] (reference angle)\n') - self.write_blocknum(); - self.write( '#3 = [#1 - #2] (angle)\n' ) - self.write_blocknum(); - self.write( '#4 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + '] * COS[ #3 ]] - [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * SIN[ #3 ]]]\n' ) - self.write_blocknum(); - self.write( '#5 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + '] * SIN[ #3 ]] + [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * COS[ #3 ]]]\n' ) - - self.write_blocknum(); - self.write( '#6 = [[' + (self.fmt.string(x_final)) + ' * COS[ #3 ]] - [' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]]]\n' ) - self.write_blocknum(); - self.write( '#7 = [[' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]] + [' + (self.fmt.string(y_final)) + ' * COS[ #3 ]]]\n' ) - - self.write_blocknum(); - self.write( self.RAPID() + ' X [ #4 + #6 ] Y [ #5 + #7 ]\n' ) - - def BEST_POSSIBLE_SPEED(self, motion_blending_tolerance, naive_cam_tolerance): - statement = 'G64' - - if (motion_blending_tolerance > 0): - statement += ' P ' + str(motion_blending_tolerance) - - if (naive_cam_tolerance > 0): - statement += ' Q ' + str(naive_cam_tolerance) - - return(statement) - - def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance ): - self.write_blocknum() - if (mode == 0): - self.write( self.EXACT_PATH_MODE() + '\n' ) - if (mode == 1): - self.write( self.EXACT_STOP_MODE() + '\n' ) - if (mode == 2): - self.write( self.BEST_POSSIBLE_SPEED( motion_blending_tolerance, naive_cam_tolerance ) + '\n' ) + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + if (x != None): + self.x = x + if (y != None): + self.y = y + if (z != None): + self.z = z + + def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + self.arc(True, x, y, z, i, j, k, r) + + def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + self.arc(False, x, y, z, i, j, k, r) + + def dwell(self, t): + self.write_blocknum() + self.write_preps() + self.write(self.FORMAT_DWELL() % t) + self.write_misc() + self.write('\n') + + def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + def rapid_unhome(self): + pass + + def set_machine_coordinates(self): + self.write(self.SPACE() + self.MACHINE_COORDINATES()) + self.prev_g0123 = '' + + ############################################################################ + # CRC + + def use_CRC(self): + return self.useCrc + + def CRC_nominal_path(self): + return self.useCrcCenterline + + def start_CRC(self, left=True, radius=0.0): + # set up prep code, to be output on next line + if self.t == None: + raise "No tool specified for start_CRC()" + self.write_blocknum() + if left: + self.write(self.SPACE() + 'G41') + else: + self.write(self.SPACE() + 'G42') + self.write((self.SPACE() + 'D%i\n') % self.t) + + def end_CRC(self): + self.write_blocknum() + self.write(self.SPACE() + 'G40\n') + + ############################################################################ + # Cycles + + def pattern(self): + pass + + def pocket(self): + pass + + def profile(self): + pass + + # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). + # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to + # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. + # Instead, this routine combines the Z value and the depth value to determine the bottom of + # the hole. + # + # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts + # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. + # + # The peck_depth value is the incremental depth (Q value) that tells the peck drilling + # cycle how deep to go on each peck until the full depth is achieved. + # + # NOTE: This routine forces the mode to absolute mode so that the values passed into + # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't + # revert it. I must set the mode so that I can be sure the values I'm passing in make + # sense to the end-machine. + # + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + if (standoff == None): + # This is a bad thing. All the drilling cycles need a retraction (and starting) height. + return + + if (z == None): + return # We need a Z value as well. This input parameter represents the top of the hole + + if self.drillExpanded: + # for machines which don't understand G81, G82 etc. + if peck_depth == None: + peck_depth = depth + current_z = z + self.rapid(x, y) + + first = True + + while True: + next_z = current_z - peck_depth + if next_z < z - depth: + next_z = z - depth + if next_z >= current_z: + break + if first: + self.rapid(z=z + standoff) + else: + self.rapid(z=current_z) + self.feed(z=next_z) + self.rapid(z=z + standoff) + current_z = next_z + if dwell: + self.dwell(dwell) + first = False + + # we should pass clearance height into here, but my machine is on and I'm in a hurry... 22nd June 2011 danheeks + self.rapid(z=z + 5.0) + + return + + self.write_preps() + self.write_blocknum() + + if (peck_depth != 0): + # We're pecking. Let's find a tree. + if self.drill_modal: + if self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth) != self.prev_drill: + self.write(self.SPACE() + self.PECK_DRILL() + self.SPACE() + + self.PECK_DEPTH(self.fmt, peck_depth)) + self.prev_drill = self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth) + else: + self.write(self.PECK_DRILL() + self.PECK_DEPTH(self.fmt, peck_depth)) + + else: + # We're either just drilling or drilling with dwell. + if (dwell == 0): + # We're just drilling. + if self.drill_modal: + if self.DRILL() != self.prev_drill: + self.write(self.SPACE() + self.DRILL()) + self.prev_drill = self.DRILL() + else: + self.write(self.SPACE() + self.DRILL()) + + else: + # We're drilling with dwell. + + if self.drill_modal: + if self.DRILL_WITH_DWELL(self.FORMAT_DWELL(), dwell) != self.prev_drill: + self.write(self.SPACE() + self.DRILL_WITH_DWELL(self.FORMAT_DWELL(), dwell)) + self.prev_drill = self.DRILL_WITH_DWELL(self.FORMAT_DWELL(), dwell) + else: + self.write(self.SPACE() + self.DRILL_WITH_DWELL(self.FORMAT_DWELL(), dwell)) + + # self.write(self.DRILL_WITH_DWELL(self.FORMAT_DWELL(),dwell)) + + # Set the retraction point to the 'standoff' distance above the starting z height. + retract_height = z + standoff + if (x != None): + dx = x - self.x + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + self.x = x + + if (y != None): + dy = y - self.y + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + self.y = y + + # In the end, we will be standoff distance above the z value passed in. + dz = (z + standoff) - self.z + + if self.drill_modal: + if z != self.prev_z: + self.write(self.SPACE() + self.Z() + (self.fmt.string(z - depth))) + self.prev_z = z + else: + # This is the 'z' value for the bottom of the hole. + self.write(self.SPACE() + self.Z() + (self.fmt.string(z - depth))) + # We want to remember where z is at the end (at the top of the hole) + self.z = (z + standoff) + + if self.drill_modal: + if self.prev_retract != self.RETRACT(self.fmt, retract_height): + self.write(self.SPACE() + self.RETRACT(self.fmt, retract_height)) + self.prev_retract = self.RETRACT(self.fmt, retract_height) + else: + self.write(self.SPACE() + self.RETRACT(self.fmt, retract_height)) + + if (self.fhv): + self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) + + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + + # G33.1 tapping with EMC for now + # unsynchronized (chuck) taps NIY (tap_mode = 1) + + def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): + # mystery parameters: + # zretract=None, dwell_bottom=None,pitch=None, stoppos=None, spin_in=None, spin_out=None): + # I dont see how to map these to EMC Gcode + + if (standoff == None): + # This is a bad thing. All the drilling cycles need a retraction (and starting) height. + return + if (z == None): + return # We need a Z value as well. This input parameter represents the top of the hole + if (pitch == None): + return # We need a pitch value. + if (direction == None): + return # We need a direction value. + + if (tap_mode != 0): + raise "only rigid tapping currently supported" + + self.write_preps() + self.write_blocknum() + self.write_spindle() + self.write('\n') + + # rapid to starting point; z first, then x,y iff given + + # Set the retraction point to the 'standoff' distance above the starting z height. + retract_height = z + standoff + + # unsure if this is needed: + if self.z != retract_height: + self.rapid(z=retract_height) + + # then continue to x,y if given + if (x != None) or (y != None): + self.write_blocknum() + self.write(self.RAPID()) + + if (x != None): + self.write(self.X() + self.fmt.string(x + self.shift_x)) + self.x = x + + if (y != None): + self.write(self.Y() + self.fmt.string(y + self.shift_y)) + self.y = y + self.write('\n') + + self.write_blocknum() + self.write(self.TAP()) + self.write(self.TAP_DEPTH(self.ffmt, pitch) + self.SPACE()) + # This is the 'z' value for the bottom of the tap. + self.write(self.Z() + self.fmt.string(z - depth)) + self.write_misc() + self.write('\n') + + self.z = retract_height # this cycle returns to the start position, so remember that as z value + + def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): + pass + + def end_canned_cycle(self): + if self.drillExpanded: + return + self.write_blocknum() + self.write(self.SPACE() + self.END_CANNED_CYCLE() + '\n') + self.prev_drill = '' + self.prev_g0123 = '' + self.prev_z = '' + self.prev_f = '' + self.prev_retract = '' + ############################################################################ + # Misc + + def comment(self, text): + self.write((self.COMMENT(text) + '\n')) + + def insert(self, text): + pass + + def block_delete(self, on=False): + pass + + def variable(self, id): + return (self.VARIABLE() % id) + + def variable_set(self, id, value): + self.write_blocknum() + self.write(self.SPACE() + (self.VARIABLE() % id) + + self.SPACE() + (self.VARIABLE_SET() % value) + '\n') + + # This routine uses the G92 coordinate system offsets to establish a temporary coordinate + # system at the machine's current position. It can then use absolute coordinates relative + # to this position which makes coding easy. It then moves to the 'point along edge' which + # should be above the workpiece but still on one edge. It then backs off from the edge + # to the 'retracted point'. It then plunges down by the depth value specified. It then + # probes back towards the 'destination point'. The probed X,Y location are stored + # into the 'intersection variable' variables. Finally the machine moves back to the + # original location. This is important so that the results of multiple calls to this + # routine may be compared meaningfully. + def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None): + self.write_blocknum() + self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM() + + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) + + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write_blocknum() + self.write_feedrate() + self.write('\t(Set the feed rate for probing)\n') + + self.rapid(point_along_edge_x, point_along_edge_y) + self.rapid(retracted_point_x, retracted_point_y) + self.feed(z=depth) + + self.write_blocknum() + self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + + ' Y ' + (self.fmt.string(destination_point_y))) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Back off the workpiece and re-probe more slowly') + self.write_blocknum() + self.write(self.SPACE() + ('#' + intersection_variable_x + + '= [#5061 - [ 0.5 * ' + probe_offset_x_component + ']]\n')) + self.write_blocknum() + self.write(self.SPACE() + ('#' + intersection_variable_y + + '= [#5062 - [ 0.5 * ' + probe_offset_y_component + ']]\n')) + self.write_blocknum() + self.write(self.RAPID()) + self.write(self.SPACE() + ' X #' + intersection_variable_x + + ' Y #' + intersection_variable_y + '\n') + + self.write_blocknum() + self.write(self.SPACE() + self.FEEDRATE() + self.ffmt.string(self.fh / 2.0) + '\n') + + self.write_blocknum() + self.write((self.SPACE() + self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x) + ) + ' Y ' + (self.fmt.string(destination_point_y))) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Store the probed location somewhere we can get it again later') + self.write_blocknum() + self.write(('#' + intersection_variable_x + '=' + probe_offset_x_component + + ' (Portion of probe radius that contributes to the X coordinate)\n')) + self.write_blocknum() + self.write(('#' + intersection_variable_x + + '=[#' + intersection_variable_x + ' + #5061]\n')) + self.write_blocknum() + self.write(('#' + intersection_variable_y + '=' + probe_offset_y_component + + ' (Portion of probe radius that contributes to the Y coordinate)\n')) + self.write_blocknum() + self.write(('#' + intersection_variable_y + + '=[#' + intersection_variable_y + ' + #5062]\n')) + + self.comment('Now move back to the original location') + self.rapid(retracted_point_x, retracted_point_y) + self.rapid(z=0) + self.rapid(point_along_edge_x, point_along_edge_y) + self.rapid(x=0, y=0) + + self.write_blocknum() + self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + + ('\t(Restore the previous coordinate system)\n'))) + + def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): + self.write_blocknum() + self.write((self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + + ('\t(Temporarily make this the origin)\n'))) + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write_blocknum() + self.write(self.FEEDRATE() + ' [' + self.ffmt.string(self.fh) + ' / 5.0 ]') + self.write('\t(Set the feed rate for probing)\n') + + if x != None and y != None: + self.write_blocknum() + self.write(self.RAPID()) + self.write(' X ' + x + ' Y ' + y + '\n') + + self.write_blocknum() + self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + ' Z ' + + (self.fmt.string(depth)) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Store the probed location somewhere we can get it again later') + self.write_blocknum() + self.write(('#' + intersection_variable_z + '= #5063\n')) + + self.comment('Now move back to the original location') + self.rapid(z=0) + self.rapid(x=0, y=0) + + self.write_blocknum() + self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + + ('\t(Restore the previous coordinate system)\n'))) + + def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): + pass + + def open_log_file(self, xml_file_name=None): + pass + + def log_coordinate(self, x=None, y=None, z=None): + pass + + def log_message(self, message=None): + pass + + def close_log_file(self): + pass + + # Rapid movement to the midpoint between the two points specified. + # NOTE: The points are specified either as strings representing numbers or as strings + # representing variable names. This allows the HeeksCNC module to determine which + # variable names are used in these various routines. + def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): + self.write_blocknum() + self.write(self.RAPID()) + if ((x1 != None) and (x2 != None)): + self.write((' X ' + '[[[' + x1 + ' - ' + x2 + '] / 2.0] + ' + x2 + ']')) + + if ((y1 != None) and (y2 != None)): + self.write((' Y ' + '[[[' + y1 + ' - ' + y2 + '] / 2.0] + ' + y2 + ']')) + + if ((z1 != None) and (z2 != None)): + self.write((' Z ' + '[[[' + z1 + ' - ' + z2 + '] / 2.0] + ' + z2 + ']')) + + self.write('\n') + + # Rapid movement to the intersection of two lines (in the XY plane only). This routine + # is based on information found in http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ + # written by Paul Bourke. The ua_numerator, ua_denominator, ua and ub parameters + # represent variable names (with the preceding '#' included in them) for use as temporary + # variables. They're specified here simply so that HeeksCNC can manage which variables + # are used in which GCode calculations. + # + # As per the notes on the web page, the ua_denominator and ub_denominator formulae are + # the same so we don't repeat this. If the two lines are coincident or parallel then + # no movement occurs. + # + # NOTE: The points are specified either as strings representing numbers or as strings + # representing variable names. This allows the HeeksCNC module to determine which + # variable names are used in these various routines. + def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): + self.comment('Find the intersection of the two lines made up by the four probed points') + self.write_blocknum() + self.write(ua_numerator + '=[[[' + x4 + ' - ' + x3 + '] * [' + y1 + ' - ' + + y3 + ']] - [[' + y4 + ' - ' + y3 + '] * [' + x1 + ' - ' + x3 + ']]]\n') + self.write_blocknum() + self.write(ua_denominator + '=[[[' + y4 + ' - ' + y3 + '] * [' + x2 + ' - ' + + x1 + ']] - [[' + x4 + ' - ' + x3 + '] * [' + y2 + ' - ' + y1 + ']]]\n') + self.write_blocknum() + self.write(ub_numerator + '=[[[' + x2 + ' - ' + x1 + '] * [' + y1 + ' - ' + + y3 + ']] - [[' + y2 + ' - ' + y1 + '] * [' + x1 + ' - ' + x3 + ']]]\n') + + self.comment('If they are not parallel') + self.write('O900 IF [' + ua_denominator + ' NE 0]\n') + self.comment('And if they are not coincident') + self.write('O901 IF [' + ua_numerator + ' NE 0 ]\n') + + self.write_blocknum() + self.write(' ' + ua + '=[' + ua_numerator + ' / ' + ua_denominator + ']\n') + self.write_blocknum() + # NOTE: ub denominator is the same as ua denominator + self.write(' ' + ub + '=[' + ub_numerator + ' / ' + ua_denominator + ']\n') + self.write_blocknum() + self.write(' ' + intersection_x + '=[' + x1 + + ' + [[' + ua + ' * [' + x2 + ' - ' + x1 + ']]]]\n') + self.write_blocknum() + self.write(' ' + intersection_y + '=[' + y1 + + ' + [[' + ua + ' * [' + y2 + ' - ' + y1 + ']]]]\n') + self.write_blocknum() + self.write(' ' + self.RAPID()) + self.write(' X ' + intersection_x + ' Y ' + intersection_y + '\n') + + self.write('O901 ENDIF\n') + self.write('O900 ENDIF\n') + + # We need to calculate the rotation angle based on the line formed by the + # x1,y1 and x2,y2 coordinate pair. With that angle, we need to move + # x_offset and y_offset distance from the current (0,0,0) position. + # + # The x1,y1,x2 and y2 parameters are all variable names that contain the actual + # values. + # The x_offset and y_offset are both numeric (floating point) values + def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): + self.comment('Rapid to rotated coordinate') + self.write_blocknum() + self.write('#1 = [atan[' + y2 + ' - ' + y1 + ']/[' + + x2 + ' - ' + x1 + ']] (nominal_angle)\n') + self.write_blocknum() + self.write('#2 = [atan[' + ref_y + ']/[' + ref_x + ']] (reference angle)\n') + self.write_blocknum() + self.write('#3 = [#1 - #2] (angle)\n') + self.write_blocknum() + self.write('#4 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + + '] * COS[ #3 ]] - [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * SIN[ #3 ]]]\n') + self.write_blocknum() + self.write('#5 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + + '] * SIN[ #3 ]] + [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * COS[ #3 ]]]\n') + + self.write_blocknum() + self.write('#6 = [[' + (self.fmt.string(x_final)) + ' * COS[ #3 ]] - [' + + (self.fmt.string(y_final)) + ' * SIN[ #3 ]]]\n') + self.write_blocknum() + self.write('#7 = [[' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]] + [' + + (self.fmt.string(y_final)) + ' * COS[ #3 ]]]\n') + + self.write_blocknum() + self.write(self.RAPID() + ' X [ #4 + #6 ] Y [ #5 + #7 ]\n') + + def BEST_POSSIBLE_SPEED(self, motion_blending_tolerance, naive_cam_tolerance): + statement = 'G64' + + if (motion_blending_tolerance > 0): + statement += ' P ' + str(motion_blending_tolerance) + + if (naive_cam_tolerance > 0): + statement += ' Q ' + str(naive_cam_tolerance) + + return(statement) + + def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance): + self.write_blocknum() + if (mode == 0): + self.write(self.EXACT_PATH_MODE() + '\n') + if (mode == 1): + self.write(self.EXACT_STOP_MODE() + '\n') + if (mode == 2): + self.write(self.BEST_POSSIBLE_SPEED( + motion_blending_tolerance, naive_cam_tolerance) + '\n') ################################################################################ diff --git a/scripts/addons/cam/nc/heiden530.py b/scripts/addons/cam/nc/heiden530.py index d7473f871..1a5e4061b 100644 --- a/scripts/addons/cam/nc/heiden530.py +++ b/scripts/addons/cam/nc/heiden530.py @@ -13,6 +13,7 @@ from .format import Format from .format import * + class Creator(iso.Creator): def __init__(self): iso.Creator.__init__(self) @@ -34,15 +35,14 @@ def __init__(self): self.shift_y = 0.0 self.shift_z = 0.0 - ############################################################################ - ## Codes + # Codes def SPACE(self): return(' ') def NEW_LINE(self): return('\n') def BLOCK(self): return('%i') - def COMMENT(self,comment): return( (';%s' % comment ) ) + def COMMENT(self, comment): return((';%s' % comment)) def BEGIN_PGM(self): return('BEGIN PGM %i') def END_PGM(self): return('END PGM %i') @@ -65,7 +65,7 @@ def Y(self): return('Y') def Z(self): return('Z') ############################################################################ - ## Internals + # Internals def write_blocknum(self): self.write(self.BLOCK() % self.n) @@ -76,7 +76,7 @@ def write_spindle(self): self.write(self.NEW_LINE()) ############################################################################ - ## Programs + # Programs def program_begin(self, id, name=''): self.program_id = id @@ -99,7 +99,7 @@ def program_end(self): self.write(self.NEW_LINE()) ############################################################################ - ## Settings + # Settings def absolute(self): pass @@ -111,7 +111,7 @@ def set_plane(self, plane): pass ############################################################################ - ## Tools + # Tools def tool_change(self, id): self.t = id @@ -122,9 +122,9 @@ def tool_change(self, id): self.write(self.TOOL() % self.t) ############################################################################ - ## Moves + # Moves - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write_blocknum() @@ -135,14 +135,14 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) else: self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) self.x = x if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) else: self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) @@ -150,7 +150,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): self.y = y if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) else: self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) @@ -162,8 +162,8 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - (x, y, z, a, b, c,axis_count)=self.filter_xyz(x, y, z) - if axis_count==0: return + (x, y, z, a, b, c, axis_count) = self.filter_xyz(x, y, z) + if axis_count == 0: return self.write_blocknum() @@ -201,7 +201,7 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write_misc() ############################################################################ - ## Misc + # Misc def comment(self, text): self.write((self.COMMENT(text) + '\n')) diff --git a/scripts/addons/cam/nc/heiden_read.py b/scripts/addons/cam/nc/heiden_read.py index bcd14760d..e2f81fe44 100644 --- a/scripts/addons/cam/nc/heiden_read.py +++ b/scripts/addons/cam/nc/heiden_read.py @@ -10,6 +10,8 @@ import math ################################################################################ + + class Parser(nc.Parser): def __init__(self, writer): @@ -97,7 +99,7 @@ def ParseWord(self, word): def Parsey(self, name): self.files_open(name) - for_full_machine_sim = True # to do, make derived class to do this + for_full_machine_sim = True # to do, make derived class to do this #for_full_machine_sim = False self.f = None @@ -135,16 +137,22 @@ def Parsey(self, name): self.ParseWord(word) if (self.move and not self.no_move): - if (self.arc==0): + if (self.arc == 0): self.add_line(self.x, self.y, self.z, self.a, self.b, self.rapid) else: self.add_arc(self.x, self.y, self.z, self.i, self.j, self.k, self.r, self.arc) - if self.x != None: self.oldx = self.x - if self.y != None: self.oldy = self.y - if self.z != None: self.oldz = self.z - if self.a != None: self.olda = self.a - if self.b != None: self.oldb = self.b - if self.c != None: self.oldc = self.c + if self.x != None: + self.oldx = self.x + if self.y != None: + self.oldy = self.y + if self.z != None: + self.oldz = self.z + if self.a != None: + self.olda = self.a + if self.b != None: + self.oldb = self.b + if self.c != None: + self.oldc = self.c elif (self.t): self.change_tool(self.t) diff --git a/scripts/addons/cam/nc/hm50.py b/scripts/addons/cam/nc/hm50.py index 2e0b065ba..2282edad1 100644 --- a/scripts/addons/cam/nc/hm50.py +++ b/scripts/addons/cam/nc/hm50.py @@ -1,19 +1,20 @@ from . import nc from . import emc2 + class Creator(emc2.Creator): - def __init__(self): - emc2.Creator.__init__(self) + def __init__(self): + emc2.Creator.__init__(self) - def program_begin(self, id, comment): - self.write( ('(' + comment + ')' + '\n') ) + def program_begin(self, id, comment): + self.write(('(' + comment + ')' + '\n')) - def tool_change(self, id): - self.write('G53 G00 Z30\n') - self.write((self.TOOL() % id) + '\n') - self.write('G01 Z100.000 F800.000\n') - self.write('M0\n') - self.write('G01 Z10.000 F300.000\n') + def tool_change(self, id): + self.write('G53 G00 Z30\n') + self.write((self.TOOL() % id) + '\n') + self.write('G01 Z100.000 F800.000\n') + self.write('M0\n') + self.write('G01 Z10.000 F300.000\n') nc.creator = Creator() diff --git a/scripts/addons/cam/nc/hm50_read.py b/scripts/addons/cam/nc/hm50_read.py index 25f8cf320..3df5337c7 100644 --- a/scripts/addons/cam/nc/hm50_read.py +++ b/scripts/addons/cam/nc/hm50_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/hpgl2d.py b/scripts/addons/cam/nc/hpgl2d.py index 7b6642c18..fa7b8a9db 100644 --- a/scripts/addons/cam/nc/hpgl2d.py +++ b/scripts/addons/cam/nc/hpgl2d.py @@ -7,18 +7,19 @@ from . import nc import math + class Creator(nc.Creator): def __init__(self): nc.Creator.__init__(self) self.x = int(0) - self.y = int(0) # these are in machine units, like 0.01mm or maybe 0.25mm - self.metric() # set self.units_to_mc_units + self.y = int(0) # these are in machine units, like 0.01mm or maybe 0.25mm + self.metric() # set self.units_to_mc_units def imperial(self): - self.units_to_mc_units = 2540 # multiplier from inches to machine units + self.units_to_mc_units = 2540 # multiplier from inches to machine units def metric(self): - self.units_to_mc_units = 100 # multiplier from mm to machine units + self.units_to_mc_units = 100 # multiplier from mm to machine units def program_begin(self, id, name=''): self.write('IN;\n') @@ -89,12 +90,15 @@ def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): start_angle = math.atan2(sdy, sdx) end_angle = math.atan2(edy, edx) if cw: - if start_angle < end_angle: start_angle += 2 * math.pi + if start_angle < end_angle: + start_angle += 2 * math.pi else: - if end_angle < start_angle: end_angle += 2 * math.pi + if end_angle < start_angle: + end_angle += 2 * math.pi a = math.fabs(end_angle - start_angle) - if cw: a = -a + if cw: + a = -a mcx, mcy = self.get_machine_x_y(cx, cy) @@ -106,4 +110,5 @@ def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): self.arc(False, x, y, z, i, j, k, r) + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/hpgl2d_read.py b/scripts/addons/cam/nc/hpgl2d_read.py index c1825bca2..4a49c5fd5 100644 --- a/scripts/addons/cam/nc/hpgl2d_read.py +++ b/scripts/addons/cam/nc/hpgl2d_read.py @@ -2,6 +2,7 @@ import sys import math + class Parser(num_reader.NumReader): def __init__(self, writer): @@ -21,12 +22,16 @@ def ParsePuOrPd(self, up): if len(x) > 0: y = self.get_number() if len(y) > 0: - if up: color = "rapid" - else: color = "feed" + if up: + color = "rapid" + else: + color = "feed" self.add_word(color) self.begin_path(color) - if up: z = self.up_z - else: z = self.down_z + if up: + z = self.up_z + else: + z = self.down_z if self.up != up: self.add_line(self.x * self.units_to_mm, self.y * self.units_to_mm, z) self.add_line(int(x) * self.units_to_mm, int(y) * self.units_to_mm, z) @@ -61,10 +66,13 @@ def ParseAA(self): ex = int(cx) + radius * math.cos(end_angle) ey = int(cy) + radius * math.sin(end_angle) - if int(a) > 0: d = 1 - else: d = -1 + if int(a) > 0: + d = 1 + else: + d = -1 - self.add_arc(ex * self.units_to_mm, ey * self.units_to_mm, i = int(-sdx) * self.units_to_mm, j = int(-sdy) * self.units_to_mm, d = d) + self.add_arc(ex * self.units_to_mm, ey * self.units_to_mm, i=int(-sdx) + * self.units_to_mm, j=int(-sdy) * self.units_to_mm, d=d) self.end_path() self.up = False self.x = int(ex) @@ -76,15 +84,14 @@ def ParseFromFirstLetter(self, c): if self.line_index < self.line_length: c1 = self.line[self.line_index] self.parse_word += c1 - if c1 == 'U': # PU + if c1 == 'U': # PU self.ParsePuOrPd(True) - elif c1 == 'D': # PD + elif c1 == 'D': # PD self.ParsePuOrPd(False) elif c == 'A': self.line_index = self.line_index + 1 if self.line_index < self.line_length: c1 = self.line[self.line_index] self.parse_word += c1 - if c1 == 'A': # AA, arc absolute + if c1 == 'A': # AA, arc absolute self.ParseAA() - diff --git a/scripts/addons/cam/nc/hpgl2dv.py b/scripts/addons/cam/nc/hpgl2dv.py index 717d9f970..1f1be7942 100644 --- a/scripts/addons/cam/nc/hpgl2dv.py +++ b/scripts/addons/cam/nc/hpgl2dv.py @@ -9,14 +9,16 @@ from . import nc from . import hpgl2d + class Creator(hpgl2d.Creator): def __init__(self): hpgl2d.Creator.__init__(self) def imperial(self): - self.units_to_mc_units = 101.6 # multiplier from inches to machine units + self.units_to_mc_units = 101.6 # multiplier from inches to machine units def metric(self): - self.units_to_mc_units = 4 # multiplier from mm to machine units + self.units_to_mc_units = 4 # multiplier from mm to machine units + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/hpgl2dv_read.py b/scripts/addons/cam/nc/hpgl2dv_read.py index def61e0ff..a4b8d13b3 100644 --- a/scripts/addons/cam/nc/hpgl2dv_read.py +++ b/scripts/addons/cam/nc/hpgl2dv_read.py @@ -3,6 +3,7 @@ # same as hpgl2d, but with 0.25mm units, instead of 0.01mm + class Parser(hpgl.Parser): def __init__(self, writer): hpgl.ParserHgpl2d.__init__(self, writer) diff --git a/scripts/addons/cam/nc/hpgl3d.py b/scripts/addons/cam/nc/hpgl3d.py index 42948bc72..8f8f8564f 100644 --- a/scripts/addons/cam/nc/hpgl3d.py +++ b/scripts/addons/cam/nc/hpgl3d.py @@ -8,11 +8,12 @@ from . import hpgl2d import math + class Creator(hpgl2d.Creator): def __init__(self): hpgl2d.Creator.__init__(self) self.z = int(0) - self.metric() # set self.units_to_mc_units + self.metric() # set self.units_to_mc_units self.doing_rapid = True def program_begin(self, id, name=''): @@ -42,7 +43,8 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): # for now, do all rapid moves at V50 ( 50 mm/s ) mx, my, mz = self.get_machine_xyz(x, y, z) if mx != self.x or my != self.y or mz != self.z: - if self.doing_rapid == False: self.write('V50.0;') + if self.doing_rapid == False: + self.write('V50.0;') self.write(('Z%i' % mx) + (',%i' % my) + (',%i;\n' % mz)) self.x = mx self.y = my @@ -54,11 +56,13 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): # for now, do all feed moves at V10 ( 10 mm/s ) mx, my, mz = self.get_machine_xyz(x, y, z) if mx != self.x or my != self.y or mz != self.z: - if self.doing_rapid == True: self.write('V10.0;') + if self.doing_rapid == True: + self.write('V10.0;') self.write(('Z%i' % mx) + (',%i' % my) + (',%i;\n' % mz)) self.x = mx self.y = my self.z = mz self.doing_rapid = False + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/hpgl3d_read.py b/scripts/addons/cam/nc/hpgl3d_read.py index 646fb883b..732689462 100644 --- a/scripts/addons/cam/nc/hpgl3d_read.py +++ b/scripts/addons/cam/nc/hpgl3d_read.py @@ -2,6 +2,7 @@ import sys import math + class Parser(num_reader.NumReader): def __init__(self, writer): @@ -27,11 +28,14 @@ def ParseZ(self): if len(y) > 0: z = self.get_number() if len(z) > 0: - if self.f > 40: color = "rapid" - else: color = "feed" + if self.f > 40: + color = "rapid" + else: + color = "feed" self.add_word(color) self.begin_path(color) - self.add_line(int(x) * self.units_to_mm, int(y) * self.units_to_mm, int(z) * self.units_to_mm) + self.add_line(int(x) * self.units_to_mm, int(y) * + self.units_to_mm, int(z) * self.units_to_mm) self.end_path() self.x = int(x) self.y = int(y) @@ -42,4 +46,3 @@ def ParseFromFirstLetter(self, c): self.ParseZ() elif c == 'V': self.ParseV() - diff --git a/scripts/addons/cam/nc/hxml_writer.py b/scripts/addons/cam/nc/hxml_writer.py index 455f82c21..39ad2fb97 100644 --- a/scripts/addons/cam/nc/hxml_writer.py +++ b/scripts/addons/cam/nc/hxml_writer.py @@ -1,5 +1,6 @@ import tempfile + class HxmlWriter: def __init__(self): self.file_out = open(tempfile.gettempdir()+'/backplot.xml', 'w') @@ -26,25 +27,32 @@ def add_text(self, s, col, cdata): s.replace('"', '"') s.replace('<', '<') s.replace('>', '>') - if (cdata) : (cd1, cd2) = ('') - else : (cd1, cd2) = ('', '') - if (col != None) : self.file_out.write('\t\t'+cd1+s+cd2+'\n') - else : self.file_out.write('\t\t'+cd1+s+cd2+'\n') + if (cdata): + (cd1, cd2) = ('') + else: + (cd1, cd2) = ('', '') + if (col != None): + self.file_out.write('\t\t'+cd1+s+cd2+'\n') + else: + self.file_out.write('\t\t'+cd1+s+cd2+'\n') def set_mode(self, units): self.file_out.write('\t\t\n') def metric(self): - self.set_mode(units = 1.0) + self.set_mode(units=1.0) def imperial(self): - self.set_mode(units = 25.4) + self.set_mode(units=25.4) def begin_path(self, col): - if (col != None) : self.file_out.write('\t\t\n') - else : self.file_out.write('\t\t\n') + if (col != None): + self.file_out.write('\t\t\n') + else: + self.file_out.write('\t\t\n') def end_path(self): self.file_out.write('\t\t\n') @@ -71,7 +79,7 @@ def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): def tool_change(self, id): self.file_out.write('\t\t\n') @@ -81,36 +89,50 @@ def spindle(self, s, clockwise): def feedrate(self, f): pass - def add_line(self, x, y, z, a = None, b = None, c = None): + def add_line(self, x, y, z, a=None, b=None, c=None): self.file_out.write('\t\t\t\n') - if x != None: self.oldx = x - if y != None: self.oldy = y - if z != None: self.oldz = z - - def add_arc(self, x, y, z, i, j, k, r = None, d = None): + if x != None: + self.oldx = x + if y != None: + self.oldy = y + if z != None: + self.oldz = z + + def add_arc(self, x, y, z, i, j, k, r=None, d=None): self.file_out.write('\t\t\t\n') - if x != None: self.oldx = x - if y != None: self.oldy = y - if z != None: self.oldz = z + if x != None: + self.oldx = x + if y != None: + self.oldy = y + if z != None: + self.oldz = z diff --git a/scripts/addons/cam/nc/iso.py b/scripts/addons/cam/nc/iso.py index 32701e1f0..5b115b93f 100644 --- a/scripts/addons/cam/nc/iso.py +++ b/scripts/addons/cam/nc/iso.py @@ -11,1328 +11,1404 @@ from .format import * ################################################################################ + + class Creator(nc.Creator): - def __init__(self): - nc.Creator.__init__(self) - - # internal variables - self.a = 0 - self.b = 0 - self.c = 0 - self.f = Address('F', fmt = Format(number_of_decimal_places = 2)) - self.fh = None - self.fv = None - self.fhv = False - self.g_plane = Address('G', fmt = Format(number_of_decimal_places = 0)) - self.g_list = [] - self.i = 0 - self.j = 0 - self.k = 0 - self.m = [] - self.r = 0 - self.s = AddressPlusMinus('S', fmt = Format(number_of_decimal_places = 2), modal = False) - self.t = None - self.x = None - self.y = None - self.z = None - self.g0123_modal = False - self.drill_modal = False - self.prev_f = '' - self.prev_g0123 = '' - self.prev_drill = '' - self.prev_retract = '' - self.prev_z = '' - self.useCrc = False - self.useCrcCenterline = False - self.gCRC = '' - self.fmt = Format() - self.absolute_flag = True - self.ffmt = Format(number_of_decimal_places = 2) - self.sfmt = Format(number_of_decimal_places = 1) - self.in_quadrant_splitting = False - self.in_canned_cycle = False - self.first_drill_pos = True - self.shift_x = 0.0 - self.shift_y = 0.0 - self.shift_z = 0.0 - self.start_of_line = False - self.internal_coolant_on = None - self.g98_not_g99 = None # True for G98 ouput, False for G99 output - self.current_fixture = None - self.fixture_wanted = '54' - self.move_done_since_tool_change = False - self.tool_defn_params = {} - self.program_id = None - self.current_sub_id = None - self.subroutine_files = [] - self.program_name = None - self.temp_file_to_append_on_close = None - self.fixture_order = ['54', '55', '56', '57', '58', '59'] - for i in range(1, 50): - self.fixture_order.append('54.' + str(i)) - self.output_disabled = False - self.z_for_g43 = None - - # optional settings - self.arc_centre_absolute = False - self.arc_centre_positive = False - self.drillExpanded = False - self.dwell_allowed_in_G83 = False - self.can_do_helical_arcs = True - self.z_for_g53 = None # set this to a value to output G53 Zvalue in tool change and at program end - self.output_h_and_d_at_tool_change = False - self.output_block_numbers = True - self.start_block_number = 10 - self.block_number_increment = 10 - self.block_number_restart_after = None - self.output_tool_definitions = True - self.output_tool_change = True - self.output_g43_on_tool_change_line = False - self.output_internal_coolant_commands = False - self.output_g98_and_g99 = True - self.output_g43_z_before_drilling_if_g98 = False - self.output_cutviewer_comments = False - self.output_fixtures = False - self.use_this_program_id = None - self.subroutines_in_own_files = False - self.pattern_done_with_subroutine = False - self.output_comment_before_tool_change = True - self.output_arcs_as_lines = False - self.m_codes_on_their_own_line = False - - ############################################################################ - ## Codes - - def SPACE_STR(self): return '' - def SPACE(self): - if self.start_of_line == True: - self.start_of_line = False - return '' - else: - return self.SPACE_STR() - - def FORMAT_FEEDRATE(self): return('%.2f') - def FORMAT_ANG(self): return('%.1f') - def FORMAT_TIME(self): return self.fmt - - def BLOCK(self): return('N%i') - def COMMENT(self,comment): return( ('(%s)' % comment ) ) - def VARIABLE(self): return( '#%i') - def VARIABLE_SET(self): return( '=%.3f') - - def PROGRAM(self): return( 'O%i') - def PROGRAM_END(self): return( 'M02') - - def SUBPROG_CALL(self): return( 'M98' + self.SPACE() + 'P%i') - def SUBPROG_END(self): return( 'M99') - - def STOP_OPTIONAL(self): return('M01') - def STOP(self): return('M00') - - def IMPERIAL(self): return('G20') - def METRIC(self): return('G21') - def ABSOLUTE(self): return('G90') - def INCREMENTAL(self): return('G91') - def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92') - def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1') - def POLAR_ON(self): return('G16') - def POLAR_OFF(self): return('G15') - def PLANE_XY(self): return('17') - def PLANE_XZ(self): return('18') - def PLANE_YZ(self): return('19') - - def TOOL(self): return('T%i' + self.SPACE() + 'M06') - def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1') - - def WORKPLANE(self): return('G%i') - def WORKPLANE_BASE(self): return(53) - - def SPINDLE_CW(self): return('M03') - def SPINDLE_CCW(self): return('M04') - def COOLANT_OFF(self): return('M09') - def COOLANT_MIST(self): return('M07') - def COOLANT_FLOOD(self): return('M08') - def GEAR_OFF(self): return('?') - def GEAR(self): return('M%i') - def GEAR_BASE(self): return(37) - - def RAPID(self): return('G00') - def FEED(self): return('G01') - def ARC_CW(self): return('G02') - def ARC_CCW(self): return('G03') - def DWELL(self, dwell): return('G04' + self.SPACE() + self.TIME() + (self.FORMAT_TIME().string(dwell))) - def DRILL(self): return('G81') - def DRILL_WITH_DWELL(self, dwell): return('G82' + self.SPACE() + self.TIME() + (self.FORMAT_TIME().string(dwell))) - def PECK_DRILL(self): return('G83') - def PECK_DEPTH(self, depth): return('Q' + (self.fmt.string(depth))) - def RETRACT(self, height): return('R' + (self.fmt.string(height))) - def END_CANNED_CYCLE(self): return('G80') - def TAP(self): return('G84') - def TAP_DEPTH(self, depth): return('K' + (self.fmt.string(depth))) - def INTERNAL_COOLANT_ON(self): return('M18') - def INTERNAL_COOLANT_OFF(self): return('M9') - - def X(self): return('X') - def Y(self): return('Y') - def Z(self): return('Z') - def A(self): return('A') - def B(self): return('B') - def C(self): return('C') - def CENTRE_X(self): return('I') - def CENTRE_Y(self): return('J') - def CENTRE_Z(self): return('K') - def RADIUS(self): return('R') - def TIME(self): return('P') - - def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2') - def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3') - def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4') - def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5') - - def MACHINE_COORDINATES(self): return('G53') - - def EXACT_PATH_MODE(self): return('G61') - def EXACT_STOP_MODE(self): return('G61.1') - - def RETRACT_TO_CLEARANCE(self): return('G98') - def RETRACT_TO_STANDOFF(self): return('G99') - - ############################################################################ - ## Internals - def write(self, s): - if self.output_disabled == False: - nc.Creator.write(self, s) - if '\n' in s: - self.start_of_line = s[-1] == '\n' - - def write_feedrate(self): - self.f.write(self) - - def write_preps(self): - i = 0 - if self.g_plane.str: - i += 1 - self.g_plane.write(self) - for g in self.g_list: - if i > 0: - self.write('\n' if self.m_codes_on_their_own_line else self.SPACE()) - self.write(g) - i += 1 - self.g_list = [] - - def write_misc(self): - if (len(self.m)): - self.write('\n' if self.m_codes_on_their_own_line else self.SPACE()) - self.write(self.m.pop()) - - def write_spindle(self): - if self.s.str: - self.write('\n' if self.m_codes_on_their_own_line else '') - self.s.write(self) - - def output_fixture(self): - if self.current_fixture != self.fixture_wanted: - self.current_fixture = self.fixture_wanted - self.g_list.append('G' + str(self.current_fixture)) - - def increment_fixture(self): - for i in range(0, len(self.fixture_order) - 1): - if self.fixture_order[i] == self.fixture_wanted: - self.fixture_wanted = self.fixture_order[i+1] - return - raise 'too many fixtures wanted!' - - def get_fixture(self): - return self.fixture_wanted - - def set_fixture(self, fixture): - self.fixture_wanted = fixture - - ############################################################################ - ## Programs - - def program_begin(self, id, name=''): - if self.use_this_program_id: - id = self.use_this_program_id - if self.PROGRAM() != None: - self.writem([(self.PROGRAM() % id), self.SPACE(), (self.COMMENT(name))]) - self.write('\n') - self.program_id = id - self.program_name = name - - def add_stock(self, type_name, params): - if self.output_cutviewer_comments: - self.write("(STOCK/" + type_name) - for param in params: - self.write(",") - self.write(str(param)) - self.write(")\n") - - def program_stop(self, optional=False): - if (optional) : - self.write(self.SPACE() + self.STOP_OPTIONAL() + '\n') - self.prev_g0123 = '' - else : - self.write(self.STOP() + '\n') - self.prev_g0123 = '' - - def number_file(self, filename): - import tempfile - temp_filename = tempfile.gettempdir()+'/renumbering.txt' - - # make a copy of file - f_in = open(filename, 'r') - f_out = open(temp_filename, 'w') - while (True): - line = f_in.readline() - if (len(line) == 0) : break - f_out.write(line) - f_in.close() - f_out.close() - - # read copy - f_in = open(temp_filename, 'r') - f_out = open(filename, 'w') - n = self.start_block_number - while (True): - line = f_in.readline() - - if (len(line) == 0) : break - f_out.write(self.BLOCK() % n + self.SPACE() + line) - n += self.block_number_increment - if self.block_number_restart_after != None: - if n >= self.block_number_restart_after: - n = self.start_block_number - f_in.close() - f_out.close() - - def program_end(self): - if self.z_for_g53 != None: - self.write(self.SPACE() + self.MACHINE_COORDINATES() + self.SPACE() + 'Z' + self.fmt.string(self.z_for_g53) + '\n') - self.write(self.SPACE() + self.PROGRAM_END() + '\n') - - if self.temp_file_to_append_on_close != None: - f_in = open(self.temp_file_to_append_on_close, 'r') - while (True): - line = f_in.readline() - if (len(line) == 0) : break - self.write(line) - f_in.close() - - self.file_close() - - if self.output_block_numbers: - # number every line of the file afterwards - self.number_file(self.filename) - - for f in self.subroutine_files: - self.number_file(f) - - def flush_nc(self): - if len(self.g_list) == 0 and len(self.m) == 0: return - self.write_preps() - self.write_misc() - self.write('\n') - - ############################################################################ - ## Subprograms - - def make_subroutine_name(self, id): - s = self.filename - for i in reversed(range(0, len(s))): - if s[i] == '.': - return s[0:i] + 'sub' + str(id) + s[i:] - - # '.' not found - return s + 'sub' + str(id) - - def sub_begin(self, id, name=None): - if id == None: - if self.current_sub_id == None: - self.current_sub_id = self.program_id - self.current_sub_id += 1 - id = self.current_sub_id - - if name == None: - name = self.program_name + ' subroutine ' + str(id) - - self.save_file = self.file - if self.subroutines_in_own_files: - new_name = self.make_subroutine_name(id) - self.file = open(new_name, 'w') - self.subroutine_files.append(new_name) - else: - ## use temporary file - import tempfile - temp_filename = tempfile.gettempdir()+'/subroutines.txt' - if self.temp_file_to_append_on_close == None: - self.temp_file_to_append_on_close = temp_filename - self.file = open(temp_filename, 'w') - else: - self.file = open(temp_filename, 'a') - - if self.PROGRAM() != None: - self.write((self.PROGRAM() % id) + self.SPACE() + (self.COMMENT(name))) - self.write('\n') - - def sub_call(self, id): - if id == None: - id = self.current_sub_id - self.write(self.SPACE() + (self.SUBPROG_CALL() % id) + '\n') - - def sub_end(self): - self.write(self.SPACE() + self.SUBPROG_END() + '\n') - - self.file.close() - self.file = self.save_file - - def disable_output(self): - self.output_disabled = True - - def enable_output(self): - self.output_disabled = False - - ############################################################################ - ## Settings - - def imperial(self): - self.g_list.append(self.IMPERIAL()) - self.fmt.number_of_decimal_places = 4 - - def metric(self): - self.g_list.append(self.METRIC()) - self.fmt.number_of_decimal_places = 3 - - def absolute(self): - self.g_list.append(self.ABSOLUTE()) - self.absolute_flag = True - - def incremental(self): - self.g_list.append(self.INCREMENTAL()) - self.absolute_flag = False - - def polar(self, on=True): - if (on) : self.g_list.append(self.POLAR_ON()) - else : self.g_list.append(self.POLAR_OFF()) - - def set_plane(self, plane): - if (plane == 0) : self.g_plane.set(self.PLANE_XY()) - elif (plane == 1) : self.g_plane.set(self.PLANE_XZ()) - elif (plane == 2) : self.g_plane.set(self.PLANE_YZ()) - - def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): - self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM())) - if (x != None): self.write( self.SPACE() + 'X ' + (self.fmt.string(x + self.shift_x)) ) - if (y != None): self.write( self.SPACE() + 'Y ' + (self.fmt.string(y + self.shift_y)) ) - if (z != None): self.write( self.SPACE() + 'Z ' + (self.fmt.string(z + self.shift_z)) ) - if (a != None): self.write( self.SPACE() + 'A ' + (self.fmt.string(a)) ) - if (b != None): self.write( self.SPACE() + 'B ' + (self.fmt.string(b)) ) - if (c != None): self.write( self.SPACE() + 'C ' + (self.fmt.string(c)) ) - self.write('\n') - - def remove_temporary_origin(self): - self.write(self.SPACE() + (self.REMOVE_TEMPORARY_COORDINATE_SYSTEM())) - self.write('\n') - ############################################################################ - ## new graphics origin- make a new coordinate system and snap it onto the geometry - ## the toolpath generated should be translated - def translate(self,x=None, y=None, z=None): - self.shift_x = -x - self.shift_y = -y - self.shift_z = -z - - ############################################################################ - ## Tools - - def tool_change(self, id): - if self.output_comment_before_tool_change: - if id in self.tool_defn_params: - self.comment('tool change to ' + self.tool_defn_params[id]['name']); - - if self.output_cutviewer_comments: - import cutviewer - if id in self.tool_defn_params: - cutviewer.tool_defn(self, id, self.tool_defn_params[id]) - if (self.t != None) and (self.z_for_g53 != None): - self.write('G53 Z' + str(self.z_for_g53) + '\n') - self.write(self.SPACE() + (self.TOOL() % id)) - if self.output_g43_on_tool_change_line == True: - self.write(self.SPACE() + 'G43') - self.write('\n') - if self.output_h_and_d_at_tool_change == True: - if self.output_g43_on_tool_change_line == False: - self.write(self.SPACE() + 'G43') - self.write(self.SPACE() + 'D' + str(id) + self.SPACE() + 'H' + str(id) + '\n') - self.t = id - self.move_done_since_tool_change = False - - def tool_defn(self, id, name='',params=None): - self.tool_defn_params[id] = params - if self.output_tool_definitions: - self.write(self.SPACE() + self.TOOL_DEFINITION()) - self.write(self.SPACE() + ('P%i' % id) + ' ') - - if (params['diameter'] != None): - self.write(self.SPACE() + ('R%.3f' % (float(params['diameter'])/2))) - - if (params['cutting edge height'] != None): - self.write(self.SPACE() + 'Z%.3f' % float(params['cutting edge height'])) - - self.write('\n') - - def offset_radius(self, id, radius=None): - pass - - def offset_length(self, id, length=None): - pass - - def current_tool(self): - return self.t - - - ############################################################################ - ## Datums - - def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 - # These are selected by values from 1 to 9 inclusive. - def workplane(self, id): - if ((id >= 1) and (id <= 6)): - self.g_list.append(self.WORKPLANE() % (id + self.WORKPLANE_BASE())) - if ((id >= 7) and (id <= 9)): - self.g_list.append(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) - - - ############################################################################ - ## Rates + Modes - - def feedrate(self, f): - self.f.set(f) - self.fhv = False - - def feedrate_hv(self, fh, fv): - self.fh = fh - self.fv = fv - self.fhv = True - - def calc_feedrate_hv(self, h, v): - if math.fabs(v) > math.fabs(h * 2): - # some horizontal, so it should be fine to use the horizontal feed rate - self.f.set(self.fv) - else: - # not much, if any horizontal component, so use the vertical feed rate - self.f.set(self.fh) - - def spindle(self, s, clockwise): - if clockwise == True: - self.s.set(s, self.SPINDLE_CW(), self.SPINDLE_CCW()) - else: - self.s.set(s, self.SPINDLE_CCW(), self.SPINDLE_CW()) - - def coolant(self, mode=0): - if (mode <= 0) : self.m.append(self.COOLANT_OFF()) - elif (mode == 1) : self.m.append(self.COOLANT_MIST()) - elif (mode == 2) : self.m.append(self.COOLANT_FLOOD()) - - def gearrange(self, gear=0): - if (gear <= 0) : self.m.append(self.GEAR_OFF()) - elif (gear <= 4) : self.m.append(self.GEAR() % (gear + GEAR_BASE())) - - ############################################################################ - ## Moves - - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ): - (x, y, z, a, b, c,axis_count)=self.filter_xyz(x, y, z, a, b, c) - if axis_count==0: return - self.on_move() - - if self.g0123_modal: - if self.prev_g0123 != self.RAPID(): - self.write(self.SPACE() + self.RAPID()) - self.prev_g0123 = self.RAPID() - else: - self.write(self.SPACE() + self.RAPID()) - self.write_preps() - if (x != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - else: - dx = x - self.x - self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) - self.x = x - if (y != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - else: - dy = y - self.y - self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) - - self.y = y - if (z != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) - else: - dz = z - self.z - self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) - - self.z = z - - if (a != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.A() + (self.fmt.string(a))) - else: - da = a - self.a - self.write(self.SPACE() + self.A() + (self.fmt.string(da))) - self.a = a - - if (b != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.B() + (self.fmt.string(b))) - else: - db = b - self.b - self.write(self.SPACE() + self.B() + (self.fmt.string(db))) - self.b = b - - if (c != None): - if (self.absolute_flag ): - self.write(self.SPACE() + self.C() + (self.fmt.string(c))) - else: - dc = c - self.c - self.write(self.SPACE() + self.C() + (self.fmt.string(dc))) - self.c = c - self.write_spindle() - self.write_misc() - self.write('\n') - - def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - (x, y, z, a, b, c,axis_count)=self.filter_xyz(x, y, z, a, b, c) - if axis_count==0: return - self.on_move() - if self.g0123_modal: - if self.prev_g0123 != self.FEED(): - self.writem([self.SPACE() , self.FEED()]) - self.prev_g0123 = self.FEED() - else: - self.write(self.SPACE() + self.FEED()) - self.write_preps() - dx = dy = dz = 0 - if (x != None): - dx = x - self.x - if (self.absolute_flag ): - self.writem([self.SPACE() , self.X() , (self.fmt.string(x + self.shift_x))]) - else: - self.writem([self.SPACE() , self.X() , (self.fmt.string(dx))]) - self.x = x - if (y != None): - dy = y - self.y - if (self.absolute_flag ): - self.writem([self.SPACE() , self.Y() , (self.fmt.string(y + self.shift_y))]) - else: - self.writem([self.SPACE() , self.Y() , (self.fmt.string(dy))]) - - self.y = y - if (z != None): - dz = z - self.z - if (self.absolute_flag ): - self.writem([self.SPACE() , self.Z() , (self.fmt.string(z + self.shift_z))]) - else: - self.writem([self.SPACE() , self.Z() , (self.fmt.string(dz))]) - - self.z = z - - if (a != None): - da = a - self.a - if (self.absolute_flag ): - self.writem([self.SPACE() , self.A() , (self.fmt.string(a))]) - else: - self.writem([self.SPACE() , self.A() , (self.fmt.string(da))]) - self.a = a - - if (b != None): - db = b - self.b - if (self.absolute_flag ): - self.writem([self.SPACE() , self.B() , (self.fmt.string(b))]) - else: - self.writem([self.SPACE() , self.B() , (self.fmt.string(db))]) - self.b = b - - if (c != None): - dc = c - self.c - if (self.absolute_flag ): - self.writem([self.SPACE() , self.C() , (self.fmt.string(c))]) - else: - self.writem([self.SPACE() , self.C() , (self.fmt.string(dc))]) - self.c = c - - if (self.fhv) : self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - - def filter_xyz(self, x=None, y=None, z=None, a=None, b=None, c=None): - """ Check if x,y,z,a,b,c are the same and set them to None if they are - return value = (x,y,z,a,b,c,count) where count is the number of - axis moves left. - """ - rv = [x,y,z,a,b,c,0] - comparisons = ((x,self.shift_x,self.x),(y,self.shift_y,self.y),(z,self.shift_z,self.z), - (a,0,self.a),(b,0,self.b),(c,0,self.c)) - - for i,(new_val,shift,current_val) in enumerate(comparisons): - if new_val is not None: - if self.fmt.string(new_val+shift) == self.fmt.string(current_val): - rv[i]=None - else: - rv[6]+=1 - return rv - - - def get_quadrant(self, dx, dy): - if dx < 0: - if dy < 0: - return 2 - else: - return 1 - - else: - if dy < 0: - return 3 - else: - return 0 - - def quadrant_start(self, q, i, j, rad): - while q > 3: q = q - 4 - if q == 0: - return i + rad, j - if q == 1: - return i, j + rad - if q == 2: - return i - rad, j - return i, j - rad - - def quadrant_end(self, q, i, j, rad): - return self.quadrant_start(q + 1, i, j, rad) - - def get_arc_angle(self, sdx, sdy, edx, edy, cw): - angle_s = math.atan2(sdy, sdx); - angle_e = math.atan2(edy, edx); - if cw: - if angle_s < angle_e: angle_s = angle_s + 2 * math.pi - else: - if angle_e < angle_s: angle_e = angle_e + 2 * math.pi - return angle_e - angle_s - - def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - (x,y,z,_,_,_,axis_count) = self.filter_xyz(x,y,z) - if axis_count==0: return - - if self.output_arcs_as_lines or (self.can_do_helical_arcs == False and self.in_quadrant_splitting == False and (z != None) and (math.fabs(z - self.z) > 0.000001) and (self.fmt.string(z) != self.fmt.string(self.z))): - # split the helical arc into little line feed moves - - if x == None: x = self.x - if y == None: y = self.y - sdx = self.x - i - sdy = self.y - j - edx = x - i - edy = y - j - radius = math.sqrt(sdx*sdx + sdy*sdy) - arc_angle = self.get_arc_angle(sdx, sdy, edx, edy, cw) - angle_start = math.atan2(sdy, sdx); - tolerance = 0.02 - angle_step = 2.0 * math.atan( math.sqrt ( tolerance /(radius - tolerance) )) - segments = int(math.fabs(arc_angle / angle_step) + 1) - angle_step = arc_angle / segments - angle = angle_start - if z != None: - z_step = float(z - self.z)/segments - next_z = self.z - - for p in range(0, segments): - angle = angle + angle_step - next_x = i + radius * math.cos(angle) - next_y = j + radius * math.sin(angle) - if z == None: - next_z = None - else: - next_z = next_z + z_step - self.feed(next_x, next_y, next_z) - return - - if self.arc_centre_positive == True and self.in_quadrant_splitting == False: - # split in to quadrant arcs - self.in_quadrant_splitting = True - - if x == None: x = self.x - if y == None: y = self.y - sdx = self.x - i - sdy = self.y - j - edx = x - i - edy = y - j - - qs = self.get_quadrant(sdx, sdy) - qe = self.get_quadrant(edx, edy) - - if qs == qe: - arc_angle = math.fabs(self.get_arc_angle(sdx, sdy, edx, edy, cw)) - # arc_angle will be either less than pi/2 or greater than 3pi/2 - if arc_angle > 3.14: - if cw: - qs = qs + 4 - else: - qe = qe + 4 - - if qs == qe: - self.arc(cw, x, y, z, i, j, k, r) - else: - rad = math.sqrt(sdx * sdx + sdy * sdy) - if cw: - if qs < qe: qs = qs + 4 - else: - if qe < qs: qe = qe + 4 - - q = qs - while 1: - x1 = x - y1 = y - if q != qe: - if cw: - x1, y1 = self.quadrant_start(q, i, j, rad) - else: - x1, y1 = self.quadrant_end(q, i, j, rad) - - if (self.fmt.string(x1) != self.fmt.string(self.x)) or (self.fmt.string(y1) != self.fmt.string(self.y)): - if (math.fabs(x1 - self.x) > 0.01) or (math.fabs(y1 - self.y) > 0.01): - self.arc(cw, x1, y1, z, i, j, k, r) - else: - self.feed(x1, y1, z) - if q == qe: - break - if cw: - q = q - 1 - else: - q = q + 1 - - self.in_quadrant_splitting = False - return - - self.on_move() - arc_g_code = '' - if cw: arc_g_code = self.ARC_CW() - else: arc_g_code = self.ARC_CCW() - if self.g0123_modal: - if self.prev_g0123 != arc_g_code: - self.write(self.SPACE() + arc_g_code) - self.prev_g0123 = arc_g_code - else: - self.write(self.SPACE() + arc_g_code) - self.write_preps() - if (x != None): - dx = x - self.x - if (self.absolute_flag ): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - else: - self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) - if (y != None): - dy = y - self.y - if (self.absolute_flag ): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - else: - self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) - if (z != None): - dz = z - self.z - if (self.absolute_flag ): - self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) - if (i != None): - if self.arc_centre_absolute == False: - i = i - self.x - s = self.fmt.string(i) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_X() + s) - if (j != None): - if self.arc_centre_absolute == False: - j = j - self.y - s = self.fmt.string(j) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_Y() + s) - if (k != None): - if self.arc_centre_absolute == False: - k = k - self.z - s = self.fmt.string(k) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.CENTRE_Z() + s) - if (r != None): - s = self.fmt.string(r) - if self.arc_centre_positive == True: - if s[0] == '-': - s = s[1:] - self.write(self.SPACE() + self.RADIUS() + s) + def __init__(self): + nc.Creator.__init__(self) + + # internal variables + self.a = 0 + self.b = 0 + self.c = 0 + self.f = Address('F', fmt=Format(number_of_decimal_places=2)) + self.fh = None + self.fv = None + self.fhv = False + self.g_plane = Address('G', fmt=Format(number_of_decimal_places=0)) + self.g_list = [] + self.i = 0 + self.j = 0 + self.k = 0 + self.m = [] + self.r = 0 + self.s = AddressPlusMinus('S', fmt=Format(number_of_decimal_places=2), modal=False) + self.t = None + self.x = None + self.y = None + self.z = None + self.g0123_modal = False + self.drill_modal = False + self.prev_f = '' + self.prev_g0123 = '' + self.prev_drill = '' + self.prev_retract = '' + self.prev_z = '' + self.useCrc = False + self.useCrcCenterline = False + self.gCRC = '' + self.fmt = Format() + self.absolute_flag = True + self.ffmt = Format(number_of_decimal_places=2) + self.sfmt = Format(number_of_decimal_places=1) + self.in_quadrant_splitting = False + self.in_canned_cycle = False + self.first_drill_pos = True + self.shift_x = 0.0 + self.shift_y = 0.0 + self.shift_z = 0.0 + self.start_of_line = False + self.internal_coolant_on = None + self.g98_not_g99 = None # True for G98 ouput, False for G99 output + self.current_fixture = None + self.fixture_wanted = '54' + self.move_done_since_tool_change = False + self.tool_defn_params = {} + self.program_id = None + self.current_sub_id = None + self.subroutine_files = [] + self.program_name = None + self.temp_file_to_append_on_close = None + self.fixture_order = ['54', '55', '56', '57', '58', '59'] + for i in range(1, 50): + self.fixture_order.append('54.' + str(i)) + self.output_disabled = False + self.z_for_g43 = None + + # optional settings + self.arc_centre_absolute = False + self.arc_centre_positive = False + self.drillExpanded = False + self.dwell_allowed_in_G83 = False + self.can_do_helical_arcs = True + self.z_for_g53 = None # set this to a value to output G53 Zvalue in tool change and at program end + self.output_h_and_d_at_tool_change = False + self.output_block_numbers = True + self.start_block_number = 10 + self.block_number_increment = 10 + self.block_number_restart_after = None + self.output_tool_definitions = True + self.output_tool_change = True + self.output_g43_on_tool_change_line = False + self.output_internal_coolant_commands = False + self.output_g98_and_g99 = True + self.output_g43_z_before_drilling_if_g98 = False + self.output_cutviewer_comments = False + self.output_fixtures = False + self.use_this_program_id = None + self.subroutines_in_own_files = False + self.pattern_done_with_subroutine = False + self.output_comment_before_tool_change = True + self.output_arcs_as_lines = False + self.m_codes_on_their_own_line = False + + ############################################################################ + # Codes + + def SPACE_STR(self): return '' + + def SPACE(self): + if self.start_of_line == True: + self.start_of_line = False + return '' + else: + return self.SPACE_STR() + + def FORMAT_FEEDRATE(self): return('%.2f') + def FORMAT_ANG(self): return('%.1f') + def FORMAT_TIME(self): return self.fmt + + def BLOCK(self): return('N%i') + def COMMENT(self, comment): return(('(%s)' % comment)) + def VARIABLE(self): return('#%i') + def VARIABLE_SET(self): return('=%.3f') + + def PROGRAM(self): return('O%i') + def PROGRAM_END(self): return('M02') + + def SUBPROG_CALL(self): return('M98' + self.SPACE() + 'P%i') + def SUBPROG_END(self): return('M99') + + def STOP_OPTIONAL(self): return('M01') + def STOP(self): return('M00') + + def IMPERIAL(self): return('G20') + def METRIC(self): return('G21') + def ABSOLUTE(self): return('G90') + def INCREMENTAL(self): return('G91') + def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92') + def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1') + def POLAR_ON(self): return('G16') + def POLAR_OFF(self): return('G15') + def PLANE_XY(self): return('17') + def PLANE_XZ(self): return('18') + def PLANE_YZ(self): return('19') + + def TOOL(self): return('T%i' + self.SPACE() + 'M06') + def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1') + + def WORKPLANE(self): return('G%i') + def WORKPLANE_BASE(self): return(53) + + def SPINDLE_CW(self): return('M03') + def SPINDLE_CCW(self): return('M04') + def COOLANT_OFF(self): return('M09') + def COOLANT_MIST(self): return('M07') + def COOLANT_FLOOD(self): return('M08') + def GEAR_OFF(self): return('?') + def GEAR(self): return('M%i') + def GEAR_BASE(self): return(37) + + def RAPID(self): return('G00') + def FEED(self): return('G01') + def ARC_CW(self): return('G02') + def ARC_CCW(self): return('G03') + def DWELL(self, dwell): return('G04' + self.SPACE() + + self.TIME() + (self.FORMAT_TIME().string(dwell))) + + def DRILL(self): return('G81') + def DRILL_WITH_DWELL(self, dwell): return('G82' + self.SPACE() + + self.TIME() + (self.FORMAT_TIME().string(dwell))) + + def PECK_DRILL(self): return('G83') + def PECK_DEPTH(self, depth): return('Q' + (self.fmt.string(depth))) + def RETRACT(self, height): return('R' + (self.fmt.string(height))) + def END_CANNED_CYCLE(self): return('G80') + def TAP(self): return('G84') + def TAP_DEPTH(self, depth): return('K' + (self.fmt.string(depth))) + def INTERNAL_COOLANT_ON(self): return('M18') + def INTERNAL_COOLANT_OFF(self): return('M9') + + def X(self): return('X') + def Y(self): return('Y') + def Z(self): return('Z') + def A(self): return('A') + def B(self): return('B') + def C(self): return('C') + def CENTRE_X(self): return('I') + def CENTRE_Y(self): return('J') + def CENTRE_Z(self): return('K') + def RADIUS(self): return('R') + def TIME(self): return('P') + + def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2') + def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3') + def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4') + def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5') + + def MACHINE_COORDINATES(self): return('G53') + + def EXACT_PATH_MODE(self): return('G61') + def EXACT_STOP_MODE(self): return('G61.1') + + def RETRACT_TO_CLEARANCE(self): return('G98') + def RETRACT_TO_STANDOFF(self): return('G99') + + ############################################################################ + # Internals + def write(self, s): + if self.output_disabled == False: + nc.Creator.write(self, s) + if '\n' in s: + self.start_of_line = s[-1] == '\n' + + def write_feedrate(self): + self.f.write(self) + + def write_preps(self): + i = 0 + if self.g_plane.str: + i += 1 + self.g_plane.write(self) + for g in self.g_list: + if i > 0: + self.write('\n' if self.m_codes_on_their_own_line else self.SPACE()) + self.write(g) + i += 1 + self.g_list = [] + + def write_misc(self): + if (len(self.m)): + self.write('\n' if self.m_codes_on_their_own_line else self.SPACE()) + self.write(self.m.pop()) + + def write_spindle(self): + if self.s.str: + self.write('\n' if self.m_codes_on_their_own_line else '') + self.s.write(self) + + def output_fixture(self): + if self.current_fixture != self.fixture_wanted: + self.current_fixture = self.fixture_wanted + self.g_list.append('G' + str(self.current_fixture)) + + def increment_fixture(self): + for i in range(0, len(self.fixture_order) - 1): + if self.fixture_order[i] == self.fixture_wanted: + self.fixture_wanted = self.fixture_order[i+1] + return + raise 'too many fixtures wanted!' + + def get_fixture(self): + return self.fixture_wanted + + def set_fixture(self, fixture): + self.fixture_wanted = fixture + + ############################################################################ + # Programs + + def program_begin(self, id, name=''): + if self.use_this_program_id: + id = self.use_this_program_id + if self.PROGRAM() != None: + self.writem([(self.PROGRAM() % id), self.SPACE(), (self.COMMENT(name))]) + self.write('\n') + self.program_id = id + self.program_name = name + + def add_stock(self, type_name, params): + if self.output_cutviewer_comments: + self.write("(STOCK/" + type_name) + for param in params: + self.write(",") + self.write(str(param)) + self.write(")\n") + + def program_stop(self, optional=False): + if (optional): + self.write(self.SPACE() + self.STOP_OPTIONAL() + '\n') + self.prev_g0123 = '' + else: + self.write(self.STOP() + '\n') + self.prev_g0123 = '' + + def number_file(self, filename): + import tempfile + temp_filename = tempfile.gettempdir()+'/renumbering.txt' + + # make a copy of file + f_in = open(filename, 'r') + f_out = open(temp_filename, 'w') + while (True): + line = f_in.readline() + if (len(line) == 0): + break + f_out.write(line) + f_in.close() + f_out.close() + + # read copy + f_in = open(temp_filename, 'r') + f_out = open(filename, 'w') + n = self.start_block_number + while (True): + line = f_in.readline() + + if (len(line) == 0): + break + f_out.write(self.BLOCK() % n + self.SPACE() + line) + n += self.block_number_increment + if self.block_number_restart_after != None: + if n >= self.block_number_restart_after: + n = self.start_block_number + f_in.close() + f_out.close() + + def program_end(self): + if self.z_for_g53 != None: + self.write(self.SPACE() + self.MACHINE_COORDINATES() + + self.SPACE() + 'Z' + self.fmt.string(self.z_for_g53) + '\n') + self.write(self.SPACE() + self.PROGRAM_END() + '\n') + + if self.temp_file_to_append_on_close != None: + f_in = open(self.temp_file_to_append_on_close, 'r') + while (True): + line = f_in.readline() + if (len(line) == 0): + break + self.write(line) + f_in.close() + + self.file_close() + + if self.output_block_numbers: + # number every line of the file afterwards + self.number_file(self.filename) + + for f in self.subroutine_files: + self.number_file(f) + + def flush_nc(self): + if len(self.g_list) == 0 and len(self.m) == 0: + return + self.write_preps() + self.write_misc() + self.write('\n') + + ############################################################################ + # Subprograms + + def make_subroutine_name(self, id): + s = self.filename + for i in reversed(range(0, len(s))): + if s[i] == '.': + return s[0:i] + 'sub' + str(id) + s[i:] + + # '.' not found + return s + 'sub' + str(id) + + def sub_begin(self, id, name=None): + if id == None: + if self.current_sub_id == None: + self.current_sub_id = self.program_id + self.current_sub_id += 1 + id = self.current_sub_id + + if name == None: + name = self.program_name + ' subroutine ' + str(id) + + self.save_file = self.file + if self.subroutines_in_own_files: + new_name = self.make_subroutine_name(id) + self.file = open(new_name, 'w') + self.subroutine_files.append(new_name) + else: + # use temporary file + import tempfile + temp_filename = tempfile.gettempdir()+'/subroutines.txt' + if self.temp_file_to_append_on_close == None: + self.temp_file_to_append_on_close = temp_filename + self.file = open(temp_filename, 'w') + else: + self.file = open(temp_filename, 'a') + + if self.PROGRAM() != None: + self.write((self.PROGRAM() % id) + self.SPACE() + (self.COMMENT(name))) + self.write('\n') + + def sub_call(self, id): + if id == None: + id = self.current_sub_id + self.write(self.SPACE() + (self.SUBPROG_CALL() % id) + '\n') + + def sub_end(self): + self.write(self.SPACE() + self.SUBPROG_END() + '\n') + + self.file.close() + self.file = self.save_file + + def disable_output(self): + self.output_disabled = True + + def enable_output(self): + self.output_disabled = False + + ############################################################################ + # Settings + + def imperial(self): + self.g_list.append(self.IMPERIAL()) + self.fmt.number_of_decimal_places = 4 + + def metric(self): + self.g_list.append(self.METRIC()) + self.fmt.number_of_decimal_places = 3 + + def absolute(self): + self.g_list.append(self.ABSOLUTE()) + self.absolute_flag = True + + def incremental(self): + self.g_list.append(self.INCREMENTAL()) + self.absolute_flag = False + + def polar(self, on=True): + if (on): + self.g_list.append(self.POLAR_ON()) + else: + self.g_list.append(self.POLAR_OFF()) + + def set_plane(self, plane): + if (plane == 0): + self.g_plane.set(self.PLANE_XY()) + elif (plane == 1): + self.g_plane.set(self.PLANE_XZ()) + elif (plane == 2): + self.g_plane.set(self.PLANE_YZ()) + + def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): + self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM())) + if (x != None): + self.write(self.SPACE() + 'X ' + (self.fmt.string(x + self.shift_x))) + if (y != None): + self.write(self.SPACE() + 'Y ' + (self.fmt.string(y + self.shift_y))) + if (z != None): + self.write(self.SPACE() + 'Z ' + (self.fmt.string(z + self.shift_z))) + if (a != None): + self.write(self.SPACE() + 'A ' + (self.fmt.string(a))) + if (b != None): + self.write(self.SPACE() + 'B ' + (self.fmt.string(b))) + if (c != None): + self.write(self.SPACE() + 'C ' + (self.fmt.string(c))) + self.write('\n') + + def remove_temporary_origin(self): + self.write(self.SPACE() + (self.REMOVE_TEMPORARY_COORDINATE_SYSTEM())) + self.write('\n') + ############################################################################ + # new graphics origin- make a new coordinate system and snap it onto the geometry + # the toolpath generated should be translated + + def translate(self, x=None, y=None, z=None): + self.shift_x = -x + self.shift_y = -y + self.shift_z = -z + + ############################################################################ + # Tools + + def tool_change(self, id): + if self.output_comment_before_tool_change: + if id in self.tool_defn_params: + self.comment('tool change to ' + self.tool_defn_params[id]['name']) + + if self.output_cutviewer_comments: + import cutviewer + if id in self.tool_defn_params: + cutviewer.tool_defn(self, id, self.tool_defn_params[id]) + if (self.t != None) and (self.z_for_g53 != None): + self.write('G53 Z' + str(self.z_for_g53) + '\n') + self.write(self.SPACE() + (self.TOOL() % id)) + if self.output_g43_on_tool_change_line == True: + self.write(self.SPACE() + 'G43') + self.write('\n') + if self.output_h_and_d_at_tool_change == True: + if self.output_g43_on_tool_change_line == False: + self.write(self.SPACE() + 'G43') + self.write(self.SPACE() + 'D' + str(id) + self.SPACE() + 'H' + str(id) + '\n') + self.t = id + self.move_done_since_tool_change = False + + def tool_defn(self, id, name='', params=None): + self.tool_defn_params[id] = params + if self.output_tool_definitions: + self.write(self.SPACE() + self.TOOL_DEFINITION()) + self.write(self.SPACE() + ('P%i' % id) + ' ') + + if (params['diameter'] != None): + self.write(self.SPACE() + ('R%.3f' % (float(params['diameter'])/2))) + + if (params['cutting edge height'] != None): + self.write(self.SPACE() + 'Z%.3f' % float(params['cutting edge height'])) + + self.write('\n') + + def offset_radius(self, id, radius=None): + pass + + def offset_length(self, id, length=None): + pass + + def current_tool(self): + return self.t + + ############################################################################ + # Datums + + def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 + # These are selected by values from 1 to 9 inclusive. + def workplane(self, id): + if ((id >= 1) and (id <= 6)): + self.g_list.append(self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + if ((id >= 7) and (id <= 9)): + self.g_list.append( + ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6)))) + + ############################################################################ + ## Rates + Modes + + def feedrate(self, f): + self.f.set(f) + self.fhv = False + + def feedrate_hv(self, fh, fv): + self.fh = fh + self.fv = fv + self.fhv = True + + def calc_feedrate_hv(self, h, v): + if math.fabs(v) > math.fabs(h * 2): + # some horizontal, so it should be fine to use the horizontal feed rate + self.f.set(self.fv) + else: + # not much, if any horizontal component, so use the vertical feed rate + self.f.set(self.fh) + + def spindle(self, s, clockwise): + if clockwise == True: + self.s.set(s, self.SPINDLE_CW(), self.SPINDLE_CCW()) + else: + self.s.set(s, self.SPINDLE_CCW(), self.SPINDLE_CW()) + + def coolant(self, mode=0): + if (mode <= 0): + self.m.append(self.COOLANT_OFF()) + elif (mode == 1): + self.m.append(self.COOLANT_MIST()) + elif (mode == 2): + self.m.append(self.COOLANT_FLOOD()) + + def gearrange(self, gear=0): + if (gear <= 0): + self.m.append(self.GEAR_OFF()) + elif (gear <= 4): + self.m.append(self.GEAR() % (gear + GEAR_BASE())) + + ############################################################################ + # Moves + + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): + (x, y, z, a, b, c, axis_count) = self.filter_xyz(x, y, z, a, b, c) + if axis_count == 0: + return + self.on_move() + + if self.g0123_modal: + if self.prev_g0123 != self.RAPID(): + self.write(self.SPACE() + self.RAPID()) + self.prev_g0123 = self.RAPID() + else: + self.write(self.SPACE() + self.RAPID()) + self.write_preps() + if (x != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + else: + dx = x - self.x + self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) + self.x = x + if (y != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + else: + dy = y - self.y + self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) + + self.y = y + if (z != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) + else: + dz = z - self.z + self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) + + self.z = z + + if (a != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.A() + (self.fmt.string(a))) + else: + da = a - self.a + self.write(self.SPACE() + self.A() + (self.fmt.string(da))) + self.a = a + + if (b != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.B() + (self.fmt.string(b))) + else: + db = b - self.b + self.write(self.SPACE() + self.B() + (self.fmt.string(db))) + self.b = b + + if (c != None): + if (self.absolute_flag): + self.write(self.SPACE() + self.C() + (self.fmt.string(c))) + else: + dc = c - self.c + self.write(self.SPACE() + self.C() + (self.fmt.string(dc))) + self.c = c + self.write_spindle() + self.write_misc() + self.write('\n') + + def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): + (x, y, z, a, b, c, axis_count) = self.filter_xyz(x, y, z, a, b, c) + if axis_count == 0: + return + self.on_move() + if self.g0123_modal: + if self.prev_g0123 != self.FEED(): + self.writem([self.SPACE(), self.FEED()]) + self.prev_g0123 = self.FEED() + else: + self.write(self.SPACE() + self.FEED()) + self.write_preps() + dx = dy = dz = 0 + if (x != None): + dx = x - self.x + if (self.absolute_flag): + self.writem([self.SPACE(), self.X(), (self.fmt.string(x + self.shift_x))]) + else: + self.writem([self.SPACE(), self.X(), (self.fmt.string(dx))]) + self.x = x + if (y != None): + dy = y - self.y + if (self.absolute_flag): + self.writem([self.SPACE(), self.Y(), (self.fmt.string(y + self.shift_y))]) + else: + self.writem([self.SPACE(), self.Y(), (self.fmt.string(dy))]) + + self.y = y + if (z != None): + dz = z - self.z + if (self.absolute_flag): + self.writem([self.SPACE(), self.Z(), (self.fmt.string(z + self.shift_z))]) + else: + self.writem([self.SPACE(), self.Z(), (self.fmt.string(dz))]) + + self.z = z + + if (a != None): + da = a - self.a + if (self.absolute_flag): + self.writem([self.SPACE(), self.A(), (self.fmt.string(a))]) + else: + self.writem([self.SPACE(), self.A(), (self.fmt.string(da))]) + self.a = a + + if (b != None): + db = b - self.b + if (self.absolute_flag): + self.writem([self.SPACE(), self.B(), (self.fmt.string(b))]) + else: + self.writem([self.SPACE(), self.B(), (self.fmt.string(db))]) + self.b = b + + if (c != None): + dc = c - self.c + if (self.absolute_flag): + self.writem([self.SPACE(), self.C(), (self.fmt.string(c))]) + else: + self.writem([self.SPACE(), self.C(), (self.fmt.string(dc))]) + self.c = c + + if (self.fhv): + self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + + def filter_xyz(self, x=None, y=None, z=None, a=None, b=None, c=None): + """ Check if x,y,z,a,b,c are the same and set them to None if they are + return value = (x,y,z,a,b,c,count) where count is the number of + axis moves left. + """ + rv = [x, y, z, a, b, c, 0] + comparisons = ((x, self.shift_x, self.x), (y, self.shift_y, self.y), (z, self.shift_z, self.z), + (a, 0, self.a), (b, 0, self.b), (c, 0, self.c)) + + for i, (new_val, shift, current_val) in enumerate(comparisons): + if new_val is not None: + if self.fmt.string(new_val+shift) == self.fmt.string(current_val): + rv[i] = None + else: + rv[6] += 1 + return rv + + def get_quadrant(self, dx, dy): + if dx < 0: + if dy < 0: + return 2 + else: + return 1 + + else: + if dy < 0: + return 3 + else: + return 0 + + def quadrant_start(self, q, i, j, rad): + while q > 3: + q = q - 4 + if q == 0: + return i + rad, j + if q == 1: + return i, j + rad + if q == 2: + return i - rad, j + return i, j - rad + + def quadrant_end(self, q, i, j, rad): + return self.quadrant_start(q + 1, i, j, rad) + + def get_arc_angle(self, sdx, sdy, edx, edy, cw): + angle_s = math.atan2(sdy, sdx) + angle_e = math.atan2(edy, edx) + if cw: + if angle_s < angle_e: + angle_s = angle_s + 2 * math.pi + else: + if angle_e < angle_s: + angle_e = angle_e + 2 * math.pi + return angle_e - angle_s + + def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + (x, y, z, _, _, _, axis_count) = self.filter_xyz(x, y, z) + if axis_count == 0: + return + + if self.output_arcs_as_lines or (self.can_do_helical_arcs == False and self.in_quadrant_splitting == False and (z != None) and (math.fabs(z - self.z) > 0.000001) and (self.fmt.string(z) != self.fmt.string(self.z))): + # split the helical arc into little line feed moves + + if x == None: + x = self.x + if y == None: + y = self.y + sdx = self.x - i + sdy = self.y - j + edx = x - i + edy = y - j + radius = math.sqrt(sdx*sdx + sdy*sdy) + arc_angle = self.get_arc_angle(sdx, sdy, edx, edy, cw) + angle_start = math.atan2(sdy, sdx) + tolerance = 0.02 + angle_step = 2.0 * math.atan(math.sqrt(tolerance / (radius - tolerance))) + segments = int(math.fabs(arc_angle / angle_step) + 1) + angle_step = arc_angle / segments + angle = angle_start + if z != None: + z_step = float(z - self.z)/segments + next_z = self.z + + for p in range(0, segments): + angle = angle + angle_step + next_x = i + radius * math.cos(angle) + next_y = j + radius * math.sin(angle) + if z == None: + next_z = None + else: + next_z = next_z + z_step + self.feed(next_x, next_y, next_z) + return + + if self.arc_centre_positive == True and self.in_quadrant_splitting == False: + # split in to quadrant arcs + self.in_quadrant_splitting = True + + if x == None: + x = self.x + if y == None: + y = self.y + sdx = self.x - i + sdy = self.y - j + edx = x - i + edy = y - j + + qs = self.get_quadrant(sdx, sdy) + qe = self.get_quadrant(edx, edy) + + if qs == qe: + arc_angle = math.fabs(self.get_arc_angle(sdx, sdy, edx, edy, cw)) + # arc_angle will be either less than pi/2 or greater than 3pi/2 + if arc_angle > 3.14: + if cw: + qs = qs + 4 + else: + qe = qe + 4 + + if qs == qe: + self.arc(cw, x, y, z, i, j, k, r) + else: + rad = math.sqrt(sdx * sdx + sdy * sdy) + if cw: + if qs < qe: + qs = qs + 4 + else: + if qe < qs: + qe = qe + 4 + + q = qs + while 1: + x1 = x + y1 = y + if q != qe: + if cw: + x1, y1 = self.quadrant_start(q, i, j, rad) + else: + x1, y1 = self.quadrant_end(q, i, j, rad) + + if (self.fmt.string(x1) != self.fmt.string(self.x)) or (self.fmt.string(y1) != self.fmt.string(self.y)): + if (math.fabs(x1 - self.x) > 0.01) or (math.fabs(y1 - self.y) > 0.01): + self.arc(cw, x1, y1, z, i, j, k, r) + else: + self.feed(x1, y1, z) + if q == qe: + break + if cw: + q = q - 1 + else: + q = q + 1 + + self.in_quadrant_splitting = False + return + + self.on_move() + arc_g_code = '' + if cw: + arc_g_code = self.ARC_CW() + else: + arc_g_code = self.ARC_CCW() + if self.g0123_modal: + if self.prev_g0123 != arc_g_code: + self.write(self.SPACE() + arc_g_code) + self.prev_g0123 = arc_g_code + else: + self.write(self.SPACE() + arc_g_code) + self.write_preps() + if (x != None): + dx = x - self.x + if (self.absolute_flag): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + else: + self.write(self.SPACE() + self.X() + (self.fmt.string(dx))) + if (y != None): + dy = y - self.y + if (self.absolute_flag): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + else: + self.write(self.SPACE() + self.Y() + (self.fmt.string(dy))) + if (z != None): + dz = z - self.z + if (self.absolute_flag): + self.write(self.SPACE() + self.Z() + (self.fmt.string(z + self.shift_z))) + else: + self.write(self.SPACE() + self.Z() + (self.fmt.string(dz))) + if (i != None): + if self.arc_centre_absolute == False: + i = i - self.x + s = self.fmt.string(i) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_X() + s) + if (j != None): + if self.arc_centre_absolute == False: + j = j - self.y + s = self.fmt.string(j) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_Y() + s) + if (k != None): + if self.arc_centre_absolute == False: + k = k - self.z + s = self.fmt.string(k) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.CENTRE_Z() + s) + if (r != None): + s = self.fmt.string(r) + if self.arc_centre_positive == True: + if s[0] == '-': + s = s[1:] + self.write(self.SPACE() + self.RADIUS() + s) # use horizontal feed rate - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - if (x != None): - self.x = x - if (y != None): - self.y = y - if (z != None): - self.z = z - - def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - self.arc(True, x, y, z, i, j, k, r) - - def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - self.arc(False, x, y, z, i, j, k, r) - - def dwell(self, t): - self.write_preps() - self.write(self.SPACE() + self.DWELL(t)) - self.write_misc() - self.write('\n') - - def on_move(self): - if self.output_fixtures: - self.output_fixture() - self.move_done_since_tool_change = True - - def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): - pass - - def rapid_unhome(self): - pass - - def set_machine_coordinates(self): - self.write(self.SPACE() + self.MACHINE_COORDINATES()) - self.prev_g0123 = '' - - ############################################################################ - ## CRC - - def use_CRC(self): - return self.useCrc - - def CRC_nominal_path(self): - return self.useCrcCenterline - - def start_CRC(self, left = True, radius = 0.0): - # set up prep code, to be output on next line - if self.t == None: - raise "No tool specified for start_CRC()" - if left: - self.write(self.SPACE() + 'G41') - else: - self.write(self.SPACE() + 'G42') - self.write((self.SPACE() + 'D%i\n') % self.t) - - def end_CRC(self): - self.write(self.SPACE() + 'G40\n') - - ############################################################################ - ## Cycles - - def pattern(self): - pass - - def pattern_uses_subroutine(self): - return self.pattern_done_with_subroutine - - def pocket(self): - pass - - def profile(self): - pass - - def write_internal_coolant_commands(self, internal_coolant_on): - if (internal_coolant_on != None) and (self.output_internal_coolant_commands == True): - if internal_coolant_on == True: - if self.internal_coolant_on != True: - self.write(self.SPACE()) - self.write(self.INTERNAL_COOLANT_ON() + '\n') - self.internal_coolant_on = True - else: - if self.internal_coolant_on != False: - self.write(self.SPACE()) - self.write(self.INTERNAL_COOLANT_OFF() + '\n') - self.internal_coolant_on = False - - # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). - # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to - # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. - # Instead, this routine combines the Z value and the depth value to determine the bottom of - # the hole. - # - # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts - # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. - # - # The peck_depth value is the incremental depth (Q value) that tells the peck drilling - # cycle how deep to go on each peck until the full depth is achieved. - # - # NOTE: This routine forces the mode to absolute mode so that the values passed into - # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't - # revert it. I must set the mode so that I can be sure the values I'm passing in make - # sense to the end-machine. - # - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): - if (depthparams.clearance_height == None): - self.first_drill_pos = False - return - - self.write_internal_coolant_commands(internal_coolant_on) - - drillExpanded = self.drillExpanded - if (depthparams.step_down != 0) and (dwell != 0): - # pecking and dwell together - if self.dwell_allowed_in_G83 != True: - drillExpanded = True - - if drillExpanded: - # for machines which don't understand G81, G82 etc. - peck_depth = depthparams.step_down - if peck_depth == None: - peck_depth = depthparams.final_depth - current_z = depthparams.start_depth - self.rapid(x, y) - - first = True - last_cut = False - - while True: - next_z = current_z - peck_depth - if next_z < (depthparams.final_depth + 0.001): - next_z = depthparams.final_depth - last_cut = True - if next_z >= current_z: - break; - if first: - self.rapid(z = depthparams.start_depth + depthparams.rapid_safety_space) - else: - self.rapid(z = current_z) - self.feed(z = next_z) - if dwell != 0 and last_cut: - self.dwell(dwell) - if last_cut:self.rapid(z = depthparams.clearance_height) - else: - if rapid_to_clearance: - self.rapid(z = depthparams.clearance_height) - else: - self.rapid(z = depthparams.start_depth + depthparams.rapid_safety_space) - current_z = next_z - first = False - - self.first_drill_pos = False - return - - if self.output_g98_and_g99 == True: - if rapid_to_clearance == True: - if self.output_g43_z_before_drilling_if_g98: - if self.fmt.string(depthparams.clearance_height) != self.z_for_g43: - self.z_for_g43 = self.fmt.string(depthparams.clearance_height) - self.write(self.SPACE() + 'G43' + self.SPACE() + 'Z' + self.z_for_g43 + '\n') - - if self.first_drill_pos ==True and rapid_to_clearance == True: - self.rapid(x, y) - self.rapid(z = depthparams.clearance_height) - - self.in_canned_cycle = True - self.write_preps() - - if (depthparams.step_down != 0): - # G83 peck drilling - if self.drill_modal: - if self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down) != self.prev_drill: - self.write(self.SPACE() + self.PECK_DRILL() + self.SPACE() + self.PECK_DEPTH(depthparams.step_down)) - self.prev_drill = self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down) - else: - self.write(self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down)) - - if (self.dwell != 0) and self.dwell_allowed_in_G83: - self.write(self.SPACE() + self.TIME() + (self.FORMAT_TIME().string(dwell))) - - else: - # We're either just drilling or drilling with dwell. - if (dwell == 0): - # We're just drilling. - if self.drill_modal: - if self.DRILL() != self.prev_drill: - self.write(self.SPACE() + self.DRILL()) - self.prev_drill = self.DRILL() - else: - self.write(self.SPACE() + self.DRILL()) - - else: - # We're drilling with dwell. - - if self.drill_modal: - if self.DRILL_WITH_DWELL(dwell) != self.prev_drill: - self.write(self.SPACE() + self.DRILL_WITH_DWELL(dwell)) - self.prev_drill = self.DRILL_WITH_DWELL(dwell) - else: - self.write(self.SPACE() + self.DRILL_WITH_DWELL(dwell)) - - if self.output_g98_and_g99 == True: - if rapid_to_clearance == True: - if self.g98_not_g99 != True: - self.write(self.SPACE() + self.RETRACT_TO_CLEARANCE()) - self.g98_not_g99 = True - else: - if self.g98_not_g99 != False: - self.write(self.SPACE() + self.RETRACT_TO_STANDOFF()) - self.g98_not_g99 = False - - # Set the retraction point to the 'standoff' distance above the starting z height. - retract_height = depthparams.start_depth + depthparams.rapid_safety_space - if (x != None): - self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) - self.x = x - - if (y != None): - self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) - self.y = y - - if self.drill_modal: - if depthparams.start_depth != self.prev_z: - self.write(self.SPACE() + self.Z() + (self.fmt.string(depthparams.final_depth))) - self.prev_z=depthparams.start_depth - else: - self.write(self.SPACE() + self.Z() + (self.fmt.string(depthparams.final_depth))) # This is the 'z' value for the bottom of the hole. - self.z = (depthparams.start_depth + depthparams.rapid_safety_space) # We want to remember where z is at the end (at the top of the hole) - - if self.drill_modal: - if self.prev_retract != self.RETRACT(retract_height) : - self.write(self.SPACE() + self.RETRACT(retract_height)) - self.prev_retract = self.RETRACT(retract_height) - else: - self.write(self.SPACE() + self.RETRACT(retract_height)) - - if (self.fv) : - self.f.set(self.fv) - - self.write_feedrate() - self.write_spindle() - self.write_misc() - self.write('\n') - self.first_drill_pos = False - - def end_canned_cycle(self): - if self.in_canned_cycle == False: - return - self.write(self.SPACE() + self.END_CANNED_CYCLE() + '\n') - self.write_internal_coolant_commands(0) - self.prev_drill = '' - self.prev_g0123 = '' - self.prev_z = '' - self.prev_f = '' - self.prev_retract = '' - self.in_canned_cycle = False - self.first_drill_pos = True - - ############################################################################ - ## Misc - - def comment(self, text): - self.write((self.COMMENT(text) + '\n')) - - def insert(self, text): - pass - - def block_delete(self, on=False): - pass - - def variable(self, id): - return (self.VARIABLE() % id) - - def variable_set(self, id, value): - self.write(self.SPACE() + (self.VARIABLE() % id) + self.SPACE() + (self.VARIABLE_SET() % value) + '\n') - - # This routine uses the G92 coordinate system offsets to establish a temporary coordinate - # system at the machine's current position. It can then use absolute coordinates relative - # to this position which makes coding easy. It then moves to the 'point along edge' which - # should be above the workpiece but still on one edge. It then backs off from the edge - # to the 'retracted point'. It then plunges down by the depth value specified. It then - # probes back towards the 'destination point'. The probed X,Y location are stored - # into the 'intersection variable' variables. Finally the machine moves back to the - # original location. This is important so that the results of multiple calls to this - # routine may be compared meaningfully. - def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None ): - self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) - - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write_feedrate() - self.write('\t(Set the feed rate for probing)\n') - - self.rapid(point_along_edge_x,point_along_edge_y) - self.rapid(retracted_point_x,retracted_point_y) - self.feed(z=depth) - - self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + ' Y ' + (self.fmt.string(destination_point_y)) ) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Back off the workpiece and re-probe more slowly') - self.write(self.SPACE() + ('#' + intersection_variable_x + '= [#5061 - [ 0.5 * ' + probe_offset_x_component + ']]\n')) - self.write(self.SPACE() + ('#' + intersection_variable_y + '= [#5062 - [ 0.5 * ' + probe_offset_y_component + ']]\n')) - self.write(self.RAPID()) - self.write(self.SPACE() + ' X #' + intersection_variable_x + ' Y #' + intersection_variable_y + '\n') - - self.write(self.SPACE() + self.FEEDRATE() + self.ffmt.string(self.fh / 2.0) + '\n') - - self.write((self.SPACE() + self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + ' Y ' + (self.fmt.string(destination_point_y)) ) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Store the probed location somewhere we can get it again later') - self.write(('#' + intersection_variable_x + '=' + probe_offset_x_component + ' (Portion of probe radius that contributes to the X coordinate)\n')) - self.write(('#' + intersection_variable_x + '=[#' + intersection_variable_x + ' + #5061]\n')) - self.write(('#' + intersection_variable_y + '=' + probe_offset_y_component + ' (Portion of probe radius that contributes to the Y coordinate)\n')) - self.write(('#' + intersection_variable_y + '=[#' + intersection_variable_y + ' + #5062]\n')) - - self.comment('Now move back to the original location') - self.rapid(retracted_point_x,retracted_point_y) - self.rapid(z=0) - self.rapid(point_along_edge_x,point_along_edge_y) - self.rapid(x=0, y=0) - - self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + ('\t(Restore the previous coordinate system)\n'))) - - def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): - self.write((self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) - if (self.fhv) : self.calc_feedrate_hv(1, 0) - self.write(self.FEEDRATE() + ' [' + self.ffmt.string(self.fh) + ' / 5.0 ]') - self.write('\t(Set the feed rate for probing)\n') - - if x != None and y != None: - self.write(self.RAPID()) - self.write(' X ' + x + ' Y ' + y + '\n') - - self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + ' Z ' + (self.fmt.string(depth)) + ('\t(Probe towards our destination point)\n'))) - - self.comment('Store the probed location somewhere we can get it again later') - self.write(('#' + intersection_variable_z + '= #5063\n')) - - self.comment('Now move back to the original location') - self.rapid(z=0) - self.rapid(x=0, y=0) - - self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + ('\t(Restore the previous coordinate system)\n'))) - - - def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): - pass - - def open_log_file(self, xml_file_name=None ): - pass - - def log_coordinate(self, x=None, y=None, z=None): - pass - - def log_message(self, message=None): - pass - - def close_log_file(self): - pass - - # Rapid movement to the midpoint between the two points specified. - # NOTE: The points are specified either as strings representing numbers or as strings - # representing variable names. This allows the HeeksCNC module to determine which - # variable names are used in these various routines. - def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): - self.write(self.RAPID()) - if ((x1 != None) and (x2 != None)): - self.write((' X ' + '[[[' + x1 + ' - ' + x2 + '] / 2.0] + ' + x2 + ']')) - - if ((y1 != None) and (y2 != None)): - self.write((' Y ' + '[[[' + y1 + ' - ' + y2 + '] / 2.0] + ' + y2 + ']')) - - if ((z1 != None) and (z2 != None)): - self.write((' Z ' + '[[[' + z1 + ' - ' + z2 + '] / 2.0] + ' + z2 + ']')) - - self.write('\n') - - # Rapid movement to the intersection of two lines (in the XY plane only). This routine - # is based on information found in http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ - # written by Paul Bourke. The ua_numerator, ua_denominator, ua and ub parameters - # represent variable names (with the preceding '#' included in them) for use as temporary - # variables. They're specified here simply so that HeeksCNC can manage which variables - # are used in which GCode calculations. - # - # As per the notes on the web page, the ua_denominator and ub_denominator formulae are - # the same so we don't repeat this. If the two lines are coincident or parallel then - # no movement occurs. - # - # NOTE: The points are specified either as strings representing numbers or as strings - # representing variable names. This allows the HeeksCNC module to determine which - # variable names are used in these various routines. - def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): - self.comment('Find the intersection of the two lines made up by the four probed points') - self.write(ua_numerator + '=[[[' + x4 + ' - ' + x3 + '] * [' + y1 + ' - ' + y3 + ']] - [[' + y4 + ' - ' + y3 + '] * [' + x1 + ' - ' + x3 + ']]]\n') - self.write(ua_denominator + '=[[[' + y4 + ' - ' + y3 + '] * [' + x2 + ' - ' + x1 + ']] - [[' + x4 + ' - ' + x3 + '] * [' + y2 + ' - ' + y1 + ']]]\n') - self.write(ub_numerator + '=[[[' + x2 + ' - ' + x1 + '] * [' + y1 + ' - ' + y3 + ']] - [[' + y2 + ' - ' + y1 + '] * [' + x1 + ' - ' + x3 + ']]]\n') - - self.comment('If they are not parallel') - self.write('O900 IF [' + ua_denominator + ' NE 0]\n') - self.comment('And if they are not coincident') - self.write('O901 IF [' + ua_numerator + ' NE 0 ]\n') - - self.write(' ' + ua + '=[' + ua_numerator + ' / ' + ua_denominator + ']\n') - self.write(' ' + ub + '=[' + ub_numerator + ' / ' + ua_denominator + ']\n') # NOTE: ub denominator is the same as ua denominator - self.write(' ' + intersection_x + '=[' + x1 + ' + [[' + ua + ' * [' + x2 + ' - ' + x1 + ']]]]\n') - self.write(' ' + intersection_y + '=[' + y1 + ' + [[' + ua + ' * [' + y2 + ' - ' + y1 + ']]]]\n') - self.write(' ' + self.RAPID()) - self.write(' X ' + intersection_x + ' Y ' + intersection_y + '\n') - - self.write('O901 ENDIF\n') - self.write('O900 ENDIF\n') - - # We need to calculate the rotation angle based on the line formed by the - # x1,y1 and x2,y2 coordinate pair. With that angle, we need to move - # x_offset and y_offset distance from the current (0,0,0) position. - # - # The x1,y1,x2 and y2 parameters are all variable names that contain the actual - # values. - # The x_offset and y_offset are both numeric (floating point) values - def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): - self.comment('Rapid to rotated coordinate') - self.write( '#1 = [atan[' + y2 + ' - ' + y1 + ']/[' + x2 +' - ' + x1 + ']] (nominal_angle)\n') - self.write( '#2 = [atan[' + ref_y + ']/[' + ref_x + ']] (reference angle)\n') - self.write( '#3 = [#1 - #2] (angle)\n' ) - self.write( '#4 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + '] * COS[ #3 ]] - [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * SIN[ #3 ]]]\n' ) - self.write( '#5 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + '] * SIN[ #3 ]] + [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * COS[ #3 ]]]\n' ) - - self.write( '#6 = [[' + (self.fmt.string(x_final)) + ' * COS[ #3 ]] - [' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]]]\n' ) - self.write( '#7 = [[' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]] + [' + (self.fmt.string(y_final)) + ' * COS[ #3 ]]]\n' ) - - self.write( self.RAPID() + ' X [ #4 + #6 ] Y [ #5 + #7 ]\n' ) - - def BEST_POSSIBLE_SPEED(self, motion_blending_tolerance, naive_cam_tolerance): - statement = 'G64' - - if (motion_blending_tolerance > 0): - statement += ' P ' + str(motion_blending_tolerance) - - if (naive_cam_tolerance > 0): - statement += ' Q ' + str(naive_cam_tolerance) - - return(statement) - - def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance ): - if (mode == 0): - self.write( self.EXACT_PATH_MODE() + '\n' ) - if (mode == 1): - self.write( self.EXACT_STOP_MODE() + '\n' ) - if (mode == 2): - self.write( self.BEST_POSSIBLE_SPEED( motion_blending_tolerance, naive_cam_tolerance ) + '\n' ) + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + if (x != None): + self.x = x + if (y != None): + self.y = y + if (z != None): + self.z = z + + def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + self.arc(True, x, y, z, i, j, k, r) + + def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + self.arc(False, x, y, z, i, j, k, r) + + def dwell(self, t): + self.write_preps() + self.write(self.SPACE() + self.DWELL(t)) + self.write_misc() + self.write('\n') + + def on_move(self): + if self.output_fixtures: + self.output_fixture() + self.move_done_since_tool_change = True + + def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): + pass + + def rapid_unhome(self): + pass + + def set_machine_coordinates(self): + self.write(self.SPACE() + self.MACHINE_COORDINATES()) + self.prev_g0123 = '' + + ############################################################################ + # CRC + + def use_CRC(self): + return self.useCrc + + def CRC_nominal_path(self): + return self.useCrcCenterline + + def start_CRC(self, left=True, radius=0.0): + # set up prep code, to be output on next line + if self.t == None: + raise "No tool specified for start_CRC()" + if left: + self.write(self.SPACE() + 'G41') + else: + self.write(self.SPACE() + 'G42') + self.write((self.SPACE() + 'D%i\n') % self.t) + + def end_CRC(self): + self.write(self.SPACE() + 'G40\n') + + ############################################################################ + # Cycles + + def pattern(self): + pass + + def pattern_uses_subroutine(self): + return self.pattern_done_with_subroutine + + def pocket(self): + pass + + def profile(self): + pass + + def write_internal_coolant_commands(self, internal_coolant_on): + if (internal_coolant_on != None) and (self.output_internal_coolant_commands == True): + if internal_coolant_on == True: + if self.internal_coolant_on != True: + self.write(self.SPACE()) + self.write(self.INTERNAL_COOLANT_ON() + '\n') + self.internal_coolant_on = True + else: + if self.internal_coolant_on != False: + self.write(self.SPACE()) + self.write(self.INTERNAL_COOLANT_OFF() + '\n') + self.internal_coolant_on = False + + # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). + # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to + # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. + # Instead, this routine combines the Z value and the depth value to determine the bottom of + # the hole. + # + # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts + # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. + # + # The peck_depth value is the incremental depth (Q value) that tells the peck drilling + # cycle how deep to go on each peck until the full depth is achieved. + # + # NOTE: This routine forces the mode to absolute mode so that the values passed into + # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't + # revert it. I must set the mode so that I can be sure the values I'm passing in make + # sense to the end-machine. + # + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + if (depthparams.clearance_height == None): + self.first_drill_pos = False + return + + self.write_internal_coolant_commands(internal_coolant_on) + + drillExpanded = self.drillExpanded + if (depthparams.step_down != 0) and (dwell != 0): + # pecking and dwell together + if self.dwell_allowed_in_G83 != True: + drillExpanded = True + + if drillExpanded: + # for machines which don't understand G81, G82 etc. + peck_depth = depthparams.step_down + if peck_depth == None: + peck_depth = depthparams.final_depth + current_z = depthparams.start_depth + self.rapid(x, y) + + first = True + last_cut = False + + while True: + next_z = current_z - peck_depth + if next_z < (depthparams.final_depth + 0.001): + next_z = depthparams.final_depth + last_cut = True + if next_z >= current_z: + break + if first: + self.rapid(z=depthparams.start_depth + depthparams.rapid_safety_space) + else: + self.rapid(z=current_z) + self.feed(z=next_z) + if dwell != 0 and last_cut: + self.dwell(dwell) + if last_cut: + self.rapid(z=depthparams.clearance_height) + else: + if rapid_to_clearance: + self.rapid(z=depthparams.clearance_height) + else: + self.rapid(z=depthparams.start_depth + depthparams.rapid_safety_space) + current_z = next_z + first = False + + self.first_drill_pos = False + return + + if self.output_g98_and_g99 == True: + if rapid_to_clearance == True: + if self.output_g43_z_before_drilling_if_g98: + if self.fmt.string(depthparams.clearance_height) != self.z_for_g43: + self.z_for_g43 = self.fmt.string(depthparams.clearance_height) + self.write(self.SPACE() + 'G43' + self.SPACE() + + 'Z' + self.z_for_g43 + '\n') + + if self.first_drill_pos == True and rapid_to_clearance == True: + self.rapid(x, y) + self.rapid(z=depthparams.clearance_height) + + self.in_canned_cycle = True + self.write_preps() + + if (depthparams.step_down != 0): + # G83 peck drilling + if self.drill_modal: + if self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down) != self.prev_drill: + self.write(self.SPACE() + self.PECK_DRILL() + self.SPACE() + + self.PECK_DEPTH(depthparams.step_down)) + self.prev_drill = self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down) + else: + self.write(self.PECK_DRILL() + self.PECK_DEPTH(depthparams.step_down)) + + if (self.dwell != 0) and self.dwell_allowed_in_G83: + self.write(self.SPACE() + self.TIME() + (self.FORMAT_TIME().string(dwell))) + + else: + # We're either just drilling or drilling with dwell. + if (dwell == 0): + # We're just drilling. + if self.drill_modal: + if self.DRILL() != self.prev_drill: + self.write(self.SPACE() + self.DRILL()) + self.prev_drill = self.DRILL() + else: + self.write(self.SPACE() + self.DRILL()) + + else: + # We're drilling with dwell. + + if self.drill_modal: + if self.DRILL_WITH_DWELL(dwell) != self.prev_drill: + self.write(self.SPACE() + self.DRILL_WITH_DWELL(dwell)) + self.prev_drill = self.DRILL_WITH_DWELL(dwell) + else: + self.write(self.SPACE() + self.DRILL_WITH_DWELL(dwell)) + + if self.output_g98_and_g99 == True: + if rapid_to_clearance == True: + if self.g98_not_g99 != True: + self.write(self.SPACE() + self.RETRACT_TO_CLEARANCE()) + self.g98_not_g99 = True + else: + if self.g98_not_g99 != False: + self.write(self.SPACE() + self.RETRACT_TO_STANDOFF()) + self.g98_not_g99 = False + + # Set the retraction point to the 'standoff' distance above the starting z height. + retract_height = depthparams.start_depth + depthparams.rapid_safety_space + if (x != None): + self.write(self.SPACE() + self.X() + (self.fmt.string(x + self.shift_x))) + self.x = x + + if (y != None): + self.write(self.SPACE() + self.Y() + (self.fmt.string(y + self.shift_y))) + self.y = y + + if self.drill_modal: + if depthparams.start_depth != self.prev_z: + self.write(self.SPACE() + self.Z() + (self.fmt.string(depthparams.final_depth))) + self.prev_z = depthparams.start_depth + else: + # This is the 'z' value for the bottom of the hole. + self.write(self.SPACE() + self.Z() + (self.fmt.string(depthparams.final_depth))) + # We want to remember where z is at the end (at the top of the hole) + self.z = (depthparams.start_depth + depthparams.rapid_safety_space) + + if self.drill_modal: + if self.prev_retract != self.RETRACT(retract_height): + self.write(self.SPACE() + self.RETRACT(retract_height)) + self.prev_retract = self.RETRACT(retract_height) + else: + self.write(self.SPACE() + self.RETRACT(retract_height)) + + if (self.fv): + self.f.set(self.fv) + + self.write_feedrate() + self.write_spindle() + self.write_misc() + self.write('\n') + self.first_drill_pos = False + + def end_canned_cycle(self): + if self.in_canned_cycle == False: + return + self.write(self.SPACE() + self.END_CANNED_CYCLE() + '\n') + self.write_internal_coolant_commands(0) + self.prev_drill = '' + self.prev_g0123 = '' + self.prev_z = '' + self.prev_f = '' + self.prev_retract = '' + self.in_canned_cycle = False + self.first_drill_pos = True + + ############################################################################ + # Misc + + def comment(self, text): + self.write((self.COMMENT(text) + '\n')) + + def insert(self, text): + pass + + def block_delete(self, on=False): + pass + + def variable(self, id): + return (self.VARIABLE() % id) + + def variable_set(self, id, value): + self.write(self.SPACE() + (self.VARIABLE() % id) + + self.SPACE() + (self.VARIABLE_SET() % value) + '\n') + + # This routine uses the G92 coordinate system offsets to establish a temporary coordinate + # system at the machine's current position. It can then use absolute coordinates relative + # to this position which makes coding easy. It then moves to the 'point along edge' which + # should be above the workpiece but still on one edge. It then backs off from the edge + # to the 'retracted point'. It then plunges down by the depth value specified. It then + # probes back towards the 'destination point'. The probed X,Y location are stored + # into the 'intersection variable' variables. Finally the machine moves back to the + # original location. This is important so that the results of multiple calls to this + # routine may be compared meaningfully. + def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None): + self.write(self.SPACE() + (self.SET_TEMPORARY_COORDINATE_SYSTEM() + + (' X 0 Y 0 Z 0') + ('\t(Temporarily make this the origin)\n'))) + + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write_feedrate() + self.write('\t(Set the feed rate for probing)\n') + + self.rapid(point_along_edge_x, point_along_edge_y) + self.rapid(retracted_point_x, retracted_point_y) + self.feed(z=depth) + + self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x)) + + ' Y ' + (self.fmt.string(destination_point_y))) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Back off the workpiece and re-probe more slowly') + self.write(self.SPACE() + ('#' + intersection_variable_x + + '= [#5061 - [ 0.5 * ' + probe_offset_x_component + ']]\n')) + self.write(self.SPACE() + ('#' + intersection_variable_y + + '= [#5062 - [ 0.5 * ' + probe_offset_y_component + ']]\n')) + self.write(self.RAPID()) + self.write(self.SPACE() + ' X #' + intersection_variable_x + + ' Y #' + intersection_variable_y + '\n') + + self.write(self.SPACE() + self.FEEDRATE() + self.ffmt.string(self.fh / 2.0) + '\n') + + self.write((self.SPACE() + self.PROBE_TOWARDS_WITH_SIGNAL() + (' X ' + (self.fmt.string(destination_point_x) + ) + ' Y ' + (self.fmt.string(destination_point_y))) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Store the probed location somewhere we can get it again later') + self.write(('#' + intersection_variable_x + '=' + probe_offset_x_component + + ' (Portion of probe radius that contributes to the X coordinate)\n')) + self.write(('#' + intersection_variable_x + + '=[#' + intersection_variable_x + ' + #5061]\n')) + self.write(('#' + intersection_variable_y + '=' + probe_offset_y_component + + ' (Portion of probe radius that contributes to the Y coordinate)\n')) + self.write(('#' + intersection_variable_y + + '=[#' + intersection_variable_y + ' + #5062]\n')) + + self.comment('Now move back to the original location') + self.rapid(retracted_point_x, retracted_point_y) + self.rapid(z=0) + self.rapid(point_along_edge_x, point_along_edge_y) + self.rapid(x=0, y=0) + + self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + + ('\t(Restore the previous coordinate system)\n'))) + + def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): + self.write((self.SET_TEMPORARY_COORDINATE_SYSTEM() + (' X 0 Y 0 Z 0') + + ('\t(Temporarily make this the origin)\n'))) + if (self.fhv): + self.calc_feedrate_hv(1, 0) + self.write(self.FEEDRATE() + ' [' + self.ffmt.string(self.fh) + ' / 5.0 ]') + self.write('\t(Set the feed rate for probing)\n') + + if x != None and y != None: + self.write(self.RAPID()) + self.write(' X ' + x + ' Y ' + y + '\n') + + self.write((self.PROBE_TOWARDS_WITH_SIGNAL() + ' Z ' + + (self.fmt.string(depth)) + ('\t(Probe towards our destination point)\n'))) + + self.comment('Store the probed location somewhere we can get it again later') + self.write(('#' + intersection_variable_z + '= #5063\n')) + + self.comment('Now move back to the original location') + self.rapid(z=0) + self.rapid(x=0, y=0) + + self.write((self.REMOVE_TEMPORARY_COORDINATE_SYSTEM() + + ('\t(Restore the previous coordinate system)\n'))) + + def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): + pass + + def open_log_file(self, xml_file_name=None): + pass + + def log_coordinate(self, x=None, y=None, z=None): + pass + + def log_message(self, message=None): + pass + + def close_log_file(self): + pass + + # Rapid movement to the midpoint between the two points specified. + # NOTE: The points are specified either as strings representing numbers or as strings + # representing variable names. This allows the HeeksCNC module to determine which + # variable names are used in these various routines. + def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): + self.write(self.RAPID()) + if ((x1 != None) and (x2 != None)): + self.write((' X ' + '[[[' + x1 + ' - ' + x2 + '] / 2.0] + ' + x2 + ']')) + + if ((y1 != None) and (y2 != None)): + self.write((' Y ' + '[[[' + y1 + ' - ' + y2 + '] / 2.0] + ' + y2 + ']')) + + if ((z1 != None) and (z2 != None)): + self.write((' Z ' + '[[[' + z1 + ' - ' + z2 + '] / 2.0] + ' + z2 + ']')) + + self.write('\n') + + # Rapid movement to the intersection of two lines (in the XY plane only). This routine + # is based on information found in http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ + # written by Paul Bourke. The ua_numerator, ua_denominator, ua and ub parameters + # represent variable names (with the preceding '#' included in them) for use as temporary + # variables. They're specified here simply so that HeeksCNC can manage which variables + # are used in which GCode calculations. + # + # As per the notes on the web page, the ua_denominator and ub_denominator formulae are + # the same so we don't repeat this. If the two lines are coincident or parallel then + # no movement occurs. + # + # NOTE: The points are specified either as strings representing numbers or as strings + # representing variable names. This allows the HeeksCNC module to determine which + # variable names are used in these various routines. + def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): + self.comment('Find the intersection of the two lines made up by the four probed points') + self.write(ua_numerator + '=[[[' + x4 + ' - ' + x3 + '] * [' + y1 + ' - ' + + y3 + ']] - [[' + y4 + ' - ' + y3 + '] * [' + x1 + ' - ' + x3 + ']]]\n') + self.write(ua_denominator + '=[[[' + y4 + ' - ' + y3 + '] * [' + x2 + ' - ' + + x1 + ']] - [[' + x4 + ' - ' + x3 + '] * [' + y2 + ' - ' + y1 + ']]]\n') + self.write(ub_numerator + '=[[[' + x2 + ' - ' + x1 + '] * [' + y1 + ' - ' + + y3 + ']] - [[' + y2 + ' - ' + y1 + '] * [' + x1 + ' - ' + x3 + ']]]\n') + + self.comment('If they are not parallel') + self.write('O900 IF [' + ua_denominator + ' NE 0]\n') + self.comment('And if they are not coincident') + self.write('O901 IF [' + ua_numerator + ' NE 0 ]\n') + + self.write(' ' + ua + '=[' + ua_numerator + ' / ' + ua_denominator + ']\n') + # NOTE: ub denominator is the same as ua denominator + self.write(' ' + ub + '=[' + ub_numerator + ' / ' + ua_denominator + ']\n') + self.write(' ' + intersection_x + + '=[' + x1 + ' + [[' + ua + ' * [' + x2 + ' - ' + x1 + ']]]]\n') + self.write(' ' + intersection_y + + '=[' + y1 + ' + [[' + ua + ' * [' + y2 + ' - ' + y1 + ']]]]\n') + self.write(' ' + self.RAPID()) + self.write(' X ' + intersection_x + ' Y ' + intersection_y + '\n') + + self.write('O901 ENDIF\n') + self.write('O900 ENDIF\n') + + # We need to calculate the rotation angle based on the line formed by the + # x1,y1 and x2,y2 coordinate pair. With that angle, we need to move + # x_offset and y_offset distance from the current (0,0,0) position. + # + # The x1,y1,x2 and y2 parameters are all variable names that contain the actual + # values. + # The x_offset and y_offset are both numeric (floating point) values + def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): + self.comment('Rapid to rotated coordinate') + self.write('#1 = [atan[' + y2 + ' - ' + y1 + ']/[' + + x2 + ' - ' + x1 + ']] (nominal_angle)\n') + self.write('#2 = [atan[' + ref_y + ']/[' + ref_x + ']] (reference angle)\n') + self.write('#3 = [#1 - #2] (angle)\n') + self.write('#4 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + + '] * COS[ #3 ]] - [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * SIN[ #3 ]]]\n') + self.write('#5 = [[[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(x_current)) + + '] * SIN[ #3 ]] + [[' + (self.fmt.string(0)) + ' - ' + (self.fmt.string(y_current)) + '] * COS[ #3 ]]]\n') + + self.write('#6 = [[' + (self.fmt.string(x_final)) + ' * COS[ #3 ]] - [' + + (self.fmt.string(y_final)) + ' * SIN[ #3 ]]]\n') + self.write('#7 = [[' + (self.fmt.string(y_final)) + ' * SIN[ #3 ]] + [' + + (self.fmt.string(y_final)) + ' * COS[ #3 ]]]\n') + + self.write(self.RAPID() + ' X [ #4 + #6 ] Y [ #5 + #7 ]\n') + + def BEST_POSSIBLE_SPEED(self, motion_blending_tolerance, naive_cam_tolerance): + statement = 'G64' + + if (motion_blending_tolerance > 0): + statement += ' P ' + str(motion_blending_tolerance) + + if (naive_cam_tolerance > 0): + statement += ' Q ' + str(naive_cam_tolerance) + + return(statement) + + def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance): + if (mode == 0): + self.write(self.EXACT_PATH_MODE() + '\n') + if (mode == 1): + self.write(self.EXACT_STOP_MODE() + '\n') + if (mode == 2): + self.write(self.BEST_POSSIBLE_SPEED( + motion_blending_tolerance, naive_cam_tolerance) + '\n') ################################################################################ diff --git a/scripts/addons/cam/nc/iso_codes.py b/scripts/addons/cam/nc/iso_codes.py index 3c17f37a1..1cba92e10 100644 --- a/scripts/addons/cam/nc/iso_codes.py +++ b/scripts/addons/cam/nc/iso_codes.py @@ -1,4 +1,5 @@ class Codes(): - pass + pass + codes = Codes() diff --git a/scripts/addons/cam/nc/iso_crc.py b/scripts/addons/cam/nc/iso_crc.py index 312b00e11..61144d3ec 100644 --- a/scripts/addons/cam/nc/iso_crc.py +++ b/scripts/addons/cam/nc/iso_crc.py @@ -10,6 +10,8 @@ import math ################################################################################ + + class Creator(iso.Creator): def __init__(self): @@ -18,4 +20,5 @@ def __init__(self): ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/iso_crc_read.py b/scripts/addons/cam/nc/iso_crc_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/iso_crc_read.py +++ b/scripts/addons/cam/nc/iso_crc_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/iso_modal.py b/scripts/addons/cam/nc/iso_modal.py index 98508791f..ffdde3a97 100644 --- a/scripts/addons/cam/nc/iso_modal.py +++ b/scripts/addons/cam/nc/iso_modal.py @@ -10,6 +10,8 @@ import math ################################################################################ + + class Creator(iso.Creator): def __init__(self): @@ -19,4 +21,5 @@ def __init__(self): self.drill_modal = True ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/iso_modal_read.py b/scripts/addons/cam/nc/iso_modal_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/iso_modal_read.py +++ b/scripts/addons/cam/nc/iso_modal_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/iso_read.py b/scripts/addons/cam/nc/iso_read.py index a923bcd88..9e729a657 100644 --- a/scripts/addons/cam/nc/iso_read.py +++ b/scripts/addons/cam/nc/iso_read.py @@ -10,20 +10,23 @@ import sys ################################################################################ + + class Parser(nc.Parser): def __init__(self, writer): nc.Parser.__init__(self, writer) - self.pattern_main = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') + self.pattern_main = re.compile( + '([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') self.arc_centre_absolute = False self.arc_centre_positive = False self.oldx = None self.oldy = None self.oldz = None - #if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point - # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal + # if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point + # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal # add your character here > [(!;] for comments char # then look for the 'comment' function towards the end of the file and add another elif @@ -86,7 +89,7 @@ def ParseWord(self, word): self.path_col = "feed" self.col = "feed" elif (word == 'G82' or word == 'g82'): - self.drill = True; + self.drill = True self.no_move = True self.path_col = "feed" self.col = "feed" @@ -99,7 +102,8 @@ def ParseWord(self, word): self.absolute() elif (word == 'G91' or word == 'g91'): self.incremental() - elif (word[0] == 'G') : col = "prep" + elif (word[0] == 'G'): + col = "prep" elif (word[0] == 'I' or word[0] == 'i'): self.col = "axis" self.i = eval(word[1:]) @@ -112,19 +116,22 @@ def ParseWord(self, word): self.col = "axis" self.k = eval(word[1:]) self.move = True - elif (word[0] == 'M') : self.col = "misc" - elif (word[0] == 'N') : self.col = "blocknum" - elif (word[0] == 'O') : self.col = "program" + elif (word[0] == 'M'): + self.col = "misc" + elif (word[0] == 'N'): + self.col = "blocknum" + elif (word[0] == 'O'): + self.col = "program" elif (word[0] == 'P' or word[0] == 'p'): - if (self.no_move != True): - self.col = "axis" - self.p = eval(word[1:]) - self.move = True + if (self.no_move != True): + self.col = "axis" + self.p = eval(word[1:]) + self.move = True elif (word[0] == 'Q' or word[0] == 'q'): - if (self.no_move != True): - self.col = "axis" - self.q = eval(word[1:]) - self.move = True + if (self.no_move != True): + self.col = "axis" + self.q = eval(word[1:]) + self.move = True elif (word[0] == 'R' or word[0] == 'r'): self.col = "axis" self.r = eval(word[1:]) @@ -132,9 +139,9 @@ def ParseWord(self, word): elif (word[0] == 'S' or word[0] == 's'): self.col = "axis" self.writer.spindle(word[1:], (float(word[1:]) >= 0.0)) - elif (word[0] == 'T') : + elif (word[0] == 'T'): self.col = "tool" - self.writer.tool_change( eval(word[1:]) ) + self.writer.tool_change(eval(word[1:])) elif (word[0] == 'X' or word[0] == 'x'): self.col = "axis" self.x = eval(word[1:]) @@ -147,9 +154,15 @@ def ParseWord(self, word): self.col = "axis" self.z = eval(word[1:]) self.move = True - elif (word[0] == '(') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == '!') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == ';') : (self.col, self.cdata) = ("comment", True) - elif (word[0] == '#') : self.col = "variable" - elif (word[0] == ':') : self.col = "blocknum" - elif (ord(word[0]) <= 32) : self.cdata = True + elif (word[0] == '('): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == '!'): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == ';'): + (self.col, self.cdata) = ("comment", True) + elif (word[0] == '#'): + self.col = "variable" + elif (word[0] == ':'): + self.col = "blocknum" + elif (ord(word[0]) <= 32): + self.cdata = True diff --git a/scripts/addons/cam/nc/lathe1.py b/scripts/addons/cam/nc/lathe1.py index adec62097..2d3b0e2c8 100644 --- a/scripts/addons/cam/nc/lathe1.py +++ b/scripts/addons/cam/nc/lathe1.py @@ -10,6 +10,8 @@ import math ################################################################################ + + class CreatorIso(nc.Creator): def __init__(self): @@ -48,7 +50,7 @@ def __init__(self): self.absolute_flag = True self.ffmt = iso.codes.FORMAT_FEEDRATE() ############################################################################ - ## Internals + # Internals def write_feedrate(self): if self.f_modal: @@ -64,39 +66,40 @@ def write_preps(self): self.g = '' def write_misc(self): - if (len(self.m)) : self.write(self.m.pop()) + if (len(self.m)): + self.write(self.m.pop()) def write_spindle(self): self.write(self.s) self.s = '' ############################################################################ - ## Programs + # Programs def program_begin(self, id, name=''): self.write((iso.codes.PROGRAM() % id) + iso.codes.SPACE() + (iso.codes.COMMENT(name))) self.write('\n') def program_stop(self, optional=False): - if (optional) : + if (optional): self.write(iso.codes.STOP_OPTIONAL() + '\n') self.prev_g0123 = '' - else : + else: self.write(iso.codes.STOP() + '\n') self.prev_g0123 = '' - def program_end(self): self.write(iso.codes.PROGRAM_END() + '\n') def flush_nc(self): - if len(self.g) == 0 and len(self.m) == 0: return + if len(self.g) == 0 and len(self.m) == 0: + return self.write_preps() self.write_misc() self.write('\n') ############################################################################ - ## Subprograms + # Subprograms def sub_begin(self, id, name=''): self.write((iso.codes.PROGRAM() % id) + iso.codes.SPACE() + (iso.codes.COMMENT(name))) @@ -109,7 +112,7 @@ def sub_end(self): self.write(iso.codes.SUBPROG_END() + '\n') ############################################################################ - ## Settings + # Settings def imperial(self): self.g += iso.codes.IMPERIAL() @@ -128,22 +131,33 @@ def incremental(self): self.absolute_flag = False def polar(self, on=True): - if (on) : self.g += iso.codes.POLAR_ON() - else : self.g += iso.codes.POLAR_OFF() + if (on): + self.g += iso.codes.POLAR_ON() + else: + self.g += iso.codes.POLAR_OFF() def set_plane(self, plane): - if (plane == 0) : self.g += iso.codes.PLANE_XY() - elif (plane == 1) : self.g += iso.codes.PLANE_XZ() - elif (plane == 2) : self.g += iso.codes.PLANE_YZ() + if (plane == 0): + self.g += iso.codes.PLANE_XY() + elif (plane == 1): + self.g += iso.codes.PLANE_XZ() + elif (plane == 2): + self.g += iso.codes.PLANE_YZ() def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write((iso.codes.SET_TEMPORARY_COORDINATE_SYSTEM())) - if (x != None): self.write( iso.codes.SPACE() + 'X ' + (self.fmt % x) ) - if (y != None): self.write( iso.codes.SPACE() + 'Y ' + (self.fmt % y) ) - if (z != None): self.write( iso.codes.SPACE() + 'Z ' + (self.fmt % z) ) - if (a != None): self.write( iso.codes.SPACE() + 'A ' + (self.fmt % a) ) - if (b != None): self.write( iso.codes.SPACE() + 'B ' + (self.fmt % b) ) - if (c != None): self.write( iso.codes.SPACE() + 'C ' + (self.fmt % c) ) + if (x != None): + self.write(iso.codes.SPACE() + 'X ' + (self.fmt % x)) + if (y != None): + self.write(iso.codes.SPACE() + 'Y ' + (self.fmt % y)) + if (z != None): + self.write(iso.codes.SPACE() + 'Z ' + (self.fmt % z)) + if (a != None): + self.write(iso.codes.SPACE() + 'A ' + (self.fmt % a)) + if (b != None): + self.write(iso.codes.SPACE() + 'B ' + (self.fmt % b)) + if (c != None): + self.write(iso.codes.SPACE() + 'C ' + (self.fmt % c)) self.write('\n') def remove_temporary_origin(self): @@ -151,7 +165,7 @@ def remove_temporary_origin(self): self.write('\n') ############################################################################ - ## Tools + # Tools def tool_change(self, id): self.write((iso.codes.TOOL() % id) + '\n') @@ -167,7 +181,7 @@ def offset_length(self, id, length=None): pass ############################################################################ - ## Datums + # Datums def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): pass @@ -181,8 +195,8 @@ def workplane(self, id): if ((id >= 1) and (id <= 6)): self.g += iso.codes.WORKPLANE() % (id + iso.codes.WORKPLANE_BASE()) if ((id >= 7) and (id <= 9)): - self.g += ((iso.codes.WORKPLANE() % (6 + iso.codes.WORKPLANE_BASE())) + ('.%i' % (id - 6))) - + self.g += ((iso.codes.WORKPLANE() % + (6 + iso.codes.WORKPLANE_BASE())) + ('.%i' % (id - 6))) ############################################################################ ## Rates + Modes @@ -205,7 +219,8 @@ def calc_feedrate_hv(self, h, v): self.f = iso.codes.FEEDRATE() + (self.ffmt % self.fh) def spindle(self, s, clockwise): - if s < 0: clockwise = not clockwise + if s < 0: + clockwise = not clockwise s = abs(s) self.s = iso.codes.SPINDLE(iso.codes.FORMAT_ANG(), s) if clockwise: @@ -214,16 +229,21 @@ def spindle(self, s, clockwise): self.s = self.s + iso.codes.SPINDLE_CCW() def coolant(self, mode=0): - if (mode <= 0) : self.m.append(iso.codes.COOLANT_OFF()) - elif (mode == 1) : self.m.append(iso.codes.COOLANT_MIST()) - elif (mode == 2) : self.m.append(iso.codes.COOLANT_FLOOD()) + if (mode <= 0): + self.m.append(iso.codes.COOLANT_OFF()) + elif (mode == 1): + self.m.append(iso.codes.COOLANT_MIST()) + elif (mode == 2): + self.m.append(iso.codes.COOLANT_FLOOD()) def gearrange(self, gear=0): - if (gear <= 0) : self.m.append(iso.codes.GEAR_OFF()) - elif (gear <= 4) : self.m.append(iso.codes.GEAR() % (gear + GEAR_BASE())) + if (gear <= 0): + self.m.append(iso.codes.GEAR_OFF()) + elif (gear <= 4): + self.m.append(iso.codes.GEAR() % (gear + GEAR_BASE())) ############################################################################ - ## Moves + # Moves def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write_blocknum() @@ -237,7 +257,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.X() + (self.fmt % (y*2))) else: self.write(iso.codes.X() + (self.fmt % (dy*2))) @@ -246,16 +266,15 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.Z() + (self.fmt % x)) else: self.write(iso.codes.Z() + (self.fmt % dx)) self.x = x - if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): pass #self.write(iso.codes.Z() + (self.fmt % z)) else: @@ -266,7 +285,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (a != None): da = a - self.a - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.A() + (self.fmt % a)) else: self.write(iso.codes.A() + (self.fmt % da)) @@ -274,7 +293,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (b != None): db = b - self.b - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.B() + (self.fmt % b)) else: self.write(iso.codes.B() + (self.fmt % db)) @@ -282,7 +301,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (c != None): dc = c - self.c - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.C() + (self.fmt % c)) else: self.write(iso.codes.C() + (self.fmt % dc)) @@ -292,7 +311,8 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write('\n') def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - if self.same_xyz(x, y, z): return + if self.same_xyz(x, y, z): + return self.write_blocknum() if self.g0123_modal: if self.prev_g0123 != iso.codes.FEED(): @@ -305,7 +325,7 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.X() + (self.fmt % (y*2))) else: self.write(iso.codes.X() + (self.fmt % (dy*2))) @@ -314,7 +334,7 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.Z() + (self.fmt % x)) else: self.write(iso.codes.Z() + (self.fmt % dx)) @@ -322,7 +342,7 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): pass #self.write(iso.codes.Z() + (self.fmt % z)) else: @@ -330,7 +350,8 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): #self.write(iso.codes.Z() + (self.fmt % dz)) self.z = z - if (self.fhv) : self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) + if (self.fhv): + self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) self.write_feedrate() self.write_spindle() self.write_misc() @@ -350,11 +371,14 @@ def same_xyz(self, x=None, y=None, z=None): return True def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - if self.same_xyz(x, y, z): return + if self.same_xyz(x, y, z): + return self.write_blocknum() arc_g_code = '' - if cw: arc_g_code = iso.codes.ARC_CW() - else: arc_g_code = iso.codes.ARC_CCW() + if cw: + arc_g_code = iso.codes.ARC_CW() + else: + arc_g_code = iso.codes.ARC_CCW() if self.g0123_modal: if self.prev_g0123 != arc_g_code: self.write(arc_g_code) @@ -365,23 +389,23 @@ def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): # make X take y values and multiply by 2 for diameter values for lathe if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.X() + (self.fmt % (y*2))) else: self.write(iso.codes.X() + (self.fmt % (dy*2))) self.y = y -#make Z take x values for lathe +# make Z take x values for lathe if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(iso.codes.Z() + (self.fmt % x)) else: self.write(iso.codes.Z() + (self.fmt % dx)) self.x = x if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): pass #self.write(iso.codes.X() + (self.fmt % z)) else: @@ -389,12 +413,17 @@ def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): #self.write(iso.codes.X() + (self.fmt % dz)) self.z = z - if (j != None) : self.write(iso.codes.CENTRE_X() + (self.fmt % j)) #change the order - if (i != None) : self.write(iso.codes.CENTRE_Z() + (self.fmt % i)) #and reversed i and j - if (k != None) :pass # self.write(iso.codes.CENTRE_Z() + (self.fmt % k)) - if (r != None) : self.write(iso.codes.RADIUS() + (self.fmt % r)) + if (j != None): + self.write(iso.codes.CENTRE_X() + (self.fmt % j)) # change the order + if (i != None): + self.write(iso.codes.CENTRE_Z() + (self.fmt % i)) # and reversed i and j + if (k != None): + pass # self.write(iso.codes.CENTRE_Z() + (self.fmt % k)) + if (r != None): + self.write(iso.codes.RADIUS() + (self.fmt % r)) # use horizontal feed rate - if (self.fhv) : self.calc_feedrate_hv(1, 0) + if (self.fhv): + self.calc_feedrate_hv(1, 0) self.write_feedrate() self.write_spindle() self.write_misc() @@ -424,12 +453,12 @@ def set_machine_coordinates(self): self.prev_g0123 = '' ############################################################################ - ## CRC + # CRC def use_CRC(self): return self.useCrc - def start_CRC(self, left = True, radius = 0.0): + def start_CRC(self, left=True, radius=0.0): # set up prep code, to be output on next line if self.t == None: raise "No tool specified for start_CRC()" @@ -443,12 +472,11 @@ def end_CRC(self): self.write('\n') ############################################################################ - ## Cycles + # Cycles def pattern(self): pass - def profile(self): pass @@ -461,7 +489,7 @@ def end_canned_cycle(self): self.prev_f = '' self.prev_retract = '' ############################################################################ - ## Misc + # Misc def comment(self, text): self.write((iso.codes.COMMENT(text) + '\n')) @@ -481,4 +509,5 @@ def variable_set(self, id, value): ################################################################################ + nc.creator = CreatorIso() diff --git a/scripts/addons/cam/nc/lathe1_read.py b/scripts/addons/cam/nc/lathe1_read.py index 6d7892f77..8297825b0 100644 --- a/scripts/addons/cam/nc/lathe1_read.py +++ b/scripts/addons/cam/nc/lathe1_read.py @@ -10,31 +10,34 @@ import sys ################################################################################ + + class Parser(nc.Parser): def __init__(self, writer): nc.Parser.__init__(self, writer) - self.pattern_main = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') + self.pattern_main = re.compile( + '([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') - #if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point - # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal + # if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point + # followed by a possible deimcal, or a letter followed by # with a decimal . deimcal # add your character here > [(!;] for comments char # then look for the 'comment' function towards the end of the file and add another elif def Parse(self, name, oname=None): - self.files_open(name,oname) + self.files_open(name, oname) - #self.begin_ncblock() - #self.begin_path(None) - #self.add_line(z=500) - #self.end_path() - #self.end_ncblock() + # self.begin_ncblock() + # self.begin_path(None) + # self.add_line(z=500) + # self.end_path() + # self.end_ncblock() path_col = None f = None arc = 0 - uw = 0 + uw = 0 while (self.readline()): a = None @@ -113,7 +116,7 @@ def Parse(self, name, oname=None): path_col = "feed" col = "feed" elif (word == 'G82' or word == 'g82'): - drill = True; + drill = True no_move = True path_col = "feed" col = "feed" @@ -126,7 +129,8 @@ def Parse(self, name, oname=None): self.absolute() elif (word == 'G91' or word == 'g91'): self.incremental() - elif (word[0] == 'G') : col = "prep" + elif (word[0] == 'G'): + col = "prep" elif (word[0] == 'I' or word[0] == 'i'): col = "axis" i = eval(word[1:]) @@ -139,9 +143,12 @@ def Parse(self, name, oname=None): col = "axis" k = eval(word[1:]) move = True - elif (word[0] == 'M') : col = "misc" - elif (word[0] == 'N') : col = "blocknum" - elif (word[0] == 'O') : col = "program" + elif (word[0] == 'M'): + col = "misc" + elif (word[0] == 'N'): + col = "blocknum" + elif (word[0] == 'O'): + col = "program" elif (word[0] == 'P' or word[0] == 'p'): col = "axis" p = eval(word[1:]) @@ -158,9 +165,9 @@ def Parse(self, name, oname=None): col = "axis" s = eval(word[1:]) move = True - elif (word[0] == 'T') : + elif (word[0] == 'T'): col = "tool" - self.set_tool( eval(word[1:]) ) + self.set_tool(eval(word[1:])) elif (word[0] == 'X' or word[0] == 'x'): col = "axis" x = eval(word[1:]) @@ -173,24 +180,30 @@ def Parse(self, name, oname=None): col = "axis" u = eval(word[1:]) move = True - uw=1 + uw = 1 elif (word[0] == 'W' or word[0] == 'w'): col = "axis" w = eval(word[1:]) move = True - uw=1 + uw = 1 elif (word[0] == 'Z' or word[0] == 'z'): col = "axis" z = eval(word[1:]) move = True - elif (word[0] == '(') : (col, cdata) = ("comment", True) - elif (word[0] == '!') : (col, cdata) = ("comment", True) - elif (word[0] == ';') : (col, cdata) = ("comment", True) - elif (word[0] == '#') : col = "variable" - elif (word[0] == ':') : col = "blocknum" - elif (ord(word[0]) <= 32) : cdata = True + elif (word[0] == '('): + (col, cdata) = ("comment", True) + elif (word[0] == '!'): + (col, cdata) = ("comment", True) + elif (word[0] == ';'): + (col, cdata) = ("comment", True) + elif (word[0] == '#'): + col = "variable" + elif (word[0] == ':'): + col = "blocknum" + elif (ord(word[0]) <= 32): + cdata = True self.add_text(word, col, cdata) if (drill): @@ -208,17 +221,18 @@ def Parse(self, name, oname=None): else: if (move and not no_move): self.begin_path(path_col) - if (arc==-1): + if (arc == -1): self.add_arc(x, y, z, i, j, k, r, arc) - elif (arc==1): - #self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one + elif (arc == 1): + # self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one self.add_arc(x, y, z, i, j, k, r, arc) - #else : self.add_line(x, y, z, a, b, c) - elif(uw==1): - self.add_lathe_increment_line(u,w) + # else : self.add_line(x, y, z, a, b, c) + elif(uw == 1): + self.add_lathe_increment_line(u, w) - else : self.add_line(x, y, z, a, b, c) - self.end_path() + else: + self.add_line(x, y, z, a, b, c) + self.end_path() self.end_ncblock() diff --git a/scripts/addons/cam/nc/lynx_otter_o.py b/scripts/addons/cam/nc/lynx_otter_o.py index bf4301f02..4680ef18c 100644 --- a/scripts/addons/cam/nc/lynx_otter_o.py +++ b/scripts/addons/cam/nc/lynx_otter_o.py @@ -3,49 +3,50 @@ class Creator(iso.Creator): - def __init__(self): - iso.Creator.__init__(self) + def __init__(self): + iso.Creator.__init__(self) - def SPACE_STR(self): return(' ') + def SPACE_STR(self): return(' ') - def COMMENT(self, comment): return('') + def COMMENT(self, comment): return('') - def PROGRAM(self): return(None) + def PROGRAM(self): return(None) - def FORMAT_DWELL(self): return( self.SPACE() + self.DWELL() + ' X%f') - def SPINDLE_OFF(self): return('M05\n') - #optimize - def RAPID(self): return('G00') - def FEED(self): return('G01') + def FORMAT_DWELL(self): return(self.SPACE() + self.DWELL() + ' X%f') + def SPINDLE_OFF(self): return('M05\n') + # optimize + def RAPID(self): return('G00') + def FEED(self): return('G01') - # def IMPERIAL(self): return('G20\n') - # def METRIC(self): return('G21\n') - # def ABSOLUTE(self): return('G90\n') - # def INCREMENTAL(self): return('G91\n') - # def PLANE_XY(self): return('17\n') - # def PLANE_XZ(self): return('18\n') - # def PLANE_YZ(self): return('19\n') + # def IMPERIAL(self): return('G20\n') + # def METRIC(self): return('G21\n') + # def ABSOLUTE(self): return('G90\n') + # def INCREMENTAL(self): return('G91\n') + # def PLANE_XY(self): return('17\n') + # def PLANE_XZ(self): return('18\n') + # def PLANE_YZ(self): return('19\n') - def dwell(self, t): - pass - """ + def dwell(self, t): + pass + """ self.write_blocknum() self.write_preps() self.write(self.FORMAT_DWELL() % t) self.write_misc() self.write('\n') """ - def tool_change(self, id): - pass - # self.write_blocknum() - # self.write(self.SPACE() + (self.TOOL() % id) + '\n') - # self.write_blocknum() - # self.write(self.SPACE() + self.s.str) - # self.write('\n') - # self.flush_nc() - # self.t = id - - def PROGRAM_END(self): return( self.SPACE() + self.SPINDLE_OFF() + self.SPACE() + 'M30') + + def tool_change(self, id): + pass + # self.write_blocknum() + # self.write(self.SPACE() + (self.TOOL() % id) + '\n') + # self.write_blocknum() + # self.write(self.SPACE() + self.s.str) + # self.write('\n') + # self.flush_nc() + # self.t = id + + def PROGRAM_END(self): return(self.SPACE() + self.SPINDLE_OFF() + self.SPACE() + 'M30') nc.creator = Creator() diff --git a/scripts/addons/cam/nc/mach3.py b/scripts/addons/cam/nc/mach3.py index 25d608586..f2fc8f3b7 100644 --- a/scripts/addons/cam/nc/mach3.py +++ b/scripts/addons/cam/nc/mach3.py @@ -1,19 +1,21 @@ from . import nc from . import iso + class Creator(iso.Creator): - def __init__(self): - iso.Creator.__init__(self) + def __init__(self): + iso.Creator.__init__(self) + + def SPACE_STR(self): return(' ') - def SPACE_STR(self): return(' ') + def program_begin(self, id, comment): + self.write(('(' + 'GCode created using the HeeksCNC Mach3 post processor' + ')' + '\n')) + self.write(('(' + comment + ')' + '\n')) - def program_begin(self, id, comment): - self.write( ('(' + 'GCode created using the HeeksCNC Mach3 post processor' + ')' + '\n') ) - self.write( ('(' + comment + ')' + '\n') ) + def tool_change(self, id): + self.write('G43H%i' % id + '\n') + self.write((self.TOOL() % id) + '\n') + self.t = id - def tool_change(self, id): - self.write('G43H%i'% id +'\n') - self.write((self.TOOL() % id) + '\n') - self.t = id nc.creator = Creator() diff --git a/scripts/addons/cam/nc/mach3_read.py b/scripts/addons/cam/nc/mach3_read.py index 3a830598d..00575a3c3 100644 --- a/scripts/addons/cam/nc/mach3_read.py +++ b/scripts/addons/cam/nc/mach3_read.py @@ -2,6 +2,8 @@ from . import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/makerbotHBP.py b/scripts/addons/cam/nc/makerbotHBP.py index 0a5ad904a..49db7118d 100644 --- a/scripts/addons/cam/nc/makerbotHBP.py +++ b/scripts/addons/cam/nc/makerbotHBP.py @@ -8,6 +8,8 @@ now = datetime.datetime.now() ################################################################################ + + class CreatorMakerbotHBP(iso_modal.CreatorIsoModal): def __init__(self): iso_modal.CreatorIsoModal.__init__(self) @@ -19,33 +21,35 @@ def __init__(self): ################################################################################ # program begin and end + def program_begin(self, id, name=''): self.write((maker.codes.COMMENT(now))) - self.write((maker.codes.EXTRUDER_TEMP('220')) + (maker.codes.COMMENT('Extruder Temp')) ) - self.write((maker.codes.BUILD_BED_TEMP('110'))+ (maker.codes.COMMENT('Build Bed Temp')) ) - self.write((maker.codes.FAN_OFF()) + (maker.codes.COMMENT('Fan Off')) ) - self.write((maker.codes.METRIC()) + (maker.codes.COMMENT('Metric units')) ) - self.write((maker.codes.ABSOLUTE()) + (maker.codes.COMMENT('Absolute units')) ) + self.write((maker.codes.EXTRUDER_TEMP('220')) + (maker.codes.COMMENT('Extruder Temp'))) + self.write((maker.codes.BUILD_BED_TEMP('110')) + (maker.codes.COMMENT('Build Bed Temp'))) + self.write((maker.codes.FAN_OFF()) + (maker.codes.COMMENT('Fan Off'))) + self.write((maker.codes.METRIC()) + (maker.codes.COMMENT('Metric units'))) + self.write((maker.codes.ABSOLUTE()) + (maker.codes.COMMENT('Absolute units'))) self.write('G92 X0 Y0 Z0 (You are now at 0,0,0)\n') self.write('G0 Z15 (Move up for warmup)\n') - self.write((maker.codes.EXTRUDER_SPEED_PWM('255')) + (maker.codes.COMMENT('Extruder Speed')) ) + self.write((maker.codes.EXTRUDER_SPEED_PWM('255')) + + (maker.codes.COMMENT('Extruder Speed'))) self.write('M6 T0 (Wait for tool to heat up)\n') self.write('G04 P5000 (Wait 5 seconds)\n') - self.write((maker.codes.EXTRUDER_ON_FWD()) + (maker.codes.COMMENT('Extruder On')) ) + self.write((maker.codes.EXTRUDER_ON_FWD()) + (maker.codes.COMMENT('Extruder On'))) self.write('G04 P5000 (Wait 5 seconds)\n') - self.write((maker.codes.EXTRUDER_OFF()) + (maker.codes.COMMENT('Extruder Off')) ) + self.write((maker.codes.EXTRUDER_OFF()) + (maker.codes.COMMENT('Extruder Off'))) self.write('M01 (The heated build platform is heating up. Wait until after the lights have turned off for the first time, clear the test extrusion, and click yes.)\n') self.write('G0 Z0 (Go back to zero.)\n') def program_end(self): self.write((maker.codes.COMMENT('End of the file. Begin cool-down'))) - self.write((maker.codes.EXTRUDER_TEMP('0')) + (maker.codes.COMMENT('Extruder Temp')) ) - self.write((maker.codes.BUILD_BED_TEMP('0')) + (maker.codes.COMMENT('Build Bed Temp')) ) - self.write((maker.codes.FAN_ON()) + (maker.codes.COMMENT('Fan On')) ) + self.write((maker.codes.EXTRUDER_TEMP('0')) + (maker.codes.COMMENT('Extruder Temp'))) + self.write((maker.codes.BUILD_BED_TEMP('0')) + (maker.codes.COMMENT('Build Bed Temp'))) + self.write((maker.codes.FAN_ON()) + (maker.codes.COMMENT('Fan On'))) self.write('G92 Z0 (zero our z axis - hack b/c skeinforge mangles gcodes in end.txt)\n') self.write('G1 Z10 (go up 10 b/c it was zeroed earlier.)\n') self.write('G1 X0 Y0 Z10 (go to 0,0,z)\n') - self.write((maker.codes.STEPPERS_OFF()) + (maker.codes.COMMENT('Steppers Off')) ) + self.write((maker.codes.STEPPERS_OFF()) + (maker.codes.COMMENT('Steppers Off'))) def program_stop(self): self.write((maker.codes.EXTRUDER_TEMP('0'))) @@ -58,7 +62,7 @@ def write_blocknum(self): pass def set_plane(self, plane): - pass + pass def workplane(self, id): pass @@ -69,32 +73,32 @@ def spindle(self, s, clockwise): # Extruder Control def extruder_on(self): - self.write((maker.codes.EXTRUDER_ON()) + ('\n')) + self.write((maker.codes.EXTRUDER_ON()) + ('\n')) def extruder_off(self): - self.write((maker.codes.EXTRUDER_OFF()) + ('\n')) + self.write((maker.codes.EXTRUDER_OFF()) + ('\n')) def set_extruder_flowrate(self, flowrate): - self.write((maker.codes.EXTRUDER_SPEED_PWM(flowrate)) + ('\n')) + self.write((maker.codes.EXTRUDER_SPEED_PWM(flowrate)) + ('\n')) def extruder_temp(self, temp): - self.write((maker.codes.EXTRUDER_TEMP(temp)) + ('\n')) + self.write((maker.codes.EXTRUDER_TEMP(temp)) + ('\n')) ################################################################################ # Build Environment Control def build_bed_temp(self, temp): - self.write((maker.codes.BUILD_BED_TEMP(temp)) + ('\n')) + self.write((maker.codes.BUILD_BED_TEMP(temp)) + ('\n')) def chamber_temp(self, temp): - self.write((maker.codes.CHAMBER_TEMP(temp)) + ('\n')) + self.write((maker.codes.CHAMBER_TEMP(temp)) + ('\n')) ################################################################################ # Fan Control def fan_on(self): - self.write((maker.codes.FAN_ON()) + ('\n')) + self.write((maker.codes.FAN_ON()) + ('\n')) def fan_off(self): - self.write((maker.codes.FAN_OFF()) + ('\n')) + self.write((maker.codes.FAN_OFF()) + ('\n')) ################################################################################ # Custom routines @@ -111,15 +115,15 @@ def insert(self, text): ################################################################################ # tool info def tool_change(self, id): - pass + pass # self.write_blocknum() # self.write((maker.codes.TOOL() % id) + '\n') # self.t = id def tool_defn(self, id, name='', params=None): - pass + pass ############################################################################ -## Moves +# Moves def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write_blocknum() @@ -132,14 +136,14 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write_preps() if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.X() + (self.fmt % x)) else: self.write(maker.codes.X() + (self.fmt % dx)) self.x = x if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Y() + (self.fmt % y)) else: self.write(maker.codes.Y() + (self.fmt % dy)) @@ -147,7 +151,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.y = y if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Z() + (self.fmt % z)) else: self.write(maker.codes.Z() + (self.fmt % dz)) @@ -156,7 +160,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (a != None): da = a - self.a - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.A() + (self.fmt % a)) else: self.write(maker.codes.A() + (self.fmt % da)) @@ -164,7 +168,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (b != None): db = b - self.b - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.B() + (self.fmt % b)) else: self.write(maker.codes.B() + (self.fmt % db)) @@ -172,7 +176,7 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): if (c != None): dc = c - self.c - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.C() + (self.fmt % c)) else: self.write(maker.codes.C() + (self.fmt % dc)) @@ -182,7 +186,8 @@ def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.write('\n') def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - if self.same_xyz(x, y, z): return + if self.same_xyz(x, y, z): + return self.write_blocknum() if self.g0123_modal: if self.prev_g0123 != maker.codes.FEED(): @@ -194,14 +199,14 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): dx = dy = dz = 0 if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.X() + (self.fmt % x)) else: self.write(maker.codes.X() + (self.fmt % dx)) self.x = x if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Y() + (self.fmt % y)) else: self.write(maker.codes.Y() + (self.fmt % dy)) @@ -209,13 +214,14 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): self.y = y if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Z() + (self.fmt % z)) else: self.write(maker.codes.Z() + (self.fmt % dz)) self.z = z - if (self.fhv) : self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) + if (self.fhv): + self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) self.write_feedrate() self.write_spindle() self.write_misc() @@ -235,11 +241,14 @@ def same_xyz(self, x=None, y=None, z=None): return True def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - if self.same_xyz(x, y, z): return + if self.same_xyz(x, y, z): + return self.write_blocknum() arc_g_code = '' - if cw: arc_g_code = maker.codes.ARC_CW() - else: arc_g_code = maker.codes.ARC_CCW() + if cw: + arc_g_code = maker.codes.ARC_CW() + else: + arc_g_code = maker.codes.ARC_CCW() if self.g0123_modal: if self.prev_g0123 != arc_g_code: self.write(arc_g_code) @@ -249,31 +258,36 @@ def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): self.write_preps() if (x != None): dx = x - self.x - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.X() + (self.fmt % x)) else: self.write(maker.codes.X() + (self.fmt % dx)) self.x = x if (y != None): dy = y - self.y - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Y() + (self.fmt % y)) else: self.write(maker.codes.Y() + (self.fmt % dy)) self.y = y if (z != None): dz = z - self.z - if (self.absolute_flag ): + if (self.absolute_flag): self.write(maker.codes.Z() + (self.fmt % z)) else: self.write(maker.codes.Z() + (self.fmt % dz)) self.z = z - if (i != None) : self.write(maker.codes.CENTRE_X() + (self.fmt % i)) - if (j != None) : self.write(maker.codes.CENTRE_Y() + (self.fmt % j)) - if (k != None) : self.write(maker.codes.CENTRE_Z() + (self.fmt % k)) - if (r != None) : self.write(maker.codes.RADIUS() + (self.fmt % r)) + if (i != None): + self.write(maker.codes.CENTRE_X() + (self.fmt % i)) + if (j != None): + self.write(maker.codes.CENTRE_Y() + (self.fmt % j)) + if (k != None): + self.write(maker.codes.CENTRE_Z() + (self.fmt % k)) + if (r != None): + self.write(maker.codes.RADIUS() + (self.fmt % r)) # use horizontal feed rate - if (self.fhv) : self.calc_feedrate_hv(1, 0) + if (self.fhv): + self.calc_feedrate_hv(1, 0) self.write_feedrate() self.write_spindle() self.write_misc() @@ -302,4 +316,5 @@ def set_machine_coordinates(self): self.write(maker.codes.MACHINE_COORDINATES()) self.prev_g0123 = '' + nc.creator = CreatorMakerbotHBP() diff --git a/scripts/addons/cam/nc/makerbotHBP_read.py b/scripts/addons/cam/nc/makerbotHBP_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/makerbotHBP_read.py +++ b/scripts/addons/cam/nc/makerbotHBP_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/makerbot_codes.py b/scripts/addons/cam/nc/makerbot_codes.py index 14b8b3366..814f1a6f3 100644 --- a/scripts/addons/cam/nc/makerbot_codes.py +++ b/scripts/addons/cam/nc/makerbot_codes.py @@ -8,121 +8,122 @@ # Many of these codes have nothing to do with reprap/additive machining but are left here in anticipation of future hybrid machines. class Codes(): - def SPACE(self): return(' ') - def FORMAT_FEEDRATE(self): return('%.2f') - def FORMAT_IN(self): return('%.5f') - def FORMAT_MM(self): return('%.3f') - def FORMAT_ANG(self): return('%.1f') - def FORMAT_TIME(self): return('%.2f') - def FORMAT_DWELL(self): return('P%f') - - def BLOCK(self): return('N%i' + self.SPACE()) - def COMMENT(self,comment): return( (' (%s)\n' % comment ) ) - def VARIABLE(self): return( '#%i') - def VARIABLE_SET(self): return( '=%.3f') - - def PROGRAM(self): return( 'O%i') - def PROGRAM_END(self): return( 'M02') - - def SUBPROG_CALL(self): return( 'M98' + self.SPACE() + 'P%i') - def SUBPROG_END(self): return( 'M99') - - def STOP_OPTIONAL(self): return('M01') - def STOP(self): return('M00') - - def IMPERIAL(self): return(self.SPACE() + 'G20') - def METRIC(self): return(self.SPACE() + 'G21' + self.SPACE()) - def ABSOLUTE(self): return(self.SPACE() + 'G90' + self.SPACE()) - def INCREMENTAL(self): return(self.SPACE() + 'G91') - def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92' + self.SPACE()) - def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1' + self.SPACE()) - def POLAR_ON(self): return(self.SPACE() + 'G16') - def POLAR_OFF(self): return(self.SPACE() + 'G15') - def PLANE_XY(self): return(self.SPACE() + 'G17') - def PLANE_XZ(self): return(self.SPACE() + 'G18') - def PLANE_YZ(self): return(self.SPACE() + 'G19') - - def TOOL(self): return(self.SPACE() +'T%i') - def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1' + self.SPACE()) - - def WORKPLANE(self): return('G%i') - def WORKPLANE_BASE(self): return(53) - - def FEEDRATE(self): return((self.SPACE() + ' F')) - def SPINDLE(self, format, speed): return(self.SPACE() + 'S' + (format % speed)) - def SPINDLE_CW(self): return(self.SPACE() + 'M03') - def SPINDLE_CCW(self): return(self.SPACE() + 'M04') - def COOLANT_OFF(self): return(self.SPACE() + 'M09') - def COOLANT_MIST(self): return(self.SPACE() + 'M07') - def COOLANT_FLOOD(self): return(self.SPACE() + 'M08') - def GEAR_OFF(self): return(self.SPACE() + '?') - def GEAR(self): return('M%i') - def GEAR_BASE(self): return(37) - - def RAPID(self): return('G0') - def FEED(self): return('G1') - def ARC_CW(self): return('G2') - def ARC_CCW(self): return('G3') - def DWELL(self): return('G04') - def DRILL(self): return(self.SPACE() + 'G81') - def DRILL_WITH_DWELL(self, format, dwell): return(self.SPACE() + 'G82' + (format % dwell)) - def PECK_DRILL(self): return(self.SPACE() + 'G83') - def PECK_DEPTH(self, format, depth): return(self.SPACE() + 'Q' + (format % depth)) - def RETRACT(self, format, height): return(self.SPACE() + 'R' + (format % height)) - def END_CANNED_CYCLE(self): return(self.SPACE() + 'G80') - - def X(self): return(self.SPACE() + 'X') - def Y(self): return(self.SPACE() + 'Y') - def Z(self): return(self.SPACE() + 'Z') - def A(self): return(self.SPACE() + 'A') - def B(self): return(self.SPACE() + 'B') - def C(self): return(self.SPACE() + 'C') - def CENTRE_X(self): return(self.SPACE() + 'I') - def CENTRE_Y(self): return(self.SPACE() + 'J') - def CENTRE_Z(self): return(self.SPACE() + 'K') - def RADIUS(self): return(self.SPACE() + 'R') - def TIME(self): return(self.SPACE() + 'P') - - def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2' + self.SPACE()) - def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3' + self.SPACE()) - def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4' + self.SPACE()) - def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5' + self.SPACE()) - - def MACHINE_COORDINATES(self): return('G53' + self.SPACE()) - - def EXTRUDER_ON (self): return('M101') #deprecated - def EXTRUDER_OFF (self): return('M103') - def EXTRUDER_TEMP (self, degree_celsius): return('M104 S' + '%s' % degree_celsius) - def EXTRUDER_TEMP_WAIT (self, degree_celsius): return('M109 S' + '%s' % degree_celsius) - def READ_EXTRUDER_TEMP (self): return('M105') - def EXTRUDER_SPEED_PWM (self, speed_in_PWM): return('M108 S' + '%s' % speed_in_PWM) #deprecated - def EXTRUDER_SPEED_RPM (self, speed_in_RPM): return('M108 P' + '%s' % speed_in_RPM) #deprecated - - def STEPPERS_OFF(self): return(self.SPACE() + 'M118') - - def ALL_WAIT (self): return(self.SPACE() + 'M116') # Wait for all temperature and slow-changing variables to reach set values - - def FAN_ON (self): return(self.SPACE() + 'M106') - def FAN_OFF (self): return(self.SPACE() + 'M107') - - def VALVE_OPEN (self, delay): return(self.SPACE() + ('M126 P' + '%' % delay) ) - def VALVE_CLOSE (self, delay): return(self.SPACE() + ('M127 P' + '%' % delay) ) - - def BUILD_BED_TEMP (self, degree_celsius): return('M140 S' + '%s' % degree_celsius) - def BED_HOLDING_PRESSURE (self, pressure): return('M142 S' + '%s' % pressure) - - def CHAMBER_TEMP (self, degree_celsius): return('M141 S' + '%s' % degree_celsius) - -#The following codes are listed on the reprap wiki page at http://reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes but require more study. + def SPACE(self): return(' ') + def FORMAT_FEEDRATE(self): return('%.2f') + def FORMAT_IN(self): return('%.5f') + def FORMAT_MM(self): return('%.3f') + def FORMAT_ANG(self): return('%.1f') + def FORMAT_TIME(self): return('%.2f') + def FORMAT_DWELL(self): return('P%f') + + def BLOCK(self): return('N%i' + self.SPACE()) + def COMMENT(self, comment): return((' (%s)\n' % comment)) + def VARIABLE(self): return('#%i') + def VARIABLE_SET(self): return('=%.3f') + + def PROGRAM(self): return('O%i') + def PROGRAM_END(self): return('M02') + + def SUBPROG_CALL(self): return('M98' + self.SPACE() + 'P%i') + def SUBPROG_END(self): return('M99') + + def STOP_OPTIONAL(self): return('M01') + def STOP(self): return('M00') + + def IMPERIAL(self): return(self.SPACE() + 'G20') + def METRIC(self): return(self.SPACE() + 'G21' + self.SPACE()) + def ABSOLUTE(self): return(self.SPACE() + 'G90' + self.SPACE()) + def INCREMENTAL(self): return(self.SPACE() + 'G91') + def SET_TEMPORARY_COORDINATE_SYSTEM(self): return('G92' + self.SPACE()) + def REMOVE_TEMPORARY_COORDINATE_SYSTEM(self): return('G92.1' + self.SPACE()) + def POLAR_ON(self): return(self.SPACE() + 'G16') + def POLAR_OFF(self): return(self.SPACE() + 'G15') + def PLANE_XY(self): return(self.SPACE() + 'G17') + def PLANE_XZ(self): return(self.SPACE() + 'G18') + def PLANE_YZ(self): return(self.SPACE() + 'G19') + + def TOOL(self): return(self.SPACE() + 'T%i') + def TOOL_DEFINITION(self): return('G10' + self.SPACE() + 'L1' + self.SPACE()) + + def WORKPLANE(self): return('G%i') + def WORKPLANE_BASE(self): return(53) + + def FEEDRATE(self): return((self.SPACE() + ' F')) + def SPINDLE(self, format, speed): return(self.SPACE() + 'S' + (format % speed)) + def SPINDLE_CW(self): return(self.SPACE() + 'M03') + def SPINDLE_CCW(self): return(self.SPACE() + 'M04') + def COOLANT_OFF(self): return(self.SPACE() + 'M09') + def COOLANT_MIST(self): return(self.SPACE() + 'M07') + def COOLANT_FLOOD(self): return(self.SPACE() + 'M08') + def GEAR_OFF(self): return(self.SPACE() + '?') + def GEAR(self): return('M%i') + def GEAR_BASE(self): return(37) + + def RAPID(self): return('G0') + def FEED(self): return('G1') + def ARC_CW(self): return('G2') + def ARC_CCW(self): return('G3') + def DWELL(self): return('G04') + def DRILL(self): return(self.SPACE() + 'G81') + def DRILL_WITH_DWELL(self, format, dwell): return(self.SPACE() + 'G82' + (format % dwell)) + def PECK_DRILL(self): return(self.SPACE() + 'G83') + def PECK_DEPTH(self, format, depth): return(self.SPACE() + 'Q' + (format % depth)) + def RETRACT(self, format, height): return(self.SPACE() + 'R' + (format % height)) + def END_CANNED_CYCLE(self): return(self.SPACE() + 'G80') + + def X(self): return(self.SPACE() + 'X') + def Y(self): return(self.SPACE() + 'Y') + def Z(self): return(self.SPACE() + 'Z') + def A(self): return(self.SPACE() + 'A') + def B(self): return(self.SPACE() + 'B') + def C(self): return(self.SPACE() + 'C') + def CENTRE_X(self): return(self.SPACE() + 'I') + def CENTRE_Y(self): return(self.SPACE() + 'J') + def CENTRE_Z(self): return(self.SPACE() + 'K') + def RADIUS(self): return(self.SPACE() + 'R') + def TIME(self): return(self.SPACE() + 'P') + + def PROBE_TOWARDS_WITH_SIGNAL(self): return('G38.2' + self.SPACE()) + def PROBE_TOWARDS_WITHOUT_SIGNAL(self): return('G38.3' + self.SPACE()) + def PROBE_AWAY_WITH_SIGNAL(self): return('G38.4' + self.SPACE()) + def PROBE_AWAY_WITHOUT_SIGNAL(self): return('G38.5' + self.SPACE()) + + def MACHINE_COORDINATES(self): return('G53' + self.SPACE()) + + def EXTRUDER_ON(self): return('M101') # deprecated + def EXTRUDER_OFF(self): return('M103') + def EXTRUDER_TEMP(self, degree_celsius): return('M104 S' + '%s' % degree_celsius) + def EXTRUDER_TEMP_WAIT(self, degree_celsius): return('M109 S' + '%s' % degree_celsius) + def READ_EXTRUDER_TEMP(self): return('M105') + def EXTRUDER_SPEED_PWM(self, speed_in_PWM): return('M108 S' + '%s' % speed_in_PWM) # deprecated + def EXTRUDER_SPEED_RPM(self, speed_in_RPM): return('M108 P' + '%s' % speed_in_RPM) # deprecated + + def STEPPERS_OFF(self): return(self.SPACE() + 'M118') + + # Wait for all temperature and slow-changing variables to reach set values + def ALL_WAIT(self): return(self.SPACE() + 'M116') + + def FAN_ON(self): return(self.SPACE() + 'M106') + def FAN_OFF(self): return(self.SPACE() + 'M107') + + def VALVE_OPEN(self, delay): return(self.SPACE() + ('M126 P' + '%' % delay)) + def VALVE_CLOSE(self, delay): return(self.SPACE() + ('M127 P' + '%' % delay)) + + def BUILD_BED_TEMP(self, degree_celsius): return('M140 S' + '%s' % degree_celsius) + def BED_HOLDING_PRESSURE(self, pressure): return('M142 S' + '%s' % pressure) + + def CHAMBER_TEMP(self, degree_celsius): return('M141 S' + '%s' % degree_celsius) + +# The following codes are listed on the reprap wiki page at http://reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes but require more study. # -#G28 G Y Xnnn Ynnn Znnn Move to origin (on specified axes only, if X/Y/Z parameters are present) -#M105 M N none Request current extruder and base temperatures (in Celsius) -#M110 M N none Set current line number to Nxxx value preceeding command -#M111 M N Snnn Set debug level bitfield to value of parameter (default 6) -#M112 M N none Emergency stop (stop immediately, discarding any buffered commands) -#M113 M N Snnn Set Extruder PWM (to value defined by pot, or to parameter value if present) -#M114 M N none Get Current Position (return current X, Y, Z and E values) -#M117 M N none Get Zero Position (return X, Y, Z and E values of endstop hits) +# G28 G Y Xnnn Ynnn Znnn Move to origin (on specified axes only, if X/Y/Z parameters are present) +# M105 M N none Request current extruder and base temperatures (in Celsius) +# M110 M N none Set current line number to Nxxx value preceeding command +# M111 M N Snnn Set debug level bitfield to value of parameter (default 6) +# M112 M N none Emergency stop (stop immediately, discarding any buffered commands) +# M113 M N Snnn Set Extruder PWM (to value defined by pot, or to parameter value if present) +# M114 M N none Get Current Position (return current X, Y, Z and E values) +# M117 M N none Get Zero Position (return X, Y, Z and E values of endstop hits) codes = Codes() diff --git a/scripts/addons/cam/nc/nc.py b/scripts/addons/cam/nc/nc.py index c4632fa82..1860ad516 100644 --- a/scripts/addons/cam/nc/nc.py +++ b/scripts/addons/cam/nc/nc.py @@ -21,688 +21,785 @@ ncFLOOD = 2 ################################################################################ + + class Creator: - def __init__(self): - pass + def __init__(self): + pass + + ############################################################################ + # Internals + + def file_open(self, name): + # self.buffer=[] + self.file = open(name, 'w') + self.filename = name + + def file_close(self): + # self.file.write(''.join(self.buffer)) + # self.buffer=[] + self.file.close() + + def write(self, s): + self.file.write(s) + # self.buffer.append(s) + # if len(self.buffer)>100000: + # self.file.write(''.join(self.buffer)) + # self.buffer=[] + + def writem(self, a): + self.file.write(''.join(a)) + # self.buffer.extend(a) + ############################################################################ + # Programs + + def program_begin(self, id, name=''): + """Begin a program""" + pass + + def add_stock(self, type_name, params): + pass + + def program_stop(self, optional=False): + """Stop the machine""" + pass + + def program_end(self): + """End the program""" + pass + + def flush_nc(self): + """Flush all pending codes""" + pass + + ############################################################################ + # Subprograms + + def sub_begin(self, id, name=''): + """Begin a subprogram""" + pass + + def sub_call(self, id): + """Call a subprogram""" + pass + + def sub_end(self): + """Return from a subprogram""" + pass + + ############################################################################ + # Settings + + def imperial(self): + """Set imperial units""" + pass + + def metric(self): + """Set metric units""" + pass + + def absolute(self): + """Set absolute coordinates""" + pass + + def incremental(self): + """Set incremental coordinates""" + pass + + def polar(self, on=True): + """Set polar coordinates""" + pass + + def set_plane(self, plane): + """Set plane""" + pass + + def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Set temporary origin G92""" + pass + + def remove_temporary_origin(self): + """Remote temporary origin G92.1""" + pass + + ############################################################################ + # Tools + + def tool_change(self, id): + """Change the tool""" + pass + + def tool_defn(self, id, name='', params=None): + """Define a tool""" + pass + + def offset_radius(self, id, radius=None): + """Set tool radius offsetting""" + pass + + def offset_length(self, id, length=None): + """Set tool length offsetting""" + pass + + def current_tool(self): + return None + + ############################################################################ + # Datums + + def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Shift the datum""" + pass - ############################################################################ - ## Internals + def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Set the datum""" + pass - def file_open(self, name): - #self.buffer=[] - self.file = open(name, 'w') - self.filename = name + def workplane(self, id): + """Set the workplane""" + pass - def file_close(self): - #self.file.write(''.join(self.buffer)) - #self.buffer=[] - self.file.close() + def clearanceplane(self, z=None): + """set clearance plane""" + pass - def write(self, s): - self.file.write(s) - #self.buffer.append(s) - #if len(self.buffer)>100000: - # self.file.write(''.join(self.buffer)) - # self.buffer=[] + ############################################################################ + # APT360 like Transformation Definitions + # These definitions were created while looking at Irvin Kraal's book on APT + # - Numerical Control Progamming in APT - page 211 - def writem(self, a): - self.file.write(''.join(a)) - #self.buffer.extend(a) - ############################################################################ - ## Programs + def matrix(self, a1=None, b1=None, c1=None, a2=None, b2=None, c2=None, a3=None, b3=None, c3=None): + """Create a matrix for transformations""" + pass - def program_begin(self, id, name=''): - """Begin a program""" - pass + def translate(self, x=None, y=None, z=None): + """Translate in x,y,z direction""" + pass - def add_stock(self, type_name, params): - pass + def rotate(self, xyrot=None, yzrot=None, zxrot=None, angle=None): + """Rotate about a coordinate axis""" + pass - def program_stop(self, optional=False): - """Stop the machine""" - pass + def scale(self, k=None): + """Scale by factor k""" + pass - def program_end(self): - """End the program""" - pass + def matrix_product(self, matrix1=None, matrix2=None): + """Create matrix that is the product of two other matrices""" + pass - def flush_nc(self): - """Flush all pending codes""" - pass + def mirror_plane(self, plane1=None, plane2=None, plane3=None): + """Mirror image about one or more coordinate planes""" + pass - ############################################################################ - ## Subprograms - - def sub_begin(self, id, name=''): - """Begin a subprogram""" - pass - - def sub_call(self, id): - """Call a subprogram""" - pass - - def sub_end(self): - """Return from a subprogram""" - pass - - ############################################################################ - ## Settings - - def imperial(self): - """Set imperial units""" - pass - - def metric(self): - """Set metric units""" - pass - - def absolute(self): - """Set absolute coordinates""" - pass - - def incremental(self): - """Set incremental coordinates""" - pass - - def polar(self, on=True): - """Set polar coordinates""" - pass - - def set_plane(self, plane): - """Set plane""" - pass - - def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): - """Set temporary origin G92""" - pass - - def remove_temporary_origin(self): - """Remote temporary origin G92.1""" - pass - - ############################################################################ - ## Tools - - def tool_change(self, id): - """Change the tool""" - pass - - def tool_defn(self, id, name='', params=None): - """Define a tool""" - pass - - def offset_radius(self, id, radius=None): - """Set tool radius offsetting""" - pass - - def offset_length(self, id, length=None): - """Set tool length offsetting""" - pass - - def current_tool(self): - return None - - ############################################################################ - ## Datums - - def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): - """Shift the datum""" - pass - - def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): - """Set the datum""" - pass - - def workplane(self, id): - """Set the workplane""" - pass - - def clearanceplane(self,z=None): - """set clearance plane""" - pass - - ############################################################################ - ## APT360 like Transformation Definitions - ## These definitions were created while looking at Irvin Kraal's book on APT - ## - Numerical Control Progamming in APT - page 211 - - def matrix(self,a1=None,b1=None,c1=None,a2=None,b2=None,c2=None,a3=None,b3=None,c3=None): - """Create a matrix for transformations""" - pass - def translate(self,x=None,y=None,z=None): - """Translate in x,y,z direction""" - pass - def rotate(self,xyrot=None,yzrot=None,zxrot=None,angle=None): - """Rotate about a coordinate axis""" - pass - def scale(self,k=None): - """Scale by factor k""" - pass - def matrix_product(self,matrix1=None,matrix2=None): - """Create matrix that is the product of two other matrices""" - pass - def mirror_plane(self,plane1=None,plane2=None,plane3=None): - """Mirror image about one or more coordinate planes""" - pass - def mirror_line(self,line=None): - """Mirror about a line""" - pass - - - ############################################################################ - ## Rates + Modes - - def feedrate(self, f): - """Set the feedrate""" - pass - - def feedrate_hv(self, fh, fv): - """Set the horizontal and vertical feedrates""" - pass - - def spindle(self, s, clockwise=True): - """Set the spindle speed""" - pass - - def coolant(self, mode=0): - """Set the coolant mode""" - pass - - def gearrange(self, gear=0): - """Set the gear range""" - pass - - ############################################################################ - ## Moves - - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): - """Rapid move""" - pass - - def feed(self, x=None, y=None, z=None, a = None, b = None, c = None): - """Feed move""" - pass - - def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - """Clockwise arc move""" - pass - - def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - """Counterclockwise arc move""" - pass - - def dwell(self, t): - """Dwell""" - pass + def mirror_line(self, line=None): + """Mirror about a line""" + pass - def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): - """Rapid relative to home position""" - pass + ############################################################################ + ## Rates + Modes - def rapid_unhome(self): - """Return from rapid home""" - pass - - def set_machine_coordinates(self): - """Set machine coordinates""" - pass + def feedrate(self, f): + """Set the feedrate""" + pass - ############################################################################ - ## Cutter radius compensation + def feedrate_hv(self, fh, fv): + """Set the horizontal and vertical feedrates""" + pass - def use_CRC(self): - """CRC""" - return False + def spindle(self, s, clockwise=True): + """Set the spindle speed""" + pass - ############################################################################ - ## Cycles + def coolant(self, mode=0): + """Set the coolant mode""" + pass - def pattern(self): - """Simple pattern eg. circle, rect""" - pass + def gearrange(self, gear=0): + """Set the gear range""" + pass - def pocket(self): - """Pocket routine""" - pass + ############################################################################ + # Moves - def profile(self): - """Profile routine""" - pass + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Rapid move""" + pass - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): - """Drilling routines""" - pass + def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Feed move""" + pass - # original prototype was: - # def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None): - # - # current call is like so: - # tap(x=10, y=10, z=0, tap_mode=0, depth=12.7, standoff=6.35, direction=0, pitch=1.25) - # just add tap_mode & direction parameters + def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + """Clockwise arc move""" + pass - def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): - """Tapping routines""" - pass + def arc_ccw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + """Counterclockwise arc move""" + pass - def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): - """Boring routines""" - pass + def dwell(self, t): + """Dwell""" + pass - def end_canned_cycle(self): - pass + def rapid_home(self, x=None, y=None, z=None, a=None, b=None, c=None): + """Rapid relative to home position""" + pass - ############################################################################ - ## Misc + def rapid_unhome(self): + """Return from rapid home""" + pass - def comment(self, text): - """Insert a comment""" - pass + def set_machine_coordinates(self): + """Set machine coordinates""" + pass - def insert(self, text): - """APT style INSERT statement""" - pass + ############################################################################ + # Cutter radius compensation - def block_delete(self, on=False): - """block to ignore if block delete switch is on""" - pass + def use_CRC(self): + """CRC""" + return False - def variable(self, id): - """Insert a variable""" - pass + ############################################################################ + # Cycles - def variable_set(self, id, value): - """Set a variable""" - pass + def pattern(self): + """Simple pattern eg. circle, rect""" + pass - def probe_linear_centre_outside(self, x1=None, y1=None, depth=None, x2=None, y2=None ): - pass + def pocket(self): + """Pocket routine""" + pass - def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None ): - pass + def profile(self): + """Profile routine""" + pass - def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): - pass + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + """Drilling routines""" + pass - def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): - pass + # original prototype was: + # def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None): + # + # current call is like so: + # tap(x=10, y=10, z=0, tap_mode=0, depth=12.7, standoff=6.35, direction=0, pitch=1.25) + # just add tap_mode & direction parameters - def open_log_file(self, xml_file_name=None ): - pass + def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): + """Tapping routines""" + pass - def log_coordinate(self, x=None, y=None, z=None): - pass + def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): + """Boring routines""" + pass - def log_message(self, message=None): - pass + def end_canned_cycle(self): + pass - def close_log_file(self): - pass + ############################################################################ + # Misc - def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): - pass + def comment(self, text): + """Insert a comment""" + pass - def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): - pass + def insert(self, text): + """APT style INSERT statement""" + pass - def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): - pass + def block_delete(self, on=False): + """block to ignore if block delete switch is on""" + pass - def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance ): - pass + def variable(self, id): + """Insert a variable""" + pass - ############################################################################ - ## NC code creator for additive machines like RepRap + def variable_set(self, id, value): + """Set a variable""" + pass + def probe_linear_centre_outside(self, x1=None, y1=None, depth=None, x2=None, y2=None): + pass - def wipe(self): - """wipe routine""" - pass + def probe_single_point(self, point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None): + pass - def extruder_on(self): - """Turn on the extruder""" - pass + def probe_downward_point(self, x=None, y=None, depth=None, intersection_variable_z=None): + pass - def extruder_off(self): - """turn off the extruder""" - pass + def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): + pass - def set_extruder_flowrate(self, flowrate): - """Set the flowrate for the extruder""" - pass + def open_log_file(self, xml_file_name=None): + pass - def extruder_temp(self, temp): - """Set the extruder temp in celsius""" - pass + def log_coordinate(self, x=None, y=None, z=None): + pass - def fan_on(self): - """turn on the cooling fan""" - pass + def log_message(self, message=None): + pass - def fan_off(self): - """turn off the cooling fan""" - pass + def close_log_file(self): + pass - def build_bed_temp(self, temp): - """Set the bed temp in celsius""" - pass + def rapid_to_midpoint(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): + pass - def chamber_temp(self, temp): - """Set the chamber temp in celsius""" - pass + def rapid_to_intersection(self, x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): + pass - def begin_ncblock(self): - # if the moves have come from backplotting nc code, then the nc code text can be given with these three functions - pass + def rapid_to_rotated_coordinate(self, x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): + pass - def end_ncblock(self): - pass + def set_path_control_mode(self, mode, motion_blending_tolerance, naive_cam_tolerance): + pass - def add_text(self, s, col, cdata): - pass + ############################################################################ + # NC code creator for additive machines like RepRap + + def wipe(self): + """wipe routine""" + pass + + def extruder_on(self): + """Turn on the extruder""" + pass + + def extruder_off(self): + """turn off the extruder""" + pass + + def set_extruder_flowrate(self, flowrate): + """Set the flowrate for the extruder""" + pass + + def extruder_temp(self, temp): + """Set the extruder temp in celsius""" + pass + + def fan_on(self): + """turn on the cooling fan""" + pass + + def fan_off(self): + """turn off the cooling fan""" + pass + + def build_bed_temp(self, temp): + """Set the bed temp in celsius""" + pass + + def chamber_temp(self, temp): + """Set the chamber temp in celsius""" + pass + + def begin_ncblock(self): + # if the moves have come from backplotting nc code, then the nc code text can be given with these three functions + pass + + def end_ncblock(self): + pass + + def add_text(self, s, col, cdata): + pass ################################################################################ + creator = Creator() ############################################################################ -## Internals +# Internals + def write(s): - creator.write(s) + creator.write(s) + def output(filename): - creator.file_open(filename) + creator.file_open(filename) ############################################################################ -## Programs +# Programs + def program_begin(id, name=''): - creator.program_begin(id, name) + creator.program_begin(id, name) + def add_stock(type_name, params): - creator.add_stock(type_name, params) + creator.add_stock(type_name, params) + def program_stop(optional=False): - creator.program_stop(optional) + creator.program_stop(optional) + def program_end(): - creator.program_end() + creator.program_end() + def flush_nc(): - creator.flush_nc() + creator.flush_nc() ############################################################################ -## Subprograms +# Subprograms + def sub_begin(id, name=''): - creator.sub_begin(id, name) + creator.sub_begin(id, name) + def sub_call(id): - creator.sub_call(id) + creator.sub_call(id) + def sub_end(): - creator.sub_end() + creator.sub_end() ############################################################################ -## Settings +# Settings + def imperial(): - creator.imperial() + creator.imperial() + def metric(): - creator.metric() + creator.metric() + def absolute(): - creator.absolute() + creator.absolute() + def incremental(): - creator.incremental() + creator.incremental() + def polar(on=True): - creator.polar(on) + creator.polar(on) + def set_plane(plane): - creator.set_plane(plane) + creator.set_plane(plane) + def set_temporary_origin(x=None, y=None, z=None, a=None, b=None, c=None): - creator.set_temporary_origin(x,y,z,a,b,c) + creator.set_temporary_origin(x, y, z, a, b, c) + def remove_temporary_origin(): - creator.remove_temporary_origin() + creator.remove_temporary_origin() ############################################################################ -## Tools +# Tools + def tool_change(id): - creator.tool_change(id) + creator.tool_change(id) + def tool_defn(id, name='', params=None): - creator.tool_defn(id, name, params) + creator.tool_defn(id, name, params) + def offset_radius(id, radius=None): - creator.offset_radius(id, radius) + creator.offset_radius(id, radius) + def offset_length(id, length=None): - creator.offset_length(id, length) + creator.offset_length(id, length) + def current_tool(self): - return creator.current_tool() + return creator.current_tool() ############################################################################ -## Datums +# Datums + def datum_shift(x=None, y=None, z=None, a=None, b=None, c=None): - creator.datum_shift(x, y, z, a, b, c) + creator.datum_shift(x, y, z, a, b, c) + def datum_set(x=None, y=None, z=None, a=None, b=None, c=None): - creator.datum_set(x, y, z, a, b, c) + creator.datum_set(x, y, z, a, b, c) + def workplane(id): - creator.workplane(id) + creator.workplane(id) + def clearanceplane(z=None): - creator.clearanceplane(z) + creator.clearanceplane(z) ############################################################################ -## APT360 like Transformation Definitions -## These definitions were created while looking at Irvin Kraal's book on APT -## - Numerical Control Progamming in APT - page 211 +# APT360 like Transformation Definitions +# These definitions were created while looking at Irvin Kraal's book on APT +# - Numerical Control Progamming in APT - page 211 -def matrix(a1=None,b1=None,c1=None,a2=None,b2=None,c2=None,a3=None,b3=None,c3=None): - creator.matrix(a1,b1,c1,a2,b2,c2,a3,b3,c3) -def translate(x=None,y=None,z=None): - creator.translate(x,y,z) +def matrix(a1=None, b1=None, c1=None, a2=None, b2=None, c2=None, a3=None, b3=None, c3=None): + creator.matrix(a1, b1, c1, a2, b2, c2, a3, b3, c3) + + +def translate(x=None, y=None, z=None): + creator.translate(x, y, z) + + +def rotate(xyrot=None, yzrot=None, zxrot=None, angle=None): + creator.rotate(xyrot, yzrot, zxrot, angle) -def rotate(xyrot=None,yzrot=None,zxrot=None,angle=None): - creator.rotate(xyrot,yzrot,zxrot,angle) def scale(k=None): - creator.scale(k) + creator.scale(k) -def matrix_product(matrix1=None,matrix2=None): - creator.matrix_product(matrix1,matrix2) -def mirror_plane(plane1=None,plane2=None,plane3=None): - creator.mirror_plane(plane1,plane2,plane3) +def matrix_product(matrix1=None, matrix2=None): + creator.matrix_product(matrix1, matrix2) -def mirror_line(line=None): - creator.mirror_line(line) +def mirror_plane(plane1=None, plane2=None, plane3=None): + creator.mirror_plane(plane1, plane2, plane3) + + +def mirror_line(line=None): + creator.mirror_line(line) ############################################################################ ## Rates + Modes def feedrate(f): - creator.feedrate(f) + creator.feedrate(f) + def feedrate_hv(fh, fv): - creator.feedrate_hv(fh, fv) + creator.feedrate_hv(fh, fv) + def spindle(s, clockwise=True): - creator.spindle(s, clockwise) + creator.spindle(s, clockwise) + def coolant(mode=0): - creator.coolant(mode) + creator.coolant(mode) + def gearrange(gear=0): - creator.gearrange(gear) + creator.gearrange(gear) ############################################################################ -## Moves +# Moves + def rapid(x=None, y=None, z=None, a=None, b=None, c=None): - creator.rapid(x, y, z, a, b, c) + creator.rapid(x, y, z, a, b, c) + + +def feed(x=None, y=None, z=None, a=None, b=None, c=None): + creator.feed(x, y, z) -def feed(x=None, y=None, z=None, a = None, b = None, c = None): - creator.feed(x, y, z) def arc_cw(x=None, y=None, z=None, i=None, j=None, k=None, r=None): - creator.arc_cw(x, y, z, i, j, k, r) + creator.arc_cw(x, y, z, i, j, k, r) + def arc_ccw(x=None, y=None, z=None, i=None, j=None, k=None, r=None): - creator.arc_ccw(x, y, z, i, j, k, r) + creator.arc_ccw(x, y, z, i, j, k, r) + def dwell(t): - creator.dwell(t) + creator.dwell(t) + def rapid_home(x=None, y=None, z=None, a=None, b=None, c=None): - creator.rapid_home(x, y, z, a, b, c) + creator.rapid_home(x, y, z, a, b, c) + def rapid_unhome(): - creator.rapid_unhome() + creator.rapid_unhome() + def set_machine_coordinates(): - creator.set_machine_coordinates() + creator.set_machine_coordinates() ############################################################################ -## Cutter radius compensation +# Cutter radius compensation + def use_CRC(): - return creator.use_CRC() + return creator.use_CRC() + def CRC_nominal_path(): - return creator.CRC_nominal_path() + return creator.CRC_nominal_path() + + +def start_CRC(left=True, radius=0.0): + creator.start_CRC(left, radius) -def start_CRC(left = True, radius = 0.0): - creator.start_CRC(left, radius) def end_CRC(): - creator.end_CRC() + creator.end_CRC() ############################################################################ -## Cycles +# Cycles + def pattern(): - creator.pattern() + creator.pattern() + def pocket(): - creator.pocket() + creator.pocket() + def profile(): - creator.profile() + creator.profile() + -def drill(x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): - creator.drill(x, y, dwell, depthparams, retract_mode, spindle_mode, internal_coolant_on, rapid_to_clearance) +def drill(x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + creator.drill(x, y, dwell, depthparams, retract_mode, spindle_mode, + internal_coolant_on, rapid_to_clearance) def tap(x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): - creator.tap(x, y, z, zretract, depth, standoff, dwell_bottom, pitch, stoppos, spin_in, spin_out, tap_mode, direction) + creator.tap(x, y, z, zretract, depth, standoff, dwell_bottom, + pitch, stoppos, spin_in, spin_out, tap_mode, direction) + def bore(x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): - creator.bore(x, y, z, zretract, depth, standoff, dwell_Bottom, feed_in, feed_out, stoppos, shift_back, shift_right, backbore, stop) + creator.bore(x, y, z, zretract, depth, standoff, dwell_Bottom, feed_in, + feed_out, stoppos, shift_back, shift_right, backbore, stop) + def end_canned_cycle(): - creator.end_canned_cycle() + creator.end_canned_cycle() + def peck(count, first, last=None, step=0.0): - pecks = [] - peck = first - if (last == None) : last = first - for i in range(0,count): - pecks.append(peck) - if (peck - step > last) : peck -= step - return pecks + pecks = [] + peck = first + if (last == None): + last = first + for i in range(0, count): + pecks.append(peck) + if (peck - step > last): + peck -= step + return pecks ############################################################################ -## Misc +# Misc + def comment(text): - creator.comment(text) + creator.comment(text) + def insert(text): - creator.insert(text) + creator.insert(text) + def block_delete(on=False): - creator.block_delete(on) + creator.block_delete(on) + def variable(id): - creator.variable(id) + creator.variable(id) + def variable_set(id, value): - creator.variable_set(id, value) + creator.variable_set(id, value) + + +def probe_single_point(point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None): + creator.probe_single_point(point_along_edge_x, point_along_edge_y, depth, retracted_point_x, retracted_point_y, destination_point_x, + destination_point_y, intersection_variable_x, intersection_variable_y, probe_offset_x_component, probe_offset_y_component) -def probe_single_point(point_along_edge_x=None, point_along_edge_y=None, depth=None, retracted_point_x=None, retracted_point_y=None, destination_point_x=None, destination_point_y=None, intersection_variable_x=None, intersection_variable_y=None, probe_offset_x_component=None, probe_offset_y_component=None ): - creator.probe_single_point(point_along_edge_x, point_along_edge_y, depth, retracted_point_x, retracted_point_y, destination_point_x, destination_point_y, intersection_variable_x, intersection_variable_y, probe_offset_x_component, probe_offset_y_component ) def probe_downward_point(x=None, y=None, depth=None, intersection_variable_z=None): - creator.probe_downward_point(x, y, depth, intersection_variable_z) + creator.probe_downward_point(x, y, depth, intersection_variable_z) + + +def report_probe_results(x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): + creator.report_probe_results(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, + y4, z4, x5, y5, z5, x6, y6, z6, xml_file_name) -def report_probe_results(x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): - creator.report_probe_results(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, xml_file_name) -def open_log_file(xml_file_name=None ): - creator.open_log_file(xml_file_name) +def open_log_file(xml_file_name=None): + creator.open_log_file(xml_file_name) + def log_coordinate(x=None, y=None, z=None): - creator.log_coordinate(x, y, z) + creator.log_coordinate(x, y, z) + def log_message(message=None): - creator.log_message(message) + creator.log_message(message) + def close_log_file(): - creator.close_log_file() + creator.close_log_file() + def rapid_to_midpoint(x1=None, y1=None, z1=None, x2=None, y2=None, z2=None): - creator.rapid_to_midpoint(x1, y1, z1, x2, y2, z2) + creator.rapid_to_midpoint(x1, y1, z1, x2, y2, z2) + def rapid_to_intersection(x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub): - creator.rapid_to_intersection(x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub) + creator.rapid_to_intersection(x1, y1, x2, y2, x3, y3, x4, y4, intersection_x, + intersection_y, ua_numerator, ua_denominator, ua, ub_numerator, ub) + def rapid_to_rotated_coordinate(x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final): - creator.rapid_to_rotated_coordinate(x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final) + creator.rapid_to_rotated_coordinate( + x1, y1, x2, y2, ref_x, ref_y, x_current, y_current, x_final, y_final) -def set_path_control_mode(mode, motion_blending_tolerance, naive_cam_tolerance ): - creator.set_path_control_mode(mode, motion_blending_tolerance, naive_cam_tolerance ) + +def set_path_control_mode(mode, motion_blending_tolerance, naive_cam_tolerance): + creator.set_path_control_mode(mode, motion_blending_tolerance, naive_cam_tolerance) ############################################################################ -## NC code creator for additive machines like RepRap +# NC code creator for additive machines like RepRap + def wipe(): - creator.wipe() + creator.wipe() + def extruder_on(): - creator.extruder_on() + creator.extruder_on() + def extruder_off(): - creator.extruder_off() + creator.extruder_off() + def set_extruder_flowrate(flowrate): - creator.set_extruder_flowrate(flowrate) + creator.set_extruder_flowrate(flowrate) + def extruder_temp(temp=None): - creator.extruder_temp(temp) + creator.extruder_temp(temp) + def fan_on(): - creator.fan_on() + creator.fan_on() + def fan_off(): - creator.fan_off() + creator.fan_off() + def build_bed_temp(temp=None): - creator.build_bed_temp(temp) + creator.build_bed_temp(temp) + def chamber_temp(temp=None): - creator.chamber_temp(temp) + creator.chamber_temp(temp) diff --git a/scripts/addons/cam/nc/nc_read.py b/scripts/addons/cam/nc/nc_read.py index b8330107f..06ddd11e1 100644 --- a/scripts/addons/cam/nc/nc_read.py +++ b/scripts/addons/cam/nc/nc_read.py @@ -8,6 +8,7 @@ import math count = 0 + class Parser: def __init__(self, writer): @@ -23,23 +24,31 @@ def __del__(self): self.file_in.close() ############################################################################ - ## Internals + # Internals def readline(self): self.line = self.file_in.readline().rstrip() - if (len(self.line)) : return True - else : return False + if (len(self.line)): + return True + else: + return False def set_current_pos(self, x, y, z): - if (x != None) : - if self.absolute_flag or self.currentx == None: self.currentx = x - else: self.currentx = self.currentx + x - if (y != None) : - if self.absolute_flag or self.currenty == None: self.currenty = y - else: self.currenty = self.currenty + y - if (z != None) : - if self.absolute_flag or self.currentz == None: self.currentz = z - else: self.currentz = self.currentz + z + if (x != None): + if self.absolute_flag or self.currentx == None: + self.currentx = x + else: + self.currentx = self.currentx + x + if (y != None): + if self.absolute_flag or self.currenty == None: + self.currenty = y + else: + self.currenty = self.currenty + y + if (z != None): + if self.absolute_flag or self.currentz == None: + self.currentz = z + else: + self.currentz = self.currentz + z # def add_line(self, x, y, z, a, b, c): # if (x == None and y == None and z == None and a == None and b == None and c == None) : return @@ -98,10 +107,11 @@ def Parse(self, name): if self.t != None: if (self.m6 == True) or (self.need_m6_for_t_change == False): - self.writer.tool_change( self.t ) + self.writer.tool_change(self.t) if (self.drill): - if self.z != None: self.drillz = self.z + if self.z != None: + self.drillz = self.z self.writer.rapid(self.x, self.y, self.r) self.writer.feed(self.x, self.y, self.drillz) self.writer.feed(self.x, self.y, self.r) @@ -111,7 +121,7 @@ def Parse(self, name): else: if (self.move and not self.no_move): - if (self.arc==0): + if (self.arc == 0): if self.path_col == "feed": self.writer.feed(self.x, self.y, self.z) else: @@ -125,15 +135,17 @@ def Parse(self, name): else: if (self.arc_centre_positive == True) and (self.oldx != None) and (self.oldy != None): x = self.oldx - if self.x != None: x = self.x + if self.x != None: + x = self.x if (self.x > self.oldx) != (self.arc > 0): j = -j y = self.oldy - if self.y != None: y = self.y + if self.y != None: + y = self.y if (self.y > self.oldy) != (self.arc < 0): i = -i - #fix centre point + # fix centre point r = math.sqrt(i*i + j*j) p0 = area.Point(self.oldx, self.oldy) p1 = area.Point(x, y) @@ -143,7 +155,8 @@ def Parse(self, name): d = math.sqrt(r*r - h*h) n = area.Point(-v.y, v.x) n.normalize() - if self.arc == -1: d = -d + if self.arc == -1: + d = -d c = p0 + (v * 0.5) + (n * d) i = c.x j = c.y @@ -164,10 +177,11 @@ def Parse(self, name): self.writer.arc_cw(self.x, self.y, self.z, i, j, k) else: self.writer.arc_ccw(self.x, self.y, self.z, i, j, k) - if self.x != None: self.oldx = self.x - if self.y != None: self.oldy = self.y - if self.z != None: self.oldz = self.z + if self.x != None: + self.oldx = self.x + if self.y != None: + self.oldy = self.y + if self.z != None: + self.oldz = self.z self.writer.end_ncblock() - - diff --git a/scripts/addons/cam/nc/nclathe_read.py b/scripts/addons/cam/nc/nclathe_read.py index 25130d107..83d93cf87 100644 --- a/scripts/addons/cam/nc/nclathe_read.py +++ b/scripts/addons/cam/nc/nclathe_read.py @@ -15,10 +15,10 @@ def __init__(self): self.absolute_flag = True ############################################################################ - ## Internals + # Internals def files_open(self, name, oname=None): - if (oname == None ): + if (oname == None): oname = (name+'.nc.xml') self.file_in = open(name, 'r') self.file_out = open(oname, 'w') @@ -34,14 +34,16 @@ def files_close(self): def readline(self): self.line = self.file_in.readline().rstrip() - if (len(self.line)) : return True - else : return False + if (len(self.line)): + return True + else: + return False def write(self, s): self.file_out.write(s) ############################################################################ - ## Xml + # Xml def begin_ncblock(self): self.file_out.write('\t\n') @@ -54,94 +56,118 @@ def add_text(self, s, col=None, cdata=False): s.replace('"', '"') s.replace('<', '<') s.replace('>', '>') - if (cdata) : (cd1, cd2) = ('') - else : (cd1, cd2) = ('', '') - if (col != None) : self.file_out.write('\t\t'+cd1+s+cd2+'\n') - else : self.file_out.write('\t\t'+cd1+s+cd2+'\n') + if (cdata): + (cd1, cd2) = ('') + else: + (cd1, cd2) = ('', '') + if (col != None): + self.file_out.write('\t\t'+cd1+s+cd2+'\n') + else: + self.file_out.write('\t\t'+cd1+s+cd2+'\n') def set_mode(self, units=None): self.file_out.write('\t\t\n') def set_tool(self, number=None): self.file_out.write('\t\t\n') + if (number != None): + self.file_out.write(' number="'+str(number)+'"') + self.file_out.write(' />\n') def begin_path(self, col=None): - if (col != None) : self.file_out.write('\t\t\n') - else : self.file_out.write('\t\t\n') + if (col != None): + self.file_out.write('\t\t\n') + else: + self.file_out.write('\t\t\n') def end_path(self): self.file_out.write('\t\t\n') def add_line(self, x=None, y=None, z=None, a=None, b=None, c=None): - if (x == None and y == None and z == None and a == None and b == None and c == None) : return + if (x == None and y == None and z == None and a == None and b == None and c == None): + return self.file_out.write('\t\t\t\n') - def add_lathe_increment_line(self, u=None, w=None): -# needed for representing U and W moves in lathe code- these are non modal incremental moves -# U == X and W == Z - if (u == None and w == None ) : return + # needed for representing U and W moves in lathe code- these are non modal incremental moves + # U == X and W == Z + if (u == None and w == None): + return self.file_out.write('\t\t\t\n') - - - - - def add_arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, d=None): - if (x == None and y == None and z == None and i == None and j == None and k == None and r == None and d == None) : return + if (x == None and y == None and z == None and i == None and j == None and k == None and r == None and d == None): + return self.file_out.write('\t\t\t\n') def incremental(self): diff --git a/scripts/addons/cam/nc/num_reader.py b/scripts/addons/cam/nc/num_reader.py index 62c722cca..c9bd9cc91 100644 --- a/scripts/addons/cam/nc/num_reader.py +++ b/scripts/addons/cam/nc/num_reader.py @@ -4,6 +4,7 @@ # a base class for hpgl parsers, and maybe others + class NumReader(nc.Parser): def __init__(self): @@ -37,7 +38,7 @@ def add_word(self, color): self.parse_word = "" def Parse(self, name, oname=None): - self.files_open(name,oname) + self.files_open(name, oname) while self.readline(): self.begin_ncblock() @@ -59,4 +60,3 @@ def Parse(self, name, oname=None): self.end_ncblock() self.files_close() - diff --git a/scripts/addons/cam/nc/printbot3d.py b/scripts/addons/cam/nc/printbot3d.py index a450f818c..ac99559e9 100644 --- a/scripts/addons/cam/nc/printbot3d.py +++ b/scripts/addons/cam/nc/printbot3d.py @@ -8,6 +8,8 @@ import math ################################################################################ + + class CreatorPrintbot(iso_modal.CreatorIsoModal): def __init__(self): @@ -20,7 +22,7 @@ def write_blocknum(self): pass def set_plane(self, plane): - pass + pass def workplane(self, id): pass @@ -38,7 +40,7 @@ def set_extruder_flowrate(self, flowrate): self.spindle(flowrate, True) def extruder_temp(self, temp): - self.write((maker.codes.EXTRUDER_TEMP(temp)) + ('\n')) + self.write((maker.codes.EXTRUDER_TEMP(temp)) + ('\n')) # General def rapid(x=None, y=None, z=None, a=None, b=None, c=None): @@ -50,4 +52,5 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): ################################################################################ + nc.creator = CreatorPrintbot() diff --git a/scripts/addons/cam/nc/printbot3d_read.py b/scripts/addons/cam/nc/printbot3d_read.py index 79c3869f2..775e1ecee 100644 --- a/scripts/addons/cam/nc/printbot3d_read.py +++ b/scripts/addons/cam/nc/printbot3d_read.py @@ -3,6 +3,7 @@ # based on the iso reader + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/recreator.py b/scripts/addons/cam/nc/recreator.py index 5b25bf009..ce5f670bf 100644 --- a/scripts/addons/cam/nc/recreator.py +++ b/scripts/addons/cam/nc/recreator.py @@ -2,6 +2,7 @@ units = 1.0 + class Redirector(nc.Creator): def __init__(self, original): @@ -11,16 +12,19 @@ def __init__(self, original): self.x = None self.y = None self.z = None - if original.x != None: self.x = original.x * units - if original.y != None: self.y = original.y * units - if original.z != None: self.z = original.z * units + if original.x != None: + self.x = original.x * units + if original.y != None: + self.y = original.y * units + if original.z != None: + self.z = original.z * units self.imperial = False def cut_path(self): pass ############################################################################ - ## Programs + # Programs def write(self, s): self.original.write(s) @@ -53,7 +57,7 @@ def flush_nc(self): self.original.flush_nc() ############################################################################ - ## Subprograms + # Subprograms def sub_begin(self, id, name=None): self.cut_path() @@ -74,7 +78,7 @@ def enable_output(self): self.original.enable_output() ############################################################################ - ## Settings + # Settings def imperial(self): self.cut_path() @@ -103,14 +107,14 @@ def set_plane(self, plane): def set_temporary_origin(self, x=None, y=None, z=None, a=None, b=None, c=None): self.cut_path() - self.original.set_temporary_origin(x,y,z,a,b,c) + self.original.set_temporary_origin(x, y, z, a, b, c) def remove_temporary_origin(self): self.cut_path() self.original.remove_temporary_origin() ############################################################################ - ## Tools + # Tools def tool_change(self, id): self.cut_path() @@ -129,7 +133,7 @@ def offset_length(self, id, length=None): self.original.offset_length(id, length) ############################################################################ - ## Datums + # Datums def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): self.cut_path() @@ -167,14 +171,17 @@ def gearrange(self, gear=0): self.original.gearrange(gear) ############################################################################ - ## Moves + # Moves def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): self.cut_path() self.original.rapid(x, y, z, a, b, c) - if x != None: self.x = x * units - if y != None: self.y = y * units - if z != None: self.z = z * units + if x != None: + self.x = x * units + if y != None: + self.y = y * units + if z != None: + self.z = z * units def cut_path(self): pass @@ -182,13 +189,16 @@ def cut_path(self): def z2(self, z): return z - def feed(self, x=None, y=None, z=None, a = None, b = None, c = None): + def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): px = self.x py = self.y pz = self.z - if x != None: self.x = x * units - if y != None: self.y = y * units - if z != None: self.z = z * units + if x != None: + self.x = x * units + if y != None: + self.y = y * units + if z != None: + self.z = z * units if self.x == None or self.y == None or self.z == None: self.cut_path() self.original.feed(x, y, z) @@ -199,15 +209,18 @@ def feed(self, x=None, y=None, z=None, a = None, b = None, c = None): self.original.feed(self.x/units, self.y/units, self.z2(self.z)/units) return - def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True): + def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw=True): if self.x == None or self.y == None or self.z == None: raise "first attached move can't be an arc" px = self.x py = self.y pz = self.z - if x != None: self.x = x * units - if y != None: self.y = y * units - if z != None: self.z = z * units + if x != None: + self.x = x * units + if y != None: + self.y = y * units + if z != None: + self.z = z * units def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): self.arc(x, y, z, i, j, k, r, False) @@ -228,12 +241,12 @@ def rapid_unhome(self): self.original.rapid_unhome() ############################################################################ - ## Cutter radius compensation + # Cutter radius compensation def use_CRC(self): return self.original.use_CRC() - def start_CRC(self, left = True, radius = 0.0): + def start_CRC(self, left=True, radius=0.0): self.cut_path() self.original.start_CRC(left, radius) @@ -242,7 +255,7 @@ def end_CRC(self): self.original.end_CRC() ############################################################################ - ## Cycles + # Cycles def pattern(self): self.cut_path() @@ -259,30 +272,33 @@ def profile(self): self.cut_path() self.original.profile() - def circular_pocket(self, x=None, y=None, ToolDiameter=None, HoleDiameter=None, ClearanceHeight=None, StartHeight=None, MaterialTop=None, FeedRate=None, SpindleRPM=None, HoleDepth=None, DepthOfCut=None, StepOver=None ): + def circular_pocket(self, x=None, y=None, ToolDiameter=None, HoleDiameter=None, ClearanceHeight=None, StartHeight=None, MaterialTop=None, FeedRate=None, SpindleRPM=None, HoleDepth=None, DepthOfCut=None, StepOver=None): self.cut_path() - self.circular_pocket(x, y, ToolDiameter, HoleDiameter, ClearanceHeight, StartHeight, MaterialTop, FeedRate, SpindleRPM, HoleDepth, DepthOfCut, StepOver) + self.circular_pocket(x, y, ToolDiameter, HoleDiameter, ClearanceHeight, StartHeight, + MaterialTop, FeedRate, SpindleRPM, HoleDepth, DepthOfCut, StepOver) - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): self.cut_path() - self.original.drill(x, y, dwell, depthparams, spindle_mode, internal_coolant_on, rapid_to_clearance) + self.original.drill(x, y, dwell, depthparams, spindle_mode, + internal_coolant_on, rapid_to_clearance) # argument list adapted for compatibility with Tapping module # wild guess - I'm unsure about the purpose of this file and wether this works -haberlerm def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): self.cut_path() - self.original.tap( x, y, self.z2(z), self.z2(zretract), depth, standoff, dwell_bottom, pitch, stoppos, spin_in, spin_out, tap_mode, direction) - + self.original.tap(x, y, self.z2(z), self.z2(zretract), depth, standoff, + dwell_bottom, pitch, stoppos, spin_in, spin_out, tap_mode, direction) def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, feed_in=None, feed_out=None, stoppos=None, shift_back=None, shift_right=None, backbore=False, stop=False): self.cut_path() - self.original.bore(x, y, self.z2(z), self.z2(zretract), depth, standoff, dwell_Bottom, feed_in, feed_out, stoppos, shift_back, shift_right, backbore, stop) + self.original.bore(x, y, self.z2(z), self.z2(zretract), depth, standoff, dwell_Bottom, + feed_in, feed_out, stoppos, shift_back, shift_right, backbore, stop) def end_canned_cycle(self): self.original.end_canned_cycle() ############################################################################ - ## Misc + # Misc def comment(self, text): self.cut_path() diff --git a/scripts/addons/cam/nc/rez2.py b/scripts/addons/cam/nc/rez2.py index 8f9ee1ed4..bbaa82882 100644 --- a/scripts/addons/cam/nc/rez2.py +++ b/scripts/addons/cam/nc/rez2.py @@ -11,6 +11,8 @@ import circular_pocket as circular ################################################################################ + + class Creator(nc.Creator): def __init__(self): @@ -36,145 +38,150 @@ def __init__(self): self.y = 0 self.z = 500 - self.x1=0 - self.x2=0 - self.y1=0 - self.y2=0 - self.SPACE=' ' + self.x1 = 0 + self.x2 = 0 + self.y1 = 0 + self.y2 = 0 + self.SPACE = ' ' self.fmt = self.FORMAT_MM() - pass + pass ############################################################################ - ## Internals + # Internals def FORMAT_IN(self): return('%.5f') def FORMAT_MM(self): return('%.3f') - def COMMENT(self,comment): return( ('(%s)' % comment ) ) + def COMMENT(self, comment): return(('(%s)' % comment)) def write_feedrate(self): - #self.write(self.f) + # self.write(self.f) self.f = '' def write_preps(self): - #self.write(self.g) + # self.write(self.g) self.g = '' def write_misc(self): #if (len(self.m)) : self.write(self.m.pop()) - pass + pass def write_blocknum(self): #self.write(iso.BLOCK % self.n) - #self.write(iso.SPACE) + # self.write(iso.SPACE) #self.n += 10 - pass + pass def write_spindle(self): - #self.write(self.s) + # self.write(self.s) #self.s = '' - pass + pass ############################################################################ - ## Programs + # Programs def program_begin(self, id, name=''): #self.write((iso.PROGRAM % id) + iso.SPACE + (iso.COMMENT % name)) #self.write("// program v jazyku"+self.SPACE+"REZ\nMA 0.0000 , 0.0000\n") - self.write("// program v jazyku"+self.SPACE+"REZ\nGO_LEFT\nMA 0.0000 , 0.0000\n") - #self.write('\n') + self.write("// program v jazyku"+self.SPACE+"REZ\nGO_LEFT\nMA 0.0000 , 0.0000\n") + # self.write('\n') def program_stop(self, optional=False): - #self.write_blocknum() + # self.write_blocknum() #if (optional) : self.write(iso.STOP_OPTIONAL + '\n') - #else : self.write(iso.STOP + '\n') - self.write("// stop programu v jazyku REZ\n") + # else : self.write(iso.STOP + '\n') + self.write("// stop programu v jazyku REZ\n") def program_end(self): - #self.write_blocknum() + # self.write_blocknum() + #self.write(iso.PROGRAM_END + '\n') + self.write('PL_OFF \n') + self.write('PARK \n') + self.write('FS \n') + self.write('MA 0.0000 , 0.0000\n') + self.write("// koniec programu v jazyku REZ\n") #self.write(iso.PROGRAM_END + '\n') - self.write('PL_OFF \n') - self.write('PARK \n') - self.write('FS \n') - self.write('MA 0.0000 , 0.0000\n') - self.write("// koniec programu v jazyku REZ\n") - #self.write(iso.PROGRAM_END + '\n') + def flush_nc(self): - #self.write_blocknum() + # self.write_blocknum() self.write_preps() self.write_misc() - #self.write('\n') + # self.write('\n') ############################################################################ - ## Subprograms + # Subprograms def sub_begin(self, id, name=''): #self.write((iso.PROGRAM % id) + iso.SPACE + (iso.COMMENT % name)) - #self.write('\n') - pass + # self.write('\n') + pass + def sub_call(self, id): - #self.write_blocknum() + # self.write_blocknum() #self.write((iso.SUBPROG_CALL % id) + '\n') - #self.write('\n') - pass + # self.write('\n') + pass def sub_end(self): - #self.write_blocknum() + # self.write_blocknum() #self.write(iso.SUBPROG_END + '\n') - #self.write('\n') - pass + # self.write('\n') + pass ############################################################################ - ## Settings + # Settings def imperial(self): #self.g += iso.IMPERIAL #self.fmt = iso.FORMAT_IN - #self.write('\n') - pass + # self.write('\n') + pass def metric(self): #self.g += iso.METRIC #self.fmt = iso.FORMAT_MM - #self.write('\n') - pass + # self.write('\n') + pass def absolute(self): #self.g += iso.ABSOLUTE - #self.write('\n') - pass + # self.write('\n') + pass def incremental(self): #self.g += iso.INCREMENTAL - #self.write('\n') - pass + # self.write('\n') + pass + def polar(self, on=True): #if (on) : self.g += iso.POLAR_ON - #else : self.g += iso.POLAR_OFF - #self.write('\n') - pass + # else : self.g += iso.POLAR_OFF + # self.write('\n') + pass + def set_plane(self, plane): #if (plane == 0) : self.g += iso.PLANE_XY - #elif (plane == 1) : self.g += iso.PLANE_XZ - #elif (plane == 2) : self.g += iso.PLANE_YZ - #self.write('\n') - pass + # elif (plane == 1) : self.g += iso.PLANE_XZ + # elif (plane == 2) : self.g += iso.PLANE_YZ + # self.write('\n') + pass ############################################################################ - ## Tools + # Tools def tool_change(self, id): - #self.write_blocknum() + # self.write_blocknum() #self.write((iso.TOOL % id) + '\n') - #self.write('\n') - pass + # self.write('\n') + pass + def tool_defn(self, id, name='', params=None): - pass + pass def offset_radius(self, id, radius=None): - pass + pass def offset_length(self, id, length=None): - pass + pass ############################################################################ - ## Datums + # Datums def datum_shift(self, x=None, y=None, z=None, a=None, b=None, c=None): pass @@ -185,142 +192,143 @@ def datum_set(self, x=None, y=None, z=None, a=None, b=None, c=None): # This is the coordinate system we're using. G54->G59, G59.1, G59.2, G59.3 # These are selected by values from 1 to 9 inclusive. def workplane(self, id): - #if ((id >= 1) and (id <= 6)): - # self.g += iso.WORKPLANE % (id + iso.WORKPLANE_BASE) - #if ((id >= 7) and (id <= 9)): - # self.g += ((iso.WORKPLANE % (6 + iso.WORKPLANE_BASE)) + ('.%i' % (id - 6))) - pass + # if ((id >= 1) and (id <= 6)): + # self.g += iso.WORKPLANE % (id + iso.WORKPLANE_BASE) + # if ((id >= 7) and (id <= 9)): + # self.g += ((iso.WORKPLANE % (6 + iso.WORKPLANE_BASE)) + ('.%i' % (id - 6))) + pass ############################################################################ ## Rates + Modes def feedrate(self, f): #self.f = iso.FEEDRATE + (self.fmt % f) #self.fhv = False - pass + pass def feedrate_hv(self, fh, fv): #self.fh = fh #self.fv = fv #self.fhv = True - pass + pass + def calc_feedrate_hv(self, h, v): #l = math.sqrt(h*h+v*v) #if (h == 0) : self.f = iso.FEEDRATE + (self.fmt % self.fv) - #elif (v == 0) : self.f = iso.FEEDRATE + (self.fmt % self.fh) - #else: - # self.f = iso.FEEDRATE + (self.fmt % (self.fh * l * min([1/h, 1/v]))) - pass + # elif (v == 0) : self.f = iso.FEEDRATE + (self.fmt % self.fh) + # else: + # self.f = iso.FEEDRATE + (self.fmt % (self.fh * l * min([1/h, 1/v]))) + pass def spindle(self, s, clockwise): - #if s < 0: clockwise = not clockwise - #s = abs(s) + #if s < 0: clockwise = not clockwise + #s = abs(s) #self.s = iso.SPINDLE % s - #if clockwise: - # self.s = self.s + iso.SPINDLE_CW - #else: - # self.s = self.s + iso.SPINDLE_CCW - pass + # if clockwise: + # self.s = self.s + iso.SPINDLE_CW + # else: + # self.s = self.s + iso.SPINDLE_CCW + pass def coolant(self, mode=0): #if (mode <= 0) : self.m.append(iso.COOLANT_OFF) - #elif (mode == 1) : self.m.append(iso.COOLANT_MIST) - #elif (mode == 2) : self.m.append(iso.COOLANT_FLOOD) - pass + # elif (mode == 1) : self.m.append(iso.COOLANT_MIST) + # elif (mode == 2) : self.m.append(iso.COOLANT_FLOOD) + pass def gearrange(self, gear=0): #if (gear <= 0) : self.m.append(iso.GEAR_OFF) - #elif (gear <= 4) : self.m.append(iso.GEAR % (gear + GEAR_BASE)) - pass + # elif (gear <= 4) : self.m.append(iso.GEAR % (gear + GEAR_BASE)) + pass ############################################################################ - ## Moves + # Moves - #def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): - def rapid(self, x=0.0000, y=0.0000, z=0.0000, a=0.0000, b=0.0000, c=0.0000,how=False): - #self.write_blocknum() + # def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): + def rapid(self, x=0.0000, y=0.0000, z=0.0000, a=0.0000, b=0.0000, c=0.0000, how=False): + # self.write_blocknum() if (x == None): - if (y == None): - return - print 'rychlopsuv' - print x - print y - print z - print a - print b - print c - self.write('PL_OFF\n') - self.write('PARK\n') - self.write('FS\n') - self.write('MA ') - #self.write_preps() - #if (x != None): + if (y == None): + return + print 'rychlopsuv' + print x + print y + print z + print a + print b + print c + self.write('PL_OFF\n') + self.write('PARK\n') + self.write('FS\n') + self.write('MA ') + # self.write_preps() + # if (x != None): # dx = x - self.x # self.write(iso.X + (self.fmt % x)) # self.x = x - #if (y != None): + # if (y != None): # dy = y - self.y # self.write(iso.Y + (self.fmt % y)) # self.y = y - #if (z != None): + # if (z != None): # dz = z - self.z # self.write(iso.Z + (self.fmt % z)) # self.z = z #if (a != None) : self.write(iso.A + (iso.FORMAT_ANG % a)) #if (b != None) : self.write(iso.B + (iso.FORMAT_ANG % b)) #if (c != None) : self.write(iso.C + (iso.FORMAT_ANG % c)) - #self.write_spindle() - #self.write_misc() - self.write((' %.4f' %x)) - #self.write(('%f' %x) ) - self.write(' , ') - self.write((' %.4f' %y)) - self.write('\n') - self.write('SS\n') - self.write('AD_W\n') - self.write('PL_ON') - self.write('\n') - self.x=x - self.y=y - - def feed(self, x=0.0000, y=0.0000, z=0.0000,how=False): + # self.write_spindle() + # self.write_misc() + self.write((' %.4f' % x)) + #self.write(('%f' %x) ) + self.write(' , ') + self.write((' %.4f' % y)) + self.write('\n') + self.write('SS\n') + self.write('AD_W\n') + self.write('PL_ON') + self.write('\n') + self.x = x + self.y = y + + def feed(self, x=0.0000, y=0.0000, z=0.0000, how=False): if self.same_xyz(x, y, z): - return + return if (x == None): - if (y == None): - return - - print 'MA rez' - print x - print y - print z - #self.write_blocknum() - #self.write(iso.FEED) - #self.write_preps() + if (y == None): + return + + print 'MA rez' + print x + print y + print z + # self.write_blocknum() + # self.write(iso.FEED) + # self.write_preps() #dx = dy = dz = 0 - #if (x != None): + # if (x != None): # dx = x - self.x # self.write(iso.X + (self.fmt % x)) # self.x = x - #if (y != None): + # if (y != None): # dy = y - self.y # self.write(iso.Y + (self.fmt % y)) # self.y = y - #if (z != None): + # if (z != None): # dz = z - self.z # self.write(iso.Z + (self.fmt % z)) # self.z = z #if (self.fhv) : self.calc_feedrate_hv(math.sqrt(dx*dx+dy*dy), math.fabs(dz)) - #self.write_feedrate() - #self.write_spindle() - #self.write_misc() + # self.write_feedrate() + # self.write_spindle() + # self.write_misc() self.write('MA ') - self.write((' %.4f' %x)) - #self.write(('%f' %x) ) - self.write(' , ') - self.write((' %.4f' %y)) - self.write('\n') - self.x=x - self.y=y + self.write((' %.4f' % x)) + #self.write(('%f' %x) ) + self.write(' , ') + self.write((' %.4f' % y)) + self.write('\n') + self.x = x + self.y = y def same_xyz(self, x=None, y=None, z=None): if (x != None): @@ -336,96 +344,98 @@ def same_xyz(self, x=None, y=None, z=None): return True def arc(self, cw, x=0.0000, y=0.0000, z=0.0000, i=0.0000, j=0.0000, k=0.0000, r=0.0000): - if self.same_xyz(x, y, z): return - if (x == None): - if (y == None): - return - #self.write_blocknum() - print 'ARC rez' - print x - print y - print z - print i - print j - print k - print r - self.write('C ') - # if cw: self.write(iso.ARC_CW) - # else: self.write(iso.ARC_CCW) - # self.write_preps() - #if (x != None): + if self.same_xyz(x, y, z): + return + if (x == None): + if (y == None): + return + # self.write_blocknum() + print 'ARC rez' + print x + print y + print z + print i + print j + print k + print r + self.write('C ') + # if cw: self.write(iso.ARC_CW) + # else: self.write(iso.ARC_CCW) + # self.write_preps() + # if (x != None): # self.write(iso.X + (self.fmt % x)) # self.x = x - #if (y != None): + # if (y != None): # self.write(iso.Y + (self.fmt % y)) # self.y = y - #if (z != None): - # self.write(iso.Z + (self.fmt % z)) - # self.z = z + # if (z != None): + # self.write(iso.Z + (self.fmt % z)) + # self.z = z #if (i != None) : self.write(iso.CENTRE_X + (self.fmt % i)) #if (j != None) : self.write(iso.CENTRE_Y + (self.fmt % j)) #if (k != None) : self.write(iso.CENTRE_Z + (self.fmt % k)) #if (r != None) : self.write(iso.RADIUS + (self.fmt % r)) # use horizontal feed rate #if (self.fhv) : self.calc_feedrate_hv(1, 0) - #self.write_feedrate() - #self.write_spindle() - #self.write_misc() - self.write((' %.4f' %(self.x + i))) - #self.write(('%f' %x) ) - self.write(' , ') - self.write((' %.4f' %(self.y + j))) - - self.write(' , ') - angle=0.0000 - - self.x1=-i - self.y1=-j - self.x2=x-(self.x+i) - self.y2=y-(self.y+j) - - dx=self.x1*self.x2 - dy=self.y1*self.y2 - ssucin=dx+dy - r=math.sqrt((i*i)+(j*j)) - - #dx=i*(x-(self.x + i)) - #dy=j*(y-(self.y + j)) - #ssucin=dx+dy - #r=math.sqrt((i*i)+(j*j)) - ratio=ssucin/(r*r) - angle= math.acos(ratio) * 180 / math.pi - print 'angle' - print angle + # self.write_feedrate() + # self.write_spindle() + # self.write_misc() + self.write((' %.4f' % (self.x + i))) + #self.write(('%f' %x) ) + self.write(' , ') + self.write((' %.4f' % (self.y + j))) + + self.write(' , ') + angle = 0.0000 + + self.x1 = -i + self.y1 = -j + self.x2 = x-(self.x+i) + self.y2 = y-(self.y+j) + + dx = self.x1*self.x2 + dy = self.y1*self.y2 + ssucin = dx+dy + r = math.sqrt((i*i)+(j*j)) + + #dx=i*(x-(self.x + i)) + #dy=j*(y-(self.y + j)) + # ssucin=dx+dy + # r=math.sqrt((i*i)+(j*j)) + ratio = ssucin/(r*r) + angle = math.acos(ratio) * 180 / math.pi + print 'angle' + print angle # while(angle>=90.0001): # if(cw): self.write((' -90.0000\n' )) # else: self.write((' 90.0000\n')) - #self.write(('90.0000\n' )) + #self.write(('90.0000\n' )) # self.write('C ') # self.write((' %.4f' %( self.x + i) )) # self.write(' , ') # self.write((' %.4f' %( self.y + j))) # self.write(' , ') # angle-=90 - if(cw): self.write((' %.4f' %(-angle))) - else: self.write((' %.4f' %(angle))) - - - #self.write((', %.4f' % )) - self.write('\n') - self.x=x - self.y=y - self.write('// stred') - self.write((' %f' %i)) - self.write(' ') - self.write( (' %f' %j)) - self.write('\n') - - self.write('// koniec') - self.write((' %f' %self.x)) - self.write(' ') - self.write( (' %f' %self.y)) - self.write('\n') + if(cw): + self.write((' %.4f' % (-angle))) + else: + self.write((' %.4f' % (angle))) + + # self.write((', %.4f' % )) + self.write('\n') + self.x = x + self.y = y + self.write('// stred') + self.write((' %f' % i)) + self.write(' ') + self.write((' %f' % j)) + self.write('\n') + + self.write('// koniec') + self.write((' %f' % self.x)) + self.write(' ') + self.write((' %f' % self.y)) + self.write('\n') def arc_cw(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None): self.arc(True, x, y, z, i, j, k, r) @@ -447,7 +457,7 @@ def rapid_unhome(self): pass ############################################################################ - ## Cycles + # Cycles def pattern(self): pass @@ -458,54 +468,56 @@ def pocket(self): def profile(self): pass - def circular_pocket(self, x=None, y=None, ToolDiameter=None, HoleDiameter=None, ClearanceHeight=None, StartHeight=None, MaterialTop=None, FeedRate=None, SpindleRPM=None, HoleDepth=None, DepthOfCut=None, StepOver=None ): - self.write_preps() - circular.pocket.block_number = self.n - (self.g_code, self.n) = circular.pocket.GeneratePath( x,y, ToolDiameter, HoleDiameter, ClearanceHeight, StartHeight, MaterialTop, FeedRate, SpindleRPM, HoleDepth, DepthOfCut, StepOver ) - self.write(self.g_code) - - # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). - # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to - # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. - # Instead, this routine combines the Z value and the depth value to determine the bottom of - # the hole. - # - # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts - # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. - # - # The peck_depth value is the incremental depth (Q value) that tells the peck drilling - # cycle how deep to go on each peck until the full depth is achieved. - # - # NOTE: This routine forces the mode to absolute mode so that the values passed into - # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't - # revert it. I must set the mode so that I can be sure the values I'm passing in make - # sense to the end-machine. - # - def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): - if (standoff == None): - # This is a bad thing. All the drilling cycles need a retraction (and starting) height. - return - - if (z == None): return # We need a Z value as well. This input parameter represents the top of the hole + def circular_pocket(self, x=None, y=None, ToolDiameter=None, HoleDiameter=None, ClearanceHeight=None, StartHeight=None, MaterialTop=None, FeedRate=None, SpindleRPM=None, HoleDepth=None, DepthOfCut=None, StepOver=None): + self.write_preps() + circular.pocket.block_number = self.n + (self.g_code, self.n) = circular.pocket.GeneratePath(x, y, ToolDiameter, HoleDiameter, + ClearanceHeight, StartHeight, MaterialTop, FeedRate, SpindleRPM, HoleDepth, DepthOfCut, StepOver) + self.write(self.g_code) + + # The drill routine supports drilling (G81), drilling with dwell (G82) and peck drilling (G83). + # The x,y,z values are INITIAL locations (above the hole to be made. This is in contrast to + # the Z value used in the G8[1-3] cycles where the Z value is that of the BOTTOM of the hole. + # Instead, this routine combines the Z value and the depth value to determine the bottom of + # the hole. + # + # The standoff value is the distance up from the 'z' value (normally just above the surface) where the bit retracts + # to in order to clear the swarf. This combines with 'z' to form the 'R' value in the G8[1-3] cycles. + # + # The peck_depth value is the incremental depth (Q value) that tells the peck drilling + # cycle how deep to go on each peck until the full depth is achieved. + # + # NOTE: This routine forces the mode to absolute mode so that the values passed into + # the G8[1-3] cycles make sense. I don't know how to find the mode to revert it so I won't + # revert it. I must set the mode so that I can be sure the values I'm passing in make + # sense to the end-machine. + # + def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None): + if (standoff == None): + # This is a bad thing. All the drilling cycles need a retraction (and starting) height. + return + + if (z == None): + return # We need a Z value as well. This input parameter represents the top of the hole self.write_blocknum() self.write_preps() - if (peck_depth != 0): - # We're pecking. Let's find a tree. - self.write(iso.PECK_DRILL + iso.SPACE + iso.PECK_DEPTH + (self.fmt % peck_depth )) - else: - # We're either just drilling or drilling with dwell. - if (dwell == 0): - # We're just drilling. - self.write(iso.DRILL + iso.SPACE) - else: - # We're drilling with dwell. - self.write(iso.DRILL_WITH_DWELL + (iso.FORMAT_DWELL % dwell) + iso.SPACE) - - # Set the retraction point to the 'standoff' distance above the starting z height. - retract_height = z + standoff - #self.write(iso.RETRACT + (self.fmt % retract_height)) + if (peck_depth != 0): + # We're pecking. Let's find a tree. + self.write(iso.PECK_DRILL + iso.SPACE + iso.PECK_DEPTH + (self.fmt % peck_depth)) + else: + # We're either just drilling or drilling with dwell. + if (dwell == 0): + # We're just drilling. + self.write(iso.DRILL + iso.SPACE) + else: + # We're drilling with dwell. + self.write(iso.DRILL_WITH_DWELL + (iso.FORMAT_DWELL % dwell) + iso.SPACE) + + # Set the retraction point to the 'standoff' distance above the starting z height. + retract_height = z + standoff + #self.write(iso.RETRACT + (self.fmt % retract_height)) if (x != None): dx = x - self.x self.write(iso.X + (self.fmt % x) + iso.SPACE) @@ -515,11 +527,13 @@ def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=Non self.write(iso.Y + (self.fmt % y) + iso.SPACE) self.y = y - dz = (z + standoff) - self.z - # In the end, we will be standoff distance above the z value passed in. - self.write(iso.Z + (self.fmt % (z - depth)) + iso.SPACE) # This is the 'z' value for the bottom of the hole. - self.z = (z + standoff) # We want to remember where z is at the end (at the top of the hole) - self.write(iso.RETRACT + (self.fmt % retract_height)) + dz = (z + standoff) - self.z + # In the end, we will be standoff distance above the z value passed in. + # This is the 'z' value for the bottom of the hole. + self.write(iso.Z + (self.fmt % (z - depth)) + iso.SPACE) + # We want to remember where z is at the end (at the top of the hole) + self.z = (z + standoff) + self.write(iso.RETRACT + (self.fmt % retract_height)) self.write_spindle() self.write_misc() self.write('\n') @@ -529,6 +543,8 @@ def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=Non # pass # argument list adapted for compatibility with Tapping module + + def tap(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, dwell_bottom=None, pitch=None, stoppos=None, spin_in=None, spin_out=None, tap_mode=None, direction=None): pass @@ -536,10 +552,10 @@ def bore(self, x=None, y=None, z=None, zretract=None, depth=None, standoff=None, pass ############################################################################ - ## Misc + # Misc def comment(self, text): - self.write('// ' + (self.COMMENT( text)) + '\n') + self.write('// ' + (self.COMMENT(text)) + '\n') def variable(self, id): return (iso.VARIABLE % id) @@ -550,4 +566,5 @@ def variable_set(self, id, value): ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/rez2_read.py b/scripts/addons/cam/nc/rez2_read.py index 277007c76..b562fbfc2 100644 --- a/scripts/addons/cam/nc/rez2_read.py +++ b/scripts/addons/cam/nc/rez2_read.py @@ -9,21 +9,23 @@ import math ################################################################################ -class Parser(nc.Parser): +class Parser(nc.Parser): + def __init__(self, writer): nc.Parser.__init__(self, writer) - #self.pattern_main = re.compile('(\s+|\w(?:[+])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+])?\d*(?:\.\d*)?)') + # self.pattern_main = re.compile('(\s+|\w(?:[+])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+])?\d*(?:\.\d*)?)') - #rada - self.pattern_main = re.compile(r'(\s+|,|-?\w\+?\d*(?:\.\d*)?|\w#\d+|\(.*?\)|#\d+=\+?\d*(?:\.\d*)?)') - #self.pattern_main = re.compile('\s+\w') - #self.pattern_main = re.compile('(\s+|\w(?:[+])?[+-\w]\d*(?:\.\d*)?|\w\#[+-\w]\d+|\(.*?\)|[\#[+-\w]\d+\=(?:[+])?[+-\w]\d*(?:\.\d*)?)') - #self.pattern_main = re.compile('\s\w[\S]\w,\w[+-\w]\d*\w,\w[+-\w]\d*\w,\w[+-\w]\d*') - #self.pattern_main = re.compile('(\s|\w(?:)?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:)?\d*(?:\.\d*)?)') - #self.pattern_main = re.compile(' ') + # rada + self.pattern_main = re.compile( + r'(\s+|,|-?\w\+?\d*(?:\.\d*)?|\w#\d+|\(.*?\)|#\d+=\+?\d*(?:\.\d*)?)') + #self.pattern_main = re.compile('\s+\w') + # self.pattern_main = re.compile('(\s+|\w(?:[+])?[+-\w]\d*(?:\.\d*)?|\w\#[+-\w]\d+|\(.*?\)|[\#[+-\w]\d+\=(?:[+])?[+-\w]\d*(?:\.\d*)?)') + #self.pattern_main = re.compile('\s\w[\S]\w,\w[+-\w]\d*\w,\w[+-\w]\d*\w,\w[+-\w]\d*') + # self.pattern_main = re.compile('(\s|\w(?:)?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:)?\d*(?:\.\d*)?)') + #self.pattern_main = re.compile(' ') self.a = 0 self.b = 0 @@ -39,252 +41,266 @@ def __init__(self, writer): self.x = 0 self.y = 0 self.z = 500 - self.FS = 1 - self.endx=0 - self.endy=0 - self.startx=0 - self.starty=0 - self.x1=0 - self.y1=0 - self.dy=0 - self.dx=0 - self.angle=0 - self.SPACE = ' ' + self.FS = 1 + self.endx = 0 + self.endy = 0 + self.startx = 0 + self.starty = 0 + self.x1 = 0 + self.y1 = 0 + self.dy = 0 + self.dx = 0 + self.angle = 0 + self.SPACE = ' ' def add_text(self, s, col=None): s.replace('&', '&') s.replace('"', '"') s.replace('<', '<') s.replace('>', '>') - s+=self.SPACE+'\n' - if (col != None) : self.file_out.write('\t\t'+s+' \n') - else : self.file_out.write('\t\t'+s+' \n') - #def add_text(self, s, col=None): + s += self.SPACE+'\n' + if (col != None): + self.file_out.write('\t\t'+s+' \n') + else: + self.file_out.write('\t\t'+s+' \n') + # def add_text(self, s, col=None): # if (col != None) : self.file_out.write('\t\t'+s+'\n') # else : self.file_out.write('\t\t'+s+'\n') def Parse(self, name, oname=None): - self.files_open(name,oname) + self.files_open(name, oname) while (self.readline()): self.begin_ncblock() - move = False; - arc = 0; + move = False + arc = 0 path_col = None - col=None - if(self.line[0]=='C'): col = "axis" - if(self.line[0]=='M' and self.line[1]=='A'): col = "feed" - if (self.line[0] == "/" and self.line[1] == "/") : col = "comment" + col = None + if(self.line[0] == 'C'): + col = "axis" + if(self.line[0] == 'M' and self.line[1] == 'A'): + col = "feed" + if (self.line[0] == "/" and self.line[1] == "/"): + col = "comment" - if (self.FS==1 and not (self.line[0]=='S' and self.line[1]=='S') and col=="feed" ): col="rapid" - self.add_text(self.line, col) + if (self.FS == 1 and not (self.line[0] == 'S' and self.line[1] == 'S') and col == "feed"): + col = "rapid" + self.add_text(self.line, col) #words = self.pattern_main.findall(self.line) - words=self.line.split() - #print self.line - #print ' AAAA ' - words[0]=words[0]+self.SPACE - print words - for word in words: + words = self.line.split() + # print self.line + # print ' AAAA ' + words[0] = words[0]+self.SPACE + print words + for word in words: col = None - #if (word[0] == 'A' or word[0] == 'a'): + # if (word[0] == 'A' or word[0] == 'a'): # col = "axis" # self.a = eval(word[1:]) # move = True - #elif (word[0] == 'B' or word[0] == 'b'): + # elif (word[0] == 'B' or word[0] == 'b'): # col = "axis" # self.b = eval(word[1:]) - # move = True + # move = True if (word == ('C'+self.SPACE)): - #print words - col = "axis" - self.startx=self.x - self.starty=self.y - words[0]=words[0]+self.SPACE - words[2]=self.SPACE+words[2]+self.SPACE - words[4]=self.SPACE+words[4]+self.SPACE - - #print 'x,y' - #print self.x - #print self.y - #self.x1=self.x-eval(words[1]) - self.x1=self.x-eval(words[1]) - #j=self.y-eval(words[5]) - #self.y1=self.y-eval(words[3]) - self.y1=self.y-eval(words[3]) - #self.c = eval(word[1:]) - #print 'self x,y' - #print self.x1 - #print self.y1 - self.dx=(self.x1)*1 - self.dy=(self.y1)*0 - #print 'x1' - #print self.x1 - #print 'y1' - #print self.y1 - ssucin=self.dx+self.dy - r=math.sqrt(((self.x1)*(self.x1))+((self.y1)*(self.y1))) - #print 'skalarny sucin' - #print ssucin - #print 'r' - #print r - if (ssucin!=0): - ratio=ssucin/(r*1) - #print 'ratio' - #print ratio - angle= (math.acos(ratio) * 180 / math.pi) - if(self.y1<0):angle=360-angle - elif (self.y1>0): angle=+90 - elif (self.y1<0): angle=-90 - else: angle=0 - #print words[8] - #print 'angles' - #print angle - #if (i<0 and j<0): angle=180+angle - #if (i<0 and j>0): angle=180-angle - #if (j>0): angle=-angle - #print ('reverzacia') - #angle= angle+ eval(words[8]) - #print angle - self.angle=+ angle+ eval(words[5]) - #print self.angle - #if(angle>180): angle=360-angle - angle=self.angle*math.pi/180 - #print eval(words[8]) - self.endx=eval(words[1])+(r*math.cos(angle)) - #j=eval(words[5])+(r*math.sin(angle)) - self.endy=eval(words[3])+(r*math.sin(angle)) - self.x=self.endx - self.y=self.endy - path_col = "feed" - #arc=-eval(words[8])/math.fabs(eval(words[8])) - arc=eval(words[5])/math.fabs(eval(words[5])) - #if(arc==-1): arc=0 - #arc=-1 - #col = "feed" - move = True + # print words + col = "axis" + self.startx = self.x + self.starty = self.y + words[0] = words[0]+self.SPACE + words[2] = self.SPACE+words[2]+self.SPACE + words[4] = self.SPACE+words[4]+self.SPACE + # print 'x,y' + # print self.x + # print self.y + # self.x1=self.x-eval(words[1]) + self.x1 = self.x-eval(words[1]) + # j=self.y-eval(words[5]) + # self.y1=self.y-eval(words[3]) + self.y1 = self.y-eval(words[3]) + #self.c = eval(word[1:]) + # print 'self x,y' + # print self.x1 + # print self.y1 + self.dx = (self.x1)*1 + self.dy = (self.y1)*0 + # print 'x1' + # print self.x1 + # print 'y1' + # print self.y1 + ssucin = self.dx+self.dy + r = math.sqrt(((self.x1)*(self.x1))+((self.y1)*(self.y1))) + # print 'skalarny sucin' + # print ssucin + # print 'r' + # print r + if (ssucin != 0): + ratio = ssucin/(r*1) + # print 'ratio' + # print ratio + angle = (math.acos(ratio) * 180 / math.pi) + if(self.y1 < 0): + angle = 360-angle + elif (self.y1 > 0): + angle = +90 + elif (self.y1 < 0): + angle = -90 + else: + angle = 0 + # print words[8] + # print 'angles' + # print angle + #if (i<0 and j<0): angle=180+angle + #if (i<0 and j>0): angle=180-angle + #if (j>0): angle=-angle + #print ('reverzacia') + #angle= angle+ eval(words[8]) + # print angle + self.angle = + angle + eval(words[5]) + # print self.angle + #if(angle>180): angle=360-angle + angle = self.angle*math.pi/180 + # print eval(words[8]) + self.endx = eval(words[1])+(r*math.cos(angle)) + # j=eval(words[5])+(r*math.sin(angle)) + self.endy = eval(words[3])+(r*math.sin(angle)) + self.x = self.endx + self.y = self.endy + path_col = "feed" + # arc=-eval(words[8])/math.fabs(eval(words[8])) + arc = eval(words[5])/math.fabs(eval(words[5])) + #if(arc==-1): arc=0 + # arc=-1 + #col = "feed" + move = True - elif (word == 'P' and words[1]=='L' and words[4]=='F'): - self.FS=1 - elif (word == 'P' and words[1]=='L' and words[4]=='N'): - self.FS=0 - elif (word == ('FS'+self.SPACE)): - self.FS=1 - elif (word == ('SS'+self.SPACE)): - self.FS=0 + elif (word == 'P' and words[1] == 'L' and words[4] == 'F'): + self.FS = 1 + elif (word == 'P' and words[1] == 'L' and words[4] == 'N'): + self.FS = 0 + elif (word == ('FS'+self.SPACE)): + self.FS = 1 + elif (word == ('SS'+self.SPACE)): + self.FS = 0 elif (word == ('MA'+self.SPACE)): - words[2]=self.SPACE+words[2]+self.SPACE - if (self.FS==1): - path_col = "rapid" - col = "rapid" - else: - path_col = "feed" - col = "feed" - self.x=eval(words[1]) - #self.y=eval(words[6]) - self.y=eval(words[3]) - move=True - #elif (word == 'G1' or word == 'G01' or word == 'g1' or word == 'g01'): + words[2] = self.SPACE+words[2]+self.SPACE + if (self.FS == 1): + path_col = "rapid" + col = "rapid" + else: + path_col = "feed" + col = "feed" + self.x = eval(words[1]) + # self.y=eval(words[6]) + self.y = eval(words[3]) + move = True + # elif (word == 'G1' or word == 'G01' or word == 'g1' or word == 'g01'): # path_col = "feed" # col = "feed" - #elif (word == 'G2' or word == 'G02' or word == 'g2' or word == 'g02' or word == 'G12' or word == 'g12'): + # elif (word == 'G2' or word == 'G02' or word == 'g2' or word == 'g02' or word == 'G12' or word == 'g12'): # path_col = "feed" # col = "feed" # arc = -1 - #elif (word == 'G3' or word == 'G03' or word == 'g3' or word == 'g03' or word == 'G13' or word == 'g13'): + # elif (word == 'G3' or word == 'G03' or word == 'g3' or word == 'g03' or word == 'G13' or word == 'g13'): # path_col = "feed" # col = "feed" # arc = +1 - #elif (word == 'G10' or word == 'g10'): - # move = False - #elif (word == 'L1' or word == 'l1'): - # move = False - #elif (word == 'G20'): + # elif (word == 'G10' or word == 'g10'): + # move = False + # elif (word == 'L1' or word == 'l1'): + # move = False + # elif (word == 'G20'): # col = "prep" # self.set_mode(units=25.4) - #elif (word == 'G21'): + # elif (word == 'G21'): # col = "prep" # self.set_mode(units=1.0) - #elif (word == 'G81' or word == 'g81'): + # elif (word == 'G81' or word == 'g81'): # path_col = "feed" # col = "feed" - #elif (word == 'G82' or word == 'g82'): + # elif (word == 'G82' or word == 'g82'): # path_col = "feed" # col = "feed" - #elif (word == 'G83' or word == 'g83'): + # elif (word == 'G83' or word == 'g83'): # path_col = "feed" # col = "feed" - #elif (word[0] == 'G') : col = "prep" - #elif (word[0] == 'I' or word[0] == 'i'): + # elif (word[0] == 'G') : col = "prep" + # elif (word[0] == 'I' or word[0] == 'i'): # col = "axis" # self.i = eval(word[1:]) # move = True - #elif (word[0] == 'J' or word[0] == 'j'): + # elif (word[0] == 'J' or word[0] == 'j'): # col = "axis" # self.j = eval(word[1:]) # move = True - #elif (word[0] == 'K' or word[0] == 'k'): + # elif (word[0] == 'K' or word[0] == 'k'): # col = "axis" # self.k = eval(word[1:]) # move = True - #elif (word[0] == 'M') : col = "misc" - #elif (word[0] == 'N') : col = "blocknum" - #elif (word[0] == 'O') : col = "program" - #elif (word[0] == 'P' or word[0] == 'p'): + # elif (word[0] == 'M') : col = "misc" + # elif (word[0] == 'N') : col = "blocknum" + # elif (word[0] == 'O') : col = "program" + # elif (word[0] == 'P' or word[0] == 'p'): # col = "axis" # self.p = eval(word[1:]) # move = True - #elif (word[0] == 'Q' or word[0] == 'q'): + # elif (word[0] == 'Q' or word[0] == 'q'): # col = "axis" # self.q = eval(word[1:]) # move = True - #elif (word[0] == 'R' or word[0] == 'r'): + # elif (word[0] == 'R' or word[0] == 'r'): # col = "axis" # self.r = eval(word[1:]) # move = True - #elif (word[0] == 'S' or word[0zypp] == 's'): + # elif (word[0] == 'S' or word[0zypp] == 's'): # col = "axis" # self.s = eval(word[1:]) # move = True - #elif (word[0] == 'T') : col = "tool" - #elif (word[0] == 'X' or word[0] == 'x'): + # elif (word[0] == 'T') : col = "tool" + # elif (word[0] == 'X' or word[0] == 'x'): # col = "axis" # = eval(word[1:]) # move = True - #elif (word[0] == 'Y' or word[0] == 'y'): + # elif (word[0] == 'Y' or word[0] == 'y'): # col = "axis" # self.y = eval(word[1:]) # move = True - #elif (word[0] == 'Z' or word[0] == 'z'): + # elif (word[0] == 'Z' or word[0] == 'z'): # col = "axis" # self.z = eval(word[1:]) # move = True - elif (word[0] == '(') : col = "comment" - elif (word[0] == '#') : col = "variable" - elif (words[0] == ("//"+self.SPACE)) : col = "comment" - elif (words[0] == ("/*"+self.SPACE)) : col = "comment" - #self.add_text(word, col) + elif (word[0] == '('): + col = "comment" + elif (word[0] == '#'): + col = "variable" + elif (words[0] == ("//"+self.SPACE)): + col = "comment" + elif (words[0] == ("/*"+self.SPACE)): + col = "comment" + #self.add_text(word, col) if (move): self.begin_path(path_col) - if (arc) : - #self.add_arc(self.x, self.y, 0.0000, self.i, self.j, 0.0000, arc) - #self.add_arc(self.i, self.j, 0.0000, eval(words[2])-self.x, eval(words[5])-self.y, 0.0000, arc) - #print '' - #print eval(words[2])-self.startx - #print eval(words[6])-self.starty - #self.add_arc(self.endx, self.endy, 0.0000, eval(words[1])-self.startx, eval(words[3])-self.starty, 0.0000, arc) - print arc - self.add_arc(self.endx, self.endy, 0.0000,eval(words[1])-self.startx, eval(words[3])-self.starty, 0.0000,0.0000, arc) + if (arc): + #self.add_arc(self.x, self.y, 0.0000, self.i, self.j, 0.0000, arc) + #self.add_arc(self.i, self.j, 0.0000, eval(words[2])-self.x, eval(words[5])-self.y, 0.0000, arc) + # print '' + # print eval(words[2])-self.startx + # print eval(words[6])-self.starty + #self.add_arc(self.endx, self.endy, 0.0000, eval(words[1])-self.startx, eval(words[3])-self.starty, 0.0000, arc) + print arc + self.add_arc(self.endx, self.endy, 0.0000, eval( + words[1])-self.startx, eval(words[3])-self.starty, 0.0000, 0.0000, arc) - #self.add_arc(self.x, self.y, 0.0000, self.i, self.j, 0.0000, arc) - #self.x=self.i - #self.y=self.j - else : - self.add_line(self.x, self.y) - self.end_path() + #self.add_arc(self.x, self.y, 0.0000, self.i, self.j, 0.0000, arc) + # self.x=self.i + # self.y=self.j + else: + self.add_line(self.x, self.y) + self.end_path() self.end_ncblock() diff --git a/scripts/addons/cam/nc/series1.py b/scripts/addons/cam/nc/series1.py index c33539412..4bda80351 100644 --- a/scripts/addons/cam/nc/series1.py +++ b/scripts/addons/cam/nc/series1.py @@ -3,6 +3,8 @@ import math ################################################################################ + + class Creator(iso_modal.Creator): def __init__(self): @@ -24,8 +26,9 @@ def metric(self): self.fmt.number_of_decimal_places = 2 def SPACE(self): - return('') + return('') ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/series1_read.py b/scripts/addons/cam/nc/series1_read.py index e94a2b4b2..f07ff91f3 100644 --- a/scripts/addons/cam/nc/series1_read.py +++ b/scripts/addons/cam/nc/series1_read.py @@ -3,6 +3,7 @@ # use the iso reader, but with i_and_j_always_positive + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/shopbot_mtc.py b/scripts/addons/cam/nc/shopbot_mtc.py index 773c2e101..57276d902 100644 --- a/scripts/addons/cam/nc/shopbot_mtc.py +++ b/scripts/addons/cam/nc/shopbot_mtc.py @@ -19,206 +19,205 @@ import bpy ################################################################################ + + class Creator(nc.Creator): - def __init__(self): - nc.Creator.__init__(self) - - s=bpy.context.scene - cm=s.cam_machine - self.fmt = Format() - self.ffmt = Format(number_of_decimal_places = 2) - self.sfmt = Format(number_of_decimal_places = 1) - self.unitscale = 1 - self.startx = cm.starting_position.x - self.starty = cm.starting_position.y - self.startz = cm.starting_position.z - self.tcx = cm.mtc_position.x - self.tcy = cm.mtc_position.y - self.tcz = cm.mtc_position.z - self.endx = cm.ending_position.x - self.endy = cm.ending_position.y - self.endz = cm.ending_position.z - self.metric_flag = False - self.absolute_flag = True - - ############################################################################ - ## Codes - - def SPACE(self): return('') - def COMMENT(self,comment): return( '\' %s' % comment ) - def TOOL(self): return('T%i' + self.SPACE() + 'M06') - - ############################################################################ - ## Internals - - def write_feedrate(self): - self.f.write(self) - - def write_spindle(self): - self.s.write(self) - - ############################################################################ - ## Programs - - def program_begin(self, id, name=''): - self.writem([self.SPACE() , self.COMMENT(name)]) - self.write('\n\n') - self.write('IF %(25)=1 THEN GOTO UNIT_ERROR\n') - self.write('\n') - - def program_end(self): - self.write('C7\n') - self.write('JZ,' + self.fmt.string(self.endz) + '\n') - self.write('J2,' + self.fmt.string(self.endx) + ',' + self.fmt.string(self.endy) + '\n') - self.write('END\n') - self.write('\'\n') - self.write('UNIT_ERROR:\n') - self.write('C#,91\n') - self.write('END\n') - - def flush_nc(self): - return - - ############################################################################ - ## Subprograms - - - ############################################################################ - ## Settings - - def imperial(self): - self.fmt.number_of_decimal_places = 4 - self.unitscale = 0.0254 - self.metric_flag=False - - def metric(self): - self.metric_flag=True - self.unitscale = 1 - self.fmt.number_of_decimal_places = 3 - - def absolute(self): - self.absolute_flag = True - self.write('SA\n') - - def incremental(self): - self.absolute_flag = False - self.write('SR\n') - - def set_plane(self, plane): - return - - ############################################################################ - ## new graphics origin- make a new coordinate system and snap it onto the geometry - ## the toolpath generated should be translated - - - ############################################################################ - ## Tools - - def tool_change(self, id): - self.write('C7\n') - self.write('&Tool=' + self.fmt.string(id) + '\n') - self.write('JZ,' + (self.fmt.string(self.tcz)) + '\n') - self.write('J2,' + (self.fmt.string(self.tcx)) + ',' + (self.fmt.string(self.tcy)) + '\n') - self.write('\' Use tool '+ self.fmt.string(id) + '\n') - self.write('PAUSE\n') - self.write('C2\n') - self.t = id - self.write('C6\n') - self.write('PAUSE 2\n') - - ############################################################################ - ## Datums - - - ############################################################################ - ## Rates + Modes - - def feedrate(self, f): - if (self.metric_flag == True): - self.write('MS,' + (self.sfmt.string(f)) + ',' + (self.sfmt.string(f)) + '\n') - else: - self.write('MS,' + (self.sfmt.string(f*self.unitscale)) + ',' + (self.sfmt.string(f*self.unitscale)) + '\n') - - def spindle(self, s, clockwise): - self.write('TR,' + self.fmt.string(s) + '\n') - - ############################################################################ - ## Moves - - def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): - # different commands for X only, or Y only, or Z only, or (X and Y), or (X, Y, and Z) - if (x != None and y != None and z != None): - self.write('J3,' + (self.fmt.string(x * self.unitscale))) - self.write(',' + (self.fmt.string(y * self.unitscale))) - self.write(',' + (self.fmt.string(z * self.unitscale))) - self.write('\n') - elif (x != None and y != None and z == None): - self.write('J2,' + (self.fmt.string(x * self.unitscale))) - self.write(',' + (self.fmt.string(y * self.unitscale))) - self.write('\n') - elif (x != None): - self.write('JX,' + (self.fmt.string(x * self.unitscale)) + '\n') - elif (y != None): - self.write('JY,' + (self.fmt.string(y * self.unitscale)) + '\n') - elif (z != None): - self.write('JZ,' + (self.fmt.string(z * self.unitscale)) + '\n') - - def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): - if (x != None and y != None and z != None): - self.write('M3,' + (self.fmt.string(x * self.unitscale))) - self.write(',' + (self.fmt.string(y * self.unitscale))) - self.write(',' + (self.fmt.string(z * self.unitscale))) - self.write('\n') - elif (x != None and y != None and z == None): - self.write('M2,' + (self.fmt.string(x * self.unitscale))) - self.write(',' + (self.fmt.string(y * self.unitscale))) - self.write('\n') - elif (x != None): - self.write('MX,' + (self.fmt.string(x * self.unitscale)) + '\n') - elif (y != None): - self.write('MY,' + (self.fmt.string(y * self.unitscale)) + '\n') - elif (z != None): - self.write('MZ,' + (self.fmt.string(z * self.unitscale)) + '\n') - - def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): - if (r != None): - self.write('CG,' + self.fmt.string(r * self.unitscale * 2)) - self.write(',' + self.fmt.string(x * self.unitscale)) - self.write(',' + self.fmt.string(y * self.unitscale)) - self.write(', ,') - self.write(',T,1') - self.write('\n') - else: - self.write('CG, ') - self.write(',' + self.fmt.string(x * self.unitscale)) - self.write(',' + self.fmt.string(y * self.unitscale)) - self.write(',' + self.fmt.string(i * self.unitscale)) - self.write(',' + self.fmt.string(j * self.unitscale)) - self.write(',T,1') - self.write('\n') - return - - ############################################################################ - ## CRC - - - ############################################################################ - ## Cycles - - - ############################################################################ - ## Misc - - def comment(self, text): - self.write((self.COMMENT(text) + '\n')) - - def variable(self, id): - return (self.VARIABLE() % id) - - def variable_set(self, id, value): - self.write('&' + (self.VARIABLE() % id) + self.SPACE() + (self.VARIABLE_SET() % value) + '\n') + def __init__(self): + nc.Creator.__init__(self) + + s = bpy.context.scene + cm = s.cam_machine + self.fmt = Format() + self.ffmt = Format(number_of_decimal_places=2) + self.sfmt = Format(number_of_decimal_places=1) + self.unitscale = 1 + self.startx = cm.starting_position.x + self.starty = cm.starting_position.y + self.startz = cm.starting_position.z + self.tcx = cm.mtc_position.x + self.tcy = cm.mtc_position.y + self.tcz = cm.mtc_position.z + self.endx = cm.ending_position.x + self.endy = cm.ending_position.y + self.endz = cm.ending_position.z + self.metric_flag = False + self.absolute_flag = True + + ############################################################################ + # Codes + + def SPACE(self): return('') + def COMMENT(self, comment): return('\' %s' % comment) + def TOOL(self): return('T%i' + self.SPACE() + 'M06') + + ############################################################################ + # Internals + + def write_feedrate(self): + self.f.write(self) + + def write_spindle(self): + self.s.write(self) + + ############################################################################ + # Programs + + def program_begin(self, id, name=''): + self.writem([self.SPACE(), self.COMMENT(name)]) + self.write('\n\n') + self.write('IF %(25)=1 THEN GOTO UNIT_ERROR\n') + self.write('\n') + + def program_end(self): + self.write('C7\n') + self.write('JZ,' + self.fmt.string(self.endz) + '\n') + self.write('J2,' + self.fmt.string(self.endx) + ',' + self.fmt.string(self.endy) + '\n') + self.write('END\n') + self.write('\'\n') + self.write('UNIT_ERROR:\n') + self.write('C#,91\n') + self.write('END\n') + + def flush_nc(self): + return + + ############################################################################ + # Subprograms + + ############################################################################ + # Settings + + def imperial(self): + self.fmt.number_of_decimal_places = 4 + self.unitscale = 0.0254 + self.metric_flag = False + + def metric(self): + self.metric_flag = True + self.unitscale = 1 + self.fmt.number_of_decimal_places = 3 + + def absolute(self): + self.absolute_flag = True + self.write('SA\n') + + def incremental(self): + self.absolute_flag = False + self.write('SR\n') + + def set_plane(self, plane): + return + + ############################################################################ + # new graphics origin- make a new coordinate system and snap it onto the geometry + # the toolpath generated should be translated + + ############################################################################ + # Tools + + def tool_change(self, id): + self.write('C7\n') + self.write('&Tool=' + self.fmt.string(id) + '\n') + self.write('JZ,' + (self.fmt.string(self.tcz)) + '\n') + self.write('J2,' + (self.fmt.string(self.tcx)) + ',' + (self.fmt.string(self.tcy)) + '\n') + self.write('\' Use tool ' + self.fmt.string(id) + '\n') + self.write('PAUSE\n') + self.write('C2\n') + self.t = id + self.write('C6\n') + self.write('PAUSE 2\n') + + ############################################################################ + # Datums + + ############################################################################ + ## Rates + Modes + + def feedrate(self, f): + if (self.metric_flag == True): + self.write('MS,' + (self.sfmt.string(f)) + ',' + (self.sfmt.string(f)) + '\n') + else: + self.write('MS,' + (self.sfmt.string(f*self.unitscale)) + + ',' + (self.sfmt.string(f*self.unitscale)) + '\n') + + def spindle(self, s, clockwise): + self.write('TR,' + self.fmt.string(s) + '\n') + + ############################################################################ + # Moves + + def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None): + # different commands for X only, or Y only, or Z only, or (X and Y), or (X, Y, and Z) + if (x != None and y != None and z != None): + self.write('J3,' + (self.fmt.string(x * self.unitscale))) + self.write(',' + (self.fmt.string(y * self.unitscale))) + self.write(',' + (self.fmt.string(z * self.unitscale))) + self.write('\n') + elif (x != None and y != None and z == None): + self.write('J2,' + (self.fmt.string(x * self.unitscale))) + self.write(',' + (self.fmt.string(y * self.unitscale))) + self.write('\n') + elif (x != None): + self.write('JX,' + (self.fmt.string(x * self.unitscale)) + '\n') + elif (y != None): + self.write('JY,' + (self.fmt.string(y * self.unitscale)) + '\n') + elif (z != None): + self.write('JZ,' + (self.fmt.string(z * self.unitscale)) + '\n') + + def feed(self, x=None, y=None, z=None, a=None, b=None, c=None): + if (x != None and y != None and z != None): + self.write('M3,' + (self.fmt.string(x * self.unitscale))) + self.write(',' + (self.fmt.string(y * self.unitscale))) + self.write(',' + (self.fmt.string(z * self.unitscale))) + self.write('\n') + elif (x != None and y != None and z == None): + self.write('M2,' + (self.fmt.string(x * self.unitscale))) + self.write(',' + (self.fmt.string(y * self.unitscale))) + self.write('\n') + elif (x != None): + self.write('MX,' + (self.fmt.string(x * self.unitscale)) + '\n') + elif (y != None): + self.write('MY,' + (self.fmt.string(y * self.unitscale)) + '\n') + elif (z != None): + self.write('MZ,' + (self.fmt.string(z * self.unitscale)) + '\n') + + def arc(self, cw, x=None, y=None, z=None, i=None, j=None, k=None, r=None): + if (r != None): + self.write('CG,' + self.fmt.string(r * self.unitscale * 2)) + self.write(',' + self.fmt.string(x * self.unitscale)) + self.write(',' + self.fmt.string(y * self.unitscale)) + self.write(', ,') + self.write(',T,1') + self.write('\n') + else: + self.write('CG, ') + self.write(',' + self.fmt.string(x * self.unitscale)) + self.write(',' + self.fmt.string(y * self.unitscale)) + self.write(',' + self.fmt.string(i * self.unitscale)) + self.write(',' + self.fmt.string(j * self.unitscale)) + self.write(',T,1') + self.write('\n') + return + + ############################################################################ + # CRC + + ############################################################################ + # Cycles + + ############################################################################ + # Misc + + def comment(self, text): + self.write((self.COMMENT(text) + '\n')) + + def variable(self, id): + return (self.VARIABLE() % id) + + def variable_set(self, id, value): + self.write('&' + (self.VARIABLE() % id) + self.SPACE() + + (self.VARIABLE_SET() % value) + '\n') ################################################################################ diff --git a/scripts/addons/cam/nc/siegkx1.py b/scripts/addons/cam/nc/siegkx1.py index 7aa272cdf..5fc50586c 100644 --- a/scripts/addons/cam/nc/siegkx1.py +++ b/scripts/addons/cam/nc/siegkx1.py @@ -11,6 +11,8 @@ import math ################################################################################ + + class Creator(iso_modal.Creator): def __init__(self): diff --git a/scripts/addons/cam/nc/siegkx1_read.py b/scripts/addons/cam/nc/siegkx1_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/siegkx1_read.py +++ b/scripts/addons/cam/nc/siegkx1_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/tnc151.py b/scripts/addons/cam/nc/tnc151.py index 3975e5f45..4dd5cce52 100644 --- a/scripts/addons/cam/nc/tnc151.py +++ b/scripts/addons/cam/nc/tnc151.py @@ -9,6 +9,8 @@ import math ################################################################################ + + class Creator(iso_modal.Creator): def __init__(self): @@ -21,12 +23,12 @@ def __init__(self): self.waiting_t = None self.waiting_for_program_begin = False - ######## Codes + # Codes def SPACE(self): return(' ') def TOOL(self): return('T%i') - ######## Overridden functions + # Overridden functions def write_blocknum(self): self.write(self.BLOCK() % self.n) @@ -50,8 +52,8 @@ def metric(self): self.write(' G71\n') self.fmt.number_of_decimal_places = 3 - # no tool definition lines wanted + def tool_defn(self, id, name='', params=None): pass @@ -87,4 +89,5 @@ def workplane(self, id): pass ################################################################################ + nc.creator = Creator() diff --git a/scripts/addons/cam/nc/tnc151_read.py b/scripts/addons/cam/nc/tnc151_read.py index 075c24e09..2ca0b6f50 100644 --- a/scripts/addons/cam/nc/tnc151_read.py +++ b/scripts/addons/cam/nc/tnc151_read.py @@ -2,6 +2,8 @@ import sys # just use the iso reader + + class Parser(iso.Parser): def __init__(self, writer): iso.Parser.__init__(self, writer) diff --git a/scripts/addons/cam/nc/winpc.py b/scripts/addons/cam/nc/winpc.py index 82a47214b..e92b3de95 100644 --- a/scripts/addons/cam/nc/winpc.py +++ b/scripts/addons/cam/nc/winpc.py @@ -6,6 +6,7 @@ now = datetime.datetime.now() + class Creator(iso_modal.Creator): def __init__(self): iso_modal.Creator.__init__(self) @@ -16,21 +17,25 @@ def __init__(self): def SPACE_STR(self): return ' ' - def TOOL(self): return('T%i' + self.SPACE() ) + def TOOL(self): return('T%i' + self.SPACE()) ############################################################################ -## Internal +# Internal + + def write_spindle(self): return '' ############################################################################ -## Programs +# Programs def program_begin(self, id, comment): if (self.useCrc == False): - self.write( ('(Created with win-pc post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) + self.write(('(Created with win-pc post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) else: - self.write( ('(Created with win-pc Cutter Radius Compensation post processor ' + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n') ) + self.write(('(Created with win-pc Cutter Radius Compensation post processor ' + + str(now.strftime("%Y/%m/%d %H:%M")) + ')' + '\n')) #self.rapid( x=0.0, y=0.0, z=30.0 ) def program_end(self): @@ -38,7 +43,7 @@ def program_end(self): #self.rapid( x=0.0, y=0.0, z=30.0 ) ############################################################################ -## Settings +# Settings def tool_defn(self, id, name='', params=None): #self.write('G43 \n') @@ -55,18 +60,22 @@ def comment(self, text): # These are selected by values from 1 to 9 inclusive. def workplane(self, id): if ((id >= 1) and (id <= 6)): - self.write( (self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\t (Select Relative Coordinate System)\n') + self.write((self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + + '\t (Select Relative Coordinate System)\n') if ((id >= 7) and (id <= 9)): - self.write( ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\t (Select Relative Coordinate System)\n') + self.write(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % + (id - 6))) + '\t (Select Relative Coordinate System)\n') ############################################################################ -## Moves +# Moves ############################################################################ ## Rates + Modes -## All feedrates are given in mm/s +# All feedrates are given in mm/s + + def feedrate(self, f): self.f.set(f/60) self.fhv = False @@ -86,10 +95,12 @@ def calc_feedrate_hv(self, h, v): ############################################################################ -## Probe routines - def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None ): +# Probe routines + + + def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=None, x3=None, y3=None, z3=None, x4=None, y4=None, z4=None, x5=None, y5=None, z5=None, x6=None, y6=None, z6=None, xml_file_name=None): if (xml_file_name != None): - self.comment('Generate an XML document describing the probed coordinates found'); + self.comment('Generate an XML document describing the probed coordinates found') self.write_blocknum() self.write('(LOGOPEN,') self.write(xml_file_name) @@ -261,7 +272,7 @@ def report_probe_results(self, x1=None, y1=None, z1=None, x2=None, y2=None, z2=N self.write_blocknum() self.write('(LOGCLOSE)\n') - def open_log_file(self, xml_file_name=None ): + def open_log_file(self, xml_file_name=None): self.write_blocknum() self.write('(LOGOPEN,') self.write(xml_file_name) @@ -298,8 +309,9 @@ def log_coordinate(self, x=None, y=None, z=None): self.write_blocknum() self.write('(LOG,)\n') - def log_message(self, message=None ): + def log_message(self, message=None): self.write_blocknum() self.write('(LOG,' + message + ')\n') + nc.creator = Creator()