Exemplo n.º 1
0
def rectangle_rounded_corners(x_center, y_center, x_dimension, y_dimension, corner_radius, tool_diameter, feed_rate,
                              z_feed_rate, from_z, to_z, step_z, safety_z):
    r"""Generate Gcode to cut a rectangle with rounded corners

    Parameters
    ----------
    x_dimension : float
        The dimension of the rectangle along the x axis
    y_dimension : float
        The dimension of the rectangle along the y axis
    feed_rate : float
        Feed rate in mm/min

    Note
    ----
    The milling head travels CCW around the rectangle
    
    """
    
    gcode = list()
    gcode.append(gcodes.g0_gcode(x=0, y=0, z=safety_z))
    # go to start point (LOWER LEFT CORNER)
    gcode.append(gcodes.g0_gcode(x=x_center - x_dimension / 2 + corner_radius,
                                 y=y_center - y_dimension / 2 - tool_diameter / 2))

    for h in _generate_heights(from_z, to_z, step_z):
        gcode.append(gcodes.g1_gcode(z=h, feedrate=z_feed_rate))
        # LOWER EDGE
        gcode.append(gcodes.g1_gcode(x=x_center + x_dimension / 2 - corner_radius, feedrate=feed_rate))
        # BOTTOM RIGHT CORNER
        gcode.append(gcodes.g3_gcode(x_end_point=x_center + x_dimension / 2 + tool_diameter / 2,
                                     y_end_point=y_center - y_dimension / 2 + corner_radius,
                                     x_center_offset=0.0, y_center_offset=corner_radius + tool_diameter / 2,
                                     spiral_end_altitude=h, feedrate=feed_rate))
        # RIGHT EDGE
        gcode.append(gcodes.g1_gcode(y=y_center + y_dimension / 2 - corner_radius, feedrate=feed_rate))
        # UPPER RIGHT CORNER
        gcode.append(gcodes.g3_gcode(x_end_point=x_center + x_dimension / 2 - corner_radius,
                                     y_end_point=y_center + y_dimension / 2 + tool_diameter / 2,
                                     x_center_offset=-corner_radius - tool_diameter / 2,
                                     y_center_offset=0.0, spiral_end_altitude=h, feedrate=feed_rate))
        # TOP EDGE
        gcode.append(gcodes.g1_gcode(x=x_center - x_dimension / 2 + corner_radius, feedrate=feed_rate))
        gcode.append(gcodes.g3_gcode(x_end_point=x_center - x_dimension / 2 - tool_diameter / 2,
                                     y_end_point=y_center + y_dimension / 2 - corner_radius,
                                     x_center_offset=0.0, y_center_offset=-corner_radius - tool_diameter / 2,
                                     spiral_end_altitude=h, feedrate=feed_rate))
        gcode.append(gcodes.g1_gcode(y=y_center - y_dimension / 2 + corner_radius, feedrate=feed_rate))
        gcode.append(gcodes.g3_gcode(x_end_point=x_center - x_dimension / 2 + corner_radius,
                                     y_end_point=y_center - y_dimension / 2 - tool_diameter / 2,
                                     x_center_offset=corner_radius + tool_diameter / 2, y_center_offset=0.0,
                                     spiral_end_altitude=h, feedrate=feed_rate))

    gcode.append(gcodes.g1_gcode(z=safety_z, feedrate=feed_rate))
    
    return ''.join(gcode)
Exemplo n.º 2
0
def cylinder(x_center, y_center, cylinder_diameter, tool_diameter, feed_rate, from_z, to_z, step_z, safety_z):
    r"""Generate Gcode to cut a cylinder"""
    gcode = list()
    gcode.append(gcodes.g0_gcode(z=safety_z))
    gcode.append(gcodes.g0_gcode(x=x_center - (cylinder_diameter + tool_diameter) / 2 + tool_diameter / 2, y=y_center))

    for h in _generate_heights(from_z, to_z, step_z):
        gcode.append(gcodes.g3_gcode(x_center_offset=(cylinder_diameter + tool_diameter) / 2 - tool_diameter / 2,
                                     y_center_offset=0, spiral_end_altitude=h, feedrate=feed_rate))

    gcode.append(gcodes.g1_gcode(z=safety_z, feedrate=feed_rate))
    return ''.join(gcode)