Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start code does not represent actual start code #13943

Open
2 tasks
kandrejevs2 opened this issue Dec 1, 2022 · 14 comments
Open
2 tasks

Start code does not represent actual start code #13943

kandrejevs2 opened this issue Dec 1, 2022 · 14 comments
Labels
Type: Discussion Open-ended discussion (compared to specific question).

Comments

@kandrejevs2
Copy link

Application Version

5.2.1

Platform

Linux ubuntu

Printer

Creality ender 3 v2 neo

Reproduction steps

  1. go to manage printers -> machine settings
    there is printer start g-code section

  2. slice the model and view the exported Gcode- more code is added to beginning of the file before start code

basically my issue is that after printer does auto bed leveling the nozzle touches the bed as last step of G29 command. since cura have injected gcode before my start code to heat the bed and the nozzle to the printing temperatures and it causes oozing and a booger of filament is wiped in the center of build plate as last step of ABL routine before priming the nozzle.

to prevent this, code that is injected by cura like:

M104 S215
M105
M109 S215

and other lines should be part of actual start code so the user could modify order of execution and fine tune behavior.

Actual results

printer start Gcode

; Ender 3 Custom Start G-code
G92 E0 ; Reset Extruder
G28 ; Home all axes
G29 ; Auto bed leveling
G1 Z0.3 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X5 Y20 Z0.3 F5000.0 ; Move over to prevent blob squish

Gcode generated by cura

;FLAVOR:Marlin
;TIME:1780
;Filament used: 5.03382m
;Layer height: 0.32
;MINX:89.49
;MINY:89.54
;MINZ:0.32
;MAXX:130.41
;MAXY:130.46
;MAXZ:45.44
;Generated with Cura_SteamEngine 5.2.1
M140 S60
M105
M190 S60
M104 S215
M105
M109 S215
M82 ;absolute extrusion mode
; Ender 3 Custom Start G-code
G92 E0 ; Reset Extruder
G28 ; Home all axes
G29 ; Auto bed leveling
G1 Z50 F240 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y10 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X5 Y20 Z0.3 F5000.0 ; Move over to prevent blob squish
G92 E0
G92 E0
G1 F2700 E-5
;LAYER_COUNT:142
;LAYER:0

Expected results

I would expect that start code is the actual start code of the printer and nothing is added to it before.

Checklist of files to include

  • Log file
  • Project file

Additional information & file uploads

otherwise my solution is either to try to clean the booger of the plate while printer does nozzle priming line or I have to modify start code to cancel out preheating right after it has been heated, do the ABL routine and turn back on nozzle heating which adds significant delay to print time.

@kandrejevs2 kandrejevs2 added Status: Triage This ticket requires input from someone of the Cura team Type: Bug The code does not produce the intended behavior. labels Dec 1, 2022
@GregValiant GregValiant added Type: Discussion Open-ended discussion (compared to specific question). and removed Type: Bug The code does not produce the intended behavior. Status: Triage This ticket requires input from someone of the Cura team labels Dec 1, 2022
@GregValiant
Copy link
Collaborator

GregValiant commented Dec 1, 2022

Thanks for the report.
This is expected behavior. That is the stock Ender 3 StartUp Gcode and it's provided via the Printer Definition file that was submitted to UltiMaker by Creality (or a contributor) for inclusion in Cura.

If there is no mention of temperatures in the StartUp Gcode then Cura adds temperature lines before the StartUp is inserted. It is a safety to prevent cold extrusions. You need to make an adjustment to your StartUp Gcode.
I've highlighted the main changes. You can copy and paste this into your Machine Settings. The curly brackets around the keywords like {material_bed_temperature_layer_0} are required so Cura will know to replace the keywords with the actual numbers when the gcode is created. I've added beginning and ending semi-colons so it's easier to read in the gcode file.

;
; Ender 3 Custom Start G-code
;
G21 ;Metric units
M82 ;Absolute extrusion mode
G90 ;Absolute movement mode
M220 S100 ;reset feed rate
M221 S100 ;reset flow rate

G92 E0 ; Reset Extruder
G28 ;Home all axes
G0 F600 Z5 ;Move up
M104 S160 ;Warm up the hot end to below ooze temp
M190 S{material_bed_temperature_layer_0} ;Heat the bed to the Initial Layer temperature and wait for it.

G29 ; Auto bed leveling
G0 F600 Z10 ;Make sure the nozzle is up off the bed.
G0 F4500 X0 Y0 ;Move to the left from corner
M105 ;report temperatures
M109 S{material_print_temperature_layer_0} ;Heat the hot end to the Initial Layer Print Temperature.

G0 X0.1 Y25 Z0.3 F5000.0 ; Move to start position
G1 F1500 E2 ;Short prime
G1 F1500 X0.1 Y200.0 E15 ; Draw the first purge line
G0 F5000 X3.0 Y200.0 ; Move to side a little
G1 X3.0 Y25 Z0.3 F1500.0 E30 ; Draw the second purge line
G92 E0 ; Reset Extruder
G1 F1500 E-2 ;short retraction
G92 E0 ;Rest Extruder
G1 F600 Z15 ; Move Z Axis up
G4 S1 ;Wait for one second for the string to harden
G0 X3.0 Y35 Z0.35 F5000.0 ; Move to wipe start
G0 F3600 X3.0 Y50 ;Wipe the booger off on the purge line
G1 F600 Z2 ;Move up for print start

;
; End of StartUp Gcode
;

I'll remove the "Bug" label as what you have there is what was provided by Creality (or a contributor). It would work fine if you didn't have ABL. With ABL it does need to be tweaked.

@kandrejevs2
Copy link
Author

wouldn't it make more sense to add this code in printer start code dialog rather than just silently adding "pre-start code we though you are forgetting, but we won't ask if it is really what you want" 😃

@GregValiant
Copy link
Collaborator

GregValiant commented Dec 1, 2022

Most people don't know enough about Gcode to make their own changes. They would just dismiss the dialog. Plus, the dialog would come up a lot and be really annoying. Better to just learn the software (and gcode). Competence is the best solution.
And remember that when you install a printer it does show the Machine Settings dialog and the startup gcode.

@kandrejevs2
Copy link
Author

I meant adding heating commands to manage printers -> machine settings -> start G-code dialog and for example indicate error if it lacks temperature commands.
it is already pre-populated with G28 and nozzle priming among other things, might as well add temperatures there rather than having undocumented behaviour that adds more code before it if it doesn't meet certain criteria.

image

@GregValiant
Copy link
Collaborator

If you will install an Ender 3 Pro you will see that the StartUp gcode is written that way.
Ultimaker has no idea what the requirements of other manufacturers printers might be. That can't go out and buy one of every printer out there to test them.
The stock Ender 3 StartUp Gcode has extrusions in it for the purge lines. I think they were counting on Cura adding the temperature lines so they didn't cause cold extrusions.

@fieldOfView
Copy link
Collaborator

The "historical" reason why it is done like it is now is that the heatup sequence is added by CuraEngine (the actual slicer that does the work), and CuraEngine can also be used without the Cura frontend.

I think it would be a good idea to have the Cura dialog detect the absence of a heatup sequence and add a note that a heatup sequence will be added. Then again, that dialog is very cramped to begin with, so I think the gcode snippets should be moved somewhere else (a tabof their own?)

@GregValiant
Copy link
Collaborator

Separate tabs for StartUp Gcode and Ending Gcode could work. When switching to the "StartUp Gcode" tab a check could be run to see if heating commands are in there. If there are none then a popup could inform the user that heating lines will be added prior to the StartUp. With the expanding use of ABL systems it could be helpful. Adding two more tabs might make it a bit more cluttered on a multi-extruder printer though.
@fieldOfView Do we have a possible feature request here?

@JohnScottUK
Copy link

JohnScottUK commented Jan 30, 2023

I get the cold extrusion protection. You should be looking for M104/M140 and M109/M190. That does not explain the spurious M82. Why does Cura add this?

M82 ;absolute extrusion mode

before the custom start code. That looks dangerous. You should have that after custom code or M83 if the relative option is check in printer settings. If I use M83 in custom code and don't set it back, does Cura realise?

A bit of investigation (not knowing the software), I find https://github.com/Ultimaker/CuraEngine/blob/cc03a5711c1a28e91cd48c1ffef19dba852b4ca1/src/gcodeExport.cpp#L1018 might be the cause.

It seems to say "ensure absolute extrusion mode" when entering start gcode, but then only sets relative if it is selected. Maybe it should set absolute on entering (which can be reset) and then ensures either relative/absolute as you won't know what mode the custom start gcode left it in.

This particular element is nothing to do with printer profiles - but coding in CuraEngine.

@GregValiant
Copy link
Collaborator

M83 ;last line of starting gcode
;
;End of StartUp
;
M83 ;relative extrusion mode > first line after starting gcode

That line is always inserted when in relative mode regardless of what came before.
Using that same startup gcode then when using "Absolute Extrusion" an M82 is not added and so the print would start with Absolute E values but in Relative Mode at the printer.
BUT as a user I had inserted that line in my StartUp and explicitly stated that I want Relative Extrusion. Personally I am not fond of software that makes decisions for me and I would view it as my fault if the print was a mess.

@JohnScottUK
Copy link

JohnScottUK commented Jan 30, 2023

That line is always inserted when in relative mode regardless of what came before.

Not with Cura 5.2.2. Steps to reproduce (Note this is from Cura 5.2.2, but the root cause is CuraEngine):

Set your custom gcode:

; === BEGIN CUSTOM START GCODE ===
M140 S{material_bed_temperature_layer_0}
M104 S{material_print_temperature_layer_0}

M190 S{material_bed_temperature_layer_0}
M109 S{material_print_temperature_layer_0}

G28
M83; === USE RELATIVE EXTRUSION ===
; ... Insert whatever pre-print gcode you need - like purge lines or whatever

=== END CUSTOM START GCODE ===

Slice and check generated gcode:

;FLAVOR:Marlin
;TIME:1501
;Filament used: 1.01495m
;Layer height: 0.2
;MINX:89
;MINY:89
;MINZ:0.2
;MAXX:131
;MAXY:131
;MAXZ:20
;Generated with Cura_SteamEngine 5.2.2
M82 ;absolute extrusion mode
; === BEGIN CUSTOM START GCODE ===
M140 S60
M104 S205.0

M190 S60
M109 S205.0

G28
M83; === USE RELATIVE EXTRUSION ===

=== END CUSTOM START GCODE ===

G92 E0
G92 E0
G1 F2400 E-0.8
;LAYER_COUNT:100
;LAYER:0
M107
G0 F6000 X92.198 Y92.264 Z0.2
;TYPE:SKIRT
G1 F2400 E0
G1 F1200 X92.886 Y91.627 E0.03119
G1 X93.626 Y91.051 E0.06237
G1 X94.412 Y90.539 E0.09357
G1 X95.239 Y90.097 E0.12476
G1 X96.101 Y89.727 E0.15596
G1 X96.991 Y89.431 E0.18716
G1 X97.903 Y89.213 E0.21835
G1 X98.83 Y89.072 E0.24953
G1 X99.701 Y89.013 E0.27857
G1 X100.33 Y89 E0.29949
...

Note the M82 before custom gcode, the M83 relative extrusion within the cusom gcode and no M82 after custom gcode.

Extrusion mode is left as relative but E values generated indicate absolute.

@JohnScottUK
Copy link

JohnScottUK commented Jan 30, 2023

BUT as a user I had inserted that line in my StartUp and explicitly stated that I want Relative Extrusion. Personally I am not fond of software that makes decisions for me and I would view it as my fault if the print was a mess.

But as a user, I would expect some signal that something may appear before my start gcode and that CuraEngine not assume I have not chosen a local extrusion/coordinate movement for my start gcode purposes.

Would seem reasonable to G90 before custom start code and then either M82/M83 based on what extrusion mode it requires after so you're not dependent on an assumption.

Or even better, not put any "pre-start" statements before the "start" statements - making my custom "start" code be at the "start", instead of "not quite the start". Then add code after if required (like G90, M82 if relative extrusion and M140&M190 to ensure print-start temps.

@kandrejevs2
Copy link
Author

kandrejevs2 commented Jan 30, 2023

I kind of agree with both of your views. in current state this management is just a mess. you have some validations, some assumptions that are silently injected at the very beginning which can be then dismissed by user error or otherwise, but in some cases you can't make printer do what you want because there are some undocumented protections going on.

regarding absolute/relative movements and extrusions, that should be part of actual g code and not rely on assumption it is not changed, but otherwise software should not interfere if user f**ks around he should be able to find out.

@GregValiant
Copy link
Collaborator

GregValiant commented Jan 30, 2023

I just sliced this with 5.2.2. Someone from the Cura team will take a look.
;Generated with Cura_SteamEngine 5.2.2
M82 ;absolute extrusion mode
;
; Greg's E3Pro StartUp
;
G90
G21
M82 ;This is in my startup because my purge lines are in Absolute.
blah, blah
M83 ;I added this just to demonstrate
;
;End of StartUp
;
M83 ;relative extrusion mode >Cura put this one in
G1 F2100 E-6
;LAYER_COUNT:250
;LAYER:0

@JohnScottUK
Copy link

JohnScottUK commented Jan 31, 2023

I just sliced this with 5.2.2. Someone from the Cura team will take a look.

Having two M83 when Cura generates relative extrusion isn't really a problem. Cura wants relative extrusion and asked for it when it was set by custom gcode. For example, there's plenty of redundant G92 E0 reset extruders statements in the file that have no effect.

The real problem is if my custom gcode leaves the machine in relative extrusion and CuraEngine does not reset it back to absolute gcode, but then proceeds to export gcode statements using absolute extrusion E values (because relative extrusion has not been requested).

What should be expected is that after custom gcode, CuraEngine adds either M82/M83 to ensure the extrusion mode is as expected by the rest of the gcode. So it should say:

;
;End of StartUp
;
M82 ;absolute extrusion mode >Cura put this one in
G1 F2100 E-6
;LAYER_COUNT:250
;LAYER:0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Discussion Open-ended discussion (compared to specific question).
Projects
None yet
Development

No branches or pull requests

4 participants