From d6b69938abcff61ca1c2323899ec74eac149f13b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 20 May 2019 22:36:57 -0400 Subject: gcode: Don't apply the SET_GCODE_OFFSET to the next g-code command The SET_GCODE_OFFSET command could cause unwanted behavior when an offset is applied to the following g-code command. (In particular, when the following command is an extrude only move - as in issue #1289.) Don't apply the offset immediately. Instead, add support for a MOVE=1 parameter which will schedule a move to apply the given offset. Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'klippy/gcode.py') diff --git a/klippy/gcode.py b/klippy/gcode.py index 3cbb1ae4..56d5c9a8 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -601,6 +601,7 @@ class GCodeParser: self.extrude_factor = new_extrude_factor cmd_SET_GCODE_OFFSET_help = "Set a virtual offset to g-code positions" def cmd_SET_GCODE_OFFSET(self, params): + move_delta = [0., 0., 0., 0.] for axis, pos in self.axis2pos.items(): if axis in params: offset = self.get_float(axis, params) @@ -610,9 +611,19 @@ class GCodeParser: else: continue delta = offset - self.homing_position[pos] - self.last_position[pos] += delta + move_delta[pos] = delta self.base_position[pos] += delta self.homing_position[pos] = offset + # Move the toolhead the given offset if requested + if self.get_int('MOVE', params, 0): + speed = self.get_float('MOVE_SPEED', params, + self.speed * self.speed_factor, above=0.) + for pos, delta in enumerate(move_delta): + self.last_position[pos] += delta + try: + self.move_with_transform(self.last_position, speed) + except homing.EndstopError as e: + raise error(str(e)) def cmd_M206(self, params): # Offset axes offsets = { self.axis2pos[a]: self.get_float(a, params) -- cgit v1.2.3-70-g09d2