Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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 printCLPoints(cl_filtered_paths):
    ngc_writer.preamble()
    
    for path in cl_filtered_paths:
        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()
Exemplo n.º 5
0
def printCLPoints(cl_filtered_paths):
    ngc_writer.preamble()

    for path in cl_filtered_paths:
        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()
Exemplo n.º 6
0
    print_scale= float(text_length)/float(0.6)    
    times = insert_many_polygons(vd,segs) # insert segments into vd
    
    # count the number of segments
    num_segs = 0
    for s in segs:
        num_segs = num_segs + len(s)
    
    text_length = (extents.maxx-extents.minx)*scale*print_scale
    text_height = (extents.maxy-extents.miny)*scale*print_scale
    
    # print comments to g-code file
    print "( ttt2medial.py - experimental v-carving script )"
    print "( TTT++",ttt.version(),"                      )"
    print "( OpenVoronoi",ovd.version(),"                )"
    print "( number of polygons: ", len(segs),"                )"
    print "( number of segments: ", num_segs ,"                )"
    print "( text length: ", text_length ," )"
    print "( text height: ",text_height,"                )"
    print "( VD built in %02.3f seconds   = %02f  us* n*log2{n} )" % ( sum(times), 1e6*float(sum(times))/(float(num_segs)*float(math.log10(num_segs)/math.log10(2)))    )
    print "( VD check: ", vd.check(), "                              )"
    
    pi = ovd.PolygonInterior( True ) # filter so that only polygon interior remains
    vd.filter_graph(pi)
    ma = ovd.MedialAxis() # filter so that only medial axis remains
    vd.filter_graph(ma)
    
    ngc_writer.preamble()
    printMedial( vd , print_scale) # the actual cutting g-code
    ngc_writer.postamble()
Exemplo n.º 7
0
    cut_width = 0.002
    mapocket = ovd.MedialAxisPocket(vd3.getGraph())
    mapocket.setWidth(cut_width)
    mapocket.debug(True)
    t_before = time.time()
    mapocket.run()
    t_after = time.time()
    # print "( MA-pocket done in %.3f s. Got %d MICs )" % ((t_after-t_before),len(mic_list) )

    mic_components = mapocket.get_mic_components()

    mic_list = mic_components[0]  # mapocket.get_mic_list()

    ngc_writer.scale = 10 / 0.03
    ngc_writer.preamble()

    for mic_list in mic_components:
        drawToolPath(myscreen, mic_list, cut_width)

    ngc_writer.postamble()

    sys.stdout = sys.__stdout__  # remember to reset sys.stdout!

    f = open('output.nc', 'w')
    for item in foo.content:
        if item != '\n':
            print >> f, item
    f.close()

    print "python done."