def surface_front(amount): if amount < 0.1: print 'Not surfacing front, returning' return None print "Surfacing front with amount", amount surface_amount = min(amount, 4) surface_heights = [] while surface_amount <= amount: surface_heights.append(surface_amount) surface_amount = max(surface_amount+2, amount) print "surface amounts", surface_heights program = [ cam.comment("Surface front by %f mm" % amount), cam.flip_stock(), cam.change_tool("3/8in endmill"), cam.spindle_speed(20000), cam.feedrate(2000), cam.start_spindle(),] 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(), cam.flip_stock(), ] return program
def surface_back(amount): return [ cam.change_tool("1/4in endmill"), cam.spindle_speed("20000"), cam.start_spindle(), cam.surface_along_y(-80, -100, -5, 100, 0.25 / 2, amount), cam.stop_spindle(), cam.retract_spindle(), cam.dactivate_pin("stock_clamp"), ] if amount > 0 else None
def surface_back(amount): return [ cam.change_tool("1/4in endmill"), cam.spindle_speed("20000"), cam.start_spindle(), cam.surface_along_y(-80, -100, -5, 100, 0.25/2, amount), cam.stop_spindle(), cam.retract_spindle(), cam.dactivate_pin("stock_clamp"), ] if amount > 0 else None
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 surface_front(amount): log("Surfacing front with amount %f" % amount) return [ cam.flip_stock(), cam.change_tool("1/4in endmill"), cam.spindle_speed(20000), cam.feedrate(2000), cam.start_spindle(), cam.surface_along_y(-80, -100, -5, 100, 3.175, amount), cam.stop_spindle(), cam.retract_spindle(), cam.flip_stock(), ] if amount < 0 else None
def contour_face(body_removal, hinge_removal, nosepad_removal, temple_height, face_c, lens_c, x_pos): ''' Create the heightmap of the frame, surfacing the back and adding thickness for the hinge location and the nosepads. ''' if body_removal == hinge_removal == nosepad_removal == 0: return [] # Nothing to do cutter_radius = 6.35 / 2 # 3/4 inch cutter entry_point = [x_pos, 110, 0] facing_contour = poly.dilate(0.05, lens_c) # Reshape the facing contour so the first point is near the hinge center_y = poly.bottom(facing_contour) + (poly.top(facing_contour) - poly.bottom(facing_contour)) / 2 center_x = poly.right(facing_contour) + (poly.left(facing_contour) - poly.right(facing_contour)) / 2 split_idx = -1 for idx, pt in enumerate(facing_contour): if pt[1] > center_y and (idx + 1) < len(facing_contour): if (pt[0] < x_pos and facing_contour[idx + 1][0] > x_pos) or ( pt[0] > x_pos and facing_contour[idx + 1][0] < x_pos): split_idx = idx break if split_idx < 0: print 'Error contouring back of frame: could not locate entry point for surfacing cut' return [] facing_contour = poly.new_start(facing_contour, split_idx) # Ensure we're going clockwise, i.e. starting at the hinge and moving up over the frame if poly.is_ccw(facing_contour): facing_contour = poly.reverse(facing_contour) # Calculate the Z values # We'll need a few helper values. nosepad_start is the inflection point of the nose bridge. nosepad_start = max([pt[0] for pt in face_c if pt[1] == 0]) + cutter_radius hinge_rampdown_start_x = x_pos + temple_height / 2 + cutter_radius hinge_rampdown_start_y = facing_contour[0][1] - cutter_radius hinge_rampup_start_x = x_pos - temple_height / 2 - cutter_radius hinge_rampup_start_y = facing_contour[0][1] - cutter_radius print nosepad_start, hinge_rampdown_start_x, hinge_rampdown_start_y, hinge_rampup_start_x, hinge_rampup_start_y ''' Arbitrary heuristic, adjusted for aesthetics. 1. If we're past the center point of the lens hole, we're either on the body of the frame or over the raised hinge point. 2. If we're before the center point we're either on the body or over the nosepiece. 1a. If we're above the cutter-radius-adjusted top of the temple, we're ramping down 1b. If we're below the cutter-radius-adjusted bottom of the temple, we're ramping up 1c. Otherwise we're at body thickness 2a. If we're above the top of the nose cutout, we're at body thickness 2b. When we reach nose cutout, we do a s-curve over 3 mm to nosepad height 2c. Continue for length of cutter diameter to get rear of cutter over highest point 2d. Continue for 10mm 2e. S-curve down over 10mm ''' print hinge_removal, body_removal def add_hinge_heights(contour): heightmap = [] over_hinge = True # Start over hinge items_to_skip = 0 # for fast-forwarding enumeration for idx, pt in enumerate(contour): if items_to_skip > 0: items_to_skip = items_to_skip - 1 if items_to_skip == 0: print 'first post ramp point', contour[idx + 1] continue if pt[1] < center_y: heightmap = heightmap + [pt] # Going up and around: start ramping down when we're clear of X or Y elif pt[0] > x_pos: if pt[0] > hinge_rampdown_start_x or pt[ 1] < hinge_rampdown_start_y: if (over_hinge): # starting transition transition_length = poly.polyline_length( contour[:(idx + 1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length + 5, False) ramp_segment = poly.ramp(ramp_segment, hinge_removal, body_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) print 'last ramp segment', ramp_segment[-1] over_hinge = False else: # past transition but still on hinge side of lens hole heightmap = heightmap + [pt + [body_removal]] else: # We're on the top part but haven't reached the transition yet heightmap = heightmap + [pt + [hinge_removal]] # Coming back up to the hinge: start ramping up if we encroach on both x and y elif pt[0] < x_pos and (pt[0] > hinge_rampup_start_x and pt[1] > hinge_rampdown_start_y): if (not over_hinge): # starting transition print pt, x_pos, hinge_rampup_start_x, hinge_rampdown_start_y, idx transition_length = poly.polyline_length( contour[:(idx + 1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length + 5, False) ramp_segment = poly.ramp(ramp_segment, body_removal, hinge_removal, False) heightmap = heightmap + ramp_segment items_to_skip = len(ramp_segment) over_hinge = True else: # Over flat hinge area heightmap = heightmap + [pt + [hinge_removal]] else: # We're over the body area but back on the hinge side heightmap = heightmap + [pt + [body_removal]] return heightmap def add_nosepad_heights(contour): heightmap = [] over_nosepad = False past_nosepad = False nosepad_flat_idx = -1 items_to_skip = 0 # for fast-forwarding the enumeration for idx, pt in enumerate(contour): if items_to_skip > 0: items_to_skip = items_to_skip - 1 continue if pt[1] >= center_y: heightmap = heightmap + [pt] elif not over_nosepad and not past_nosepad: if pt[0] < nosepad_start: # Transition transition_length = poly.polyline_length( contour[:(idx + 1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length + 5, False) ramp_segment = poly.ramp(ramp_segment, body_removal, nosepad_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) nosepad_flat_idx = idx + items_to_skip # we'll need this to go down over_nosepad = True else: # we're past the nosepad heightmap = heightmap + [pt + [body_removal]] elif over_nosepad and not past_nosepad: if nosepad_flat_idx < 0: print "ERROR! I think I'm on the nosepad but have not transitioned yet" return [] # We'll be cutting the far side with the back of the cutter, so need to move at # least the diameter to get any flat at all flat_length = poly.polyline_length( contour[nosepad_flat_idx:(idx + 1)], False) - (cutter_radius * 2) if flat_length < 5: heightmap = heightmap + [pt + [nosepad_removal]] else: # ramp down transition_length = poly.polyline_length( contour[:(idx + 1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length + 5, False) ramp_segment = poly.ramp(ramp_segment, nosepad_removal, body_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) nosepad_flat_idx = idx + items_to_skip # we'll need this to go down over_nosepad = False past_nosepad = True else: heightmap = heightmap + [pt + [body_removal]] return heightmap facing_contour = add_hinge_heights(facing_contour) facing_contour = add_nosepad_heights(facing_contour) facing_contour = poly.reverse(facing_contour) right_facing = poly.mirror_y(facing_contour, True) passes = [1] heights = [p[2] for p in facing_contour] r = [ cam.change_tool("1/4in ballmill"), cam.spindle_speed(22000), cam.feedrate(1000), cam.start_spindle(), cam.rmp(entry_point), cam.contour(facing_contour, True), ] for dilate in passes: dilated = poly.reverse(poly.dilate(dilate, facing_contour)) # dilated = add_hinge_heights(dilated) dilated = add_nosepad_heights(dilated) r = r + [ cam.contour(dilated, True), ] return r
def contour_face(body_removal, hinge_removal, nosepad_removal, temple_height, face_c, lens_c, x_pos): ''' Create the heightmap of the frame, surfacing the back and adding thickness for the hinge location and the nosepads. ''' if body_removal == hinge_removal == nosepad_removal == 0: return [] # Nothing to do cutter_radius = 6.35/2 # 3/4 inch cutter entry_point = [x_pos, 110, 0] facing_contour = poly.dilate(0.05, lens_c) # Reshape the facing contour so the first point is near the hinge center_y = poly.bottom(facing_contour) + (poly.top(facing_contour) - poly.bottom(facing_contour))/2 center_x = poly.right(facing_contour) + (poly.left(facing_contour) - poly.right(facing_contour))/2 split_idx = -1 for idx, pt in enumerate(facing_contour): if pt[1] > center_y and (idx+1) < len(facing_contour): if (pt[0] < x_pos and facing_contour[idx+1][0] > x_pos) or (pt[0] > x_pos and facing_contour[idx+1][0] < x_pos): split_idx = idx break if split_idx < 0: print 'Error contouring back of frame: could not locate entry point for surfacing cut' return [] facing_contour = poly.new_start(facing_contour, split_idx) # Ensure we're going clockwise, i.e. starting at the hinge and moving up over the frame if poly.is_ccw(facing_contour): facing_contour = poly.reverse(facing_contour) # Calculate the Z values # We'll need a few helper values. nosepad_start is the inflection point of the nose bridge. nosepad_start = max([pt[0] for pt in face_c if pt[1] == 0]) + cutter_radius hinge_rampdown_start_x = x_pos + temple_height/2 + cutter_radius hinge_rampdown_start_y = facing_contour[0][1] - cutter_radius hinge_rampup_start_x = x_pos - temple_height/2 - cutter_radius hinge_rampup_start_y = facing_contour[0][1] - cutter_radius print nosepad_start, hinge_rampdown_start_x, hinge_rampdown_start_y, hinge_rampup_start_x, hinge_rampup_start_y ''' Arbitrary heuristic, adjusted for aesthetics. 1. If we're past the center point of the lens hole, we're either on the body of the frame or over the raised hinge point. 2. If we're before the center point we're either on the body or over the nosepiece. 1a. If we're above the cutter-radius-adjusted top of the temple, we're ramping down 1b. If we're below the cutter-radius-adjusted bottom of the temple, we're ramping up 1c. Otherwise we're at body thickness 2a. If we're above the top of the nose cutout, we're at body thickness 2b. When we reach nose cutout, we do a s-curve over 3 mm to nosepad height 2c. Continue for length of cutter diameter to get rear of cutter over highest point 2d. Continue for 10mm 2e. S-curve down over 10mm ''' print hinge_removal, body_removal def add_hinge_heights(contour): heightmap = [] over_hinge = True # Start over hinge items_to_skip = 0 # for fast-forwarding enumeration for idx, pt in enumerate(contour): if items_to_skip > 0: items_to_skip = items_to_skip - 1 if items_to_skip == 0: print 'first post ramp point', contour[idx+1] continue if pt[1] < center_y: heightmap = heightmap + [pt] # Going up and around: start ramping down when we're clear of X or Y elif pt[0] > x_pos: if pt[0] > hinge_rampdown_start_x or pt[1] < hinge_rampdown_start_y: if(over_hinge): # starting transition transition_length = poly.polyline_length(contour[:(idx+1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length+5, False) ramp_segment = poly.ramp(ramp_segment, hinge_removal, body_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) print 'last ramp segment', ramp_segment[-1] over_hinge = False else: # past transition but still on hinge side of lens hole heightmap = heightmap + [pt + [body_removal]] else: # We're on the top part but haven't reached the transition yet heightmap = heightmap + [pt + [hinge_removal]] # Coming back up to the hinge: start ramping up if we encroach on both x and y elif pt[0] < x_pos and (pt[0] > hinge_rampup_start_x and pt[1] > hinge_rampdown_start_y): if(not over_hinge): # starting transition print pt, x_pos, hinge_rampup_start_x, hinge_rampdown_start_y, idx transition_length = poly.polyline_length(contour[:(idx+1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length+5, False) ramp_segment = poly.ramp(ramp_segment, body_removal, hinge_removal, False) heightmap = heightmap + ramp_segment items_to_skip = len(ramp_segment) over_hinge = True else: # Over flat hinge area heightmap = heightmap + [pt + [hinge_removal]] else: # We're over the body area but back on the hinge side heightmap = heightmap + [pt + [body_removal]] return heightmap def add_nosepad_heights(contour): heightmap = [] over_nosepad = False past_nosepad = False nosepad_flat_idx = -1 items_to_skip = 0 # for fast-forwarding the enumeration for idx, pt in enumerate(contour): if items_to_skip > 0: items_to_skip = items_to_skip-1 continue if pt[1] >= center_y: heightmap = heightmap + [pt] elif not over_nosepad and not past_nosepad: if pt[0] < nosepad_start: # Transition transition_length = poly.polyline_length(contour[:(idx+1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length+5, False) ramp_segment = poly.ramp(ramp_segment, body_removal, nosepad_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) nosepad_flat_idx = idx + items_to_skip # we'll need this to go down over_nosepad = True else: # we're past the nosepad heightmap = heightmap + [pt + [body_removal]] elif over_nosepad and not past_nosepad: if nosepad_flat_idx < 0: print "ERROR! I think I'm on the nosepad but have not transitioned yet" return [] # We'll be cutting the far side with the back of the cutter, so need to move at # least the diameter to get any flat at all flat_length = poly.polyline_length(contour[nosepad_flat_idx:(idx+1)], False) - (cutter_radius*2) if flat_length < 5: heightmap = heightmap + [pt + [nosepad_removal]] else: # ramp down transition_length = poly.polyline_length(contour[:(idx+1)], False) ramp_segment = poly.segment(contour, transition_length, transition_length+5, False) ramp_segment = poly.ramp(ramp_segment, nosepad_removal, body_removal, False) heightmap = heightmap + ramp_segment[:-1] items_to_skip = len(ramp_segment) nosepad_flat_idx = idx + items_to_skip # we'll need this to go down over_nosepad = False past_nosepad = True else: heightmap = heightmap + [pt + [body_removal]] return heightmap facing_contour = add_hinge_heights(facing_contour) facing_contour = add_nosepad_heights(facing_contour) facing_contour = poly.reverse(facing_contour) right_facing = poly.mirror_y(facing_contour, True) passes = [1] heights = [p[2] for p in facing_contour] r = [ cam.change_tool("1/4in ballmill"), cam.spindle_speed(22000), cam.feedrate(1000), cam.start_spindle(), cam.rmp(entry_point), cam.contour(facing_contour, True), ] for dilate in passes: dilated = poly.reverse(poly.dilate(dilate, facing_contour)) # dilated = add_hinge_heights(dilated) dilated = add_nosepad_heights(dilated) r = r + [ cam.contour(dilated, True),] return r