def parseLine( self, line ): "Parse a gcode line and add it to the statistics." self.characters += len( line ) self.numberOfLines += 1 splitLine = line.split() 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 == '(<extrusionDiameter>': self.extrusionDiameter = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<extrusionWidth>': self.extrusionWidth = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<layerThickness>': self.layerThickness = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == '(<procedureDone>': self.procedures.append( splitLine[ 1 ] )
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 statistics." self.characters += len(line) self.numberOfLines += 1 splitLine = line.split() 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 == "(<extrusionDiameter>": self.extrusionDiameter = float(splitLine[1]) elif firstWord == "(<layerThickness>": self.layerThickness = float(splitLine[1]) 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 getLocationSetFeedRateToSplitLine(self, splitLine): 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 commented gcode." splitLine = line.split() 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.getUnitPolar( afterCenterDifferenceAngle / steps, 1.0) 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 commented gcode." splitLine = line.split() 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.getPolar(afterCenterDifferenceAngle / steps, 1.0) 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.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 = None if self.coolTemperature != None: self.addTemperature( self.oldTemperature ) self.coolTemperature = None self.addFlowRateLineIfNecessary( self.oldFlowRateString ) elif firstWord == 'M104': self.oldTemperature = gcodec.getDoubleAfterFirstLetter( splitLine[ 1 ] ) elif firstWord == 'M108': self.setOperatingFlowString( splitLine ) if self.multiplier != None: self.addFlowRateLineIfNecessary( str( self.multiplier * 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 cool skein." splitLine = line.split() if len(splitLine) < 1: return firstWord = splitLine[0] if firstWord == "G1": self.linearMove(splitLine) elif firstWord == "(<boundaryPoint>": self.boundaryLoop.append(gcodec.getLocationFromSplitLine(None, splitLine).dropAxis(2)) elif firstWord == "(<layer>": self.distanceFeedRate.addLine(line) self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolStartLines) remainingOrbitTime = self.coolRepository.minimumLayerTime.value - self.layerTime if remainingOrbitTime > 0.0 and self.boundaryLayer != None: layerCool = ( self.coolRepository.maximumCool.value * remainingOrbitTime / self.coolRepository.minimumLayerTime.value ) if self.oldTemperature != None and layerCool != 0.0: self.coolTemperature = self.oldTemperature - layerCool self.addTemperature(self.coolTemperature) self.addCoolOrbits(remainingOrbitTime) z = float(splitLine[1]) self.boundaryLayer = euclidean.LoopLayer(z) self.highestZ = z self.layerTime = 0.0 self.distanceFeedRate.addLinesSetAbsoluteDistanceMode(self.coolEndLines) return elif firstWord == "(</layer>)": if self.coolTemperature != None: self.addTemperature(self.oldTemperature) self.coolTemperature = None elif firstWord == "M104": self.oldTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1]) elif firstWord == "(<surroundingLoop>)": self.boundaryLoop = [] self.boundaryLayer.loops.append(self.boundaryLoop) self.distanceFeedRate.addLine(line)
def getLocationSetFeedRateToSplitLine( self, splitLine ): location = gcodec.getLocationFromSplitLine( self.oldLocation, splitLine ) indexOfF = gcodec.indexOfStartingWithSecond( "F", splitLine ) if indexOfF > 0: self.feedRateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfF ] ) return location