def OutputGCode(lev, paths, fn): nw.clearance_height = config.top + config.clearance_above_top nw.feed_height = config.top + config.engage_above_top nw.feed = config.feed nw.plunge_feed = config.plunge_feed nw.writer = FileWriter(fn) nw.comment("============ START G-CODE ===============") nw.preamble() nw.pen_up() pairs = zip(lev, paths) for lev, path in sorted(pairs, key = lambda(p): -p[0]): nw.comment("level=%s" % lev) for curve in path: vertices = curve.getVertices() current = vertices[0].p nw.xy_rapid_to(current.x, current.y) nw.pen_down(lev) for v in vertices[1:]: if v.type == 0: nw.line_to(v.p.x, v.p.y, lev) else: r = math.hypot(v.p.x - v.c.x, v.p.y - v.c.y) nw.xy_arc_to(v.p.x, v.p.y, r, v.c.x, v.c.y, v.type != 1) nw.pen_up() nw.postamble() nw.comment("============ END G-CODE ===============") nw.writer.Close()
def write_zig_gcode_file(filename, n_triangles, t1,n1,tol,t2,n2, toolpath): ngc_writer.clearance_height= 5 # XY rapids at this height ngc_writer.feed_height = 3 # use z plunge-feed below this height ngc_writer.feed = 200 # feedrate ngc_writer.plunge_feed = 100 # plunge feedrate ngc_writer.metric = False # metric/inch flag ngc_writer.comment( " OpenCAMLib %s" % ocl.version() ) # git version-tag # it is probably useful to include this in all g-code output, so that bugs/problems can be tracked ngc_writer.comment( " STL surface: %s" % filename ) ngc_writer.comment( " triangles: %d" % n_triangles ) ngc_writer.comment( " OpenCamLib::AdaptivePathDropCutter run took %.2f s" % t1 ) ngc_writer.comment( " got %d raw CL-points " % n1 ) ngc_writer.comment( " filtering to tolerance %.4f " % ( tol ) ) ngc_writer.comment( " got %d filtered CL-points. Filter done in %.3f s " % ( n2 , t2 ) ) ngc_writer.preamble() # a "Zig" or one-way parallel finish path # 1) lift to clearance height # 2) XY rapid to start of path # 3) plunge to correct z-depth # 4) feed along path until end for path in toolpath: ngc_writer.pen_up() first_pt = path[0] ngc_writer.xy_rapid_to( first_pt.x, first_pt.y ) ngc_writer.pen_down( first_pt.z ) for p in path[1:]: ngc_writer.line_to(p.x,p.y,p.z) ngc_writer.postamble() # end of program
def write_zig_gcode_file(filename, n_triangles, t1, n1, tol, t2, n2, toolpath): ngc_writer.clearance_height = 5 # XY rapids at this height ngc_writer.feed_height = 3 # use z plunge-feed below this height ngc_writer.feed = 200 # feedrate ngc_writer.plunge_feed = 100 # plunge feedrate ngc_writer.metric = False # metric/inch flag ngc_writer.comment(" OpenCAMLib %s" % ocl.version()) # git version-tag # it is probably useful to include this in all g-code output, so that bugs/problems can be tracked ngc_writer.comment(" STL surface: %s" % filename) ngc_writer.comment(" triangles: %d" % n_triangles) ngc_writer.comment(" OpenCamLib::AdaptivePathDropCutter run took %.2f s" % t1) ngc_writer.comment(" got %d raw CL-points " % n1) ngc_writer.comment(" filtering to tolerance %.4f " % (tol)) ngc_writer.comment(" got %d filtered CL-points. Filter done in %.3f s " % (n2, t2)) ngc_writer.preamble() # a "Zig" or one-way parallel finish path # 1) lift to clearance height # 2) XY rapid to start of path # 3) plunge to correct z-depth # 4) feed along path until end for path in toolpath: ngc_writer.pen_up() first_pt = path[0] ngc_writer.xy_rapid_to(first_pt.x, first_pt.y) ngc_writer.pen_down(first_pt.z) for p in path[1:]: ngc_writer.line_to(p.x, p.y, p.z) ngc_writer.postamble() # end of program