From 9c03f91fa8675b53ddf0eb8f71253c7635cbe0d8 Mon Sep 17 00:00:00 2001 From: cnc Date: Tue, 2 Jun 2026 22:08:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E6=8C=89=20align-linuxcnc=20?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=EF=BC=9A=E8=A1=A5=E6=9E=81=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E6=BA=90=E7=A0=81=E8=A6=86=E7=9B=96=EF=BC=8C=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-linuxcnc-source-link.sh | 48 +++++++++++++++++++ test-native.sh | 2 + tests/gcode/linuxcnc_polar_coordinates.ngc | 5 ++ tests/gcode/linuxcnc_polar_g18_error.ngc | 3 ++ tests/gcode/linuxcnc_polar_g53_error.ngc | 3 ++ tests/gcode/linuxcnc_polar_g92_error.ngc | 3 ++ ..._polar_incremental_radius_origin_error.ngc | 3 ++ ...c_polar_incremental_theta_origin_error.ngc | 3 ++ .../linuxcnc_polar_radius_origin_error.ngc | 3 ++ tests/gcode/linuxcnc_polar_with_x_error.ngc | 3 ++ tests/gcode/linuxcnc_polar_with_y_error.ngc | 3 ++ 11 files changed, 79 insertions(+) create mode 100644 tests/gcode/linuxcnc_polar_coordinates.ngc create mode 100644 tests/gcode/linuxcnc_polar_g18_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_g53_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_g92_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_incremental_radius_origin_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_incremental_theta_origin_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_radius_origin_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_with_x_error.ngc create mode 100644 tests/gcode/linuxcnc_polar_with_y_error.ngc diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index ec8945e..8d9785a 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -547,6 +547,35 @@ CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_arc_distance_modes.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_arc_distance_modes.json" +# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc read_atsign() +# and read_carat() parse @/^ polar words; src/emc/rs274ngc/interp_internal.cc +# enhance_block() restricts polar coordinates to G17 motion without X/Y words; +# src/emc/rs274ngc/interp_find.cc find_ends() maps absolute polar radius/angle +# to XY endpoints and rejects G53 or origin-indeterminate polar motions. +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_polar_coordinates.ngc \ + >"$output_dir/cnc_sim_linuxcnc_source_polar_coordinates.json" +polar_coordinate_error_cases=( + "linuxcnc_polar_g18_error|Cannot use polar coordinate except in G17 plane" + "linuxcnc_polar_with_x_error|Cannot specify both polar coordinate and X word" + "linuxcnc_polar_with_y_error|Cannot specify both polar coordinate and Y word" + "linuxcnc_polar_g92_error|Polar coordinates can only be used for motion" + "linuxcnc_polar_g53_error|Cannot use polar coordinates with G53" + "linuxcnc_polar_radius_origin_error|Must specify angle in polar coordinate if at the origin" + "linuxcnc_polar_incremental_radius_origin_error|Incremental motion with polar coordinates is indeterminate when at the origin" + "linuxcnc_polar_incremental_theta_origin_error|G91 motion with polar coordinates is indeterminate when at the origin" +) +for case in "${polar_coordinate_error_cases[@]}"; do + fixture=${case%%|*} + expected=${case#*|} + if CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" "tests/gcode/$fixture.ngc" \ + >"$output_dir/cnc_sim_linuxcnc_source_$fixture.json" 2>"$output_dir/cnc_sim_linuxcnc_source_$fixture.err"; then + echo "expected $fixture.ngc to fail" >&2 + exit 1 + fi + grep -Fq "$expected" "$output_dir/cnc_sim_linuxcnc_source_$fixture.err" +done CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_predefined_positions.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_predefined_positions.json" @@ -2051,6 +2080,25 @@ expected_arc_centers = [(5, 5, 0), (7, 15, 0), (9, 25, 0)] if arc_centers != expected_arc_centers: raise SystemExit(f"unexpected source-linked G90.1/G91.1 arc centers: {arc_centers!r}") +polar_coordinates = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_polar_coordinates.json").read_text()) +polar_linear_events = [ + event + for event in polar_coordinates + if event["type"] == "linear-feed" +] +expected_polar_linear_ends = [(3, 10, 0), (4, 0, 10)] +if len(polar_linear_events) != len(expected_polar_linear_ends) or any( + event["line"] != line or + abs(event["end"]["x"] - x) > 1e-9 or + abs(event["end"]["y"] - y) > 1e-9 + for event, (line, x, y) in zip(polar_linear_events, expected_polar_linear_ends) +): + polar_linear_ends = [ + (event["line"], event["end"]["x"], event["end"]["y"]) + for event in polar_linear_events + ] + raise SystemExit(f"unexpected source-linked polar-coordinate endpoints: {polar_linear_ends!r}") + predefined = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_predefined_positions.json").read_text()) predefined_rapids = [ ( diff --git a/test-native.sh b/test-native.sh index c01e1da..1096b8c 100755 --- a/test-native.sh +++ b/test-native.sh @@ -145,6 +145,8 @@ grep -F 'convert_lathe_diameter_mode() scales G7/G8 X words and G76 I/J/K words' grep -F 'tests/gcode/linuxcnc_lathe_diameter_mode.ngc' docs/linuxcnc-porting.md >/dev/null grep -F 'tests/gcode/linuxcnc_lathe_diameter_g76.ngc' docs/linuxcnc-porting.md >/dev/null grep -F 'missing source-linked G7 diameter-mode G76 final threading pass' test-linuxcnc-source-link.sh >/dev/null +grep -F 'read_atsign()' test-linuxcnc-source-link.sh >/dev/null +grep -F 'tests/gcode/linuxcnc_polar_coordinates.ngc' test-linuxcnc-source-link.sh >/dev/null grep -F 'lookup_named_param()' test-linuxcnc-rs274-native.sh >/dev/null grep -F 'tests/gcode/linuxcnc_readonly_named_parameters.ngc' docs/linuxcnc-porting.md >/dev/null grep -F 'rs274ngc_pre.cc ini_load() consumes INI_FILE_NAME' test-web-wasm-node-smoke.cjs >/dev/null diff --git a/tests/gcode/linuxcnc_polar_coordinates.ngc b/tests/gcode/linuxcnc_polar_coordinates.ngc new file mode 100644 index 0000000..6c49c49 --- /dev/null +++ b/tests/gcode/linuxcnc_polar_coordinates.ngc @@ -0,0 +1,5 @@ +G21 G90 G17 +G0 X0 Y0 Z0 +G1 @10 ^0 F100 +G1 @10 ^90 +M30 diff --git a/tests/gcode/linuxcnc_polar_g18_error.ngc b/tests/gcode/linuxcnc_polar_g18_error.ngc new file mode 100644 index 0000000..6ec436c --- /dev/null +++ b/tests/gcode/linuxcnc_polar_g18_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G18 +G1 @10 ^45 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_g53_error.ngc b/tests/gcode/linuxcnc_polar_g53_error.ngc new file mode 100644 index 0000000..a361b7b --- /dev/null +++ b/tests/gcode/linuxcnc_polar_g53_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +G53 G1 @10 ^45 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_g92_error.ngc b/tests/gcode/linuxcnc_polar_g92_error.ngc new file mode 100644 index 0000000..f1a8eae --- /dev/null +++ b/tests/gcode/linuxcnc_polar_g92_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +G92 @10 ^45 +M30 diff --git a/tests/gcode/linuxcnc_polar_incremental_radius_origin_error.ngc b/tests/gcode/linuxcnc_polar_incremental_radius_origin_error.ngc new file mode 100644 index 0000000..5fb290f --- /dev/null +++ b/tests/gcode/linuxcnc_polar_incremental_radius_origin_error.ngc @@ -0,0 +1,3 @@ +G21 G91 G17 +G1 @10 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_incremental_theta_origin_error.ngc b/tests/gcode/linuxcnc_polar_incremental_theta_origin_error.ngc new file mode 100644 index 0000000..9df93e0 --- /dev/null +++ b/tests/gcode/linuxcnc_polar_incremental_theta_origin_error.ngc @@ -0,0 +1,3 @@ +G21 G91 G17 +G1 ^45 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_radius_origin_error.ngc b/tests/gcode/linuxcnc_polar_radius_origin_error.ngc new file mode 100644 index 0000000..aa65f0c --- /dev/null +++ b/tests/gcode/linuxcnc_polar_radius_origin_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +G1 @10 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_with_x_error.ngc b/tests/gcode/linuxcnc_polar_with_x_error.ngc new file mode 100644 index 0000000..e6d08d1 --- /dev/null +++ b/tests/gcode/linuxcnc_polar_with_x_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +G1 X1 @10 ^45 F100 +M30 diff --git a/tests/gcode/linuxcnc_polar_with_y_error.ngc b/tests/gcode/linuxcnc_polar_with_y_error.ngc new file mode 100644 index 0000000..396ebdf --- /dev/null +++ b/tests/gcode/linuxcnc_polar_with_y_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +G1 Y1 @10 ^45 F100 +M30