Add Post Processing script to set initial extruder offset
Description
This post processing script sets multi-extruder printers' initial extruder positions to the correct value after retracting the filament during start G-code.
-
Before priming a nozzle at the beginning of the print, the position of the filament in the nozzle is unknown but assumed to be between
switch_extruder_retraction_amountand0because the filament may have been retracted the extendedswitch_extruder_retraction_amountlength at the end of the last print (or not). When a print is started and the filament position is assumed to be 0 (at the nozzle already) no/underextrusion occurs forswitch_extruder_retraction_amountdistance of filament because the slicer assumes the printer is extruding filament when the filament is still moving down the heatbreak towards the nozzle. -
Normally multiple nozzles on a multi-extruder printer are primed by extruding some filament during the start g-code to ensure the filament is at a known position in the extrusion train. E.g. Prime by
switch_extruder_retraction_amount+ a bit more. -
When the printer has more than a single nozzle, the extruders that are NOT the
initial_extruder_nrneed to be retracted byswitch_extruder_retraction_amountafter priming to avoid oozing. -
After start G-code ends and the printing starts, the slicer assumes that each extruder starts from
0position rather than -switch_extruder_retraction_amount. When switching to each extruder for the first time, the extruder printing movements start with E position of0leading to no extrusion for a while until the filament moves down the heatbreak into the nozzle. -
The slicer remembers the extruder position when it generates code to retract the extruder by
switch_extruder_retraction_amountwhen the extruder is switched away from in the toolchange and restores the extruder position by moving the filament forward byswitch_extruder_retraction_amountdistance when the extruder is switched to in a toolchange. So this no/under extrusion problem only happens on the first toolchange until the extruder has extruded at leastswitch_extruder_retraction_amountmm of filament.
I fixed this issue by creating the post processing script to set the correct position for the extruder to -switch_extruder_retraction_amount for the first time each extruder is used. G92 E0 is corrected to G92 E-16 (if the printer had a switch_extruder_retraction_amount of 16).
I drew the below diagram to visually show the extruder position problem.
Another solution for this problem would be if Cura assumes that each extruder has been retracted to switch_extruder_retraction_amount distance at the end of the start G-code and starts each extruder's initial position at the start of the print G-code to -switch_extruder_retraction_amount instead of 0.
Type of change
- [ X] New feature (non-breaking change which adds functionality)
How Has This Been Tested?
I have run this post processing script on multiple prints and extrusion is improved due to setting extruder position to the correct value. No oozing occurs after priming because the extruder retracts filament by switch_extruder_retraction_amount in start G-code and extrusion begins immediately when the slicer switches to that extruder.
Test Configuration:
- Operating System: Win10
Checklist:
- [X] My code follows the style guidelines of this project as described in UltiMaker Meta and Cura QML best practices
- [X] I have read the Contribution guide
- [X] I have commented my code, particularly in hard-to-understand areas
- [X] I have uploaded any files required to test this change