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 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 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 index_holes(contours, thickness): # We put the index holes 1/2 between top and bottom, 160mm apart # log(str(poly.right(face_c))) # log(str(poly.left(face_c))) # log(str(poly.right(face_c) - poly.left(face_c))) # log(str((poly.right(face_c) - poly.left(face_c))/2)) # log(str(poly.right(face_c) - (poly.right(face_c) - poly.left(face_c))/2)) rightmost = -1000000 leftmost = 1000000 for contour in contours: right = poly.right(contour) left = poly.left(contour) rightmost = max(right, rightmost) leftmost = min(left, leftmost) # x_offset = poly.right(face_c) - (poly.right(face_c) - poly.left(face_c))/2 x_offset = rightmost - (rightmost - leftmost) / 2 hole_radius = 4.85 / 2 # Measured from dowel pin tool_radius = 3.175 / 2 helix_radius = hole_radius - tool_radius r_hole = [x_offset, 90] l_hole = [x_offset, -90] r = [ cam.comment("Index Holes for secondary operations"), cam.change_tool("1/8in endmill"), cam.start_spindle(15000), cam.feedrate(1000), cam.dwell(3), cam.rmh(r_hole + [-thickness - 1.0], helix_radius, 0.5, 1), cam.rmh(l_hole + [-thickness - 1.0], helix_radius, 0.5, 1), ] return r
def index_holes(contours, thickness): # We put the index holes 1/2 between top and bottom, 160mm apart # log(str(poly.right(face_c))) # log(str(poly.left(face_c))) # log(str(poly.right(face_c) - poly.left(face_c))) # log(str((poly.right(face_c) - poly.left(face_c))/2)) # log(str(poly.right(face_c) - (poly.right(face_c) - poly.left(face_c))/2)) rightmost = -1000000 leftmost = 1000000 for contour in contours: right = poly.right(contour) left = poly.left(contour) rightmost = max(right, rightmost) leftmost = min(left, leftmost) # x_offset = poly.right(face_c) - (poly.right(face_c) - poly.left(face_c))/2 x_offset = rightmost - (rightmost - leftmost)/2 hole_radius = 4.85/2 # Measured from dowel pin tool_radius = 3.175/2 helix_radius = hole_radius - tool_radius r_hole = [x_offset, 90] l_hole = [x_offset, -90] r = [ cam.comment("Index Holes for secondary operations"), cam.change_tool("1/8in endmill"), cam.start_spindle(15000), cam.feedrate(1000), cam.dwell(3), cam.rmh(r_hole + [-thickness - 1.0], helix_radius, 0.5, 1), cam.rmh(l_hole + [-thickness - 1.0], helix_radius, 0.5, 1), ] return r
def bevel_entry_hole(temples, thickness): hole_radius = 8 tool_radius = 3.175/2 # 1/2 inch helix_radius = hole_radius - tool_radius r = [ cam.comment("Entry holes for temple bevelling operation"), cam.change_tool("1/8in endmill"), cam.start_spindle(22000), cam.feedrate(800), cam.dwell(5), ]
def surface_back(amount): if amount < 0.1: return None print 'surfacing back with', amount surface_amount = min(amount, 4) surface_heights = [] while surface_amount <= amount: surface_heights.append(surface_amount); print surface_heights surface_amount = max(surface_amount+2, amount) print "surface amounts on back", surface_heights return [ cam.comment("Surface back by %f mm" % amount), cam.change_tool("3/8in endmill"), cam.spindle_speed(15000), cam.feedrate(1500), cam.start_spindle(), cam.dwell(5), cam.surface_along_y(-40, -110, 40, 110, 4.7625, -amount), cam.rapid([None, None, 20]), ] if amount > 0 else None program = [ cam.comment("Surface back by %f mm" % amount), cam.change_tool("3/8in endmill"), cam.spindle_speed(20000), cam.feedrate(2000), cam.start_spindle(), cam.dwell(5), ] for height in surface_heights: program = program + cam.surface_along_y(-40, -110, 40, 110, 4.7625, -height), program = program + [ cam.stop_spindle(), cam.retract_spindle(), ] return program
def index_holes(thickness): # We put the index holes 1/2 between top and bottom, 160mm apart hole_radius = 4.85/2 # Measured from dowel pin tool_radius = 3.175/2 helix_radius = hole_radius - tool_radius r = [ cam.comment("Index holes for secondary operations"), cam.change_tool("1/8in endmill"), cam.start_spindle(22000), cam.feedrate(1000), cam.dwell(5), # Index holes should be at 90, -90 but are shifted a bit to compensate # for inaccuracy on laser fixture cam.rmh([0, 85.00, -thickness - 1.0], helix_radius, 0.5, 1), cam.rmh([0, -85.00, -thickness - 1.0], helix_radius, 0.5, 1), ] 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 temple_hinge_pockets(temples, thinned): # 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"]) print 'Generating temple hinge pockets' 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) #pocket_depth = temples['pocket_depth'] + thinned pocket_depth = 1 + thinned; 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 left_hinge_pocket_contours = pocket_contours(l_hinge) right_hinge_pocket_contours = pocket_contours(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(rhinge_) == 1: # right_hinge_pocket # 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(22000), cam.dwell(5), cam.comment("Right Hinge Pocket"), cam.pocket(right_hinge_pocket_contours, -abs(pocket_depth), retract=0), cam.rapid([None, None, 20.0]), cam.comment("Left Hinge Pocket"), cam.pocket(left_hinge_pocket_contours, -abs(pocket_depth), retract=0), 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 + [-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]), ] return r
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