GRBL postprocessor --return-to generates code after M2

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
hohoho
Posts: 4
Joined: Thu Jul 22, 2021 12:40 pm

GRBL postprocessor --return-to generates code after M2

Post by hohoho »

So today I've stumbled upon an annoying bug(?):
When trying to use --return-to with the GRBL postprocessor to return the spindle to the (0, 0) point, nothing happens ... it doesn't return.
After inspecting the GCode:

Code: Select all

[...]
(Begin postamble)
M5
G17 G90
M2
G0 X0 Y0
I noticed the G0 X0 Y0 is put there after the M2 (End Program) command. As far as I've found out (for example at http://www.linuxcnc.org/docs/html/gcode ... ode:m2-m30) code after M2 shall be ignored and that's exactly what happens in my case. My Sainsmart 3018 Pro just ignores that G0 command.
If I manually move it above, it works fine.

So my question now would be: is this a bug or did I just happen to stumble upon a quirky edge-case (since I'm new to CNCs and FreeCAD)?
chrisb
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: GRBL postprocessor --return-to generates code after M2

Post by chrisb »

Hi and welcome to the forum!

This doesn't happen here. Upgrade to latest FreeCAD 0.20. Or did you add your own postamble?

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.25176 (Git)
Build type: Release
Branch: master
Hash: 909dfa7036f9fd36bbd3acee2a5dee161d2819fb
Python version: 3.9.5
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: C/Default (C)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
hohoho
Posts: 4
Joined: Thu Jul 22, 2021 12:40 pm

Re: GRBL postprocessor --return-to generates code after M2

Post by hohoho »

I didn't use a custom postable, the only change in the job was to set it to grbl and add the "--return-to 0,0" argument.

Looking at the current source code in master (https://github.com/FreeCAD/FreeCAD/blob ... #L313-L319), this looks like it's meant to print the postamble (the default is the "M5, G17 G90, M2" one) before the return-to statement, so I guess even updating to the newest dev version won't change much. But I'll try that later today when I get home. Thanks for the hint :)
chrisb
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: GRBL postprocessor --return-to generates code after M2

Post by chrisb »

Sorry, I retried with the additional parameter and can confirm the issue.

(Using 0.20 with Path wokbench is a very good idea nevertheless).
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: GRBL postprocessor --return-to generates code after M2

Post by chrisb »

A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
hohoho
Posts: 4
Joined: Thu Jul 22, 2021 12:40 pm

Re: GRBL postprocessor --return-to generates code after M2

Post by hohoho »

Thanks, that workaround works, too :)

But I just settled on moving the output lines in the grbl_post.py file:

Code: Select all

  if RETURN_TO:
    gcode += linenumber() + "G0 X%s Y%s" % tuple(RETURN_TO)
  if OUTPUT_COMMENTS:
    gcode += linenumber() + "(Begin postamble)\n"
  for line in POSTAMBLE.splitlines(True):
    gcode += linenumber() + line
That works, too ... I don't know if there are any side effects of doing it this way, but for now it works for me. And yeah, I tested it on the current master version, it's still there.
User avatar
sliptonic
Veteran
Posts: 3460
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: GRBL postprocessor --return-to generates code after M2

Post by sliptonic »

Are you going to submit a pull request with this fix?
hohoho
Posts: 4
Joined: Thu Jul 22, 2021 12:40 pm

Re: GRBL postprocessor --return-to generates code after M2

Post by hohoho »

Just did, https://github.com/FreeCAD/FreeCAD/pull/4936 :) I moved the line a little further up because technically it's not part of the postamble.

It would be nice if someone with more knowledge of FreeCAD than me (using it for just a few days now) could review it properly, I still don't know of possible side effects. (I'm thinking especially because it now moves there while the spindle is still on, so I don't want to create something with damage potential)
Post Reply