From 0ed1bbd56cbe79be6741471d7f590e0c57aee244 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:49:56 +1100 Subject: [PATCH] interp: G43.1 and G43.2 axis words are offsets, never a move A line with axis words and no motion code moves in the modal motion mode, except when G43.1 takes the axis words as offsets. Since G43.2 takes axis words as well (2df2871ba0), the check above lets them through for G43.2 too, but the line still became a move: after G0, "G43.2 X0 Y0" applied the offset and then went to X0 Y0. The documentation says G43.2 causes no motion. A G-code in the same line that takes axis words of its own got them too: "G1 G43.1 Z5" set the offset and fed to Z5, "G92 G43.2 X1" left a G92 offset of -2, "G28 G43.1 Z1" went through Z1 on the way home. The documentation already calls motion on a G43.1 line an error. G43.1 and G43.2 with axis words now leave the modal motion alone, and a motion code or any other G-code that takes axis words in the same line is "Cannot use two g codes that both use axis values", as for G10 and G92. G80 in the line stays fine. tests/interp/g43-axis-words: no move from G43.1 or G43.2 under G0 or G1, G43 H and G49 with axis words still move with the new offset, and every rejected combination. Reported by Sigma1912. --- docs/src/gcode/g-code.adoc | 5 ++++- src/emc/rs274ngc/interp_internal.cc | 22 +++++++++++++++------- tests/interp/g43-axis-words/expected | 28 ++++++++++++++++++++++++++++ tests/interp/g43-axis-words/test.ngc | 28 ++++++++++++++++++++++++++++ tests/interp/g43-axis-words/test.sh | 23 +++++++++++++++++++++++ tests/interp/g43-axis-words/test.tbl | 1 + 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 tests/interp/g43-axis-words/expected create mode 100644 tests/interp/g43-axis-words/test.ngc create mode 100755 tests/interp/g43-axis-words/test.sh create mode 100644 tests/interp/g43-axis-words/test.tbl diff --git a/docs/src/gcode/g-code.adoc b/docs/src/gcode/g-code.adoc index 46386681cce..7a599b97665 100644 --- a/docs/src/gcode/g-code.adoc +++ b/docs/src/gcode/g-code.adoc @@ -1688,7 +1688,8 @@ M2 (end program) It is an error if: -* motion is commanded on the same line as 'G43.1' +* motion, or another G-code that takes axis words (G10, G28, G30, G52, G92, + G68.2, G68.4), is commanded on the same line as 'G43.1' with axis words [NOTE] G43.1 does not write to the tool table. @@ -1740,6 +1741,8 @@ It is an error if: * 'H' is unspecified and no axis offsets are specified. * 'H' is specified and the given tool number does not exist in the tool table. * 'H' is specified and axes are also specified. +* motion, or another G-code that takes axis words (G10, G28, G30, G52, G92, + G68.2, G68.4), is commanded on the same line as 'G43.2' with axis words. NOTE: G43.2 does not write to the tool table. diff --git a/src/emc/rs274ngc/interp_internal.cc b/src/emc/rs274ngc/interp_internal.cc index bcccebe27c2..e976a4c3d9e 100644 --- a/src/emc/rs274ngc/interp_internal.cc +++ b/src/emc/rs274ngc/interp_internal.cc @@ -151,6 +151,7 @@ int Interp::enhance_block(block_pointer block, //!< pointer to a block to be c int ijk_flag; int polar_flag; int mode_zero_covets_axes; + int offset_covets_axes; int mode0; int mode1; @@ -180,16 +181,24 @@ int Interp::enhance_block(block_pointer block, //!< pointer to a block to be c CHKS(polar_flag, _("Polar coordinates cannot define a tilted work plane")); mode_zero_covets_axes = 1; } + // G43.1 and G43.2 take the axis words as offsets: no other G-code in the + // line can have them, and they are no move + offset_covets_axes = axis_flag && + (block->g_modes[GM_TOOL_LENGTH_OFFSET] == G_43_1 + || block->g_modes[GM_TOOL_LENGTH_OFFSET] == G_43_2); + CHKS((offset_covets_axes && mode_zero_covets_axes), + NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES); if (mode1 != -1) { if (mode1 == G_80) { - CHKS(((polar_flag || axis_flag) && (!mode_zero_covets_axes)), + CHKS(((polar_flag || axis_flag) && (!mode_zero_covets_axes) && (!offset_covets_axes)), NCE_CANNOT_USE_AXIS_VALUES_WITH_G80); CHKS((polar_flag && mode0 == G_92), _("Polar coordinates can only be used for motion")); CHKS(((!axis_flag) && (mode0 == G_52 || mode0 == G_92)), NCE_ALL_AXES_MISSING_WITH_G52_OR_G92); } else { - CHKS(mode_zero_covets_axes, NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES); + CHKS((mode_zero_covets_axes || offset_covets_axes), + NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES); CHKS(((!axis_flag && !polar_flag) && mode1 != G_0 && mode1 != G_1 && mode1 != G_2 && mode1 != G_3 && @@ -207,14 +216,13 @@ int Interp::enhance_block(block_pointer block, //!< pointer to a block to be c CHKS(((!axis_flag) && (block->g_modes[GM_MODAL_0] == G_52 || block->g_modes[GM_MODAL_0] == G_92)), NCE_ALL_AXES_MISSING_WITH_G52_OR_G92); + } else if (offset_covets_axes) { + // the offsets alone, no move } else if (axis_flag || polar_flag) { CHKS(((settings->motion_mode == -1) - || (settings->motion_mode == G_80)) && (block->g_modes[GM_TOOL_LENGTH_OFFSET] != G_43_1) - && (block->g_modes[GM_TOOL_LENGTH_OFFSET] != G_43_2), + || (settings->motion_mode == G_80)), NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM); - if (block->g_modes[GM_TOOL_LENGTH_OFFSET] != G_43_1) { - block->motion_to_be = settings->motion_mode; - } + block->motion_to_be = settings->motion_mode; } else if (!axis_flag && !polar_flag && ijk_flag && (settings->motion_mode == G_2 || settings->motion_mode == G_3)) { // this is a block like simply "i1" which should be accepted if we're in arc mode block->motion_to_be = settings->motion_mode; diff --git a/tests/interp/g43-axis-words/expected b/tests/interp/g43-axis-words/expected new file mode 100644 index 00000000000..a869f0b33dc --- /dev/null +++ b/tests/interp/g43-axis-words/expected @@ -0,0 +1,28 @@ + N..... STRAIGHT_TRAVERSE(50.0000, 50.0000, 0.0000, 0.0000, 0.0000, 0.0000) + N..... STRAIGHT_TRAVERSE(-50.0000, -50.0000, 0.0000, 0.0000, 0.0000, 0.0000) + N..... MESSAGE("G43.2 axis words: no move") + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 2.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) + N..... MESSAGE("-50.000000 -50.000000 -2.000000") + N..... MESSAGE("G43.1 axis words: no move") + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 3.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) + N..... MESSAGE("-50.000000 -50.000000 -3.000000") + N..... MESSAGE("G43 H1 with axis words: a move") + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 254.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) + N..... STRAIGHT_TRAVERSE(-50.0000, -50.0000, 5.0000, 0.0000, 0.0000, 0.0000) + N..... MESSAGE("G49 with axis words: a move") + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) + N..... STRAIGHT_TRAVERSE(-50.0000, -50.0000, 6.0000, 0.0000, 0.0000, 0.0000) + N..... MESSAGE("G1 mode: G43.2 axis words do not feed either") + N..... STRAIGHT_FEED(1.0000, -50.0000, 6.0000, 0.0000, 0.0000, 0.0000) + N..... USE_TOOL_LENGTH_OFFSET(0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000, 0.0000 0.0000 0.0000) +g0 g43.1 z5: Cannot use two g codes that both use axis values +g1 f100 g43.2 z5: Cannot use two g codes that both use axis values +g2 f100 g43.1 x1 i1: Cannot use two g codes that both use axis values +g92 g43.2 x1: Cannot use two g codes that both use axis values +g10 l20 p1 g43.1 z1: Cannot use two g codes that both use axis values +g10 l1 p1 g43.2 z1: Cannot use two g codes that both use axis values +g28 g43.1 z1: Cannot use two g codes that both use axis values +g68.2 g43.2 z1: Cannot use two g codes that both use axis values +g80 g43.1 z5: accepted +g0 g43.2 h1: accepted diff --git a/tests/interp/g43-axis-words/test.ngc b/tests/interp/g43-axis-words/test.ngc new file mode 100644 index 00000000000..6de1d60cfd6 --- /dev/null +++ b/tests/interp/g43-axis-words/test.ngc @@ -0,0 +1,28 @@ +; G43.1 and G43.2 take their axis words as offsets and do not move, even +; with a motion mode in effect; G43 and G49 with axis words move along them +; with the new offset. + +g21 +g0 x50 y50 +g10 l20 p0 x0 y0 z0 +g53 x0 y0 z0 + +(debug,G43.2 axis words: no move) +g43.2 x0 y0 +g43.2 z2 +(debug,#5420 #5421 #5422) + +(debug,G43.1 axis words: no move) +g43.1 z3 +(debug,#5420 #5421 #5422) + +(debug,G43 H1 with axis words: a move) +g43 h1 z5 + +(debug,G49 with axis words: a move) +g49 z6 + +(debug,G1 mode: G43.2 axis words do not feed either) +g1 f100 x1 +g43.2 x0 y0 +m2 diff --git a/tests/interp/g43-axis-words/test.sh b/tests/interp/g43-axis-words/test.sh new file mode 100755 index 00000000000..6803254068d --- /dev/null +++ b/tests/interp/g43-axis-words/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash +rs274 -g test.ngc -t test.tbl | awk '/MESSAGE|STRAIGHT_|USE_TOOL_LENGTH_OFFSET/ {$1=""; print}' | sed 's/-0\.0000*\b/0.0000/g' +status=${PIPESTATUS[0]} +# G43.1 and G43.2 axis words cannot also be the axis words of another G-code +# in the line; G80 and G43.2 H with a motion code stay fine +while read -r line; do + printf 'g21\n%s\nm2\n' "$line" > line.ngc + msg=$(rs274 -g line.ngc -t test.tbl 2>&1 | grep -v '^ *[0-9]\|^executing' | head -1) + echo "$line: ${msg:-accepted}" +done <<'LINES' +g0 g43.1 z5 +g1 f100 g43.2 z5 +g2 f100 g43.1 x1 i1 +g92 g43.2 x1 +g10 l20 p1 g43.1 z1 +g10 l1 p1 g43.2 z1 +g28 g43.1 z1 +g68.2 g43.2 z1 +g80 g43.1 z5 +g0 g43.2 h1 +LINES +rm -f line.ngc +exit "$status" diff --git a/tests/interp/g43-axis-words/test.tbl b/tests/interp/g43-axis-words/test.tbl new file mode 100644 index 00000000000..13f4a45a288 --- /dev/null +++ b/tests/interp/g43-axis-words/test.tbl @@ -0,0 +1 @@ +t1 p1 x0 y0 z10