Exemple #1
0
    def _handleSmartPurge(self):
        if (self._smartPurge[0] or self._smartPurge[1]) and self._IDEXPrint:
            self._startGcodeInfo.append("; - Smart Purge")
            for index, layer in enumerate(self._gcode_list):
                lines = layer.split("\n")
                applyFix = False
                if not layer.startswith(";LAYER:0") and layer.startswith(
                        ";LAYER:"):
                    temp_index = 0
                    while temp_index < len(lines):
                        if lines[temp_index].startswith(
                                "T0") or lines[temp_index].startswith("T1"):
                            # toolchange found
                            applyFix = True
                            toolChangeIndex = temp_index
                            if lines[temp_index].startswith("T0"):
                                countingForTool = 0
                            elif lines[temp_index].startswith("T1"):
                                countingForTool = 1
                        elif applyFix and self._smartPurge[
                                countingForTool] and GCodeUtils.charsInLine(
                                    ["G1", "F", "X", "Y", "E"],
                                    lines[temp_index]):
                            # first extrusion with the new tool found
                            extrudeAgainIndex = temp_index
                            temp_index = toolChangeIndex
                            foundM109 = False
                            foundFirstTravel = False
                            while temp_index <= extrudeAgainIndex:
                                if not foundFirstTravel and GCodeUtils.charsInLine(
                                    ["G", "F", "X", "Y"], lines[temp_index]):
                                    foundFirstTravel = True
                                    smartPurgeLineIndex = temp_index - 1
                                if lines[temp_index].startswith("M109 S"):
                                    foundM109 = True
                                elif foundM109 and lines[
                                        temp_index].startswith("M104 S"):
                                    # remove M104 extra line
                                    del lines[temp_index]
                                    break
                                temp_index += 1
                            lines[smartPurgeLineIndex] = lines[smartPurgeLineIndex] + \
                                                "\nG1 F" + self._switchExtruderPrimeSpeed[countingForTool] + \
                                                " E" + str(self._switchExtruderRetractionAmount[countingForTool]) + \
                                                "\nM800 F" + self._purgeSpeed[countingForTool] + \
                                                " S" + str(self._smartPurgeSParameter[countingForTool]) + \
                                                " E" + str(self._smartPurgeEParameter[countingForTool]) + \
                                                " P" + str(self._smartPurgePParameter[countingForTool]) + " ;smartpurge" + \
                                                "\nG4 P2000\nG92 E0\nG1 F" + self._retractionRetractSpeed[countingForTool] + \
                                                " E-" + str(self._switchExtruderRetractionAmount[countingForTool]) + "\nG92 E0"
                            break
                        temp_index += 1

                layer = "\n".join(lines)
                self._gcode_list[index] = layer
            Logger.log("d", "smart_purge applied")
Exemple #2
0
 def _handleFixFirstRetract(self):
     if self._fixFirstRetract:
         self._startGcodeInfo.append("; - Fix First Extrusion")
         lookingForTool = None
         countingForTool = None
         eValueT1 = None
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             if not layer.startswith(";LAYER:"):
                 # Get retract value before starting the first layer
                 for line in lines:
                     if line.startswith("T1"):
                         countingForTool = 1
                     if countingForTool and GCodeUtils.charsInLine(
                         ["G", "F", "E-"], line):
                         eValueT1 = GCodeUtils.getValue(line, "E")
                         break
             else:
                 # Fix the thing
                 if eValueT1:
                     if 'T1\nG92 E0' in layer and layer.startswith(
                             ";LAYER:0"):
                         # IDEX Starts with T0, then T1. Only T1 needs to be fixed
                         # IDEX Starts with T1, then T0. Only T1 needs to be fixed
                         # MEX  Starts with T1 and only T1 needs to be fixed
                         layer = layer.replace(
                             'T1\nG92 E0',
                             'T1\nG92 E' + str(eValueT1) + ' ;T1fix', 1)
                         break
                     elif lookingForTool == 'T1' and 'T1\nG92 E0' in layer:
                         # Starts with T0, first T1 found and fixed
                         layer = layer.replace(
                             'T1\nG92 E0',
                             'T1\nG92 E' + str(eValueT1) + ' ;T1fix', 1)
                         break
                     elif not lookingForTool:
                         # Starts with T0, T1 will need to be fixed
                         lookingForTool = 'T1'
                 else:
                     # There is no eValue to fix and it's already printing
                     break
         self._gcode_list[index] = layer
         Logger.log("d", "fix_retract applied")
Exemple #3
0
    def run(self):
        Job.yieldThread()
        # Do not change actions order as some may alter others
        if self._activeExtruders or self._fixTemperatureOscilation or self._fixFirstRetract:
            scanning = False
            printing = False
            for layer in self._gcode_list:
                lines = layer.split("\n")
                for line in lines:
                    if scanning:
                        if line.startswith("T0") or (line.startswith("T1")
                                                     and printing):
                            self._both_extruders = True
                            break
                        elif line.startswith("T1") and not printing:
                            self._idle_extruder = "T0"
                        elif GCodeUtils.charsInLine("GXYE", line):
                            printing = True
                    else:
                        if line.startswith(";LAYER_COUNT:"):
                            scanning = True
                if self._both_extruders:
                    break
            Logger.log("d", "gcode scanned")

        self._handleActiveExtruders()
        self._handleFixToolChangeZHop()
        self._handleFixFirstRetract()
        self._handleFixTemperatureOscilation()
        self._handleSmartPurge()
        self._handleRetractReduction()
        self._handleAvoidGrindingFilament()

        written_info = False
        # Write Sigma Vitamins info
        for index, layer in enumerate(self._gcode_list):
            lines = layer.split("\n")
            for temp_index in range(len(lines)):
                if layer.startswith(";Generated with Cura_SteamEngine "
                                    ) and lines[temp_index].startswith(
                                        ";Sigma ProGen"):
                    lines[temp_index] = lines[temp_index] + "\n" + "\n".join(
                        self._startGcodeInfo)
                    written_info = True
            layer = "\n".join(lines)
            self._gcode_list[index] = layer
            if written_info:
                break

        self._gcode_list[0] += ";BCN3D_FIXES\n"
        scene = Application.getInstance().getController().getScene()
        setattr(scene, "gcode_list", self._gcode_list)
        self.setResult(self._gcode_list)
Exemple #4
0
 def _handleRetractReduction(self):
     if self._retractReduction:
         self._startGcodeInfo.append("; - Reduce Retraction")
         removeRetracts = False
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             if layer.startswith(
                     ";LAYER:") and not layer.startswith(";LAYER:0"):
                 while temp_index < len(lines):
                     line = lines[temp_index]
                     if line.startswith(
                             ";TYPE:WALL-OUTER") or line.startswith(
                                 ";TYPE:SKIN") or line.startswith("T"):
                         removeRetracts = False
                     elif line.startswith(";TYPE:"):
                         removeRetracts = True
                     if removeRetracts:
                         if " E" in line and "G92" not in line:
                             eValue = GCodeUtils.getValue(line, "E")
                             lineCount = temp_index - 1
                             try:
                                 if not lines[temp_index +
                                              1].startswith("G92"):
                                     while lineCount >= 0:
                                         line = lines[lineCount]
                                         if " E" in line and "G92" not in line:
                                             if eValue < GCodeUtils.getValue(
                                                     line, "E"):
                                                 if removeRetracts:
                                                     del lines[temp_index]
                                                     temp_index -= 1
                                             break
                                         lineCount -= 1
                             except:
                                 break
                     temp_index += 1
             layer = "\n".join(lines)
             self._gcode_list[index] = layer
         Logger.log("d", "retract_reduction applied")
Exemple #5
0
 def _handleCoolDownToZeroAtEnd(self):
     if self._IDEXPrint:
         self._startGcodeInfo.append("; - Cool Down To Zero At End")
         cooledDownToZero = False
         self._gcode_list.reverse()
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             lines.reverse()
             temp_index = 0
             while temp_index < len(lines):
                 try:
                     line = lines[temp_index]
                     if GCodeUtils.charsInLine([
                             "M104 T0 S" +
                             str(self._materialStandByTemperature[0])
                     ], line) or GCodeUtils.charsInLine([
                             "M104 T1 S" +
                             str(self._materialStandByTemperature[1])
                     ], line):
                         if "T1" in line:
                             lines[
                                 temp_index] = "M104 T1 S0 ;Standby Temperature set to Zero\n"
                         else:
                             lines[
                                 temp_index] = "M104 T0 S0 ;Standby Temperature set to Zero\n"
                         cooledDownToZero = True
                         break
                     temp_index += 1
                 except:
                     break
             if cooledDownToZero:
                 lines.reverse()
                 layer = "\n".join(lines)
                 self._gcode_list[index] = layer
                 break
         self._gcode_list.reverse()
         Logger.log("d", "cool_down_to_zero_at_end applied")
Exemple #6
0
 def _handleAvoidGrindingFilament(self):
     if self._avoidGrindingFilament[0] or self._avoidGrindingFilament[1]:
         self._startGcodeInfo.append("; - Prevent Filament Grinding")
         retractionsPerExtruder = [[], []]
         countingForTool = 0
         purgedOffset = [0, 0]
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             if layer.startswith(";LAYER:"):
                 while temp_index < len(lines):
                     line = lines[temp_index]
                     if line.startswith("T0"):
                         countingForTool = 0
                         if not layer.startswith(
                                 ";LAYER:0"
                         ) and self._smartPurge[countingForTool]:
                             purgedOffset[
                                 countingForTool] += self._smartPurgePParameter[
                                     countingForTool]
                     elif line.startswith("T1"):
                         countingForTool = 1
                         if not layer.startswith(
                                 ";LAYER:0"
                         ) and self._smartPurge[countingForTool]:
                             purgedOffset[
                                 countingForTool] += self._smartPurgePParameter[
                                     countingForTool]
                     elif " E" in line and "G92" not in line:
                         eValue = GCodeUtils.getValue(line, "E")
                         lineCount = temp_index - 1
                         try:
                             if not lines[temp_index + 1].startswith("G92"):
                                 while lineCount >= 0:
                                     line = lines[lineCount]
                                     if " E" in line and "G92" not in line:
                                         if eValue < GCodeUtils.getValue(
                                                 line, "E"
                                         ) and self._avoidGrindingFilament[
                                                 countingForTool]:
                                             purgeLength = self._retractionExtrusionWindow[
                                                 countingForTool]
                                             retractionsPerExtruder[
                                                 countingForTool].append(
                                                     eValue)
                                             if len(retractionsPerExtruder[
                                                     countingForTool]
                                                    ) > self._maxRetracts[
                                                        countingForTool]:
                                                 if (retractionsPerExtruder[
                                                         countingForTool]
                                                     [-1] -
                                                         retractionsPerExtruder[
                                                             countingForTool]
                                                     [0]
                                                     ) < purgeLength + purgedOffset[
                                                         countingForTool]:
                                                     # Delete extra travels
                                                     lineCount2 = temp_index + 1
                                                     while lines[
                                                             lineCount2].startswith(
                                                                 "G0"):
                                                         if lines[
                                                                 lineCount2
                                                                 +
                                                                 1].startswith(
                                                                     "G0"):
                                                             del lines[
                                                                 lineCount2]
                                                         else:
                                                             lineCount2 += 1
                                                     # Add purge commands
                                                     count_back = 1
                                                     while not GCodeUtils.charsInLine(
                                                             "GXY", lines[
                                                                 temp_index
                                                                 -
                                                                 count_back]
                                                     ):
                                                         count_back += 1
                                                     xPosition = GCodeUtils.getValue(
                                                         lines[temp_index -
                                                               count_back],
                                                         "X")
                                                     yPosition = GCodeUtils.getValue(
                                                         lines[temp_index -
                                                               count_back],
                                                         "Y")
                                                     #todo remove when firmware updated
                                                     if Application.getInstance(
                                                     ).getMachineManager(
                                                     ).activeMachineId == "Sigma":
                                                         lines[temp_index] = lines[temp_index] + " ;prevent filament grinding on T" + \
                                                                             str(countingForTool) + "\nG1 F" + self._travelSpeed[countingForTool] + "\nT" + \
                                                                             str(abs(countingForTool - 1)) + "\nT" + \
                                                                             str(countingForTool) + "\nG91\nG1 F" + self._travelSpeed[countingForTool] + " Z" + str(self._retractionHopHeightAfterExtruderSwitch[countingForTool]) + "\nG90\nG1 F" + self._retractionPrimeSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + purgeLength, 5)) + "\nG1 F" + \
                                                                             self._purgeSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + 2 * purgeLength, 5)) + "\nG4 P2000\nG1 F" + self._retractionRetractSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + purgeLength, 5)) + "\nG92 E" + \
                                                                             str(eValue) + "\nG1 F" + self._travelSpeed[countingForTool] + " X" + \
                                                                             str(xPosition)+" Y" + str(yPosition)+"\nG91\nG1 F" + self._travelSpeed[countingForTool] + " Z-" + str(self._retractionHopHeightAfterExtruderSwitch[countingForTool]) + "\nG90 ;end of the filament grinding prevention protocol"
                                                     else:
                                                         lines[temp_index] = lines[temp_index] + " ;prevent filament grinding on T" + \
                                                                             str(countingForTool) + "\nG1 F" + self._travelSpeed[countingForTool] + "\nG71\nG91\nG1 F" + self._travelSpeed[countingForTool] + " Z" + str(self._retractionHopHeightAfterExtruderSwitch[countingForTool]) + "\nG90\nG1 F" + self._retractionPrimeSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + purgeLength, 5)) + "\nG1 F" + \
                                                                             self._purgeSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + 2 * purgeLength,5)) + "\nG4 P2000\nG1 F" + self._retractionRetractSpeed[countingForTool] + " E" + \
                                                                             str(round(eValue + purgeLength, 5)) + "\nG92 E" + \
                                                                             str(eValue) + "\nG1 F" + self._travelSpeed[countingForTool] + "\nG72\nG1 F" + self._travelSpeed[countingForTool] + " X" + \
                                                                             str(xPosition)+" Y" + str(yPosition)+"\nG91\nG1 F" + self._travelSpeed[countingForTool] + " Z-" + str(self._retractionHopHeightAfterExtruderSwitch[countingForTool]) + "\nG90 ;end of the filament grinding prevention protocol"
                                                     del lines[temp_index +
                                                               1]
                                                     temp_index -= 1
                                                     retractionsPerExtruder[countingForTool] = []
                                                     purgedOffset[
                                                         countingForTool] = 0
                                                     while (retractionsPerExtruder[
                                                             countingForTool]
                                                            [-1] -
                                                            retractionsPerExtruder[
                                                                countingForTool]
                                                            [0]
                                                            ) > purgeLength:
                                                         del retractionsPerExtruder[
                                                             countingForTool][
                                                                 0]
                                                 else:
                                                     del retractionsPerExtruder[
                                                         countingForTool][0]
                                         break
                                     elif line.startswith(
                                             "T") or line.startswith("G92"):
                                         break
                                     lineCount -= 1
                         except:
                             break
                     temp_index += 1
             layer = "\n".join(lines)
             self._gcode_list[index] = layer
         Logger.log("d", "avoid_grinding_filament applied")
Exemple #7
0
 def _handleFixToolChangeZHop(self):
     if self._fixToolChangeZHop and self._IDEXPrint:
         self._startGcodeInfo.append("; - Fix Tool Change Z Hop")
         # Fix hop
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             while temp_index < len(lines):
                 try:
                     line = lines[temp_index]
                     if GCodeUtils.charsInLine(["G0", "X", "Y", "Z"], line):
                         zValue = GCodeUtils.getValue(line, "Z")
                     line1 = lines[temp_index + 1]
                     line2 = lines[temp_index + 2]
                     line3 = lines[temp_index + 3]
                     line4 = lines[temp_index + 4]
                     if (
                             line == "T0" or line == "T1"
                     ) and line1 == "G92 E0" and line2 == "G91" and "G1 F" in line3 and line4 == "G90":
                         if line == "T0":
                             countingForTool = 0
                         else:
                             countingForTool = 1
                         lines[temp_index +
                               3] = line3.split("Z")[0] + "Z" + str(
                                   self.
                                   _retractionHopHeightAfterExtruderSwitch[
                                       countingForTool])
                         lineCount = 6  # According to extruder_start_gcode in Sigma Extruders definitions
                         while not lines[temp_index +
                                         lineCount].startswith(";TYPE"):
                             line = lines[temp_index + lineCount]
                             if line.startswith("G"):
                                 if lines[temp_index + lineCount +
                                          1].startswith("G"):
                                     del lines[temp_index + lineCount]
                                     lineCount -= 1
                                 else:
                                     xValue = GCodeUtils.getValue(line, "X")
                                     yValue = GCodeUtils.getValue(line, "Y")
                                     lines[
                                         temp_index +
                                         lineCount] = "G0 F" + self._travelSpeed[
                                             countingForTool] + " X" + str(
                                                 xValue) + " Y" + str(
                                                     yValue
                                                 ) + "\nG0 Z" + str(zValue)
                             lineCount += 1
                         break
                     temp_index += 1
                 except:
                     break
             layer = "\n".join(lines)
             # Fix strange travel to X105 Y297
             regex = r"\n.*X" + str(
                 int(self._container.getProperty(
                     "layer_start_x", "value"))) + " Y" + str(
                         int(
                             self._container.getProperty(
                                 "layer_start_y", "value"))) + ".*"
             layer = re.sub(regex, "", layer)
             self._gcode_list[index] = layer
         Logger.log("d", "fix_tool_change_z_hop applied")
Exemple #8
0
 def _handleFixTemperatureOscilation(self):
     if self._fixTemperatureOscilation and self._IDEXPrint:
         self._startGcodeInfo.append("; - Fix Temperature Oscilation")
         # Fix oscilation when using Auto Temperature
         if self._materialFlowDependentTemperature[
                 0] or self._materialFlowDependentTemperature[1]:
             # Scan all temperatures
             temperatures = []  # [(layerIndex, lineIndex, action, line)]
             for index, layer in enumerate(self._gcode_list):
                 # if index > 2: # avoid altering layer 0
                 lines = layer.split("\n")
                 temp_index = 0
                 while temp_index < len(lines):
                     line = lines[temp_index]
                     if layer.startswith(";LAYER:"):
                         if line.startswith("M109"):
                             temperatures.append(
                                 [index, temp_index, "heat", line])
                         elif line.startswith("T"):
                             temperatures.append(
                                 [index, temp_index, "toolChange", line])
                         elif line.startswith("M104"):
                             if line.startswith("M104 T"):
                                 temperatures.append(
                                     [index, temp_index, "preheat", line])
                             else:
                                 temperatures.append(
                                     [index, temp_index, "unknown", line])
                     temp_index += 1
             # Define "unknown" roles
             for elementIndex in range(len(temperatures)):
                 action = temperatures[elementIndex][2]
                 if action == "unknown":
                     if elementIndex + 1 < len(temperatures):
                         if temperatures[elementIndex +
                                         1][3].startswith("T"):
                             action = "coolDownActive"
                         else:
                             action = "setpoint"
                     temperatures[elementIndex][2] = action
                 elif action == "preheat":
                     temp_index = elementIndex - 1
                     while temp_index >= 0 and temperatures[temp_index][
                             2] != "toolChange":
                         if temperatures[temp_index][2] == 'preheat':
                             action = "coolDownIdle"
                             temperatures[temp_index][2] = action
                             break
                         temp_index -= 1
             # Correct all temperatures
             countingForTool = 0
             for elementIndex in range(len(temperatures)):
                 action = temperatures[elementIndex][2]
                 if action == "toolChange":
                     if temperatures[elementIndex][3] == "T0":
                         countingForTool = 0
                     else:
                         countingForTool = 1
                 temperature_inertia_initial_fix = self._materialInitialPrintTemperature[
                     countingForTool] - self._materialPrintTemperature[
                         countingForTool]
                 temperature_inertia_final_fix = self._materialFinalPrintTemperature[
                     countingForTool] - self._materialPrintTemperature[
                         countingForTool]
                 if action == "preheat":
                     temp_index = elementIndex + 1
                     toolChanged = False
                     while temp_index < len(temperatures):
                         if temperatures[temp_index][2] == "toolChange":
                             if toolChanged:
                                 break
                             else:
                                 toolChanged = True
                         elif temperatures[temp_index][2] == "heat":
                             heatIndex = temp_index
                         elif toolChanged and temperatures[temp_index][
                                 2] == "setpoint":
                             correctTemperatureValue = GCodeUtils.getValue(
                                 temperatures[temp_index][3],
                                 "S") + temperature_inertia_initial_fix
                             temperatures[elementIndex][3] = temperatures[
                                 elementIndex][3].split("S")[0] + "S" + str(
                                     correctTemperatureValue)
                             temperatures[heatIndex][3] = temperatures[
                                 heatIndex][3].split("S")[0] + "S" + str(
                                     correctTemperatureValue)
                             break
                         temp_index += 1
                 elif action == "coolDownIdle":
                     correctTemperatureValue = max(
                         GCodeUtils.getValue(temperatures[elementIndex][3],
                                             "S") +
                         temperature_inertia_initial_fix,
                         self._materialStandByTemperature[countingForTool])
                     temperatures[elementIndex][
                         3] = temperatures[elementIndex][3].split(
                             "S")[0] + "S" + str(correctTemperatureValue)
                 elif action == "coolDownActive":
                     temp_index = elementIndex - 1
                     while temp_index >= 0:
                         if temperatures[temp_index][2] == "coolDownActive":
                             break
                         if temperatures[temp_index][2] == "setpoint":
                             correctTemperatureValue = GCodeUtils.getValue(
                                 temperatures[temp_index][3],
                                 "S") + temperature_inertia_final_fix
                             temperatures[elementIndex][3] = temperatures[
                                 elementIndex][3].split("S")[0] + "S" + str(
                                     correctTemperatureValue)
                             break
                         temp_index -= 1
             # Set back new corrected temperatures
             for index, layer in enumerate(self._gcode_list):
                 lines = layer.split("\n")
                 temp_index = 0
                 while temp_index < len(lines) and len(temperatures) > 0:
                     if index == temperatures[0][
                             0] and temp_index == temperatures[0][1]:
                         lines[temp_index] = temperatures[0][3]
                         del temperatures[0]
                     temp_index += 1
                 layer = "\n".join(lines)
                 self._gcode_list[index] = layer
         # Force standby temperature if it exceeds Minimal Time before first print of this hotend
         idleTime = 0
         lookingForIdleExtruder = True
         applied = False
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             if layer.startswith(";LAYER:"):
                 temp_index = 0
                 while not applied and temp_index < len(lines):
                     # look for the idle extruder at start
                     if lookingForIdleExtruder:
                         if lines[temp_index].startswith("T1"):
                             idleExtruder = 0
                             lookingForIdleExtruder = False
                         elif GCodeUtils.charsInLine(
                             ["G1", "F", "X", "Y", "E"], lines[temp_index]):
                             idleExtruder = 1
                             lookingForIdleExtruder = False
                     # once idle extruder is found, look when it enters
                     elif (idleExtruder == 0
                           and lines[temp_index].startswith("T0")) or (
                               idleExtruder == 1
                               and lines[temp_index].startswith("T1")):
                         # apply fix if needed
                         if layer.startswith(";LAYER:0"):
                             applied = True
                             break
                         else:
                             idleTime = float(
                                 lines[-2].split('TIME_ELAPSED:')[1])
                             if self._machineMinCoolHeatTimeWindow[
                                     idleExtruder] > 0 and idleTime >= self._machineMinCoolHeatTimeWindow[
                                         idleExtruder]:
                                 lines[temp_index] = "M109 T" + str(
                                     idleExtruder
                                 ) + " S" + str(
                                     self._materialPrintTemperatureLayer0[
                                         idleExtruder]
                                 ) + " ;T" + str(
                                     idleExtruder
                                 ) + " set to initial layer temperature\n" + lines[
                                     temp_index]
                                 applied = True
                     temp_index += 1
                 if applied:
                     if not layer.startswith(";LAYER:0"):
                         layer = "\n".join(lines)
                         self._gcode_list[index] = layer
                     break
         if applied and not layer.startswith(";LAYER:0"):
             for index, layer in enumerate(self._gcode_list):
                 if layer.startswith(";LAYER:"):
                     layer = "M104 T" + str(idleExtruder) + " S" + str(
                         self._materialStandByTemperature[idleExtruder]
                     ) + " ;T" + str(
                         idleExtruder
                     ) + " set to standby temperature\n" + layer
                     break
             self._gcode_list[index] = layer
         Logger.log("d", "fix_temperature_oscilation applied")
Exemple #9
0
 def _handleFixFirstRetract(self):
     if self._fixFirstRetract:
         self._startGcodeInfo.append("; - Fix First Extrusion")
         startGcodeCorrected = False
         usingT1 = False
         eValue = 0
         fixExtruder = "T0"
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             while temp_index < len(lines):
                 try:
                     line = lines[temp_index]
                     # Get retract value before starting the first layer
                     if not layer.startswith(";LAYER") and line.startswith(
                             "T1"):
                         lineCount = 0
                         while not lineCount > len(
                                 lines) - temp_index or lines[
                                     temp_index +
                                     lineCount].startswith("T0"):
                             line = lines[temp_index + lineCount]
                             if GCodeUtils.charsInLine(["G", "F", "E-"],
                                                       line):
                                 eValue = GCodeUtils.getValue(line, "E")
                             lineCount += 1
                         usingT1 = True
                     # Fix the thing
                     elif layer.startswith(";LAYER:") and usingT1:
                         line1 = lines[temp_index + 1]
                         line2 = lines[temp_index + 2]
                         line3 = lines[temp_index + 3]
                         line4 = lines[temp_index + 4]
                         line5 = lines[temp_index + 5]
                         # detect first tool printing and remove unintentional retract before T1
                         if temp_index == 0 and GCodeUtils.charsInLine(
                             ["G1 F", "E"], line1
                         ) and line2 == "G92 E0" and line4 == "T1" and line5 == "G92 E0":
                             del lines[temp_index + 1]
                             del lines[temp_index + 1]
                             temp_index -= 1
                             fixExtruder = "T1"
                         # Add proper prime command to T1
                         elif fixExtruder == "T0":
                             lineCount = 0
                             while not lines[temp_index +
                                             lineCount].startswith(";TYPE"):
                                 line = lines[temp_index + lineCount]
                                 if GCodeUtils.charsInLine(
                                     ["G0", "F", "X", "Y"], line):
                                     primeCommandLine = "G1 F" + self._retractionPrimeSpeed[
                                         0] + " E0\nG92 E0 ; T0fix"
                                     lines[
                                         temp_index + lineCount +
                                         1] = lines[
                                             temp_index + lineCount +
                                             1] + "\n" + primeCommandLine + "\n"
                                     if self._both_extruders:
                                         fixExtruder = "T1"
                                     else:
                                         fixExtruder = "none"
                                     break
                                 lineCount += 1
                             temp_index += lineCount
                         elif fixExtruder == "T1" and line == "T1" and line1 == "G92 E0" and line2 == "G91" and "G1 F" in line3 and line4 == "G90":
                             lineCount = 6  # According to extruder_start_gcode in Sigma Extruders definitions
                             while not lines[temp_index +
                                             lineCount].startswith(";TYPE"):
                                 line = lines[temp_index + lineCount]
                                 if GCodeUtils.charsInLine(
                                     ["G0", "F", "X", "Y"], line):
                                     if GCodeUtils.charsInLine(
                                         ["G1 F", " E"],
                                             lines[temp_index + lineCount +
                                                   1]):
                                         del lines[temp_index + lineCount +
                                                   1]
                                     primeCommandLine = "G1 F" + self._retractionPrimeSpeed[
                                         1] + " E" + str(abs(
                                             eValue)) + "\nG92 E0 ; T1fix"
                                     lines[
                                         temp_index + lineCount +
                                         1] = lines[
                                             temp_index + lineCount +
                                             1] + "\n" + primeCommandLine + "\n"
                                     break
                                 lineCount += 1
                         startGcodeCorrected = True
                     temp_index += 1
                 except:
                     break
             layer = "\n".join(lines)
             self._gcode_list[index] = layer
             if startGcodeCorrected:
                 break
         Logger.log("d", "fix_retract applied")
Exemple #10
0
 def _handleFixTemperatureOscilation(self):
     if self._fixTemperatureOscilation and self._both_extruders:
         self._startGcodeInfo.append("; - Fix Temperature Oscilation")
         # Scan all temperatures
         temperatures = []  # [(layerIndex, lineIndex, action, line)]
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             while temp_index < len(lines):
                 line = lines[temp_index]
                 if layer.startswith(";LAYER:"):
                     if line.startswith("M109"):
                         temperatures.append(
                             [index, temp_index, "heat", line])
                     elif line.startswith("T"):
                         temperatures.append(
                             [index, temp_index, "toolChange", line])
                     elif line.startswith("M104"):
                         if line.startswith("M104 T"):
                             temperatures.append(
                                 [index, temp_index, "preheat", line])
                         else:
                             temperatures.append(
                                 [index, temp_index, "unknown", line])
                 temp_index += 1
         # Define "unknown" roles
         for elementIndex in range(len(temperatures)):
             action = temperatures[elementIndex][2]
             if action == "unknown":
                 if elementIndex + 1 < len(temperatures):
                     if temperatures[elementIndex + 1][3].startswith("T"):
                         action = "coolDownActive"
                     else:
                         action = "setpoint"
                 temperatures[elementIndex][2] = action
             elif action == "preheat":
                 temp_index = elementIndex - 1
                 while temp_index >= 0 and temperatures[temp_index][
                         2] != "toolChange":
                     if temperatures[temp_index][2] == 'preheat':
                         action = "coolDownIdle"
                         temperatures[temp_index][2] = action
                         break
                     temp_index -= 1
         # Correct all temperatures
         countingForTool = 0
         for elementIndex in range(len(temperatures)):
             action = temperatures[elementIndex][2]
             if action == "toolChange":
                 if temperatures[elementIndex][3] == "T0":
                     countingForTool = 0
                 else:
                     countingForTool = 1
             temperature_inertia_initial_fix = self._materialInitialPrintTemperature[
                 countingForTool] - self._materialPrintTemperature[
                     countingForTool]
             temperature_inertia_final_fix = self._materialFinalPrintTemperature[
                 countingForTool] - self._materialPrintTemperature[
                     countingForTool]
             if action == "preheat":
                 temp_index = elementIndex + 1
                 toolChanged = False
                 while temp_index < len(temperatures):
                     if temperatures[temp_index][2] == "toolChange":
                         if toolChanged:
                             break
                         else:
                             toolChanged = True
                     elif temperatures[temp_index][2] == "heat":
                         heatIndex = temp_index
                     elif toolChanged and temperatures[temp_index][
                             2] == "setpoint":
                         correctTemperatureValue = GCodeUtils.getValue(
                             temperatures[temp_index][3],
                             "S") + temperature_inertia_initial_fix
                         temperatures[elementIndex][3] = temperatures[
                             elementIndex][3].split("S")[0] + "S" + str(
                                 correctTemperatureValue)
                         temperatures[heatIndex][3] = temperatures[
                             heatIndex][3].split("S")[0] + "S" + str(
                                 correctTemperatureValue)
                         break
                     temp_index += 1
             elif action == "coolDownIdle":
                 correctTemperatureValue = max(
                     GCodeUtils.getValue(temperatures[elementIndex][3], "S")
                     + temperature_inertia_initial_fix,
                     self._materialStandByTemperature[countingForTool])
                 temperatures[elementIndex][3] = temperatures[elementIndex][
                     3].split("S")[0] + "S" + str(correctTemperatureValue)
             elif action == "coolDownActive":
                 temp_index = elementIndex - 1
                 while temp_index >= 0:
                     if temperatures[temp_index][2] == "coolDownActive":
                         break
                     if temperatures[temp_index][2] == "setpoint":
                         correctTemperatureValue = GCodeUtils.getValue(
                             temperatures[temp_index][3],
                             "S") + temperature_inertia_final_fix
                         temperatures[elementIndex][3] = temperatures[
                             elementIndex][3].split("S")[0] + "S" + str(
                                 correctTemperatureValue)
                         break
                     temp_index -= 1
         # Set back new corrected temperatures
         for index, layer in enumerate(self._gcode_list):
             lines = layer.split("\n")
             temp_index = 0
             while temp_index < len(lines) and len(temperatures) > 0:
                 if index == temperatures[0][
                         0] and temp_index == temperatures[0][1]:
                     lines[temp_index] = temperatures[0][3]
                     del temperatures[0]
                 temp_index += 1
             layer = "\n".join(lines)
             self._gcode_list[index] = layer
         Logger.log("d", "fix_temperature_oscilation applied")