GCode macro not executed at the end of the job

Basic Information:

Printer Model: Fabtotum Personal Fabricator
MCU / Printerboard: Totumduino (ramps like ATMega1280 based)
Host / SBC: Raspberry Pi
klippy.log

Describe your issue:

My printer is configured to be used with a laser head. I’ve written macros to run on the beginning and the end of the job. For gcode creation LaserWeb4 is used. I’ve added the macro names into the appropriate gcode sections there. Looking at the generated gcode file, the Macros are inserted.

However at the end of the job the macro is not executed. Before I created the macros the same code written directly into the Laserweb4 settings performed just fine. Any tipps what could cause this?
klippy(1).log (1.5 MB)

When simulated in Klipper it works as expected:

  1. run “START_LASER”
  2. Manually move head using the jog-menu
  3. run “END_LASER” → head returns to previous zero point (set with G92).
[gcode_macro START_LASER]
gcode:
    M5            ; Disable Laser
    G21           ; Set units to mm
    G90           ; Absolute positioning
    G0 F10000   ; Set Non-Cutting speed
    SAVE_GCODE_STATE NAME=GCODE_STATE_LASER
    G92 X0 Y0 Z0  ;Set current position as zero


[gcode_macro END_LASER]
gcode:
    M5            ; Disable Laser
    G91           ; relative
    G0 Z+20 F3000 ;
    G90           ; absolute
    G0 X0 Y0      ; Home to Starting point
    RESTORE_GCODE_STATE NAME=GCODE_STATE_LASER

Hi @groomit ,

I don’t see anything immediately wrong with your log/config. Could you please upload a G-Code file so I can look over it?

1 Like

Sure. Here it is. Thank you for taking the time!
example.gcode (776.9 KB)

1 Like

Thank you for uploading the G-Code. Could you add some simple logging in your END_LASER macro, like this:

[gcode_macro END_LASER]
gcode:
    RESPOND MSG="Disabling laser"
    M5            ; Disable Laser
    G91           ; relative
    RESPOND MSG="Moving Z up"
    G0 Z+20 F3000 ;
    G90           ; absolute
    RESPOND MSG="Homing"
    G0 X0 Y0      ; Home to Starting point
    RESPOND MSG="Restoring G-Code state"
    RESTORE_GCODE_STATE NAME=GCODE_STATE_LASER

then test with a laser job and let me know what happens?

1 Like

Most probably your RESTORE_GCODE_STATE is missing additional option
MOVE=1

Read carefully restore_gcode_state documentation

1 Like

Unfortunately no change. Where should the logging appear? It didn’t show in the console window. Nor could I find it in the klippy log. Maybe you can see more?

@gaolst
Thanks for your suggestion. Tried with MOVE=1 as well. But no luck :frowning:

klippy(2).log (2.4 MB)

Try to add additional empty new line after “END_LASER” in your GCode, it’s possible that “END_LASER” command is ignored because it don’t have “Line Feed” or “Carriage Return” in the end of command.

from you GCode file

3 Likes

YES! Thank you this has solved it. Just added an additional comment Line after the macro.

I’d think this is a pretty common source of error. Maybe the klipper gcode parser should be able to handle this. Or is there a reason for this behavior?

1 Like