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: 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)