示例#1
0
 def test_canned_return2r(self):
     m = Machine()
     m.process_gcodes(
         GCodeAbsoluteDistanceMode(),
         GCodeCannedCycleReturnToR(),
     )
     line_data = [
         ('g0 z5', {
             'Z': 5
         }),
         ('g81 x10 y20 z-2 r1', {
             'X': 10,
             'Y': 20,
             'Z': 1
         }),
     ]
     self.assert_processed_lines(line_data, m)
示例#2
0
 def test_arc_inc(self):
     m = Machine()
     m.process_gcodes(
         GCodeIncrementalDistanceMode(),
         GCodeIncrementalArcDistanceMode(),
     )
     line_data = [
         # Clockwise circle in 4 segments
         ('g2 y10 i5 j5', {
             'X': 0,
             'Y': 10
         }),
         ('   x10 i5 j-5', {
             'X': 10,
             'Y': 10
         }),
         ('   y-10 i-5 j-5', {
             'X': 10,
             'Y': 0
         }),
         ('   x-10 i-5 j5', {
             'X': 0,
             'Y': 0
         }),
         # Counter-clockwise circle in 4 segments
         ('g3 x10 i5 j5', {
             'X': 10,
             'Y': 0
         }),
         ('   y10 i-5 j5', {
             'X': 10,
             'Y': 10
         }),
         ('   x-10 i-5 j-5', {
             'X': 0,
             'Y': 10
         }),
         ('   y-10 i5 j-5', {
             'X': 0,
             'Y': 0
         }),
     ]
     self.assert_processed_lines(line_data, m)
示例#3
0
 def test_canned_loops(self):
     m = Machine()
     m.process_gcodes(
         GCodeAbsoluteDistanceMode(),
         GCodeCannedCycleReturnPrevLevel(),
     )
     line_data = [
         ('g0 z5', None),
         ('g81 x10 y20 z-2 r1 l2', {
             'X': 10,
             'Y': 20,
             'Z': 5
         }),
         ('g91', None),  # switch to incremental mode
         ('g81 x10 y20 z-2 r1 l2', {
             'X': 30,
             'Y': 60,
             'Z': 5
         }),
     ]
     self.assert_processed_lines(line_data, m)
示例#4
0
 def test_linear_inc(self):
     m = Machine()
     m.process_gcodes(GCodeIncrementalDistanceMode())
     line_data = [
         ('g1 y10', {
             'X': 0,
             'Y': 10
         }),
         ('   x10', {
             'X': 10,
             'Y': 10
         }),
         ('   y-10', {
             'X': 10,
             'Y': 0
         }),
         ('   x-10', {
             'X': 0,
             'Y': 0
         }),
     ]
     self.assert_processed_lines(line_data, m)
示例#5
0
 def test_linear_abs(self):
     m = Machine()
     m.process_gcodes(GCodeAbsoluteDistanceMode())
     line_data = [
         ('g1 x0 y10', {
             'X': 0,
             'Y': 10
         }),
         ('   x10 y10', {
             'X': 10,
             'Y': 10
         }),
         ('   x10 y0', {
             'X': 10,
             'Y': 0
         }),
         ('   x0 y0', {
             'X': 0,
             'Y': 0
         }),
     ]
     self.assert_processed_lines(line_data, m)
示例#6
0
 def test_file(self):
     m = Machine()
     with open(self.filename, 'r') as fh:
         for line_str in fh.readlines():
             line = Line(line_str)
             m.process_block(line.block)
示例#7
0
def processFile(infile, mods, modStartZ):
    m = Machine()
    outfile = getOutputFilename(infile, mods)
    print("Processing {inf} to {outf}".format(inf=infile, outf=outfile))
    with open(infile, 'r') as fhIn:
        fhOut = open(outfile, 'w')
        lineNumber = 0
        # Set all initial positions to 0
        curE = prevX = prevY = prevZ = prevE = lastZ = float(0)
        for line_text in fhIn.readlines():
            lineNumber = lineNumber + 1
            line = Line(line_text)
            if (line.comment is not None):
                debug("{line}: {comment}".format(line=lineNumber,
                                                 comment=line.comment))

            if (line.block.words is not None):
                hasX = hasY = hasZ = hasE = False
                origX, origY, origZ, origE = float(0)
                for word in line.block.words:
                    isMovement = False
                    if word.letter == "G" and word.value == 1:
                        isMovement = True
                    if (word.letter == "G" & word.value == 92):
                        prevE = 0  # Simplify3D resets E to 0 for each layer, so if we see a G92 we should consider the current position to be 0

                    hasX, origX = wordHasLetter(word, "X")
                    hasY, origY = wordHasLetter(word, "Y")
                    hasZ, origZ = wordHasLetter(word, "Z")
                    hasE, origE = wordHasLetter(word, "E")
                    if hasZ:
                        lastZ = origZ  # save last seen Z

                if isMovement:
                    # start by assuming the new XYZE will be the same as in the file
                    newX, newY, newE = origX, origY, origE
                    if (hasZ):
                        newZ = origZ
                    else:
                        # the line didn't specify Z so we have to use the last one we saw
                        origZ = lastZ
                        newZ = lastZ

                    for mod in mods:
                        adjustRoutine = mod["mod"]
                        extrudeOnly = mod["extrudeOnly"]
                        if (newZ >= modStartZ) and hasX and hasY and (
                                hasE or not extrudeOnly):
                            newX, newY, newZ, newE = adjustRoutine(
                                mod, modStartZ, m.abs_pos.X, m.abs_pos.Y,
                                m.abs_pos.Z, prevE, newX, newY, newZ, newE)

                    line = replaceOrAddLetter(line, "X", "{:.3f}".format(newX))
                    line = replaceOrAddLetter(line, "Y", "{:.3f}".format(newY))
                    line = replaceOrAddLetter(line, "Z", "{:.3f}".format(newZ))
                    line = replaceOrAddLetter(line, "E", "{:.4f}".format(newE))

                    #debug("*** X: {X} -> {nX}, Y: {Y} -> {nY}, Z: {Z} -> {nZ}, E: {E} -> {nE}".format(X = origX, Y=origY, Z= origZ, E=origE, nX = newX, nY = newY, nZ = newZ, nE = newE))
                    if (origZ != newZ) or (not hasZ):
                        line.comment = "; z {oz} to {nz}".format(oz=origZ,
                                                                 nz=newZ)

                    prevX, prevY, prevZ, prevE = newX, newY, newZ, newE

            try:
                m.process_block(line.block)
            except MachineInvalidState:
                #debug("here")
                continue
            finally:
                print(str(line), file=fhOut)