From 4e7c5fcb90e3a7ba480caac6e9706b0acba96b65 Mon Sep 17 00:00:00 2001 From: smallwhiteawhite <1368582937@qq.com> Date: Fri, 27 Nov 2026 23:26:34 -0800 Subject: [PATCH] rs274ngc: reject UVW plane switch and invalid L orientation in cutter comp Add two missing cutter radius compensation validation checks: 1. In Interp::convert_set_plane(), reject switching to UVW planes (G17.1, G18.1, G19.1) while cutter radius compensation is active using NCE_CANNOT_CHANGE_PLANES_WITH_CUTTER_RADIUS_COMP_ON, instead of deferring failure to an internal BUG abort on the next motion. 2. In Interp::convert_cutter_compensation_on(), reject out-of-range tool orientations (L > 9) on G41.1/G42.1 using "Invalid tool orientation" (matching G10 L1 Q). Add regression tests under tests/interp/bad/ for G17.1, G18.1, G19.1 with cutter comp active and for G41.1 with L10. Ref #4918 --- src/emc/rs274ngc/interp_convert.cc | 4 ++++ tests/interp/bad/ccomp-g41.1-bad-orientation.ngc | 4 ++++ tests/interp/bad/ccomp-plane-g17.1.ngc | 4 ++++ tests/interp/bad/ccomp-plane-g18.1.ngc | 4 ++++ tests/interp/bad/ccomp-plane-g19.1.ngc | 4 ++++ 5 files changed, 20 insertions(+) create mode 100644 tests/interp/bad/ccomp-g41.1-bad-orientation.ngc create mode 100644 tests/interp/bad/ccomp-plane-g17.1.ngc create mode 100644 tests/interp/bad/ccomp-plane-g18.1.ngc create mode 100644 tests/interp/bad/ccomp-plane-g19.1.ngc diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc index 183e8c5fb0e..42d97a2d4f6 100644 --- a/src/emc/rs274ngc/interp_convert.cc +++ b/src/emc/rs274ngc/interp_convert.cc @@ -2614,6 +2614,7 @@ int Interp::convert_cutter_compensation_on(CUTTER_COMP side, //!< side of pa radius = block->d_number_float / 2; if(block->l_number != -1) { CHKS((settings->plane != CANON_PLANE::XZ), _("G%d.1 with L word, but plane is not G18"), block->g_modes[GM_CUTTER_COMP]/10); + CHKS((block->l_number > 9), _("Invalid tool orientation")); orientation = block->l_number; } else { orientation = 0; @@ -5157,6 +5158,9 @@ int Interp::convert_set_plane(int g_code, //!< must be G_17, G_18, or G_1 NCE_CANNOT_CHANGE_PLANES_WITH_CUTTER_RADIUS_COMP_ON); CHKS((settings->cutter_comp_side != CUTTER_COMP::OFF && g_code == G_19 && settings->plane != CANON_PLANE::YZ), NCE_CANNOT_CHANGE_PLANES_WITH_CUTTER_RADIUS_COMP_ON); + CHKS((settings->cutter_comp_side != CUTTER_COMP::OFF && + (g_code == G_17_1 || g_code == G_18_1 || g_code == G_19_1)), + NCE_CANNOT_CHANGE_PLANES_WITH_CUTTER_RADIUS_COMP_ON); CHKS((settings->cutter_comp_side != CUTTER_COMP::OFF && g_code == G_19), NCE_RADIUS_COMP_ONLY_IN_XY_OR_XZ); diff --git a/tests/interp/bad/ccomp-g41.1-bad-orientation.ngc b/tests/interp/bad/ccomp-g41.1-bad-orientation.ngc new file mode 100644 index 00000000000..d11a6077171 --- /dev/null +++ b/tests/interp/bad/ccomp-g41.1-bad-orientation.ngc @@ -0,0 +1,4 @@ +;Invalid tool orientation +G21 G90 G18 +G41.1 D2 L10 +M2 diff --git a/tests/interp/bad/ccomp-plane-g17.1.ngc b/tests/interp/bad/ccomp-plane-g17.1.ngc new file mode 100644 index 00000000000..def15fd9bba --- /dev/null +++ b/tests/interp/bad/ccomp-plane-g17.1.ngc @@ -0,0 +1,4 @@ +;Cannot change planes with cutter radius compensation on +G21 G90 G17 G41.1 D2 +G17.1 +M2 diff --git a/tests/interp/bad/ccomp-plane-g18.1.ngc b/tests/interp/bad/ccomp-plane-g18.1.ngc new file mode 100644 index 00000000000..008382a8821 --- /dev/null +++ b/tests/interp/bad/ccomp-plane-g18.1.ngc @@ -0,0 +1,4 @@ +;Cannot change planes with cutter radius compensation on +G21 G90 G17 G41.1 D2 +G18.1 +M2 diff --git a/tests/interp/bad/ccomp-plane-g19.1.ngc b/tests/interp/bad/ccomp-plane-g19.1.ngc new file mode 100644 index 00000000000..289a863c43d --- /dev/null +++ b/tests/interp/bad/ccomp-plane-g19.1.ngc @@ -0,0 +1,4 @@ +;Cannot change planes with cutter radius compensation on +G21 G90 G17 G41.1 D2 +G19.1 +M2