def generic_nose_contour(face_con, thickness, thin_back, centering_shift): """ Use the tapered endmill to create a nose relief along the curve of the glasses frame. First construct a path that is a simple, average shape for a nose: 8 mm nose radius, 34 degree splay. Compare the curve to the spline of the glasses, if the spline crosses our naive curve, follow the glasses curve until it crosses the naive curve again, then keep following the naive curve. """ curve_offset = 0 # Set so tapered endmill cuts about 1mm from front face of frame nose_sa = math.radians(34) # Experiment with this nose_rad = 9 xfloor = -26 # set to avoid hitting clamp nose_height = 8 # again, experiment naive_poly = nose.nose_poly(nose_rad, nose_height, nose_sa, nose_sa, xfloor, curve_offset, 0) # close it #naive_poly = naive_poly + [naive_poly[0]] intersect = poly.difference(naive_poly, face_con) intersect = intersect[1:] + [intersect[0]] eroded = poly.erode(2, intersect)[0] finish = poly.erode(1.5, intersect)[0] hole_radius = 4.85/2 # Measured from dowel pin tool_radius = 3.175/2 helix_radius = hole_radius - tool_radius return [ cam.change_tool("tapered"), cam.start_spindle(20000), cam.feedrate(1000), cam.rmh(eroded[0] + [-thickness - 1.0], helix_radius, 0.5, 1), cam.contour(eroded, False), cam.contour(finish[::-1], False), ]
def lens_groove(left_c, right_c, height): """Generates the toolpath for the lens holes (holes, groove and tabs).""" print 'Generating lens grooves' if not poly.is_ccw(left_c): left_c = poly.reverse(left_c) if not poly.is_ccw(right_c): right_c = poly.reverse(right_c) lgroove = poly.erode(1.8, left_c)[0] rgroove = poly.erode(1.8, right_c)[0] left_entry = poly.erode(7.0, left_c)[0][0]; right_entry = poly.erode(7.0, right_c)[0][0]; r = [ "(Lens Grooves)", cam.change_tool("vgroove"), cam.start_spindle(20000), cam.dwell(5), cam.feedrate(2000), cam.rmp(right_entry + [height]), cam.contour(rgroove, True), cam.move(right_entry), # Get out from under the overhang cam.rmp(left_entry + [height]), cam.contour(lgroove, True), cam.move(left_entry), # Get out from under the overhang ] return r
def temple_hinge_pockets(temples): # We're operating in a 90 degree rotated fixture #l_hinge = poly.rotate_90(temples["left_hinge_contour"]) #r_hinge = poly.rotate_90(temples["right_hinge_contour"]) l_hinge = temples["left_hinge_contour"] r_hinge = temples["right_hinge_contour"] if not poly.is_ccw(l_hinge): l_hinge = poly.reverse(l_hinge) if not poly.is_ccw(r_hinge): r_hinge = poly.reverse(r_hinge) left_hinge_pocket_contours = [] while len(l_hinge) > 0: l_hinge = poly.erode(1.5875 / 2, l_hinge) if len(l_hinge) > 0: l_hinge = l_hinge[0] left_hinge_pocket_contours.append(l_hinge) right_hinge_pocket_contours = [] while len(r_hinge) > 0: r_hinge = poly.erode(1.5875 / 2, r_hinge) if len(r_hinge) > 0: r_hinge = r_hinge[0] right_hinge_pocket_contours.append(r_hinge) r = [ cam.comment("Hinge Pockets"), cam.feedrate(750), cam.change_tool("1/16in endmill"), cam.start_spindle(15000), cam.dwell(3), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(temples['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(temples['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Hinge Holes"), cam.change_tool("1mm drill"), cam.start_spindle(4500), cam.dwell(2), [ cam.rmp(p + [-8.0], retract=10.0) for p in temples['right_hinge_holes'] ], [ cam.rmp(p + [-8.0], retract=10.0) for p in temples['left_hinge_holes'] ], cam.rapid([None, None, 20.0]), cam.move([None, None, 0]), cam.contour(poly.rotate_90(temples['left_temple_contour']), True), cam.contour(poly.rotate_90(temples['right_temple_contour']), True), ] return r
def face_hinge_pockets(hinge_num, xposition, yposition): left_hinge = hinges.get_hinge(hinge_num) right_hinge = hinges.get_hinge(hinge_num, False) left_translate = [xposition, -yposition] #left_translate = [xposition, 0] right_translate = [xposition, yposition] #right_translate = [xposition, 0] # Adjust by pocket depth of hinge pocket_depth = left_hinge['pocket_depth'] left_contour = poly.translate(left_hinge["face_contour"], left_translate[0], left_translate[1]) right_contour = poly.translate(right_hinge["face_contour"], right_translate[0], right_translate[1]) left_holes = poly.translate(left_hinge["face_holes"], left_translate[0], left_translate[1]) right_holes = poly.translate(right_hinge["face_holes"], right_translate[0], right_translate[1]) if not poly.is_ccw(left_contour): left_contour = poly.reverse(left_contour) if not poly.is_ccw(right_contour): right_contour = poly.reverse(right_contour) left_hinge_pocket_contours = []; while len(left_contour) > 0: left_contour = poly.erode(1.5875/2, left_contour) if len(left_contour) > 0: left_contour = left_contour[0] left_hinge_pocket_contours.append(left_contour) right_hinge_pocket_contours = []; while len(right_contour) > 0: right_contour = poly.erode(1.5875/2, right_contour) if len(right_contour) > 0: right_contour = right_contour[0] right_hinge_pocket_contours.append(right_contour) r = [ cam.comment("Hinge Pockets"), cam.feedrate(750), cam.change_tool("1/16in endmill"), cam.start_spindle(15000), cam.dwell(3), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(right_hinge['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(left_hinge['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Hinge Holes"), cam.change_tool("1mm drill"), cam.start_spindle(4500), cam.dwell(2), [cam.rmp(p + [-8.0], retract=10.0) for p in right_holes], [cam.rmp(p + [-8.0], retract=10.0) for p in left_holes], cam.rapid([None, None, 20.0]), ] return r
def pocket_contours(contour): contours = [] erode = poly.erode(1.5875/2, contour) making_progress = True while len(erode) > 0 and making_progress: making_progress = False for path in erode: if len(path) > 5: making_progress = True contours.append(path) erode = poly.erode(1.5875/2, contours[-1]) return contours
def lens_holes(left_c, right_c, thickness): """Generates the toolpath for the lens holes (holes, groove and tabs).""" if not poly.is_ccw(left_c): left_c = poly.reverse(left_c) if not poly.is_ccw(right_c): right_c = poly.reverse(right_c) lhole = poly.erode(3.175 / 2.0, left_c)[0] rhole = poly.erode(3.175 / 2.0, right_c)[0] right_rough = poly.erode(0.1, rhole)[0] left_rough = poly.erode(0.1, lhole)[0] lgroove = poly.erode(0.8, left_c)[0] rgroove = poly.erode(0.8, right_c)[0] left_entry = poly.erode(2.0, lhole)[0][0] right_entry = poly.erode(2.0, rhole)[0][0] lhole = poly.reverse(lhole) rhole = poly.reverse(rhole) r = [ "(Lens Holes)", cam.change_tool("1/8in endmill"), cam.start_spindle(20000), cam.feedrate(2000), cam.rmh(right_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(right_rough, True), cam.contour(rhole, True), cam.rmh(left_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(left_rough, True), cam.contour(lhole, True), ] return r
def temple_hinge_pockets(temples): # We're operating in a 90 degree rotated fixture #l_hinge = poly.rotate_90(temples["left_hinge_contour"]) #r_hinge = poly.rotate_90(temples["right_hinge_contour"]) l_hinge = temples["left_hinge_contour"] r_hinge = temples["right_hinge_contour"] if not poly.is_ccw(l_hinge): l_hinge = poly.reverse(l_hinge) if not poly.is_ccw(r_hinge): r_hinge = poly.reverse(r_hinge) left_hinge_pocket_contours = []; while len(l_hinge) > 0: l_hinge = poly.erode(1.5875/2, l_hinge) if len(l_hinge) > 0: l_hinge = l_hinge[0] left_hinge_pocket_contours.append(l_hinge) right_hinge_pocket_contours = []; while len(r_hinge) > 0: r_hinge = poly.erode(1.5875/2, r_hinge) if len(r_hinge) > 0: r_hinge = r_hinge[0] right_hinge_pocket_contours.append(r_hinge) r = [ cam.comment("Hinge Pockets"), cam.feedrate(750), cam.change_tool("1/16in endmill"), cam.start_spindle(15000), cam.dwell(3), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(temples['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(temples['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Hinge Holes"), cam.change_tool("1mm drill"), cam.start_spindle(4500), cam.dwell(2), [cam.rmp(p + [-8.0], retract=10.0) for p in temples['right_hinge_holes']], [cam.rmp(p + [-8.0], retract=10.0) for p in temples['left_hinge_holes']], cam.rapid([None, None, 20.0]), cam.move([None, None, 0]), cam.contour(poly.rotate_90(temples['left_temple_contour']), True), cam.contour(poly.rotate_90(temples['right_temple_contour']), True), ] return r
def main(): """Run as a command line program.""" parser = OptionParser() parser.add_option("-i", "--infile", dest="infile", help="read specification from INFILE", metavar="INFILE") parser.add_option("-u", "--url", dest="url", help="read specification from URL", metavar="URL") parser.add_option("-o", "--outdir", dest="outdir", help="write manufacturing instruction files to OUTDIR", metavar="OUTDIR") (options, args) = parser.parse_args() if (options.infile == None and options.url == None): log("Insufficient arguments.") parser.print_help() sys.exit(0) infile = open(options.infile) if options.infile else urllib.urlopen(options.url) o = json.loads(infile.read()) drawing = dxf.drawing('test.dxf') drawing.add_layer('OUTLINE', color=1) lhole = o['lhole_con'] polyline = dxf.polyline(layer="OUTLINE") polyline.add_vertices(lhole) drawing.add(polyline) p2 = poly.erode(3.175/2.0, lhole)[0] p2 = poly.erode(2.0, p2); poly2 = dxf.polyline(layer="OUTLINE") poly2.add_vertices(p2[0]) drawing.add(poly2) drawing.save()
def lens_holes(left_c, right_c, thickness): """Generates the toolpath for the lens holes (holes, groove and tabs).""" print 'Calculating the lens holes' tool_radius = 3.175 if not poly.is_ccw(left_c): left_c = poly.reverse(left_c) if not poly.is_ccw(right_c): right_c = poly.reverse(right_c) # drawing = dxf.drawing('test.dxf') # drawing.add_layer('OUTLINE', color=1) # polyline = dxf.polyline(layer="OUTLINE") # polyline.add_vertices(left_c) # drawing.add(polyline) lhole = poly.erode(tool_radius/2.0, left_c)[0] rhole = poly.erode(tool_radius/2.001, right_c); rhole = rhole[0] # polyline = dxf.polyline(layer="OUTLINE") # polyline.add_vertices(lhole) # drawing.add(polyline) right_rough = poly.erode((tool_radius + 0.3)/2, right_c)[0] left_rough = poly.erode((tool_radius+0.3)/2, left_c)[0] #lgroove = poly.erode(0.8, left_c)[0] #rgroove = poly.erode(0.8, right_c)[0] left_entry = poly.erode(5.0, left_c)[0][0]; right_entry = poly.erode(5.0, right_c)[0][0]; lhole = poly.reverse(lhole) rhole = poly.reverse(rhole) r = [ "(Lens Holes)", cam.change_tool("1/8in endmill"), cam.start_spindle(22000), cam.feedrate(2000), cam.rmh(right_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(right_rough, True), cam.feedrate(1000), cam.contour(rhole, True), cam.feedrate(2000), cam.rmh(left_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(left_rough, True), cam.feedrate(1000), cam.contour(lhole, True), ] return r
def lens_holes(left_c, right_c, thickness): """Generates the toolpath for the lens holes (holes, groove and tabs).""" if not poly.is_ccw(left_c): left_c = poly.reverse(left_c) if not poly.is_ccw(right_c): right_c = poly.reverse(right_c) lhole = poly.erode(3.175/2.0, left_c)[0] rhole = poly.erode(3.175/2.0, right_c)[0] right_rough = poly.erode(0.1, rhole)[0] left_rough = poly.erode(0.1, lhole)[0] lgroove = poly.erode(0.8, left_c)[0] rgroove = poly.erode(0.8, right_c)[0] left_entry = poly.erode(2.0, lhole)[0][0]; right_entry = poly.erode(2.0, rhole)[0][0]; lhole = poly.reverse(lhole) rhole = poly.reverse(rhole) r = [ "(Lens Holes)", cam.change_tool("1/8in endmill"), cam.start_spindle(20000), cam.feedrate(2000), cam.rmh(right_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(right_rough, True), cam.contour(rhole, True), cam.rmh(left_entry + [-thickness - 1.0], 1.5, 0.5, 1.0), cam.contour(left_rough, True), cam.contour(lhole, True), ] return r
def mill_hinges(outdir): """Creates the g-code for the first milling operation. The first milling operation is done on an unregistered plastic blank, so includes creating registration holes for subsequent operations.""" y_offsets = [y*15 for y in range(-5, 6)] x_offsets = [x*7 for x in range(-3, 4)] hinge = hinges.get_hinge(2); contour = hinge['face_contour'] contours = [] erode = poly.erode(1.5875/2, contour) while len(erode) > 0: if len(erode) >= 1: contours.append(erode[0]) else: break erode = poly.erode(1.5875/2, contours[-1]) program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.activate_pin("stock_clamp"), cam.change_tool("1/16in endmill"), cam.rapid([0,0]), cam.start_spindle(20000), cam.dwell(3), # cam.pocket(contours, -1, -1), # cam.rapid([None, None, 20.0]), # cam.change_tool("1mm drill"), # cam.start_spindle(4500), # [cam.rmp(p + [-2.5], retract=10.0) for p in hinge['face_holes']], ] for y_offset in y_offsets: for x_offset in x_offsets: program += [ cam.rapid([x_offset, y_offset]), cam.temporary_offset((0,0)), cam.pocket(contours, -1.2, -1.2), cam.rapid([None, None, 20.0]), cam.remove_temporary_offset(), ] # program += [ # cam.change_tool("1mm drill"), # cam.start_spindle(4500), # ] # for y_offset in y_offsets: # for x_offset in x_offsets: # program += [ # cam.rapid([x_offset, y_offset]), # cam.temporary_offset((0,0)), # [cam.rmp(p + [-2.5], retract=10.0) for p in hinge['face_holes']], # cam.rapid([None, None, 20.0]), # cam.remove_temporary_offset(), # ] program += [ cam.deactivate_pin("stock_clamp"), cam.end_program(), ] open(outdir + "/face_stage1.ngc", "w").write(to_string(program))
def face_hinge_pockets(hinge_num, hinge_height, temple_position, centering_shift, thin_back): print 'Generating face hinge pockets', hinge_num xposition = hinge_height; yposition = temple_position+3.0; # 4mm for the temple, but less 1mm for temple hinge pocket print 'Position is ', xposition, yposition left_hinge = hinges.get_hinge(hinge_num) print 'Got left hinge' right_hinge = hinges.get_hinge(hinge_num, False) print 'Retrieved hinge contours' left_translate = [xposition, yposition] right_translate = [xposition, -yposition] print 'Calculated hinge translations' #right_translate = [xposition, 0] # Adjust by pocket depth of hinge #pocket_depth = left_hinge['pocket_depth']+thin_back pocket_depth = 1 + thin_back drill_depth = -thin_back - 2.0 left_contour = poly.mirror_x(poly.rotate_90(left_hinge["face_contour"]), False) right_contour = poly.mirror_x(poly.rotate_90(right_hinge["face_contour"]), False) left_holes = poly.mirror_x(poly.rotate_90(left_hinge["face_holes"]), False) right_holes = poly.mirror_x(poly.rotate_90(right_hinge["face_holes"]), False) left_contour = poly.translate(left_contour, left_translate[0], -left_translate[1]) right_contour = poly.translate(right_contour, right_translate[0], -right_translate[1]) left_holes = poly.translate(left_holes, left_translate[0], -left_translate[1]) right_holes = poly.translate(right_holes, right_translate[0], -right_translate[1]) # Now center everything on the stock left_contour = poly.translate(left_contour, centering_shift[0], -centering_shift[1]) right_contour = poly.translate(right_contour, centering_shift[0], -centering_shift[1]) left_holes = poly.translate(left_holes, centering_shift[0], -centering_shift[1]) right_holes = poly.translate(right_holes, centering_shift[0], -centering_shift[1]) if not poly.is_ccw(left_contour): left_contour = poly.reverse(left_contour) if not poly.is_ccw(right_contour): right_contour = poly.reverse(right_contour) left_hinge_pocket_contours = []; while len(left_contour) > 0: left_contour = poly.erode(1.5875/2, left_contour) if len(left_contour) > 0: left_contour = left_contour[0] left_hinge_pocket_contours.append(left_contour) right_hinge_pocket_contours = []; while len(right_contour) > 0: right_contour = poly.erode(1.5875/2, right_contour) if len(right_contour) > 0: right_contour = right_contour[0] right_hinge_pocket_contours.append(right_contour) r = [ cam.comment("Hinge Pockets"), cam.feedrate(750), cam.change_tool("1/16in endmill"), cam.start_spindle(20000), cam.dwell(3), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(pocket_depth), retract=-abs(pocket_depth)), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(pocket_depth), retract=-abs(pocket_depth)), cam.rapid([None, None, 20.0]), cam.comment("Hinge Holes"), cam.change_tool("1mm drill"), cam.start_spindle(5000), cam.dwell(2), [cam.rmp(p + [drill_depth], retract=10.0) for p in right_holes], [cam.rmp(p + [drill_depth], retract=10.0) for p in left_holes], cam.rapid([None, None, 20.0]), ] return r
def face_hinge_pockets(hinge_num, xposition, yposition): left_hinge = hinges.get_hinge(hinge_num) right_hinge = hinges.get_hinge(hinge_num, False) left_translate = [xposition, -yposition] #left_translate = [xposition, 0] right_translate = [xposition, yposition] #right_translate = [xposition, 0] # Adjust by pocket depth of hinge pocket_depth = left_hinge['pocket_depth'] left_contour = poly.translate(left_hinge["face_contour"], left_translate[0], left_translate[1]) right_contour = poly.translate(right_hinge["face_contour"], right_translate[0], right_translate[1]) left_holes = poly.translate(left_hinge["face_holes"], left_translate[0], left_translate[1]) right_holes = poly.translate(right_hinge["face_holes"], right_translate[0], right_translate[1]) if not poly.is_ccw(left_contour): left_contour = poly.reverse(left_contour) if not poly.is_ccw(right_contour): right_contour = poly.reverse(right_contour) left_hinge_pocket_contours = [] while len(left_contour) > 0: left_contour = poly.erode(1.5875 / 2, left_contour) if len(left_contour) > 0: left_contour = left_contour[0] left_hinge_pocket_contours.append(left_contour) right_hinge_pocket_contours = [] while len(right_contour) > 0: right_contour = poly.erode(1.5875 / 2, right_contour) if len(right_contour) > 0: right_contour = right_contour[0] right_hinge_pocket_contours.append(right_contour) r = [ cam.comment("Hinge Pockets"), cam.feedrate(750), cam.change_tool("1/16in endmill"), cam.start_spindle(15000), cam.dwell(3), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(right_hinge['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(left_hinge['pocket_depth']), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Hinge Holes"), cam.change_tool("1mm drill"), cam.start_spindle(4500), cam.dwell(2), [cam.rmp(p + [-8.0], retract=10.0) for p in right_holes], [cam.rmp(p + [-8.0], retract=10.0) for p in left_holes], cam.rapid([None, None, 20.0]), ] return r