Ejemplo n.º 1
0
    def cut_path(self):
        if self.path == None: return
        self.setPdcfIfNotSet()

        if (self.z > self.minz):
            self.pdcf.setZ(
                self.z
            )  # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
        else:
            self.pdcf.setZ(self.minz)  # Else use minz

    # get the points on the surface
        self.pdcf.setPath(self.path)
        self.pdcf.run()
        plist = self.pdcf.getCLPoints()

        #refine the points
        f = ocl.LineCLFilter()
        f.setTolerance(0.005)
        for p in plist:
            f.addCLPoint(p)
        f.run()
        plist = f.getCLPoints()

        i = 0
        for p in plist:
            if i > 0:
                self.original.feed(p.x / units, p.y / units,
                                   p.z / units + self.material_allowance)
            i = i + 1

        self.path = ocl.Path()
Ejemplo n.º 2
0
    def _dropcutter(self, obj, s, bb):
        import ocl
        import time

        cutter = ocl.CylCutter(self.radius * 2, 5)
        pdc = ocl.PathDropCutter()   # create a pdc
        pdc.setSTL(s)
        pdc.setCutter(cutter)
        pdc.minimumZ = 0.25
        pdc.setSampling(obj.SampleInterval)

        # some parameters for this "zigzig" pattern
        xmin = bb.XMin - cutter.getDiameter()
        xmax = bb.XMax + cutter.getDiameter()
        ymin = bb.YMin - cutter.getDiameter()
        ymax = bb.YMax + cutter.getDiameter()

        # number of lines in the y-direction
        Ny = int(bb.YLength / cutter.getDiameter())
        dy = float(ymax - ymin) / Ny  # the y step-over

        path = ocl.Path()                   # create an empty path object

        # add Line objects to the path in this loop
        for n in xrange(0, Ny):
            y = ymin + n * dy
            p1 = ocl.Point(xmin, y, 0)   # start-point of line
            p2 = ocl.Point(xmax, y, 0)   # end-point of line
            if (n % 2 == 0):  # even
                l = ocl.Line(p1, p2)     # line-object
            else:  # odd
                l = ocl.Line(p2, p1)     # line-object

            path.append(l)        # add the line to the path

        pdc.setPath(path)

        # run drop-cutter on the path
        t_before = time.time()
        pdc.run()
        t_after = time.time()
        print "calculation took ", t_after - t_before, " s"

        # retrieve the points
        clp = pdc.getCLPoints()
        print "points received: " + str(len(clp))

        # generate the path commands
        output = ""
        output += "G0 Z" + str(obj.ClearanceHeight.Value) + "\n"
        output += "G0 X" + str(clp[0].x) + " Y" + str(clp[0].y) + "\n"
        output += "G1 Z" + str(clp[0].z) + " F" + str(self.vertFeed) + "\n"

        for c in clp:
            output += "G1 X" + str(c.x) + " Y" + \
                str(c.y) + " Z" + str(c.z) + "\n"

        return output
Ejemplo n.º 3
0
    def _dropcutter(self, obj, s, bb):
        import ocl
        import time

        cutter = ocl.CylCutter(obj.ToolController.Tool.Diameter, 5)
        pdc = ocl.PathDropCutter()   # create a pdc
        pdc.setSTL(s)
        pdc.setCutter(cutter)
        pdc.minimumZ = 0.25
        pdc.setSampling(obj.SampleInterval)

        # some parameters for this "zigzig" pattern
        xmin = bb.XMin - cutter.getDiameter()
        xmax = bb.XMax + cutter.getDiameter()
        ymin = bb.YMin - cutter.getDiameter()
        ymax = bb.YMax + cutter.getDiameter()

        # number of lines in the y-direction
        Ny = int(bb.YLength / cutter.getDiameter())
        dy = float(ymax - ymin) / Ny  # the y step-over

        path = ocl.Path()                   # create an empty path object

        # add Line objects to the path in this loop
        for n in xrange(0, Ny):
            y = ymin + n * dy
            p1 = ocl.Point(xmin, y, 0)   # start-point of line
            p2 = ocl.Point(xmax, y, 0)   # end-point of line
            if (n % 2 == 0):  # even
                l = ocl.Line(p1, p2)     # line-object
            else:  # odd
                l = ocl.Line(p2, p1)     # line-object

            path.append(l)        # add the line to the path

        pdc.setPath(path)

        # run drop-cutter on the path
        t_before = time.time()
        pdc.run()
        t_after = time.time()
        print("calculation took ", t_after - t_before, " s")

        # retrieve the points
        clp = pdc.getCLPoints()
        print("points received: " + str(len(clp)))

        # generate the path commands
        output = []
        output.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
        output.append(Path.Command('G0', {'X': clp[0].x, "Y": clp[0].y, 'F': self.horizRapid}))
        output.append(Path.Command('G1', {'Z': clp[0].z, 'F': self.vertFeed}))

        for c in clp:
            output.append(Path.Command('G1', {'X': c.x, "Y": c.y, "Z": c.z, 'F': self.horizFeed}))

        return output
Ejemplo n.º 4
0
 def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True):
     px = self.x
     py = self.y
     pz = self.z
     recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw)
     
     # add an arc to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z), ocl.Point(i, j, pz), ccw))
Ejemplo n.º 5
0
        def _order(p):
            if inter.coords[0][0] < inter.coords[1][0]:
                these = list(p)
            else:
                these = list(reversed(p))

            if forward:
                these.reverse()

            path = ocl.Path()
            path.append(ocl.Line(ocl.Point(*these[0]), ocl.Point(*these[1])))
            return path
Ejemplo n.º 6
0
 def feed(self, x=None, y=None, z=None, a=None, b=None, c=None):
     px = self.x
     py = self.y
     pz = self.z
     recreator.Redirector.feed(self, x, y, z, a, b, c)
     if self.x == None or self.y == None or self.z == None:
         return
     if px == self.x and py == self.y:
         return
         
     # add a line to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))
Ejemplo n.º 7
0
 def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True):
     if self.x == None or self.y == None or self.z == None:
         raise "first attached move can't be an arc"
     px = self.x
     py = self.y
     pz = self.z
     if x != None: self.x = x * units
     if y != None: self.y = y * units
     if z != None: self.z = z * units
     
     # add an arc to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z), ocl.Point(i, j, pz), ccw))
Ejemplo n.º 8
0
 def z2(self, z):
     path = ocl.Path()
     # use a line with no length
     path.append(ocl.Line(ocl.Point(self.x, self.y, self.z), ocl.Point(self.x, self.y, self.z)))
     self.setPdcfIfNotSet()
     if (self.z>self.minz):
         self.pdcf.setZ(self.z)  # Adjust Z if we have gotten a higher limit (Fix pocketing losing steps when using attach?)
     else:
         self.pdcf.setZ(self.minz/units) # Else use minz
     self.pdcf.setPath(path)
     self.pdcf.run()
     plist = self.pdcf.getCLPoints()
     p = plist[0]
     return p.z + self.material_allowance/units
Ejemplo n.º 9
0
def YdirectionZigPath(xmin, xmax, ymin, ymax, Ny):
    paths = []
    dy = float(ymax - ymin) / (Ny - 1)  # the y step-over
    for n in xrange(0, Ny):
        path = ocl.Path()
        y = ymin + n * dy  # current y-coordinate
        if (n == Ny - 1):
            assert (y == ymax)
        elif (n == 0):
            assert (y == ymin)
        p1 = ocl.Point(xmin, y, 0)  # start-point of line
        p2 = ocl.Point(xmax, y, 0)  # end-point of line
        l = ocl.Line(p1, p2)  # line-object
        path.append(l)  # add the line to the path
        paths.append(path)
    return paths
Ejemplo n.º 10
0
def getPathsX(s, cutter, sampling, x):
    #apdc = ocl.PathDropCutter()
    apdc = ocl.AdaptivePathDropCutter()
    apdc.setSTL(s)
    apdc.setCutter(cutter)
    apdc.setZ(-20)
    apdc.setSampling(sampling)
    apdc.setMinSampling(sampling / 700)
    path = ocl.Path()
    p1 = ocl.Point(x, -1.52 * cutter.getDiameter(),
                   -111)  # start-point of line
    p2 = ocl.Point(x, +1.52 * cutter.getDiameter(), -111)  # end-point of line
    l = ocl.Line(p1, p2)  # line-object
    path.append(l)
    apdc.setPath(path)
    apdc.run()
    return apdc.getCLPoints()
Ejemplo n.º 11
0
 def feed(self, x=None, y=None, z=None):
     px = self.x
     py = self.y
     pz = self.z
     if x != None: self.x = x * units
     if y != None: self.y = y * units
     if z != None: self.z = z * units
     if self.x == None or self.y == None or self.z == None:
         self.cut_path()
         self.original.feed(x, y, z)
         return
     if px == self.x and py == self.y:
         # z move only
         self.cut_path()
         self.original.feed(self.x/units, self.y/units, self.z2(self.z)/units)
         return
         
     # add a line to the path
     if self.path == None: self.path = ocl.Path()
     self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))
Ejemplo n.º 12
0
    print("set STL surface")
    pdc.setSTL(s)
    print("set cutter")
    pdc.setCutter(cutter)  # set the cutter
    print("set minimumZ")
    pdc.minimumZ = -1  # set the minimum Z-coordinate, or "floor" for drop-cutter
    print("set the sampling interval")
    pdc.setSampling(0.0123)

    # some parameters for this "zigzig" pattern
    ymin = 0
    ymax = 12
    Ny = 40  # number of lines in the y-direction
    dy = float(ymax - ymin) / Ny  # the y step-over

    path = ocl.Path()  # create an empty path object
    # add Line objects to the path in this loop
    for n in range(0, Ny):
        y = ymin + n * dy
        p1 = ocl.Point(0, y, 0)  # start-point of line
        p2 = ocl.Point(9, y, 0)  # end-point of line
        l = ocl.Line(p1, p2)  # line-object
        path.append(l)  # add the line to the path

    print(" set the path for pdf ")
    pdc.setPath(path)

    print(" run the calculation ")
    t_before = time.time()
    pdc.run()  # run drop-cutter on the path
    t_after = time.time()
Ejemplo n.º 13
0
    cutter = ocl.CylCutter(0.6)
    #print cutter.str()

    minx=-1
    dx=0.1
    maxx=11
    
    miny=-1
    dy=1
    maxy=11
    z=-0.2
    
    pdf = ocl.PathDropCutter(s)
    pdf.SetCutter(cutter)
    
    path = ocl.Path()
    
    
    exit()
    pftp = cam.ParallelFinish()
    pftp.initCLPoints(minx,dx,maxx,miny,dy,maxy,z)
    pftp.dropCutterSTL1(cutter, s) 
    print " made ", pftp.dcCalls, " drop-cutter calls"
    
    pf2 = cam.ParallelFinish()
    pf2.initCLPoints(minx,dx,maxx,miny,dy,maxy,z)
    pf2.dropCutterSTL2(cutter, s) 
    print " made ", pf2.dcCalls, " drop-cutter calls"
    
    clpoints = pftp.getCLPoints()
    ccpoints = pftp.getCCPoints()
Ejemplo n.º 14
0
import sys
import ocl

# This example shows how to aggregate lines and arcs into path objects and then
# how to retrieve such data.
print ocl.version()

paths = []

# use Point(x,y) which sets z=0
path_id_1 = ocl.Path()
path_id_1.append(ocl.Line(ocl.Point(6, -9), ocl.Point(10.79422863,
                                                      0.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(10.79422863, 0.69615242),
             ocl.Point(4.79422863, 9.69615242)))
path_id_1.append(ocl.Line(ocl.Point(4.79422863, 9.69615242), ocl.Point(-6, 9)))
path_id_1.append(
    ocl.Line(ocl.Point(-6, 9), ocl.Point(-10.7942286, -0.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(-10.7942286, -0.69615242),
             ocl.Point(-4.79422863, -9.69615242)))
path_id_1.append(
    ocl.Line(ocl.Point(-4.79422863, -9.69615242), ocl.Point(6, -9)))
paths.append(path_id_1)

path_id_2 = ocl.Path()
path_id_2.append(
    ocl.Line(ocl.Point(15, -14, 0), ocl.Point(19.62435565, 5.99038106, 0)))
path_id_2.append(
    ocl.Line(ocl.Point(19.62435565, 5.99038106, 0),
Ejemplo n.º 15
0
    def _dropcutter(self, obj, s, bb):
        import ocl
        import time
        if obj.ToolController.Tool.ToolType == 'BallEndMill':
            cutter = ocl.BallCutter(obj.ToolController.Tool.Diameter, 5)  # TODO: 5 represents cutting edge height. Should be replaced with the data from toolcontroller?
        else:
            cutter = ocl.CylCutter(obj.ToolController.Tool.Diameter, 5)

        pdc = ocl.PathDropCutter()   # create a pdc
        pdc.setSTL(s)
        pdc.setCutter(cutter)
        pdc.setZ(obj.FinalDepth.Value + obj.DepthOffset.Value)  # set minimumZ
        pdc.setSampling(obj.SampleInterval)

        # the max and min XY area of the operation
        xmin = bb.XMin - obj.DropCutterExtraOffset.x
        xmax = bb.XMax + obj.DropCutterExtraOffset.x
        ymin = bb.YMin - obj.DropCutterExtraOffset.y
        ymax = bb.YMax + obj.DropCutterExtraOffset.y

        path = ocl.Path()                   # create an empty path object

        if obj.DropCutterDir == 'Y':
            Ny = int(bb.YLength / (cutter.getDiameter() * (obj.StepOver / 100.0)))
            dy = float(ymax - ymin) / Ny  # the y step-over

            # add Line objects to the path in this loop
            for n in xrange(0, Ny):
                y = ymin + n * dy
                p1 = ocl.Point(xmin, y, 0)   # start-point of line
                p2 = ocl.Point(xmax, y, 0)   # end-point of line
                if (n % 2 == 0):  # even
                    l = ocl.Line(p1, p2)     # line-object
                else:  # odd
                    l = ocl.Line(p2, p1)     # line-object

                path.append(l)        # add the line to the path
        else:
            Nx = int(bb.XLength / (cutter.getDiameter() * (obj.StepOver / 100.0)))
            dx = float(xmax - xmin) / Nx  # the y step-over

            # add Line objects to the path in this loop
            for n in xrange(0, Nx):
                x = xmin + n * dx
                p1 = ocl.Point(x, ymin, 0)   # start-point of line
                p2 = ocl.Point(x, ymax, 0)   # end-point of line
                if (n % 2 == 0):  # even
                    l = ocl.Line(p1, p2)     # line-object
                else:  # odd
                    l = ocl.Line(p2, p1)     # line-object

                path.append(l)        # add the line to the path

        pdc.setPath(path)

        # run drop-cutter on the path
        t_before = time.time()
        pdc.run()
        t_after = time.time()
        print("calculation took ", t_after - t_before, " s")

        # retrieve the points
        clp = pdc.getCLPoints()
        print("points received: " + str(len(clp)))

        # generate the path commands
        output = []
        output.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
        output.append(Path.Command('G0', {'X': clp[0].x, "Y": clp[0].y, 'F': self.horizRapid}))
        output.append(Path.Command('G1', {'Z': clp[0].z, 'F': self.vertFeed}))

        for c in clp:
            output.append(Path.Command('G1', {'X': c.x, "Y": c.y, "Z": c.z, 'F': self.horizFeed}))

        return output
Ejemplo n.º 16
0
def zigzag(filepath,
           tool_diameter=3.0,
           corner_radius=0.0,
           step_over=1.0,
           x0=-10.0,
           x1=10.0,
           y0=-10.0,
           y1=10.0,
           direction='X',
           mat_allowance=0.0,
           style=0,
           clearance=5.0,
           rapid_safety_space=2.0,
           start_depth=0.0,
           step_down=2.0,
           final_depth=-10.0,
           units=1.0):
    mm = True
    if math.fabs(units) > 0.000000001:
        # ocl works in mm, so convert all values to mm
        mm = False
        tool_diameter *= units
        corner_radius *= units
        step_over *= units
        x0 *= units
        x1 *= units
        y0 *= units
        y1 *= units
        mat_allowance *= units
        clearance *= units
        rapid_safety_space *= units
        start_depth *= units
        step_down *= units
        final_depth *= units
        # read the stl file, we know it is an ascii file because HeeksCNC made it
        s = STLSurfFromFile(filepath)
    cutter = ocl.CylCutter(1.0, 1.0)  # a dummy-cutter for now
    if corner_radius == 0.0:
        cutter = ocl.CylCutter(tool_diameter + mat_allowance, 100.0)
    elif corner_radius > tool_diameter / 2 - 0.000000001:
        cutter = ocl.BallCutter(tool_diameter + mat_allowance, 100.0)
    else:
        cutter = ocl.BullCutter(tool_diameter + mat_allowance, corner_radius,
                                100.0)
    if final_depth > start_depth:
        raise 'final_depth > start_depth'
    height = start_depth - final_depth
    zsteps = int(height / math.fabs(step_down) + 0.999999)
    zstep_down = height / zsteps
    incremental_rapid_to = rapid_safety_space - start_depth
    if incremental_rapid_to < 0: incremental_rapid_to = 0.1
    dcf = ocl.PathDropCutter()
    dcf.setSTL(s)
    dcf.setCutter(cutter)
    for k in range(0, zsteps):
        z1 = start_depth - k * zstep_down
        z0 = start_depth - (k + 1) * zstep_down
        dcf.setZ(z0)
        steps = int((y1 - y0) / step_over) + 1
        if direction == 'Y': steps = int((x1 - x0) / step_over) + 1
        sub_step_over = (y1 - y0) / steps
        if direction == 'Y': sub_step_over = (x1 - x0) / steps
        rapid_to = z1 + incremental_rapid_to
        path = ocl.Path()
        for i in range(0, steps + 1):
            odd_numbered_pass = (i % 2 == 1)
            u = y0 + float(i) * sub_step_over
            if direction == 'Y': u = x0 + float(i) * sub_step_over
            if style == 0:  # one way
                if direction == 'Y':
                    path.append(
                        ocl.Line(ocl.Point(u, y0, 0), ocl.Point(u, y1, 0)))
                else:
                    path.append(
                        ocl.Line(ocl.Point(x0, u, 0), ocl.Point(x1, u, 0)))
                cut_path(path, dcf, z1, mat_allowance, mm, units, rapid_to,
                         incremental_rapid_to)
                path = ocl.Path()
                if mm:
                    rapid(z=clearance)
                else:
                    rapid(z=clearance / units)

            else:  # back and forth
                if direction == 'Y':
                    if odd_numbered_pass:
                        path.append(
                            ocl.Line(ocl.Point(u, y1, 0), ocl.Point(u, y0, 0)))
                        if i < steps:
                            path.append(
                                ocl.Line(
                                    ocl.Point(u, y0, 0),
                                    ocl.Point(u + sub_step_over, y0,
                                              0)))  # feed across to next pass
                    else:
                        path.append(
                            ocl.Line(ocl.Point(u, y0, 0), ocl.Point(u, y1, 0)))
                        if i < steps:
                            path.append(
                                ocl.Line(
                                    ocl.Point(u, y1, 0),
                                    ocl.Point(u + sub_step_over, y1,
                                              0)))  # feed across to next pass
                else:  # 'X'
                    if odd_numbered_pass:
                        path.append(
                            ocl.Line(ocl.Point(x1, u, 0), ocl.Point(x0, u, 0)))
                        if i < steps:
                            path.append(
                                ocl.Line(
                                    ocl.Point(x0, u, 0),
                                    ocl.Point(x0, u + sub_step_over,
                                              0)))  # feed across to next pass
                    else:
                        path.append(
                            ocl.Line(ocl.Point(x0, u, 0), ocl.Point(x1, u, 0)))
                        if i < steps:
                            path.append(
                                ocl.Line(
                                    ocl.Point(x1, u, 0),
                                    ocl.Point(x1, u + sub_step_over,
                                              0)))  # feed across to next pass

        if style != 0:  # back and forth
            cut_path(path, dcf, z1, mat_allowance, mm, units, rapid_to,
                     incremental_rapid_to)
            if mm:
                rapid(z=clearance)
            else:
                rapid(z=clearance / units)
Ejemplo n.º 17
0
    def points_to_ocl_path(self, pts):
        path = ocl.Path()
        for p1, p2 in zip(pts[:-1], pts[1:]):
            path.append(ocl.Line(ocl.Point(*p1), ocl.Point(*p2)))

        return path