def setSkirtFeedFlowTemperature(self): "Set the skirt feed rate, flow rate and temperature to that of the next extrusion." isExtruderActive = self.isExtruderActive isSupportLayer = self.isSupportLayer for lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == "G1": self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) if isExtruderActive: if not isSupportLayer: return elif firstWord == "M101": isExtruderActive = True elif firstWord == "M103": isExtruderActive = False elif firstWord == "M104": self.skirtTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == "M108": self.skirtFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == "(<supportLayer>)": isSupportLayer = True elif firstWord == "(</supportLayer>)": isSupportLayer = False
def parseLine(self, line): 'Parse a gcode line and add it to the skirt skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<raftPerimeter>)' or firstWord == '(</raftPerimeter>)' or firstWord == '(<raftPoint>': return self.distanceFeedRate.addLine(line) if firstWord == '(<layer>': self.layerIndex += 1 if self.layerIndex < self.repository.layersTo.value: self.addSkirt(float(splitLine[1])) elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperatureInput = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == 'M108': self.oldFlowRateInput = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<supportLayer>)': self.isSupportLayer = True elif firstWord == '(</supportLayer>)': self.isSupportLayer = False
def parseLine(self, line): 'Parse a gcode line and add it to the skirt skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<raftPerimeter>)' or firstWord == '(</raftPerimeter>)' or firstWord == '(<raftPoint>': return self.distanceFeedRate.addLine(line) if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) elif firstWord == '(<layer>': self.layerIndex += 1 if self.layerIndex < self.repository.layersTo.value: self.addSkirt(float(splitLine[1])) elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperatureInput = gcodec.getDoubleAfterFirstLetter( splitLine[1]) self.skirtTemperature = self.oldTemperatureInput elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) self.skirtFlowRate = self.oldFlowRate elif firstWord == '(<supportLayer>)': self.isSupportLayer = True elif firstWord == '(</supportLayer>)': self.isSupportLayer = False
def parseLine(self, line): "Parse a gcode line and add it to the skirt skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "(<raftPerimeter>)" or firstWord == "(</raftPerimeter>)" or firstWord == "(<raftPoint>": return self.distanceFeedRate.addLine(line) if firstWord == "G1": self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) elif firstWord == "(<layer>": self.layerIndex += 1 if self.layerIndex < self.repository.layersTo.value: self.addSkirt(float(splitLine[1])) elif firstWord == "M101": self.isExtruderActive = True elif firstWord == "M103": self.isExtruderActive = False elif firstWord == "M104": self.oldTemperatureInput = gcodec.getDoubleAfterFirstLetter(splitLine[1]) self.skirtTemperature = self.oldTemperatureInput elif firstWord == "M108": self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) self.skirtFlowRate = self.oldFlowRate elif firstWord == "(<supportLayer>)": self.isSupportLayer = True elif firstWord == "(</supportLayer>)": self.isSupportLayer = False
def setSkirtFeedFlowTemperature(self): 'Set the skirt feed rate, flow rate and temperature to that of the next extrusion.' isExtruderActive = self.isExtruderActive isSupportLayer = self.isSupportLayer for lineIndex in xrange(self.lineIndex, len(self.lines)): line = self.lines[lineIndex] splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) firstWord = gcodec.getFirstWord(splitLine) if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) if isExtruderActive: if not isSupportLayer: return elif firstWord == 'M101': isExtruderActive = True elif firstWord == 'M103': isExtruderActive = False elif firstWord == 'M104': self.skirtTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M108': self.skirtFlowRate = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == '(<supportLayer>)': isSupportLayer = True elif firstWord == '(</supportLayer>)': isSupportLayer = False
def parseLine(self, line): "Parse a gcode line and add it to the dwindle skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G1": self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) if self.isActive: self.threadSections.append( ThreadSection(self.feedRateMinute, self.oldFlowRate, location, self.oldLocation) ) self.oldLocation = location elif firstWord == "(<layer>": self.layerIndex += 1 settings.printProgress(self.layerIndex, "dwindle") elif firstWord == "M101": self.isActive = True elif firstWord == "M103": self.isActive = False self.addThread() elif firstWord == "M108": self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) if len(self.threadSections) == 0: self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) # elif firstWord == 'M108': # self.oldFlowRate = float(splitLine[1][1 :]) # self.addFlowRate(self.multiplier * self.oldFlowRate) # return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max( self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) # self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature is not None: self.addTemperature(self.oldTemperature) self.coolTemperature = None # self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def getLocationSetFeedRateToSplitLine( self, splitLine ): "Get location ans set feed rate to the plsit line." location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0: self.feedRateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfF ] ) return location
def parseLine( self, line ): "Parse a gcode line and add it to the statistics." self.characters += len( line ) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon( line ) if len( splitLine ) < 1: return firstWord = splitLine[ 0 ] if firstWord == 'G1': self.linearMove( splitLine ) elif firstWord == 'G2': self.helicalMove( False, splitLine ) elif firstWord == 'G3': self.helicalMove( True, splitLine ) elif firstWord == 'M101': self.extruderSet( True ) elif firstWord == 'M102': self.extruderSet( False ) elif firstWord == 'M103': self.extruderSet( False ) elif firstWord == 'M108': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<layerThickness>': self.layerThickness = float( splitLine[ 1 ] ) self.extrusionDiameter = self.repository.extrusionDiameterOverThickness.value * self.layerThickness elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float( splitLine[ 1 ] ) elif firstWord == '(<perimeterWidth>': self.absolutePerimeterWidth = abs( float( splitLine[ 1 ] ) ) elif firstWord == '(<procedureDone>': self.procedures.append( splitLine[ 1 ] ) elif firstWord == '(<version>': self.version = splitLine[ 1 ]
def parseLine(self, line): """Parse a gcode line and add it to the skin skein.""" splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == '(<boundaryPerimeter>)': self.boundaryLayerIndex = max(0, self.boundaryLayerIndex) elif firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.perimeter is not None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<layer>': if self.boundaryLayerIndex > -1: self.boundaryLayerIndex += 1 elif firstWord == 'M101' or firstWord == 'M103': if self.perimeter is not None: return elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<perimeter>': if self.boundaryLayerIndex >= self.repository.layersFrom.value: self.perimeter = [] elif firstWord == '(</perimeter>)': self.addSkinnedPerimeter() self.perimeter = None self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the joris skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1' and self.doJoris: self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'joris') elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<edge>': if self.layerIndex >= self.layersFromBottom: self.doJoris = True elif firstWord == 'M101' and self.doJoris: self.perimeter = [] return elif firstWord == 'M103' and self.doJoris: self.addJorisedPerimeter() return elif firstWord == '(</edge>)': self.doJoris = False self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the joris skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1' and self.doJoris: self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'joris') elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<edge>': if self.layerIndex >= self.layersFromBottom: self.doJoris = True elif firstWord == 'M101' and self.doJoris: self.perimeter = [] return elif firstWord == 'M103' and self.doJoris: self.addJorisedPerimeter() return elif firstWord == '(</edge>)': self.doJoris = False self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the dwindle skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) if self.isActive: self.threadSections.append( ThreadSection(self.feedRateMinute, self.oldFlowRate, location, self.oldLocation)) self.oldLocation = location elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'dwindle') elif firstWord == 'M101': self.isActive = True elif firstWord == 'M103': self.isActive = False self.addThread() elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) if len(self.threadSections) == 0: self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == 'M108': self.oldFlowRate = float(splitLine[1][1 :]) self.addFlowRate(self.multiplier * self.oldFlowRate) return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append(gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) if self.repository.turnFanOnAtBeginning.value and self.repository.fanTurnOnLayerNr.value == self.layerCount.layerIndex: self.fanEnabled = True self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max(self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.fanEnabled: self.addFanSpeed(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) if self.oldFlowRate != None: self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None if self.oldFlowRate != None: self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the commented gcode." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'G2': self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical clockwise move to " + str(self.oldLocation) + ".") elif firstWord == 'G3': self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical counterclockwise move to " + str(self.oldLocation) + ".") elif firstWord == 'G21': self.addComment("Set units to mm.") elif firstWord == 'G28': self.addComment("Start at home.") elif firstWord == 'G90': self.addComment("Set positioning to absolute.") elif firstWord == 'M101': self.addComment("Extruder on, forward.") elif firstWord == 'M102': self.addComment("Extruder on, reverse.") elif firstWord == 'M103': self.addComment("Extruder off.") elif firstWord == 'M104': self.addComment( "Set temperature to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " C.") elif firstWord == 'M105': self.addComment("Custom code for temperature reading.") elif firstWord == 'M106': self.addComment("Turn fan on.") elif firstWord == 'M107': self.addComment("Turn fan off.") elif firstWord == 'M108': self.addComment( "Set extruder speed to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + ".") self.output.write(line + '\n')
def parseLine(self, line): "Parse a gcode line and add it to the cool skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G1": location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == "M101": # todo delete? self.isExtruderActive = True elif firstWord == "M103": self.isExtruderActive = False elif firstWord == "M104": self.oldTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == "M108": self.setOperatingFlowString(splitLine) self.addFlowRateMultipliedLineIfNecessary(self.oldFlowRate) return elif firstWord == "(<boundaryPoint>": self.boundaryLoop.append(gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == "(<layer>": self.layerCount.printProgressIncrement("cool") self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max(self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(layerTime) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolEndLines) return elif firstWord == "(</layer>)": self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRateLineIfNecessary(self.oldFlowRate) elif firstWord == "(<nestedRing>)": self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedRateToSplitLine(splitLine) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.getIndexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength centerMidpointDistance = math.sqrt( max(centerMidpointDistanceSquared, 0.0)) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVector3(halfLocationMinusOld + centerMinusMidpoint) else: center.setToVector3(halfLocationMinusOld - centerMinusMidpoint) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round(0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection))) stepPlaneAngle = euclidean.getWiddershinsUnitPolar( afterCenterDifferenceAngle / steps) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in xrange(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath(arcPoint) self.addToPath(location)
def parseLine(self, line): "Parse a gcode line and add it to the cool skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis(2)) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max( self.coolRepository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.coolRepository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(layerTime) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRateLineIfNecessary(self.oldFlowRate) elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M108': self.setOperatingFlowString(splitLine) self.addFlowRateMultipliedLineIfNecessary(self.oldFlowRate) return elif firstWord == '(<surroundingLoop>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the commented gcode." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G1": self.linearMove(splitLine) elif firstWord == "G2": self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical clockwise move to " + str(self.oldLocation) + ".") elif firstWord == "G3": self.setHelicalMoveEndpoint(splitLine) self.addComment("Helical counterclockwise move to " + str(self.oldLocation) + ".") elif firstWord == "G21": self.addComment("Set units to mm.") elif firstWord == "G28": self.addComment("Start at home.") elif firstWord == "G90": self.addComment("Set positioning to absolute.") elif firstWord == "M101": self.addComment("Extruder on, forward.") elif firstWord == "M102": self.addComment("Extruder on, reverse.") elif firstWord == "M103": self.addComment("Extruder off.") elif firstWord == "M104": self.addComment("Set temperature to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + " C.") elif firstWord == "M105": self.addComment("Custom code for temperature reading.") elif firstWord == "M106": self.addComment("Turn fan on.") elif firstWord == "M107": self.addComment("Turn fan off.") elif firstWord == "M108": self.addComment("Set extruder speed to " + str(gcodec.getDoubleAfterFirstLetter(splitLine[1])) + ".") self.output.write(line + "\n")
def helicalMove(self, isCounterclockwise, splitLine): "Get statistics for a helical move." if self.oldLocation == None: return location = self.getLocationSetFeedRateToSplitLine(splitLine) location += self.oldLocation center = self.oldLocation.copy() indexOfR = gcodec.indexOfStartingWithSecond("R", splitLine) if indexOfR > 0: radius = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) halfLocationMinusOld = location - self.oldLocation halfLocationMinusOld *= 0.5 halfLocationMinusOldLength = halfLocationMinusOld.magnitude() centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength centerMidpointDistance = math.sqrt(max(centerMidpointDistanceSquared, 0.0)) centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis(halfLocationMinusOld) centerMinusMidpoint.normalize() centerMinusMidpoint *= centerMidpointDistance if isCounterclockwise: center.setToVector3(halfLocationMinusOld + centerMinusMidpoint) else: center.setToVector3(halfLocationMinusOld - centerMinusMidpoint) else: center.x = gcodec.getDoubleForLetter("I", splitLine) center.y = gcodec.getDoubleForLetter("J", splitLine) curveSection = 0.5 center += self.oldLocation afterCenterSegment = location - center beforeCenterSegment = self.oldLocation - center afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference(afterCenterSegment, beforeCenterSegment) absoluteDifferenceAngle = abs(afterCenterDifferenceAngle) steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection, ) ) ) stepPlaneAngle = euclidean.getWiddershinsUnitPolar(afterCenterDifferenceAngle / steps) zIncrement = (afterCenterSegment.z - beforeCenterSegment.z) / float(steps) for step in xrange(1, steps): beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle(stepPlaneAngle, beforeCenterSegment) beforeCenterSegment.z += zIncrement arcPoint = center + beforeCenterSegment self.addToPath(arcPoint) self.addToPath(location)
def parseLine(self, line): "Parse a gcode line and add it to the statistics." self.characters += len(line) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'G2': self.helicalMove(False, splitLine) elif firstWord == 'G3': self.helicalMove(True, splitLine) elif firstWord == 'M101': self.extruderSet(True) elif firstWord == 'M102': self.extruderSet(False) elif firstWord == 'M103': self.extruderSet(False) elif firstWord == 'M108': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<layerHeight>': self.layerHeight = float(splitLine[1]) elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<edgeWidth>': self.absoluteEdgeWidth = abs(float(splitLine[1])) elif firstWord == '(<procedureName>': self.procedures.append(splitLine[1]) elif firstWord == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip() elif firstWord == '(<setting>': if len(splitLine) == 5: if splitLine[1] == 'dimension' and splitLine[ 2] == 'Filament_Diameter_(mm):': self.filamentDiameter = float(splitLine[3]) print(self.filamentDiameter) elif firstWord == '(<version>': self.version = splitLine[1] elif firstWord == '(<volumeFraction>': self.volumeFraction = float(splitLine[1]) if line == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip()
def parseLine(self, line): 'Parse a gcode line and add it to the skin skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.infillBoundaries != None: return if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<infill>)': if self.layerIndex >= self.layersFromBottom and self.layerIndex == self.layerIndexTop: self.infillBoundaries = [] elif firstWord == '(</infill>)': self.addSkinnedInfill() elif firstWord == '(<infillBoundary>)': if self.infillBoundaries != None: self.infillBoundary = [] self.infillBoundaries.append(self.infillBoundary) elif firstWord == '(<infillPoint>': if self.infillBoundaries != None: location = gcodec.getLocationFromSplitLine(None, splitLine) self.infillBoundary.append(location.dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('skin') self.layerIndex += 1 elif firstWord == 'M101' or firstWord == 'M103': if self.infillBoundaries != None or self.perimeter != None: return elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<perimeter>': if self.layerIndex >= self.layersFromBottom: self.perimeter = [] elif firstWord == '(<rotation>': self.rotation = gcodec.getRotationBySplitLine(splitLine) self.reverseRotation = complex(self.rotation.real, -self.rotation.imag) elif firstWord == '(</perimeter>)': self.addSkinnedPerimeter() self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the skin skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.infill != None: self.infill.append(location.dropAxis()) return if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('skin') self.layerIndex += 1 self.setInfill() elif firstWord == '(<loop>': self.infill = None elif firstWord == '(</loop>)': self.setInfill() elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<perimeter>': self.infill = None if self.layerIndex >= self.layersFromBottom: self.perimeter = [] elif firstWord == '(</perimeter>)': self.addSkinnedPerimeter() self.setInfill() self.perimeter = None if firstWord == 'M103': if self.infill != None: self.addSkinnedInfill() self.setInfill() return if firstWord == 'M101' or firstWord == 'M103': if self.infill != None: return if self.perimeter != None: return self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the leadin skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.infill != None: self.infill.append(location.dropAxis()) return if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('leadin') self.layerIndex += 1 self.setInfill() elif firstWord == '(<loop>': self.infill = None elif firstWord == '(</loop>)': self.setInfill() elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<perimeter>': self.infill = None if self.layerIndex >= self.layersFromBottom: self.perimeter = [] elif firstWord == '(</perimeter>)': self.addLeadinnedPerimeter() self.setInfill() self.perimeter = None if firstWord == 'M103': if self.infill != None: self.addLeadinnedInfill() self.setInfill() return if firstWord == 'M101' or firstWord == 'M103': if self.infill != None: return if self.perimeter != None: return self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the skin skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.oldLocation = location if self.infillBoundaries != None: return if self.perimeter != None: self.perimeter.append(location.dropAxis()) return elif firstWord == '(<infill>)': if self.layerIndex >= self.layersFromBottom and self.layerIndex == self.layerIndexTop: self.infillBoundaries = [] elif firstWord == '(</infill>)': self.addSkinnedInfill() elif firstWord == '(<infillBoundary>)': if self.infillBoundaries != None: self.infillBoundary = [] self.infillBoundaries.append(self.infillBoundary) elif firstWord == '(<infillPoint>': if self.infillBoundaries != None: location = gcodec.getLocationFromSplitLine(None, splitLine) self.infillBoundary.append(location.dropAxis()) elif firstWord == '(<layer>': self.layerIndex += 1 settings.printProgress(self.layerIndex, 'skin') elif firstWord == 'M101' or firstWord == 'M103': if self.infillBoundaries != None or self.perimeter != None: return elif firstWord == 'M108': self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<perimeter>': if self.layerIndex >= self.layersFromBottom: self.perimeter = [] elif firstWord == '(<rotation>': self.rotation = gcodec.getRotationBySplitLine(splitLine) self.reverseRotation = complex(self.rotation.real, -self.rotation.imag) elif firstWord == '(</perimeter>)': self.addSkinnedPerimeter() self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the cool skein." splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append(gcodec.getLocationFromSplitLine(None, splitLine).dropAxis(2)) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolStartLines) layerTime = self.getLayerTime() remainingOrbitTime = max(self.coolRepository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.coolRepository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(layerTime) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolEndLines) return elif firstWord == '(</layer>)': self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRateLineIfNecessary(self.oldFlowRate) elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == 'M108': self.setOperatingFlowString(splitLine) self.addFlowRateMultipliedLineIfNecessary(self.oldFlowRate) return elif firstWord == '(<surroundingLoop>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def parseLine(self, line): "Parse a gcode line and add it to the statistics." self.characters += len(line) self.numberOfLines += 1 splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': self.linearMove(splitLine) elif firstWord == 'G2': self.helicalMove( False, splitLine ) elif firstWord == 'G3': self.helicalMove( True, splitLine ) elif firstWord == 'M101': self.extruderSet( True ) elif firstWord == 'M102': self.extruderSet( False ) elif firstWord == 'M103': self.extruderSet( False ) elif firstWord == 'M108': self.extruderSpeed = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == '(<layerHeight>': self.layerHeight = float(splitLine[1]) elif firstWord == '(<operatingFeedRatePerSecond>': self.operatingFeedRatePerSecond = float(splitLine[1]) elif firstWord == '(<edgeWidth>': self.absoluteEdgeWidth = abs(float(splitLine[1])) elif firstWord == '(<procedureName>': self.procedures.append(splitLine[1]) elif firstWord == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip() elif firstWord == '(<setting>': if len(splitLine) == 5: if splitLine[1] == 'dimension' and splitLine[2] == 'Filament_Diameter_(mm):': self.filamentDiameter = float(splitLine[3]) print( self.filamentDiameter) elif firstWord == '(<version>': self.version = splitLine[1] elif firstWord == '(<volumeFraction>': self.volumeFraction = float(splitLine[1]) if line == '(<profileName>': self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip()
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[1]) elif firstWord == 'M108': self.oldFlowRate = float(splitLine[1][1:]) self.addFlowRate(self.multiplier * self.oldFlowRate) return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append( gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') "print 'Layer %d' % (self.layerCount.layerIndex)" self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolStartLines) layerTime = self.getLayerTime() "print 'Layer time : %5.3f' % (layerTime)" if not self.repository.turnFanOnAtBeginning.value and self.layerCount.layerIndex >= self.repository.fanFirstLayer.value: if (self.repository.bridgeFan.value and self.isBridgeLayer ) or layerTime <= self.repository.fullFanLayerTime.value: self.distanceFeedRate.addLine( 'M106 S%d' % (self.repository.fanmaxPWM.value)) "print 'Full Fan Speed ! (Layer time is under %5.3f' % (self.repository.fullFanLayerTime.value)" elif layerTime <= self.repository.maximumFanLayerTime.value: fanPWMArea = (self.repository.maximumFanLayerTime.value - self.repository.fullFanLayerTime.value) fanPWM = round( ((self.repository.maximumFanLayerTime.value - layerTime) / fanPWMArea) * self.repository.fanmaxPWM.value) self.distanceFeedRate.addLine('M106 S%d' % (fanPWM)) "print 'PWM Fan Speed (fanPWMArea : %5.3f / fanPWM : %d)' % (fanPWMArea, fanPWM)" else: self.distanceFeedRate.addLine('M107') "print 'Fan Off (Layer time is above %5.3f)' % (self.repository.maximumFanLayerTime.value)" remainingOrbitTime = max( self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode( self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def parseLine(self, line): """Parse a gcode line and add it to the reversal gcode. Overview: o Keep track of gcode state: current flowrate (self.flowrate), current position (self.newLocation/oldLocation) current feedrate (self.feedRateMinute) current logical extruder state (self.extruderOn) o Keep track of reversal state: (self.didReverse, self.reversalActive) o If early reversal is NOT active, it will insert a pause command at the end of each thread (G4). This will cause the extruder to move without XYZ. This is not recommended as it might cause some blobbing o If early reversal is active """ if DEBUG: self.distanceFeedRate.addLine("( line: " + line + " )") splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'M108': # If we didn't already rpmify the M108 commands, do this now line = line.replace('M108 S', 'M108 R') splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) # Keep track of current flowrate indexOfR = gcodec.getIndexOfStartingWithSecond('R', splitLine) if indexOfR > 0: self.flowrate = gcodec.getDoubleAfterFirstLetter( splitLine[indexOfR]) # Pick up all movement commands elif firstWord == 'G1': # Location at the start of this movement self.oldLocation = self.newLocation # Location at the end start of this movement self.newLocation = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine) self.feedRateMinute = gcodec.getFeedRateMinute( self.feedRateMinute, splitLine) if self.activateEarlyReversal: # If we did reverse and we're not already pushing back if (not self.extruderOn and self.filamentState == ReversalSkein.FILAMENT_REVERSED and self.pushbackWorthy and not self.pushbackActive): # If this movement crosses the push-back point, this will # move us to where pushback starts and return true. if self.detectAndMoveToReversalEvent( 'M101', self.pushbackTime): if DEBUG: self.distanceFeedRate.addLine( "( activating pushback: )") self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M101") self.pushbackActive = True self.filamentState = ReversalSkein.FILAMENT_READY # If we're going to reverse on next stop and we're not already reversing if (self.extruderOn and self.filamentState == ReversalSkein.FILAMENT_READY and self.reversalWorthy and not self.reversalActive): # If this movement crosses the reversal point, this will # move us to where reversal starts and return true. if self.detectAndMoveToReversalEvent( 'M103', self.reversalTime): if DEBUG: self.distanceFeedRate.addLine( "( activating reverse: )") self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M102") self.reversalActive = True self.filamentState = ReversalSkein.FILAMENT_REVERSED # Note: We don't return here since the current G1 command will # keep moving to the end of the current movement thread with # reversal/push-back potentially active. # Detect extruder ON commands elif firstWord == 'M101': self.extruderOn = True self.reversalWorthy = self.isNextMovementReversalWorthy( self.reversalThreshold, 'M103', 'M101') if (not self.activateEarlyReversal and self.pushbackWorthy and self.filamentState == ReversalSkein.FILAMENT_REVERSED): self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M101") self.distanceFeedRate.addLine("G04 P" + str(self.reversalTime)) self.pushbackActive = True if self.pushbackActive: self.distanceFeedRate.addLine("M108 R" + str(self.flowrate)) self.pushbackActive = False self.filamentState = ReversalSkein.FILAMENT_READY if DEBUG: self.printState() return # Motor is already on - no need to emit the M101 # Detect extruder OFF commands elif firstWord == 'M103': self.extruderOn = False self.pushbackWorthy = self.isNextMovementReversalWorthy( self.reversalThreshold, 'M101', 'M103') if (not self.activateEarlyReversal and self.reversalWorthy and self.filamentState == ReversalSkein.FILAMENT_READY): self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M102") self.distanceFeedRate.addLine("G04 P" + str(self.pushbackTime)) self.filamentState = ReversalSkein.FILAMENT_REVERSED if self.reversalActive: self.reversalActive = False self.filamentState = ReversalSkein.FILAMENT_REVERSED # For safety, reset feedrate here. It's a known issue # that some other plugins keep track of flowrate state # and removed redundant settings, so we need to keep # the original state whenever we're done with an operation self.distanceFeedRate.addLine("M108 R" + str(self.flowrate)) # If someone else inserted a reverse command, detect this and update state # (e.g. end.gcode for Makerbots does this for retracting the filament) elif firstWord == 'M102': self.extruderOn = True self.filamentState = ReversalSkein.FILAMENT_REVERSED self.reversalActive = True if DEBUG: if firstWord == 'M101' or firstWord == 'M102' or firstWord == 'M103': self.printState() # The reversal may change the feedrate for the remaining reversal movements if (self.reversalActive or self.pushbackActive) and firstWord == 'G1': line = self.distanceFeedRate.getLineWithFeedRate( self.reversalFeedrate, line, splitLine) self.distanceFeedRate.addLine(line)
def parseLine(self, line): 'Parse a gcode line and add it to the cool skein.' splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'G1': location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.highestZ = max(location.z, self.highestZ) if self.isExtruderActive: line = self.getCoolMove(line, location, splitLine) self.oldLocation = location elif firstWord == 'M101': self.isExtruderActive = True elif firstWord == 'M103': self.isExtruderActive = False elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == 'M108': self.oldFlowRate = float(splitLine[1][1 :]) self.addFlowRate(self.multiplier * self.oldFlowRate) return elif firstWord == '(<boundaryPoint>': self.boundaryLoop.append(gcodec.getLocationFromSplitLine(None, splitLine).dropAxis()) elif firstWord == '(<layer>': self.layerCount.printProgressIncrement('cool') "print 'Layer %d' % (self.layerCount.layerIndex)" self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolStartLines) layerTime = self.getLayerTime() "print 'Layer time : %5.3f' % (layerTime)" if not self.repository.turnFanOnAtBeginning.value and self.layerCount.layerIndex >= self.repository.fanFirstLayer.value: if (self.repository.bridgeFan.value and self.isBridgeLayer) or layerTime <= self.repository.fullFanLayerTime.value: self.distanceFeedRate.addLine( 'M106 S%d' % (self.repository.fanmaxPWM.value) ) "print 'Full Fan Speed ! (Layer time is under %5.3f' % (self.repository.fullFanLayerTime.value)" elif layerTime <= self.repository.maximumFanLayerTime.value: fanPWMArea = ( self.repository.maximumFanLayerTime.value - self.repository.fullFanLayerTime.value ) fanPWM = round( ( ( self.repository.maximumFanLayerTime.value - layerTime ) / fanPWMArea ) * self.repository.fanmaxPWM.value ) self.distanceFeedRate.addLine( 'M106 S%d' % (fanPWM) ) "print 'PWM Fan Speed (fanPWMArea : %5.3f / fanPWM : %d)' % (fanPWMArea, fanPWM)" else: self.distanceFeedRate.addLine( 'M107' ) "print 'Fan Off (Layer time is above %5.3f)' % (self.repository.maximumFanLayerTime.value)" remainingOrbitTime = max(self.repository.minimumLayerTime.value - layerTime, 0.0) self.addCoolTemperature(remainingOrbitTime) if self.repository.orbit.value: self.addOrbitsIfNecessary(remainingOrbitTime) else: self.setMultiplier(remainingOrbitTime) self.addFlowRate(self.multiplier * self.oldFlowRate) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = max(z, self.highestZ) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolEndLines) return elif firstWord == '(</layer>)': self.isBridgeLayer = False self.multiplier = 1.0 if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None self.addFlowRate(self.oldFlowRate) elif firstWord == '(<nestedRing>)': self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def parseLine(self, line): """Parse a gcode line and add it to the reversal gcode. Overview: o Keep track of gcode state: current flowrate (self.flowrate), current position (self.newLocation/oldLocation) current feedrate (self.feedRateMinute) current logical extruder state (self.extruderOn) o Keep track of reversal state: (self.didReverse, self.reversalActive) o If early reversal is NOT active, it will insert a pause command at the end of each thread (G4). This will cause the extruder to move without XYZ. This is not recommended as it might cause some blobbing o If early reversal is active """ if DEBUG: self.distanceFeedRate.addLine("( line: " + line + " )") splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == 'M108': # If we didn't already rpmify the M108 commands, do this now line = line.replace( 'M108 S', 'M108 R' ) splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line) # Keep track of current flowrate indexOfR = gcodec.getIndexOfStartingWithSecond('R', splitLine) if indexOfR > 0: self.flowrate = gcodec.getDoubleAfterFirstLetter(splitLine[indexOfR]) # Pick up all movement commands elif firstWord == 'G1': # Location at the start of this movement self.oldLocation = self.newLocation # Location at the end start of this movement self.newLocation = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine) self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine) if self.activateEarlyReversal: # If we did reverse and we're not already pushing back if (not self.extruderOn and self.filamentState == ReversalSkein.FILAMENT_REVERSED and self.pushbackWorthy and not self.pushbackActive): # If this movement crosses the push-back point, this will # move us to where pushback starts and return true. if self.detectAndMoveToReversalEvent('M101', self.pushbackTime): if DEBUG: self.distanceFeedRate.addLine("( activating pushback: )") self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M101") self.pushbackActive = True self.filamentState = ReversalSkein.FILAMENT_READY # If we're going to reverse on next stop and we're not already reversing if (self.extruderOn and self.filamentState == ReversalSkein.FILAMENT_READY and self.reversalWorthy and not self.reversalActive): # If this movement crosses the reversal point, this will # move us to where reversal starts and return true. if self.detectAndMoveToReversalEvent('M103', self.reversalTime): if DEBUG: self.distanceFeedRate.addLine("( activating reverse: )") self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M102") self.reversalActive = True self.filamentState = ReversalSkein.FILAMENT_REVERSED # Note: We don't return here since the current G1 command will # keep moving to the end of the current movement thread with # reversal/push-back potentially active. # Detect extruder ON commands elif firstWord == 'M101': self.extruderOn = True self.reversalWorthy = self.isNextMovementReversalWorthy(self.reversalThreshold, 'M103', 'M101') if (not self.activateEarlyReversal and self.pushbackWorthy and self.filamentState == ReversalSkein.FILAMENT_REVERSED): self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M101") self.distanceFeedRate.addLine("G04 P" + str(self.reversalTime)) self.pushbackActive = True if self.pushbackActive: self.distanceFeedRate.addLine("M108 R" + str(self.flowrate)) self.pushbackActive = False self.filamentState = ReversalSkein.FILAMENT_READY if DEBUG: self.printState() return # Motor is already on - no need to emit the M101 # Detect extruder OFF commands elif firstWord == 'M103': self.extruderOn = False self.pushbackWorthy = self.isNextMovementReversalWorthy(self.reversalThreshold, 'M101', 'M103') if (not self.activateEarlyReversal and self.reversalWorthy and self.filamentState == ReversalSkein.FILAMENT_READY): self.distanceFeedRate.addLine("M108 R" + str(self.reversalRPM)) self.distanceFeedRate.addLine("M102") self.distanceFeedRate.addLine("G04 P" + str(self.pushbackTime)) self.filamentState = ReversalSkein.FILAMENT_REVERSED if self.reversalActive: self.reversalActive = False self.filamentState = ReversalSkein.FILAMENT_REVERSED # For safety, reset feedrate here. It's a known issue # that some other plugins keep track of flowrate state # and removed redundant settings, so we need to keep # the original state whenever we're done with an operation self.distanceFeedRate.addLine("M108 R" + str(self.flowrate)) # If someone else inserted a reverse command, detect this and update state # (e.g. end.gcode for Makerbots does this for retracting the filament) elif firstWord == 'M102': self.extruderOn = True self.filamentState = ReversalSkein.FILAMENT_REVERSED self.reversalActive = True if DEBUG: if firstWord == 'M101' or firstWord == 'M102' or firstWord == 'M103': self.printState() # The reversal may change the feedrate for the remaining reversal movements if (self.reversalActive or self.pushbackActive) and firstWord == 'G1': line = self.distanceFeedRate.getLineWithFeedRate(self.reversalFeedrate, line, splitLine) self.distanceFeedRate.addLine(line)