From c2d5a63e2d97cae2aa40b326fabfe95603217225 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 31 May 2017 13:52:50 -0500 Subject: [PATCH] Path: add output precision option to linuxcnc post. Modified unit tests to use it. --- src/Mod/Path/PathScripts/linuxcnc_post.py | 12 ++- src/Mod/Path/PathTests/TestPathCore.py | 3 + src/Mod/Path/PathTests/TestPathPost.py | 2 +- src/Mod/Path/PathTests/test_linuxcnc_00.ngc | 112 ++++++++++---------- 4 files changed, 70 insertions(+), 59 deletions(-) diff --git a/src/Mod/Path/PathScripts/linuxcnc_post.py b/src/Mod/Path/PathScripts/linuxcnc_post.py index 4b161c6024..b39f1ddf96 100644 --- a/src/Mod/Path/PathScripts/linuxcnc_post.py +++ b/src/Mod/Path/PathScripts/linuxcnc_post.py @@ -39,6 +39,7 @@ Arguments for linuxcnc: --comments,--no-comments ... output comments (--comments) --line-numbers,--no-line-numbers ... prefix with line numbers (--no-lin-numbers) --show-editor, --no-show-editor ... pop up editor before writing output(--show-editor) + --output-precision=4 ... number of digits of precision. Default=4 ''' import FreeCAD from FreeCAD import Units @@ -66,6 +67,7 @@ UNIT_FORMAT = 'mm/min' MACHINE_NAME = "LinuxCNC" CORNER_MIN = {'x': 0, 'y': 0, 'z': 0} CORNER_MAX = {'x': 500, 'y': 300, 'z': 300} +PRECISION=4 # Preamble text will appear at the beginning of the GCODE output file. PREAMBLE = '''G17 G90 @@ -98,6 +100,8 @@ def processArguments(argstring): global OUTPUT_COMMENTS global OUTPUT_LINE_NUMBERS global SHOW_EDITOR + global PRECISION + for arg in argstring.split(): if arg == '--header': OUTPUT_HEADER = True @@ -115,6 +119,8 @@ def processArguments(argstring): SHOW_EDITOR = True elif arg == '--no-show-editor': SHOW_EDITOR = False + elif arg.split('=')[0] == '--output-precision': + PRECISION = arg.split('=')[1] def export(objectslist, filename, argstring): processArguments(argstring) @@ -211,8 +217,10 @@ def linenumber(): return "" def parse(pathobj): + global PRECISION out = "" lastcommand = None + precision_string = '.' + str(PRECISION) +'f' # params = ['X','Y','Z','A','B','I','J','K','F','S'] #This list control # the order of parameters @@ -251,12 +259,12 @@ def parse(pathobj): if c.Name not in ["G0", "G00"]: #linuxcnc doesn't use rapid speeds speed = Units.Quantity(c.Parameters['F'], FreeCAD.Units.Velocity) outstring.append( - param + format(float(speed.getValueAs(UNIT_FORMAT)), '.2f') ) + param + format(float(speed.getValueAs(UNIT_FORMAT)), precision_string) ) elif param == 'T': outstring.append(param + str(c.Parameters['T'])) else: outstring.append( - param + format(c.Parameters[param], '.4f')) + param + format(c.Parameters[param], precision_string)) # store the latest command lastcommand = command diff --git a/src/Mod/Path/PathTests/TestPathCore.py b/src/Mod/Path/PathTests/TestPathCore.py index da9ee3cfcd..77ccbb0941 100644 --- a/src/Mod/Path/PathTests/TestPathCore.py +++ b/src/Mod/Path/PathTests/TestPathCore.py @@ -109,6 +109,7 @@ G1X-0.5905Y-0.3937 G0Z0.5 ''' + output = '''G0 S3000.000000 X-0.590500 Y-0.393700 M03 G0 Z0.125000 @@ -119,6 +120,8 @@ G1 X-0.590500 Y0.433000 G1 X-0.590500 Y-0.393700 G0 Z0.500000 ''' + + #create a path directly form a piece of gcode. p = Path.Path() p.setFromGCode(lines) diff --git a/src/Mod/Path/PathTests/TestPathPost.py b/src/Mod/Path/PathTests/TestPathPost.py index f2b3739ae1..284969596a 100644 --- a/src/Mod/Path/PathTests/TestPathPost.py +++ b/src/Mod/Path/PathTests/TestPathPost.py @@ -84,7 +84,7 @@ class PathPostTestCases(unittest.TestCase): self.doc.recompute() job.PostProcessor = 'linuxcnc' - job.PostProcessorArgs = '--no-header --no-line-numbers --no-comments --no-show-editor' + job.PostProcessorArgs = '--no-header --no-line-numbers --no-comments --no-show-editor --output-precision=2' post = PathScripts.PathPost.CommandPathPost() (fail, gcode) = post.exportObjectsWith([job], job, False) diff --git a/src/Mod/Path/PathTests/test_linuxcnc_00.ngc b/src/Mod/Path/PathTests/test_linuxcnc_00.ngc index 4859ee3d72..9f3c6e3cca 100644 --- a/src/Mod/Path/PathTests/test_linuxcnc_00.ngc +++ b/src/Mod/Path/PathTests/test_linuxcnc_00.ngc @@ -2,68 +2,68 @@ G17 G90 G21 (Default_Tool) M6 T1.0 -M3 S0.0000 +M3 S0.00 (TC) M6 T2.0 -M3 S0.0000 +M3 S0.00 (Contour) (Uncompensated Tool Path) -G0 Z15.0000 +G0 Z15.00 G90 G17 -G0 X0.0000 Y0.0000 Z15.0000 -G0 X10.0000 Y10.0000 Z15.0000 -G0 X10.0000 Y10.0000 Z10.0000 -G1 X10.0000 Y10.0000 Z9.0000 -G1 X10.0000 Y0.0000 Z9.0000 -G1 X0.0000 Y0.0000 Z9.0000 -G1 X0.0000 Y10.0000 Z9.0000 -G1 X10.0000 Y10.0000 Z9.0000 -G1 X10.0000 Y10.0000 Z8.0000 -G1 X10.0000 Y0.0000 Z8.0000 -G1 X0.0000 Y0.0000 Z8.0000 -G1 X0.0000 Y10.0000 Z8.0000 -G1 X10.0000 Y10.0000 Z8.0000 -G1 X10.0000 Y10.0000 Z7.0000 -G1 X10.0000 Y0.0000 Z7.0000 -G1 X0.0000 Y0.0000 Z7.0000 -G1 X0.0000 Y10.0000 Z7.0000 -G1 X10.0000 Y10.0000 Z7.0000 -G1 X10.0000 Y10.0000 Z6.0000 -G1 X10.0000 Y0.0000 Z6.0000 -G1 X0.0000 Y0.0000 Z6.0000 -G1 X0.0000 Y10.0000 Z6.0000 -G1 X10.0000 Y10.0000 Z6.0000 -G1 X10.0000 Y10.0000 Z5.0000 -G1 X10.0000 Y0.0000 Z5.0000 -G1 X0.0000 Y0.0000 Z5.0000 -G1 X0.0000 Y10.0000 Z5.0000 -G1 X10.0000 Y10.0000 Z5.0000 -G1 X10.0000 Y10.0000 Z4.0000 -G1 X10.0000 Y0.0000 Z4.0000 -G1 X0.0000 Y0.0000 Z4.0000 -G1 X0.0000 Y10.0000 Z4.0000 -G1 X10.0000 Y10.0000 Z4.0000 -G1 X10.0000 Y10.0000 Z3.0000 -G1 X10.0000 Y0.0000 Z3.0000 -G1 X0.0000 Y0.0000 Z3.0000 -G1 X0.0000 Y10.0000 Z3.0000 -G1 X10.0000 Y10.0000 Z3.0000 -G1 X10.0000 Y10.0000 Z2.0000 -G1 X10.0000 Y0.0000 Z2.0000 -G1 X0.0000 Y0.0000 Z2.0000 -G1 X0.0000 Y10.0000 Z2.0000 -G1 X10.0000 Y10.0000 Z2.0000 -G1 X10.0000 Y10.0000 Z1.0000 -G1 X10.0000 Y0.0000 Z1.0000 -G1 X0.0000 Y0.0000 Z1.0000 -G1 X0.0000 Y10.0000 Z1.0000 -G1 X10.0000 Y10.0000 Z1.0000 -G1 X10.0000 Y10.0000 Z0.0000 -G1 X10.0000 Y0.0000 Z0.0000 -G1 X0.0000 Y0.0000 Z0.0000 -G1 X0.0000 Y10.0000 Z0.0000 -G1 X10.0000 Y10.0000 Z0.0000 +G0 X0.00 Y0.00 Z15.00 +G0 X10.00 Y10.00 Z15.00 +G0 X10.00 Y10.00 Z10.00 +G1 X10.00 Y10.00 Z9.00 +G1 X10.00 Y0.00 Z9.00 +G1 X0.00 Y0.00 Z9.00 +G1 X0.00 Y10.00 Z9.00 +G1 X10.00 Y10.00 Z9.00 +G1 X10.00 Y10.00 Z8.00 +G1 X10.00 Y0.00 Z8.00 +G1 X0.00 Y0.00 Z8.00 +G1 X0.00 Y10.00 Z8.00 +G1 X10.00 Y10.00 Z8.00 +G1 X10.00 Y10.00 Z7.00 +G1 X10.00 Y0.00 Z7.00 +G1 X0.00 Y0.00 Z7.00 +G1 X0.00 Y10.00 Z7.00 +G1 X10.00 Y10.00 Z7.00 +G1 X10.00 Y10.00 Z6.00 +G1 X10.00 Y0.00 Z6.00 +G1 X0.00 Y0.00 Z6.00 +G1 X0.00 Y10.00 Z6.00 +G1 X10.00 Y10.00 Z6.00 +G1 X10.00 Y10.00 Z5.00 +G1 X10.00 Y0.00 Z5.00 +G1 X0.00 Y0.00 Z5.00 +G1 X0.00 Y10.00 Z5.00 +G1 X10.00 Y10.00 Z5.00 +G1 X10.00 Y10.00 Z4.00 +G1 X10.00 Y0.00 Z4.00 +G1 X0.00 Y0.00 Z4.00 +G1 X0.00 Y10.00 Z4.00 +G1 X10.00 Y10.00 Z4.00 +G1 X10.00 Y10.00 Z3.00 +G1 X10.00 Y0.00 Z3.00 +G1 X0.00 Y0.00 Z3.00 +G1 X0.00 Y10.00 Z3.00 +G1 X10.00 Y10.00 Z3.00 +G1 X10.00 Y10.00 Z2.00 +G1 X10.00 Y0.00 Z2.00 +G1 X0.00 Y0.00 Z2.00 +G1 X0.00 Y10.00 Z2.00 +G1 X10.00 Y10.00 Z2.00 +G1 X10.00 Y10.00 Z1.00 +G1 X10.00 Y0.00 Z1.00 +G1 X0.00 Y0.00 Z1.00 +G1 X0.00 Y10.00 Z1.00 +G1 X10.00 Y10.00 Z1.00 +G1 X10.00 Y10.00 Z0.00 +G1 X10.00 Y0.00 Z0.00 +G1 X0.00 Y0.00 Z0.00 +G1 X0.00 Y10.00 Z0.00 +G1 X10.00 Y10.00 Z0.00 M05 G00 X-1.0 Y1.0 G17 G90