From c81c93896b1afe12fbb5e2ddb8751ec4e52d5e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Jul 2017 09:28:22 +0200 Subject: [PATCH] Apply tool offsets immediately and only once Less tracking of offsets and also more similar to how firmware does this. We rewrite our current position on tool change to current position plus tool offset instead of applying it for every single position change. --- src/octoprint/util/gcodeInterpreter.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index ea6d291a..2e8f62df 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -222,7 +222,6 @@ class gcode(object): lineNo = 0 readBytes = 0 pos = Vector3D(0.0, 0.0, 0.0) - toolOffset = Vector3D(0.0, 0.0, 0.0) currentE = [0.0] totalExtrusion = [0.0] maxExtrusion = [0.0] @@ -320,16 +319,16 @@ class gcode(object): # Use new coordinates if provided. If not provided, use prior coordinates (minus tool offset) # in absolute and 0.0 in relative mode. - newPos = Vector3D(x if x is not None else (0.0 if relativeMode else pos.x - toolOffset.x), - y if y is not None else (0.0 if relativeMode else pos.y - toolOffset.y), - z if z is not None else (0.0 if relativeMode else pos.z - toolOffset.z)) + newPos = Vector3D(x if x is not None else (0.0 if relativeMode else pos.x), + y if y is not None else (0.0 if relativeMode else pos.y), + z if z is not None else (0.0 if relativeMode else pos.z)) if relativeMode: # Relative mode: scale and add to current position pos += newPos * scale else: # Absolute mode: scale coordinates and apply tool offsets - pos = newPos * scale + toolOffset + pos = newPos * scale if f is not None and f != 0: feedrate = f @@ -442,14 +441,16 @@ class gcode(object): elif T is not None: if T > max_extruders: self._logger.warn("GCODE tried to select tool %d, that looks wrong, ignoring for GCODE analysis" % T) + elif T == currentExtruder: + pass else: - toolOffset.x -= offsets[currentExtruder][0] if currentExtruder < len(offsets) else 0 - toolOffset.y -= offsets[currentExtruder][1] if currentExtruder < len(offsets) else 0 + pos.x -= offsets[currentExtruder][0] if currentExtruder < len(offsets) else 0 + pos.y -= offsets[currentExtruder][1] if currentExtruder < len(offsets) else 0 currentExtruder = T - toolOffset.x += offsets[currentExtruder][0] if currentExtruder < len(offsets) else 0 - toolOffset.y += offsets[currentExtruder][1] if currentExtruder < len(offsets) else 0 + pos.x += offsets[currentExtruder][0] if currentExtruder < len(offsets) else 0 + pos.y += offsets[currentExtruder][1] if currentExtruder < len(offsets) else 0 if len(currentE) <= currentExtruder: for i in range(len(currentE), currentExtruder + 1):