Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/gcode/g-code.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
22 changes: 15 additions & 7 deletions src/emc/rs274ngc/interp_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 &&
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions tests/interp/g43-axis-words/expected
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions tests/interp/g43-axis-words/test.ngc
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions tests/interp/g43-axis-words/test.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions tests/interp/g43-axis-words/test.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t1 p1 x0 y0 z10
Loading