Jump to content
Ultimaker Community of 3D Printing Experts
  • Sign Up
shorai

Insert G-Code before layer change is at the wrong place

Recommended Posts

Posted · Insert G-Code before layer change is at the wrong place
G0 F2700 X4.099 Y17.534
M204 S3000
G1 F1500 X3.964 Y17.399 E2531.962
M204 S5000
;MESH:NONMESH
G0 F600 X3.964 Y17.399 Z0.65
G0 F2700 X234.18 Y18.18
G0 X234.25 Y18.25
;TIME_ELAPSED:5200.932078
G28
;LAYER:1
M140 S65
M106 S255
M204 S3000
;TYPE:WALL-INNER

I asked Cura to insert a G28 at each layer change. The above is the resulting code

 

As can be seen, the layer change happens just after the ;MESH;NOMESH comment

The G28 happens 4 lines later

The Layer thus prints at the home position (in my case free space)

 

On a big print and when calibrating a machine, it is useful to home perhaps every layer or ten.

Any misalignment can then be compensated for and a useful draft print be obtained.

 

The way the code is structured is also a bit misleading because the layer (Z) changes before the LAYER:nn comment

 

One cannot simply look for LAYER:nnn and restart at that command, one must look a few lines before to get the correct Z height

 

A better structure might be 

G0 F2700 X4.099 Y17.534
M204 S3000
G1 F1500 X3.964 Y17.399 E2531.962
M204 S5000

;TIME_ELAPSED:5200.932078

;LAYER:1
;  USER Process before layer change
G28
;MESH:NONMESH
G0 F600 X3.964 Y17.399 Z0.65
G0 F2700 X234.18 Y18.18
G0 X234.25 Y18.25

; USER Process After layer change
M140 S65
M106 S255
M204 S3000
;TYPE:WALL-INNER

 

It might also be useful to have macro substitutions e.g.

 

G0 $X $Y $Z

Also a READ Filament Position (E value) so that an appropriate G92 can be issued automatically 

Perhaps the simple insertion of a G92 at every layer change just after the LAYER:nnn comment to aid restarts

 

 

Share this post


Link to post
Share on other sites
Posted (edited) · Insert G-Code before layer change is at the wrong place

You have run into the problem that many have.  Gcode is a machine movement language, not a programming language.  You can use M114 to get the current location of all 4 axis (example response = X:95.52 Y:102.69 Z:1.40 E:489.90 Count X:7890 Y:8753 Z:566) but it would need to be parsed outside the Gcode to pull the E value out.

In your first code example, the G28 is at the end of layer 0.  The Z move just prior could be a Z hop, but the next two moves are non-extrusion moves.  You want the plug-in to notice that and put the G28 ahead of the non-extruding moves.  That would fix your problem, but for the next person it may not be true that the moves are non-extruding.

From the G28 Home position, the next Gcode line (in your file) must be an extrusion line.  You would need to pull out the XY position and return the head there before allowing that extrusion line to run.  Right now, it is being told to extrude from Home to whatever the next defined position is in the Gcode.  What it expects, is to be at the previous XY of 234.25, 18.25.

Some machines support G60 (save position) and G61 (return to saved position).  You might be able to incorporate them into your code.  Something like...

G60 S0

G28

G61 S0

The Marlin firmware in my machine doesn't support G60 or G61.  I have no intention of fooling with it even though from time to time it would be useful.

Edited by GregValiant

Share this post


Link to post
Share on other sites
Posted · Insert G-Code before layer change is at the wrong place

Hi @Greg Valliant.

I agreee that gcodeis not a programming language, however CURA is a g-code generator and has access to all this at the time it slices and generates the g-code. I was hinting at a macro in CURa not g-code.

 

On point 2. The Z move just prior to the G28 is in fact the layer change .... there is no further Z axix move till the end of the layer being started.

 

 My issue is with the Z layer change move being performed within the previous block and before the inserted G28 which is ssupposed to be BEFORE the layer change so that the layer change Z move will restore the machine to the correct Z level.

 

The CURA option supposedly lets me put commands in either before or after a layer change. This is clearly not happening. 

Share this post


Link to post
Share on other sites
Posted · Insert G-Code before layer change is at the wrong place

The plugin keys on the term ";layer:" rather than the Z height.  From it's point of view it does work at Layer change.  The question would seem to be why is the ;layer: comment where it is instead of at the Z change.

I agree plugins are macros.  Something similar to what you want is done by the Pause at Height plugin.  It checks the previous X Y Z E and restores them after the pause.  I played with that for a minute and it generated this code in the file:

 

G1 F2700 E942.81886 ; A retraction
G1 F300 Z0.7 ; A Z-Hop

;MESH:NONMESH
G0 F7500 X126.647 Y80.826 Z0.7
G0 X129.221 Y79.165
;TIME_ELAPSED:634.017759
;TYPE:CUSTOM
;added code by post processing
;script: PauseAtHeight.py
;current layer: 1
M83 ; switch to relative E values for any needed retraction
G1 F300 Z1.7 ; move up a millimeter to get out of the way
G1 F9000 X190 Y190 ;This parks the head - you could throw this out
G1 F300 Z15 ; too close to bed--move to at least 15mm
M104 S205 ; standby temperature
M0 ; Do the actual pause ;If this was G28 I think it would work as you want.
M109 S205 ; resume temperature
G1 F300 Z1.7
G1 F9000 X129.221 Y79.165 ;Move back to re-start X Y
G1 F300 Z0.7 ; move back down to the resume Z-hop height
G1 F2700 ; restore extrusion feedrate
M82 ; switch back to absolute E values
G92 E942.81886 ; Extruder reset
;LAYER:1
M140 S50
M106 S42.5
G0 X129.221 Y79.165 Z0.9
;TYPE:SUPPORT
G1 F300 Z0.4
G1 F2700 E948.81886

I understand what you want to do and yes, the plugins are essentially macros.  If someone was to take the Pause at Height code and loop through it NumberOfLayers times then a couple of minor changes and you would have it.  Unfortunately (I think) it would be specific to the G28 command and that probably makes it a one-off custom routine.

Maybe one of the Ultimaker folk will chime in with an opinion.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...