예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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))