def mill_temples(outdir, temples, order): #TODO: Replace with information in materials database print 'Creating milling program for temples' top_thickness = 4 # Assume 4mm temple top_raw = 4 if order.get("temple_material"): top_raw = order["temple_material"].get("top_raw_thickness") or order["temple_material"].get("top_thickness") or top_thickness print 'top raw', top_raw # Automatically determine some surfacing. The bottom thickness # is a lamination and should be thin. It should be thinned to 1mm. # The top should be thinned to bring total finished thickness to 6mm or less. thin_back = 0 if top_raw > top_thickness: thin_back = top_raw - top_thickness l_temple = temples['left_temple_contour'] r_temple = temples['right_temple_contour'] offset = frame_offset(l_temple) # Calculate entry points for bevelling operation program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.rapid([0,0]), cam.activate_pin("stock_clamp"), surface_back(thin_back), index_holes(top_raw), # cam.rapid(l_temple[0]+[0]), # cam.contour(l_temple, True), # cam.move(l_temple[0]), # cam.rapid(r_temple[0]), # cam.contour(r_temple, True), rough_temple_bevel(l_temple, thin_back), rough_temple_bevel(r_temple, thin_back), cam.change_tool("1/16in endmill"), cam.rapid([0,0]), temple_hinge_pockets(temples, thin_back), cam.change_tool("dovetail"), bevel_temple(l_temple, thin_back), bevel_temple(r_temple, thin_back), temple_hinge_clearance(l_temple, thin_back), temple_hinge_clearance(r_temple, thin_back), cam.retract_spindle(), cam.deactivate_pin("stock_clamp"), cam.change_tool("1/8in endmill"), cam.end_program() ] open(outdir + "/temples_milling.ngc", "w").write(to_string(program))
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 rough_temple_bevel(temple, thinning): p1 = extendLine(temple[-1], temple[-2], 3.175/2 - 0.5) p2 = extendLine(temple[0], temple[1], 3.175/2 - 0.5) p3 = extendLine(temple[0], temple[1], 15) p4 = extendLine(temple[-1], temple[-2], 15) # room for dovetail # p1 and p2 are just extensions of the temple - move them to the side a bit to # clearance for when the dovetail cutter comes through p1 = extendLine(p1, p2, 3) p2 = extendLine(p2, p1, 3) p3 = extendLine(p3, p4, 3) p4 = extendLine(p4, p3, 3) # Move to the dovetail cutter entry point, helix through stock. # Cut a circle big enough to admit the dovetail cutter. # Rough cut the end of the temple # Clear a return path for the dovetail cutter. return [ cam.change_tool("1/8in endmill"), cam.feedrate(1000), cam.rmh(p4 + [-5-thinning], 1, pitch=1), cam.move(p1), cam.move(p2), cam.move(p3), cam.move(p4), cam.rapid(p4 + [10]) ]
def mill_temples(outdir, temples, temple_length): #TODO: Replace with information in materials database front_surface_thickness = 0 back_surface_thickness = 4 final_front_thickness = 0 final_back_thickness = 4 thickness = final_front_thickness + final_back_thickness front_surface_removal = final_front_thickness - front_surface_thickness back_surface_removal = final_back_thickness - back_surface_thickness r_temple = poly.rotate_90(temples['right_temple_contour']) l_temple = poly.rotate_90(temples['left_temple_contour']) offset = frame_offset(l_temple) program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.activate_pin("stock_clamp"), surface_front(front_surface_removal), surface_back(back_surface_removal), cam.change_tool("1/16in endmill"), cam.rapid([0,0]), cam.temporary_offset(offset), temple_hinge_pockets(temples), index_holes([l_temple, r_temple], thickness), #thin_temples([l_temple, r_temple], temple_length), ] open(outdir + "/temples_milling.ngc", "w").write(to_string(program))
def bevel_temple_ends(path1, path2, thinning): depth = -4 - thinning # Assume a 14 degree dovetail cutter, cutting 5mm from bottom dovetail_offset = 12.35/2 - 1.25 return [ cam.comment("Bevel temple ends"), cam.change_tool("dovetail"), cam.start_spindle(20000), cam.feedrate(750), cam.rapid(path1[0]), cam.rapid([None, None, depth]), cam.move(path1[1]), cam.move(path1[2]), cam.move(path1[0]), cam.rapid([None, None, 10]), cam.rapid(path2[0]), cam.rapid([None, None, depth]), cam.move(path2[1]), cam.move(path2[2]), cam.move(path2[0]), cam.move([None, None, 20]) ]
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 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 mill_fronts(outdir, order): """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.""" # Initial thickness of the forward-facing lamination. 0 if no lamination. top_thickness = 6 bottom_thickness = 0 top_raw = 6 bottom_raw = 0 if order.get("face_material"): top_thickness = order["face_material"].get("top_thickness") bottom_thickness = order["face_material"].get("bottom_thickness") or 0 top_raw = order["face_material"].get("top_raw_thickness") or top_thickness bottom_raw = order["face_material"].get("bottom_raw_thickness") or bottom_thickness frame_thickness = top_thickness + bottom_thickness machining_z_offset = bottom_raw - bottom_thickness # top_thickness = 6 # bottom_thickness = 0 # total_thickness = 6 # top_raw = 0 # Automatically determine some surfacing. The bottom thickness # is a lamination and should be thin. It should be thinned to 1mm. # The top should be thinned to bring total finished thickness to 6mm or less. thin_back = 0 if bottom_raw > bottom_thickness: thin_back = bottom_raw - bottom_thickness thin_front = 0 if top_raw > top_thickness: thin_front = top_raw - top_thickness # The machine has the stock clamp oriented 90 degrees to the way the # software creates the contours. face_c = poly.rotate_90(order["face_con"]) left_lens_c = poly.rotate_90(order["lhole_con"]) right_lens_c = poly.mirror_y(left_lens_c, True) face_c = face_c + poly.reverse(poly.mirror_y(face_c, False))[1:] temple_height = abs(order["ltemple_con"][0][1] - order["ltemple_con"][-1][1]) msg = check_frame_size(left_lens_c) if msg: print msg sys.exit(1) # Instead of offset, we'll make sure this thing is centered on the stock offset = frame_offset(face_c) top = poly.top(face_c) bottom = poly.bottom(face_c) left = poly.left(face_c) right = poly.right(face_c) print 'frame bounding box: ', top, bottom, left, right y_shift = (top + bottom)/2 x_shift = (left + right)/2 print 'x and y shift', x_shift, y_shift face_c = poly.translate(face_c, -x_shift, -y_shift) left_lens_c = poly.translate(left_lens_c, -x_shift, -y_shift) right_lens_c = poly.translate(right_lens_c, -x_shift, -y_shift) # Groove for lenses is 2/3 of the distance from back to front. # Here we're calculating the actual cutting depth so we need to add # back the material that we surfaced away from the back. groove_depth = -(float(machining_z_offset) + (2.0/3)*float(frame_thickness)) hinge_loc = order["ltemple_con"][0][1] - (order["ltemple_con"][0][1] - order["ltemple_con"][-1][1])/2 size_info = order.get('size_info') if not size_info and order.get('usersizes'): # Legacy order size_info = order.get('usersizes') size_info["noseradius"] = size_info["nose_radius"] size_info["noseheight"] = size_info["nose_height"] size_info["splayangle"] = size_info["nose_splayangle"] size_info["ridgeangle"] = size_info["nose_ridgeangle"] generic = not size_info or len(size_info) == 0 generic = True # TESTING program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.activate_pin("stock_clamp"), cam.rapid([0,0]), surface_front(thin_front), surface_back(thin_back), cam.change_tool("1/8in endmill"), cam.rapid([0, 0]), # Note that X and Y parameters in the order are switched from our system #TODO: replace the thickness offset with the thickness of the TEMPLE, not the fronts. index_holes(frame_thickness+machining_z_offset), lens_holes(left_lens_c, right_lens_c, frame_thickness + machining_z_offset), lens_groove(left_lens_c, right_lens_c, groove_depth), # rough_nose_contour( # float(size_info["noseradius"]), # float(size_info["noseheight"]), # float(size_info["splayangle"]), # float(size_info["ridgeangle"]), # face_c, frame_thickness, machining_z_offset, -x_shift ), face_hinge_pockets(order.get("lhinge") or 1, hinge_loc, order["ltemple_x"], (-x_shift, -y_shift), machining_z_offset), #nose_pads(order, thickness), nose_contour( float(size_info["noseradius"]), float(size_info["noseheight"]), float(size_info["splayangle"]), float(size_info["ridgeangle"]), face_c, frame_thickness, machining_z_offset, -x_shift ), # nose_contour( # 7.0, 8.0, 30.0, 32.0, face_c, frame_thickness, machining_z_offset, -x_shift), #generic_nose_contour(face_c, frame_thickness, machining_z_offset, -x_shift), cam.retract_spindle(), cam.deactivate_pin("stock_clamp"), cam.change_tool("1/8in endmill"), # cam.rapid([face_c[0][0], face_c[0][1], -thin_back] ), # cam.contour(face_c, True), cam.end_program(), ] print 'Writing face milling program to ', outdir + "/face_stange1.ngc" open(outdir + "/face_stage1.ngc", "w").write(to_string(program))
def mill_lenses(outdir, order): def to_polar(polyline): return [[-math.sqrt(p[0]**2 + p[1]**2), math.degrees(math.atan2(p[1],p[0])) + 180] for p in polyline] """ Creates g-code for milling the left and right lenses for the frames.""" lens = g.Polygon(order['lhole_con']) x = lens.bounding_box() box = lens.bounding_box() center = g.Point((box.p2.x+box.p1.x)/2, (box.p2.y+box.p1.y)/2) shift_to_origin = g.Vector(-center.x, -center.y) lens = g.translate_polygon(lens, shift_to_origin) polar = g.polygon_to_uniform_polar(lens, 1500) # Inflate the polar form by 1/2 the diameter of the cutter, and convert # the angles to degrees tau = math.pi * 2 conv = 360/tau roughing = [(pt.theta*conv, pt.r+4.77) for pt in polar] # Expand for the roughing cut # left_lens_rough = poly.dilate(4.77, left_lens) # Convert to polar coordinates # left_lens_roughing_polar = to_polar(left_lens_rough) # Start the cut from 0 degrees # angle_list = [p[1] for p in left_lens_roughing_polar] # zero_idx = angle_list.index(min(angle_list)) # left_lens_roughing_polar = left_lens_roughing_polar[zero_idx:] + left_lens_roughing_polar[:zero_idx] # Cut it down to every 0.2 degrees # coarse = [] # for idx, pt in enumerate(left_lens_roughing_polar): # if idx == 0 or (pt[1]-coarse[-1][1]) >= 0.2: # coarse.append(pt) # The polar distances aren't correct quite. That's because the conversion assumed a flat # surface, but we'll actually be bending that contour around a sphere. The lens is already # spherical. So we need to adjust inwards a bit to account for the x distance actually being an arc # distance. # The radius of the sphere is 88mm (base 6 lens). ArcLength = Radius * angle, and chord # length is sin(angle) * radius. roughing = [(p[0], math.sin(-p[1]/88) * 88) for p in roughing] roughing.sort(key=lambda pt: pt[0]) closest = max([p[1] for p in roughing]) if abs(closest) < 22.5: print "Error! Cannot cut lens, it's too small.", closest roughing_reversed = [[-1*(math.degrees(-math.radians(p[1]))+360), p[1]] for p in roughing] program = [ cam.setup(), cam.select_fixture("lens_clamp"), cam.retract_spindle(), cam.change_tool("1/4in endmill"), cam.start_spindle(20000), cam.rapid([-50, 0]), ["G1 Z0 F500"], cam.polar_contour(roughing), ["G1 X-50"], ["G1 A0"], cam.stop_spindle(), cam.retract_spindle(), cam.end_program(), ] open(outdir + "/left_lens.ngc", "w").write(to_string(program)) program = [ cam.setup(), cam.select_fixture("lens_clamp"), cam.retract_spindle(), cam.change_tool("1/4in endmill"), cam.start_spindle(20000), cam.rapid([-50, 0]), ["G1 Z0 F500"], cam.polar_contour(roughing_reversed), ["G1 X-50"], ["G1 A0"], cam.stop_spindle(), cam.retract_spindle(), cam.end_program(), ] open(outdir + "/right_lens.ngc", "w").write(to_string(program))
def mill_fronts(outdir, order): """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.""" #TODO: Replace with information in materials database # Initial thickness of the forward-facing lamination. 0 if no lamination. front_surface_thickness = 0 # The final desired thickness of the fronto facing lamination. Must # be equal to or less than the front_surface_thickness. final_front_thickness = 0 # Initial thickness of the face side lamination. Use this thickness only if # stock is solid back_surface_thickness = 4 # The final thickness of the left and right extremes of the frame where the # hinge will go. Must be equal to or less than back_surface_thickness. hinge_thickness = 4 # The thickness of the highest point of the nosepad nosepad_thickness = 4 # Final thickness of the main part of the frame. Must be equal to or less than # the back_surface_thickness. final_back_thickness = 4 thickness = final_front_thickness + final_back_thickness front_surface_removal = final_front_thickness - front_surface_thickness back_surface_removal = final_back_thickness - back_surface_thickness # The machine has the stock clamp oriented 90 degrees to the way the # software creates the contours. face_c = poly.rotate_90(order["face_con"]) left_lens_c = poly.rotate_90(order["lhole_con"]) right_lens_c = poly.rotate_90(order["rhole_con"]) temple_height = abs(order["ltemple_con"][0][1] - order["ltemple_con"][-1][1]) msg = check_frame_size(face_c) if msg: print msg sys.exit(0) print 'milling front with hinge', order['lhinge'], order['rhinge'] offset = frame_offset(face_c) groove_height = back_surface_removal + (thickness / 2) print 'groove', groove_height, back_surface_removal, (thickness / 2) program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.activate_pin("stock_clamp"), surface_front(front_surface_removal), # surface_back(back_surface_removal), cam.change_tool("1/8in endmill"), cam.rapid([0, 0]), cam.temporary_offset(offset), # Note that X and Y parameters in the order are switched from our system #TODO: replace the thickness offset with the thickness of the TEMPLE, not the fronts. index_holes([face_c], back_surface_thickness), lens_holes(left_lens_c, right_lens_c, back_surface_thickness), lens_groove(left_lens_c, right_lens_c, back_surface_removal - (thickness / 2)), # contour_face( # back_surface_removal, # back_surface_thickness - hinge_thickness, # back_surface_thickness - nosepad_thickness, # temple_height, # face_c, left_lens_c, order['lhinge_y']), face_hinge_pockets(order["lhinge"], order["lhinge_y"], order["ltemple_x"]), # nose_pads(order, thickness), nose_contour(order["nose_rad"], order["nose_h"], order["nose_sa"], order["nose_ra"], face_c, back_surface_thickness), cam.retract_spindle(), cam.deactivate_pin("stock_clamp"), cam.end_program(), ] open(outdir + "/face_stage1.ngc", "w").write(to_string(program))
def mill_fronts(outdir, order): """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.""" #TODO: Replace with information in materials database # Initial thickness of the forward-facing lamination. 0 if no lamination. front_surface_thickness = 0 # The final desired thickness of the fronto facing lamination. Must # be equal to or less than the front_surface_thickness. final_front_thickness = 0 # Initial thickness of the face side lamination. Use this thickness only if # stock is solid back_surface_thickness = 4 # The final thickness of the left and right extremes of the frame where the # hinge will go. Must be equal to or less than back_surface_thickness. hinge_thickness = 4 # The thickness of the highest point of the nosepad nosepad_thickness = 4 # Final thickness of the main part of the frame. Must be equal to or less than # the back_surface_thickness. final_back_thickness =4 thickness = final_front_thickness + final_back_thickness front_surface_removal = final_front_thickness - front_surface_thickness back_surface_removal = final_back_thickness - back_surface_thickness # The machine has the stock clamp oriented 90 degrees to the way the # software creates the contours. face_c = poly.rotate_90(order["face_con"]) left_lens_c = poly.rotate_90(order["lhole_con"]) right_lens_c = poly.rotate_90(order["rhole_con"]) temple_height = abs(order["ltemple_con"][0][1] - order["ltemple_con"][-1][1]) msg = check_frame_size(face_c) if msg: print msg sys.exit(0) print 'milling front with hinge', order['lhinge'], order['rhinge'] offset = frame_offset(face_c) groove_height = back_surface_removal + (thickness/2) print 'groove', groove_height, back_surface_removal, (thickness/2) program = [ cam.setup(), cam.select_fixture("blank_clamp"), cam.retract_spindle(), cam.activate_pin("stock_clamp"), surface_front(front_surface_removal), # surface_back(back_surface_removal), cam.change_tool("1/8in endmill"), cam.rapid([0, 0]), cam.temporary_offset(offset), # Note that X and Y parameters in the order are switched from our system #TODO: replace the thickness offset with the thickness of the TEMPLE, not the fronts. index_holes([face_c], back_surface_thickness), lens_holes(left_lens_c, right_lens_c, back_surface_thickness), lens_groove(left_lens_c, right_lens_c, back_surface_removal - (thickness/2)), # contour_face( # back_surface_removal, # back_surface_thickness - hinge_thickness, # back_surface_thickness - nosepad_thickness, # temple_height, # face_c, left_lens_c, order['lhinge_y']), face_hinge_pockets(order["lhinge"], order["lhinge_y"], order["ltemple_x"]), # nose_pads(order, thickness), nose_contour(order["nose_rad"], order["nose_h"], order["nose_sa"], order["nose_ra"], face_c, back_surface_thickness), cam.retract_spindle(), cam.deactivate_pin("stock_clamp"), cam.end_program(), ] open(outdir + "/face_stage1.ngc", "w").write(to_string(program))