M400 causes pause and laser burn

Basic Information:

Printer Model: 3018 style CNC
MCU / Printerboard: BTT SKR Pico

Running Klipper and klippy latest master from git.

I’m using FlatCAM to generate Marlin-style gcode for laser burning. The problem is that it uses code like:

...
G1 X0.1394 Y23.6553 F500.00
G1 X0.1371 Y23.6446 F500.00
G1 X0.1360 Y23.6364 F500.00
M400
M5
G0 X0.0912 Y23.6407 F1500.00
G1 F100.00
M3 S10.0
G1 F500.00
G1 X0.0905 Y23.6255 F500.00
G1 X0.0905 Y15.7484 F500.00
...

In GRBL the M400 finishes all the movement then immediately moves on to the M5 that shuts the laser off. In Klipper the M400 stalls with no movement and the laser is still on. After the short pause it continues to the M5 and etc. That pause causes the laser to burn more than it should. This is no good.

Is this possibly a problem similar to the old issue of Klipper needing 100ms to perform commands?

I haven’t tried moving the M5 to before the M400. Maybe? I might need to write a new gcode generator specifically for Klipper but that is going to get old if I have to do it for all the applications I use.

Yes I understand CNC/Laser is not Klipper’s forte. Lets try to fix that. Or maybe I’m doing something wrong.

Sometimes it takes some time until someone might help you. :wink:
Why then delete everything?
We are all doing that for free in our free time so you can’t expect to get an answer right a minute after your post.

On Klipper the M400 should empty the command queue and wait until the movements and everything is being processed.
Maybe this somehow works a bit different to the way Marlin does it hence having some time between the last move and the next command.
Even though the M400 has its right to exist, what happens without it?

1 Like

I don’t know if I would call 10 days “a minute” but OK. :slight_smile:

I didn’t see the CNC thread before I posted this so I thought maybe there was some anti-CNC-Klipper rules or something I didn’t know about. I wanted to delete the thread and repost in the CNC thread but couldn’t.

In any case, right after I posted this I did the experiments I was planning and found simply removing the M400 “fixes” it. I’m still curious as to why M400 would pause for so long though. If Klipper doesn’t need it then I would think it could just skip over the command entirely unless there is some possibility of timing issues or who knows what. I’m guessing this is a thing on Marlin where it might execute something out of order if M400 isn’t used.

Anyway, I’m doing post-processing on the gcode for now to get it working with Klipper and that seems OK so that’s why I never posted again. Thanks!