Skip to content

Commit

Permalink
Merge pull request #31 from kartchnb/print-setting-correction-improve…
Browse files Browse the repository at this point in the history
…ments

Print setting correction improvements
  • Loading branch information
kartchnb authored Nov 10, 2022
2 parents 2b29c25 + 560d907 commit 198c9b5
Show file tree
Hide file tree
Showing 8 changed files with 27,156 additions and 21,497 deletions.
1 change: 0 additions & 1 deletion Controllers/ControllerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def correctPrintProperties(self)->None:
''' Correct property settings that are incompatible with this controller '''

globalContainerStack = Application.getInstance().getGlobalContainerStack()
log = ''
message = ''

# Iterate over each setting in the critical settings table
Expand Down
26 changes: 13 additions & 13 deletions Controllers/SpeedTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .ControllerBase import ControllerBase

# Import the scripts that do the actual post-processing
from ..Postprocessing import TravelSpeedTower_PostProcessing
from ..Postprocessing import PrintSpeedTower_PostProcessing
from ..Postprocessing import MiscSpeedTower_PostProcessing


Expand All @@ -25,25 +25,25 @@ class SpeedTowerController(ControllerBase):
_qmlFilename = 'SpeedTowerDialog.qml'

_presetsTable = {
'Travel Speed 20-100': {
'filename': 'speedtower travel speed 20-100.stl',
'Print Speed 20-100': {
'filename': 'speedtower print speed 20-100.stl',
'start value': 20,
'change value': 20,
'tower type': 'Travel Speed'
'tower type': 'Print Speed'
},

'Travel Speed 50-150': {
'filename': 'speedtower travel speed 50-150.stl',
'Print Speed 50-150': {
'filename': 'speedtower print speed 50-150.stl',
'start value': 50,
'change value': 20,
'tower type': 'Travel Speed'
'tower type': 'Print Speed'
},

'Travel Speed 100-200': {
'filename': 'speedtower travel speed 100-200.stl',
'Print Speed 100-200': {
'filename': 'speedtower print speed 100-200.stl',
'start value': 100,
'change value': 20,
'tower type': 'Travel Speed'
'tower type': 'Print Speed'
},
}

Expand All @@ -54,7 +54,7 @@ class SpeedTowerController(ControllerBase):
}

_towerTypesModel = [
{'value': 'Travel Speed', 'label': 'TRAVEL SPEED'},
{'value': 'Print Speed', 'label': 'PRINT SPEED'},
{'value': 'Acceleration', 'label': 'ACCELERATION'},
{'value': 'Jerk', 'label': 'JERK'},
{'value': 'Junction', 'label': 'JUNCTION'},
Expand Down Expand Up @@ -278,10 +278,10 @@ def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
if self._towerType == 'Travel Speed':
if self._towerType == 'Print Speed':
# Query the current print speed
currentPrintSpeed = Application.getInstance().getGlobalContainerStack().getProperty('speed_print', 'value')
gcode = TravelSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, currentPrintSpeed, displayOnLcd)
gcode = PrintSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, currentPrintSpeed, displayOnLcd)
else:
gcode = MiscSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, self._towerType, displayOnLcd)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This script modifies the printing travel speed for a travel speed tower
# This script modifies the printing speed for a print speed tower
#
# Cura does not use a single "print speed" when slicing a model, but uses
# different values for infill, inner walls, outer walls, etc.
Expand All @@ -7,34 +7,39 @@
# for each speed.
#
# Version 1.0 - 29 Sep 2022:
# Split off from MiscSpeedTower_PostProcessing to focus exclusively on travel speed towers
#
# Split off from MiscSpeedTower_PostProcessing to focus exclusively on print speed towers
# Version 1.1 - 05 Nov 2022:
# Renamed from TravelSpeedTower_PostProcessing.py to PrintSpeedTower_PostProcessing.py
# to better match what it actually does
# Version 1.2 - 05 Nov 2022:
# Fixed an issue with recognizing decimal speeds in gcode
# Now only displaying LCD messages for the nominal speed for each layer

import re

from UM.Logger import Logger

__version__ = '1.0'
__version__ = '1.2'



def is_travel_speed_line(line: str) -> bool:
''' Check if a given line changes the travel speed '''
def is_print_speed_line(line: str) -> bool:
''' Check if a given line changes the print speed '''
return (line.strip().startswith('G0') or line.strip().startswith('G1')) and 'F' in line



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, referenceSpeed, displayOnLcd):
''' Post-process gcode sliced by Cura
startValue = the starting travel speed (mm/s)
valueChange = the amount to change the travel speed for each section (mm/s)
startValue = the starting print speed (mm/s)
valueChange = the amount to change the print speed for each section (mm/s)
sectionLayers = the number of layers in each tower section
baseLayers = the number of layers that make up the base of the tower
referenceSpeed = the print speed selection when the gcode was generated
This value is used to determine how travel speed settings in the
This value is used to determine how print speed settings in the
gcode are modified for each level '''

Logger.log('d', 'AutoTowersGenerator beginning SpeedTower (Travel Speed) post-processing')
Logger.log('d', 'AutoTowersGenerator beginning SpeedTower (Print Speed) post-processing')
Logger.log('d', f'Starting speed = {startValue}')
Logger.log('d', f'Speed change = {valueChange}')
Logger.log('d', f'Reference speed = {referenceSpeed}')
Expand All @@ -43,7 +48,7 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, reference
Logger.log('d', f'Reference Speed = {referenceSpeed}')

# Document the settings in the g-code
gcode[0] = gcode[0] + f';SpeedTower (Travel Speed) start speed = {startValue}, speed change = {valueChange}, reference speed = {referenceSpeed}\n'
gcode[0] = gcode[0] + f';SpeedTower (Print Speed) start speed = {startValue}, speed change = {valueChange}, reference speed = {referenceSpeed}\n'

# The number of base layers needs to be modified to take into account the numbering offset in the g-code
# Layer index 0 is the bed adhesion code (skirt, brim, etc)
Expand All @@ -66,13 +71,15 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, reference

# Iterate over each command line in the layer
lines = layer.split('\n')
if displayOnLcd:
lines.insert(0, f'M117 SPD {currentValue:.1f}mm/s ;AutoTowersGenerator added')
for line in lines:
lineIndex = lines.index(line)

# Modify lines specifying travel speed
if is_travel_speed_line(line):
# Modify lines specifying print speed
if is_print_speed_line(line):
# Determine the old speed setting in the gcode
oldSpeedResult = re.search(r'F(\d+)', line.split(';')[0])
oldSpeedResult = re.search(r'F(\d+(?:\.\d*)?)', line.split(';')[0])
if oldSpeedResult:
oldSpeedString = oldSpeedResult.group(1)
oldSpeed = float(oldSpeedString)
Expand All @@ -85,18 +92,15 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, reference
# Change the speed in the gcode
if f'{oldSpeed:.1f}' != f'{newSpeed:.1f}':
# Change the speed for this line
new_line = line.replace(f'F{oldSpeedString}', f'F{newSpeed:.1f}') + f' ; AutoTowersGenerator changing speed from {(oldSpeed/60):.1f}mm/s ({oldSpeed:.1f}mm/m) to {(newSpeed/60):.1f}mm/s ({newSpeed:.1f}mm/m)'
new_line = line.replace(f'F{oldSpeedString}', f'F{newSpeed:.1f}') + f' ;AutoTowersGenerator changing speed from {(oldSpeed/60):.1f}mm/s ({oldSpeed:.1f}mm/m) to {(newSpeed/60):.1f}mm/s ({newSpeed:.1f}mm/m)'
else:
new_line = line + f' ; AutoTowersGenerator speed is already at desired {(oldSpeed/60):.1f}mm/s ({oldSpeed:.1f}mm/m)'
new_line = line + f' ;AutoTowersGenerator speed is already at desired {(oldSpeed/60):.1f}mm/s ({oldSpeed:.1f}mm/m)'

lines[lineIndex] = new_line

if displayOnLcd:
lines.insert(lineIndex + 1, f'M117 Speed {(newSpeed/60):.1f}mm/s ; AutoTowersGenerator added')

result = '\n'.join(lines)
gcode[layerIndex] = result

Logger.log('d', f'AutoTowersGenerator completing SpeedTower post-processing (Travel Speed)')
Logger.log('d', f'AutoTowersGenerator completing SpeedTower post-processing (Print Speed)')

return gcode
12 changes: 6 additions & 6 deletions Resources/OpenScad/speedtower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parameterSets": {
"travel speed 20-100": {
"print speed 20-100": {
"Base_Height": "0.8",
"Ending_Value": "100",
"Font": "Arial:style=Bold",
Expand All @@ -22,12 +22,12 @@
"Starting_Value": "20",
"Temperature_Label": "",
"Temperature_Label_Height_Multiplier": "0.3",
"Tower_Label": "TRAVEL SPEED",
"Tower_Label": "PRINT SPEED",
"Tower_Label_Height_Multiplier": "0.6",
"Value_Change": "20",
"Wall_Thickness": "0.6"
},
"travel speed 50-150": {
"print speed 50-150": {
"Base_Height": "0.8",
"Ending_Value": "150",
"Font": "Arial:style=Bold",
Expand All @@ -49,12 +49,12 @@
"Starting_Value": "50",
"Temperature_Label": "",
"Temperature_Label_Height_Multiplier": "0.3",
"Tower_Label": "TRAVEL SPEED",
"Tower_Label": "PRINT SPEED",
"Tower_Label_Height_Multiplier": "0.6",
"Value_Change": "20",
"Wall_Thickness": "0.6"
},
"travel speed 100-200": {
"print speed 100-200": {
"Base_Height": "0.8",
"Ending_Value": "200",
"Font": "Arial:style=Bold",
Expand All @@ -76,7 +76,7 @@
"Starting_Value": "100",
"Temperature_Label": "",
"Temperature_Label_Height_Multiplier": "0.3",
"Tower_Label": "TRAVEL SPEED",
"Tower_Label": "PRINT SPEED",
"Tower_Label_Height_Multiplier": "0.6",
"Value_Change": "20",
"Wall_Thickness": "0.6"
Expand Down
2 changes: 1 addition & 1 deletion Resources/QML/QT6/SpeedTowerDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ UM.Dialog
}
UM.ToolTip
{
text: "The type of speed to vary across the tower.<p>\"Travel Speed\" towers change the speed at which the nozzle moves while printing (equivalent to Cura's \"print speed\" setting).<p>\"Acceleration\" changes how fast the nozzle accelerates during printing.<p>The other towers are more specialized."
text: "The type of speed to vary across the tower.<p>\"Print Speed\" towers change the speed at which the nozzle moves while printing (equivalent to Cura's \"print speed\" setting).<p>\"Acceleration\" changes how fast the nozzle accelerates during printing.<p>The other towers are more specialized."
visible: tower_type_mouse_area.containsMouse
}

Expand Down
Loading

0 comments on commit 198c9b5

Please sign in to comment.