Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAM: Added tests for A, B, and C parameters to the linuxcnc post (Draft) #13702

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 25 additions & 9 deletions src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ***************************************************************************

Check warning on line 1 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

would reformat src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

Check warning on line 1 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing module docstring (missing-module-docstring)
# * Copyright (c) 2014 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This file is part of the FreeCAD CAx development system. *
Expand Down Expand Up @@ -28,7 +28,7 @@
import datetime
import shlex
import Path.Post.Utils as PostUtils
import PathScripts.PathUtils as PathUtils

Check warning on line 31 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Use 'from PathScripts import PathUtils' instead (consider-using-from-import)
from builtins import open as pyopen

TOOLTIP = """
Expand Down Expand Up @@ -132,14 +132,14 @@



def processArguments(argstring):

Check warning on line 135 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
global OUTPUT_HEADER

Check warning on line 136 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global OUTPUT_COMMENTS

Check warning on line 137 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global OUTPUT_LINE_NUMBERS

Check warning on line 138 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global SHOW_EDITOR

Check warning on line 139 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global PRECISION

Check warning on line 140 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global PREAMBLE

Check warning on line 141 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global POSTAMBLE

Check warning on line 142 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using the global statement (global-statement)
global UNITS
global UNIT_SPEED_FORMAT
global UNIT_FORMAT
Expand All @@ -157,7 +157,7 @@
OUTPUT_LINE_NUMBERS = True
if args.no_show_editor:
SHOW_EDITOR = False
print("Show editor = %d" % SHOW_EDITOR)

Check failure on line 160 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Argument 'builtins.bool' does not match format type 'd' (bad-string-format-type)
PRECISION = args.precision
if args.preamble is not None:
PREAMBLE = args.preamble
Expand Down Expand Up @@ -337,7 +337,7 @@
"D",
"P",
]
firstmove = Path.Command("G0", {"X": -1, "Y": -1, "Z": -1, "F": 0.0})

Check failure on line 340 in src/Mod/CAM/Path/Post/scripts/linuxcnc_post.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
currLocation.update(firstmove.Parameters) # set First location Parameters

if hasattr(pathobj, "Group"): # We have a compound or project.
Expand All @@ -355,7 +355,14 @@
# if OUTPUT_COMMENTS:
# out += linenumber() + "(" + pathobj.Label + ")\n"

for c in PathUtils.getPathWithPlacement(pathobj).Commands:
# The following "for" statement was fairly recently added
# but seems to be using the A, B, and C parameters in ways
# that don't appear to be compatible with how the PATH code
# uses the A, B, and C parameters. I have reverted the
# change here until we can figure out what it going on.
#
# for c in PathUtils.getPathWithPlacement(pathobj).Commands:
for c in pathobj.Path.Commands:

outstring = []
command = c.Name
Expand Down Expand Up @@ -408,15 +415,24 @@
):
continue
else:
pos = Units.Quantity(
c.Parameters[param], FreeCAD.Units.Length
)
outstring.append(
param
+ format(
float(pos.getValueAs(UNIT_FORMAT)), precision_string
if param in ("A", "B", "C"):
outstring.append(
param
+ format(
float(c.Parameters[param]),
precision_string
)
)
else:
pos = Units.Quantity(
c.Parameters[param], FreeCAD.Units.Length
)
outstring.append(
param
+ format(
float(pos.getValueAs(UNIT_FORMAT)), precision_string
)
)
)

# store the latest command
lastcommand = command
Expand Down
225 changes: 188 additions & 37 deletions src/Mod/CAM/Tests/TestLinuxCNCPost.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

Check warning on line 1 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

would reformat src/Mod/CAM/Tests/TestLinuxCNCPost.py
# ***************************************************************************
# * Copyright (c) 2022 sliptonic <shopinthewoods@gmail.com> *
# * Copyright (c) 2023 Larry Woestman <LarryWoestman2@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
Expand Down Expand Up @@ -78,12 +79,25 @@
"""
FreeCAD.ActiveDocument.removeObject("testpath")

def compare_sixth_line(self, path_string, expected, args, debug=False):
"""Perform a test with a single comparison to the sixth line of the output."""
nl = "\n"
if path_string:
self.docobj.Path = Path.Path([Path.Command(path_string)])

Check failure on line 86 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)

Check failure on line 86 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
else:
self.docobj.Path = Path.Path([])

Check failure on line 88 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
postables = [self.docobj]
gcode = postprocessor.export(postables, "-", args)
if debug:
print(f"--------{nl}{gcode}--------{nl}")
self.assertEqual(gcode.splitlines()[5], expected)

def test000(self):
"""Test Output Generation.
Empty path. Produces only the preamble and postable.
"""

self.docobj.Path = Path.Path([])

Check failure on line 100 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
postables = [self.docobj]

# Test generating with header
Expand All @@ -106,7 +120,7 @@
M2
"""

self.docobj.Path = Path.Path([])

Check failure on line 123 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
postables = [self.docobj]

args = "--no-header --no-show-editor"
Expand All @@ -132,44 +146,33 @@
Test Precision
Test imperial / inches
"""
c = Path.Command("G0 X10 Y20 Z30")

self.docobj.Path = Path.Path([c])
postables = [self.docobj]

args = "--no-header --no-show-editor"
gcode = postprocessor.export(postables, "-", args)
result = gcode.splitlines()[5]
expected = "G0 X10.000 Y20.000 Z30.000 "
self.assertEqual(result, expected)

args = "--no-header --precision=2 --no-show-editor"
gcode = postprocessor.export(postables, "-", args)
result = gcode.splitlines()[5]
expected = "G0 X10.00 Y20.00 Z30.00 "
self.assertEqual(result, expected)
self.compare_sixth_line(
"G0 X10 Y20 Z30",
"G0 X10.000 Y20.000 Z30.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G0 X10 Y20 Z30",
"G0 X10.00 Y20.00 Z30.00 ",
"--no-header --precision=2 --no-show-editor"
)

def test020(self):
"""
Test Line Numbers
"""
c = Path.Command("G0 X10 Y20 Z30")

self.docobj.Path = Path.Path([c])
postables = [self.docobj]

args = "--no-header --line-numbers --no-show-editor"
gcode = postprocessor.export(postables, "-", args)
result = gcode.splitlines()[5]
expected = "N160 G0 X10.000 Y20.000 Z30.000 "
self.assertEqual(result, expected)
self.compare_sixth_line(
"G0 X10 Y20 Z30",
"N160 G0 X10.000 Y20.000 Z30.000 ",
"--no-header --line-numbers --no-show-editor"
)

def test030(self):
"""
Test Pre-amble
"""

self.docobj.Path = Path.Path([])

Check failure on line 175 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
postables = [self.docobj]

args = "--no-header --no-comments --preamble='G18 G55' --no-show-editor"
Expand All @@ -181,7 +184,7 @@
"""
Test Post-amble
"""
self.docobj.Path = Path.Path([])

Check failure on line 187 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
postables = [self.docobj]
args = "--no-header --no-comments --postamble='G0 Z50\nM2' --no-show-editor"
gcode = postprocessor.export(postables, "-", args)
Expand All @@ -194,7 +197,7 @@
Test inches
"""

c = Path.Command("G0 X10 Y20 Z30")

Check failure on line 200 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
self.docobj.Path = Path.Path([c])
postables = [self.docobj]

Expand Down Expand Up @@ -274,14 +277,162 @@
"""
Test comment
"""

c = Path.Command("(comment)")

self.docobj.Path = Path.Path([c])
postables = [self.docobj]

args = "--no-header --no-show-editor"
gcode = postprocessor.export(postables, "-", args)
result = gcode.splitlines()[5]
expected = "(comment) "
self.assertEqual(result, expected)
self.compare_sixth_line(
"(comment)",
"(comment) ",
"--no-header --no-show-editor"
)

def test100(self):
"""Test A, B, & C axis output for values between 0 and 90 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A40 B50 C60",
"G1 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A40 B50 C60",
"G1 X0.3937 Y0.7874 Z1.1811 A40.0000 B50.0000 C60.0000 ",
"--no-header --inches --no-show-editor"
)

def test110(self):
"""Test A, B, & C axis output for 89 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A89 B89 C89",
"G1 X10.000 Y20.000 Z30.000 A89.000 B89.000 C89.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A89 B89 C89",
"G1 X0.3937 Y0.7874 Z1.1811 A89.0000 B89.0000 C89.0000 ",
"--no-header --inches --no-show-editor"
)

def test120(self):
"""Test A, B, & C axis output for 90 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A90 B90 C90",
"G1 X10.000 Y20.000 Z30.000 A90.000 B90.000 C90.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A90 B90 C90",
"G1 X0.3937 Y0.7874 Z1.1811 A90.0000 B90.0000 C90.0000 ",
"--no-header --inches --no-show-editor"
)

def test130(self):
"""Test A, B, & C axis output for 91 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A91 B91 C91",
"G1 X10.000 Y20.000 Z30.000 A91.000 B91.000 C91.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A91 B91 C91",
"G1 X0.3937 Y0.7874 Z1.1811 A91.0000 B91.0000 C91.0000 ",
"--no-header --inches --no-show-editor"
)

def test140(self):
"""Test A, B, & C axis output for values between 90 and 180 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A100 B110 C120",
"G1 X10.000 Y20.000 Z30.000 A100.000 B110.000 C120.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A100 B110 C120",
"G1 X0.3937 Y0.7874 Z1.1811 A100.0000 B110.0000 C120.0000 ",
"--no-header --inches --no-show-editor"
)

def test150(self):
"""Test A, B, & C axis output for values between 180 and 360 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A240 B250 C260",
"G1 X10.000 Y20.000 Z30.000 A240.000 B250.000 C260.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A240 B250 C260",
"G1 X0.3937 Y0.7874 Z1.1811 A240.0000 B250.0000 C260.0000 ",
"--no-header --inches --no-show-editor"
)

def test160(self):
"""Test A, B, & C axis output for values greater than 360 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A440 B450 C460",
"G1 X10.000 Y20.000 Z30.000 A440.000 B450.000 C460.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A440 B450 C460",
"G1 X0.3937 Y0.7874 Z1.1811 A440.0000 B450.0000 C460.0000 ",
"--no-header --inches --no-show-editor"
)

def test170(self):
"""Test A, B, & C axis output for values between 0 and -90 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-40 B-50 C-60",
"G1 X10.000 Y20.000 Z30.000 A-40.000 B-50.000 C-60.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-40 B-50 C-60",
"G1 X0.3937 Y0.7874 Z1.1811 A-40.0000 B-50.0000 C-60.0000 ",
"--no-header --inches --no-show-editor"
)

def test180(self):
"""Test A, B, & C axis output for values between -90 and -180 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-100 B-110 C-120",
"G1 X10.000 Y20.000 Z30.000 A-100.000 B-110.000 C-120.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-100 B-110 C-120",
"G1 X0.3937 Y0.7874 Z1.1811 A-100.0000 B-110.0000 C-120.0000 ",
"--no-header --inches --no-show-editor"
)

def test190(self):
"""Test A, B, & C axis output for values between -180 and -360 degrees
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-240 B-250 C-260",
"G1 X10.000 Y20.000 Z30.000 A-240.000 B-250.000 C-260.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-240 B-250 C-260",
"G1 X0.3937 Y0.7874 Z1.1811 A-240.0000 B-250.0000 C-260.0000 ",
"--no-header --inches --no-show-editor"
)

def test200(self):
"""Test A, B, & C axis output for values below -360 degress

Check warning on line 427 in src/Mod/CAM/Tests/TestLinuxCNCPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

degress ==> degrees, digress
"""
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-440 B-450 C-460",
"G1 X10.000 Y20.000 Z30.000 A-440.000 B-450.000 C-460.000 ",
"--no-header --no-show-editor"
)
self.compare_sixth_line(
"G1 X10 Y20 Z30 A-440 B-450 C-460",
"G1 X0.3937 Y0.7874 Z1.1811 A-440.0000 B-450.0000 C-460.0000 ",
"--no-header --inches --no-show-editor"
)