From b0b845193029e5a0329deb7167c30a2ce059b735 Mon Sep 17 00:00:00 2001 From: Sabin Iacob Date: Sat, 21 Dec 2019 18:19:17 +0200 Subject: [PATCH] Path: add 2 new arguments to the GRBL postprocessor --- src/Mod/Path/PathScripts/post/grbl_post.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Mod/Path/PathScripts/post/grbl_post.py b/src/Mod/Path/PathScripts/post/grbl_post.py index be05e684cd..f525f8f9d4 100755 --- a/src/Mod/Path/PathScripts/post/grbl_post.py +++ b/src/Mod/Path/PathScripts/post/grbl_post.py @@ -57,6 +57,9 @@ G17 G90 M2 ''' # default postamble text will appear following the last operation. +SPINDLE_WAIT = 0 # no waiting after M3 / M4 by default +RETURN_TO = None # no movements after end of program + # Customisation with no command line argument MODAL = False # if true commands are suppressed if the same as previous line. LINENR = 100 # line number starting value @@ -92,6 +95,8 @@ parser.add_argument('--preamble', help='set comma parser.add_argument('--postamble', help='set commands to be issued after the last command, default="M5\nG17 G90\n;M2"') parser.add_argument('--inches', action='store_true', help='Convert output for US imperial mode (G20)') parser.add_argument('--tool-change', action='store_true', help='Insert M6 for all tool changes') +parser.add_argument('--wait-for-spindle', type=int, default=0, help='Wait for spindle to reach desired speed after M3 / M4, default=0') +parser.add_argument('--return-to', default='', help='Move to the specified coordinates at the end, e.g. --return-to=0,0') TOOLTIP_ARGS = parser.format_help() @@ -128,6 +133,8 @@ def processArguments(argstring): global UNIT_FORMAT global TRANSLATE_DRILL_CYCLES global OUTPUT_TOOL_CHANGE + global SPINDLE_WAIT + global RETURN_TO try: args = parser.parse_args(shlex.split(argstring)) @@ -163,6 +170,14 @@ def processArguments(argstring): PRECISION = 4 if args.tool_change: OUTPUT_TOOL_CHANGE = True + if args.wait_for_spindle > 0: + SPINDLE_WAIT = args.wait_for_spindle + if args.return_to != '': + RETURN_TO = [int(v) for v in args.return_to.split(',')] + if len(RETURN_TO) != 2: + RETURN_TO = None + print("--return-to coordinates must be specified as ,, ignoring") + except Exception as e: return False @@ -248,6 +263,9 @@ def export(objectslist, filename, argstring): for line in POSTAMBLE.splitlines(True): gcode += linenumber() + line + if RETURN_TO: + gcode += linenumber() + "G0 X%s Y%s" % tuple(RETURN_TO) + # show the gCode result dialog if FreeCAD.GuiUp and SHOW_EDITOR: dia = PostUtils.GCodeEditorDialog() @@ -368,6 +386,13 @@ def parse(pathobj): del(outstring[:]) outstring = [] + if SPINDLE_WAIT > 0: + if command in ('M3', 'M03', 'M4', 'M04'): + out += linenumber() + format_outstring(outstring) + "\n" + out += linenumber() + format_outstring(['G4', 'P%s' % SPINDLE_WAIT]) + "\n" + del(outstring[:]) + outstring = [] + # Check for Tool Change: if command in ('M6', 'M06'): if OUTPUT_COMMENTS: