From 2f57aeefb8be849bbf9445c1ddb07429242d4b2f Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:57:35 +1100 Subject: [PATCH 1/2] preview: restate the G52 and G92 offsets by value The preview started from the startup code, which often clears the G92 offsets with G92.1, and then restated the "G92 applied" mode as G92.3, which reads them back from the preview's copy of the parameters. A G52 set in MDI was lost, so the program was drawn without it, and with a tilted work plane active the G92.3 came after the plane, which refuses a change to the G92 offsets: the preview stopped at line 0 with "Cannot change G92 offsets while a tilted work plane (G68.2) is active". The preview now restates the offsets with G52 and the machine's values, ahead of the plane, which sits inside them. tests/workplane-preview checks a G52 alone and under a plane: both ended 7 mm off or refused before, the same end as the machine now. Reported by Sigma1912. --- lib/python/preview_helpers.py | 20 +++++++++++++------- tests/workplane-preview/expected | 2 ++ tests/workplane-preview/test-ui.py | 4 ++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/python/preview_helpers.py b/lib/python/preview_helpers.py index cda36aab747..9f7b57e9fb0 100644 --- a/lib/python/preview_helpers.py +++ b/lib/python/preview_helpers.py @@ -8,16 +8,16 @@ # (issue #269), M2, which blanks the next preview, and M6 or M61, which has # no Q to restate. Cutter radius compensation (gcodes[4]) is left out, because # the blocks after it would be refused while it is on. The tool length offset -# (gcodes[9]) and the tilted work plane (gcodes[12]) are restated with their -# values instead. -MODAL_GCODES = (3, 6, 14, 7, 5, 10, 16, 8, 11, 13, 15) +# (gcodes[9]), the tilted work plane (gcodes[12]) and the G92 offsets +# (gcodes[16]) are restated with their values instead. +MODAL_GCODES = (3, 6, 14, 7, 5, 10, 8, 11, 13, 15) MODAL_MCODES = (2, 4, 5, 6, 7, 8, 9) def preview_initcodes(s, inifile): """The machine's state as G-code for a preview interpreter to start - from: the startup code, the units, the tilted work plane, the tool - in the spindle, the position, the active modes and the tool length - offset in force.""" + from: the startup code, the units, the G92 offsets, the tilted work + plane, the tool in the spindle, the position, the active modes and the + tool length offset in force.""" wrapped = axis_kinds.wrapped(inifile) s.poll() codes = [] @@ -26,12 +26,18 @@ def preview_initcodes(s, inifile): if startup: codes.append(startup) codes.append("G%d" % (20 + (s.linear_units == 1))) + axes = [(i, "XYZABCUVW"[i]) for i in range(9) if s.axis_mask & (1 << i)] + # The G92 offsets as G52 sets them, by value: the startup code may clear + # them, and G92.3 would take them from the preview's parameters. They + # come in machine units, ahead of the plane, which sits inside them and + # refuses a change to them + if any(s.g92_offset[i] for i, axis in axes): + codes.append("G52" + "".join(" %s%.12f" % (axis, s.g92_offset[i]) for i, axis in axes)) plane = workplane_code(s) if plane: codes.append(plane) codes.append("G90") codes.append("T%d M6" % s.tool_in_spindle) - axes = [(i, "XYZABCUVW"[i]) for i in range(9) if s.axis_mask & (1 << i)] position = "G53 G0" for i, axis in axes: pos = s.position[i] % 360.0 if wrapped[i] else s.position[i] diff --git a/tests/workplane-preview/expected b/tests/workplane-preview/expected index 29ffdcc2685..0626cdac2fd 100644 --- a/tests/workplane-preview/expected +++ b/tests/workplane-preview/expected @@ -4,3 +4,5 @@ composed then G68.4: same end gimbal: same end no plane: preview line 1: G68.4 needs an active tilted work plane to build on; machine: G68.4 needs an active tilted work plane to build on unfinished MDI sequence: same end +G52: same end +G52 and a plane: same end diff --git a/tests/workplane-preview/test-ui.py b/tests/workplane-preview/test-ui.py index 6770f4145f0..d0492376efb 100755 --- a/tests/workplane-preview/test-ui.py +++ b/tests/workplane-preview/test-ui.py @@ -101,4 +101,8 @@ def case(name, prog, *setup): case("gimbal", "move.ngc", "G20", "G68.2 P1 X0.5 Y0.2 Z0.1 I20 J90 K30") case("no plane", "compose.ngc", "G20") case("unfinished MDI sequence", "move.ngc", "G20", "G68.2 P2 Q1 X0 Y0 Z0") +# G52 offsets reach the preview by value, under a plane as without one +case("G52", "move.ngc", "G21", "G52 X3 Y-2 Z7") +case("G52 and a plane", "move.ngc", "G21", "G52 X3 Y-2 Z7", "G68.2 X10 Y20 Z5 I10 J20 K30") +mdi("G69", "G52 X0 Y0 Z0") c.state(linuxcnc.STATE_OFF) From 17e47c576d7bde727fa9ae3685ba76698558c2c4 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:57:35 +1100 Subject: [PATCH 2/2] gladevcp, qtvcp: show the relative position in the tilted work plane hal_glib's get_position(), which gmoccapy's and qtvcp's DROs read, and the gladevcp DRO widget left out the tilted work plane, which AXIS takes off after G92: after G68.2 Z30 and G0 X0 Y0 Z0 they showed Z30. Both now take the plane off as AXIS does. Reported by Sigma1912. --- lib/python/common/hal_glib.py | 8 ++++++++ lib/python/gladevcp/drowidget.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/python/common/hal_glib.py b/lib/python/common/hal_glib.py index 70cec83b495..d05f9fde997 100644 --- a/lib/python/common/hal_glib.py +++ b/lib/python/common/hal_glib.py @@ -1167,6 +1167,14 @@ def get_position(self): u -= self.stat.g92_offset[6] v -= self.stat.g92_offset[7] w -= self.stat.g92_offset[8] + # the tilted work plane sits inside G92 + if getattr(self.stat, 'g68_active', 0): + r = self.stat.g68_rotation + o = self.stat.g68_offset + x, y, z = x - o[0], y - o[1], z - o[2] + x, y, z = (r[0] * x + r[3] * y + r[6] * z, + r[1] * x + r[4] * y + r[7] * z, + r[2] * x + r[5] * y + r[8] * z) relp = [x, y, z, a, b, c, u, v, w] return p,relp,dtg diff --git a/lib/python/gladevcp/drowidget.py b/lib/python/gladevcp/drowidget.py index 5b446a080c3..17f907837e2 100644 --- a/lib/python/gladevcp/drowidget.py +++ b/lib/python/gladevcp/drowidget.py @@ -287,6 +287,14 @@ def position(self): u -= self.status.g92_offset[6] v -= self.status.g92_offset[7] w -= self.status.g92_offset[8] + # the tilted work plane sits inside G92 + if getattr(self.status, 'g68_active', 0): + r = self.status.g68_rotation + o = self.status.g68_offset + x, y, z = x - o[0], y - o[1], z - o[2] + x, y, z = (r[0] * x + r[3] * y + r[6] * z, + r[1] * x + r[4] * y + r[7] * z, + r[2] * x + r[5] * y + r[8] * z) relp = [x, y, z, a, b, c, u, v, w] if self.display_units_mm != self.machine_units_mm: