From 4c21e1d00f1d5c827e3213ffde0b7a43497d8033 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 21 Mar 2025 22:44:43 -0400 Subject: [PATCH] gcode_move: Internally track an axis_map to map gcode axis names Signed-off-by: Kevin O'Connor --- klippy/extras/gcode_move.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/klippy/extras/gcode_move.py b/klippy/extras/gcode_move.py index ecdadc43..d5930dc2 100644 --- a/klippy/extras/gcode_move.py +++ b/klippy/extras/gcode_move.py @@ -1,6 +1,6 @@ # G-Code G1 movement commands (and associated coordinate manipulation) # -# Copyright (C) 2016-2021 Kevin O'Connor +# Copyright (C) 2016-2025 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. import logging @@ -42,6 +42,7 @@ class GCodeMove: self.base_position = [0.0, 0.0, 0.0, 0.0] self.last_position = [0.0, 0.0, 0.0, 0.0] self.homing_position = [0.0, 0.0, 0.0, 0.0] + self.axis_map = {'X':0, 'Y': 1, 'Z': 2, 'E': 3} self.speed = 25. self.speed_factor = 1. / 60. self.extrude_factor = 1. @@ -114,23 +115,20 @@ class GCodeMove: # Move params = gcmd.get_command_parameters() try: - for pos, axis in enumerate('XYZ'): + for axis, pos in self.axis_map.items(): if axis in params: v = float(params[axis]) - if not self.absolute_coord: + absolute_coord = self.absolute_coord + if axis == 'E': + v *= self.extrude_factor + if not self.absolute_extrude: + absolute_coord = False + if not absolute_coord: # value relative to position of last move self.last_position[pos] += v else: # value relative to base coordinate position self.last_position[pos] = v + self.base_position[pos] - if 'E' in params: - v = float(params['E']) * self.extrude_factor - if not self.absolute_coord or not self.absolute_extrude: - # value relative to position of last move - self.last_position[3] += v - else: - # value relative to base coordinate position - self.last_position[3] = v + self.base_position[3] if 'F' in params: gcode_speed = float(params['F']) if gcode_speed <= 0.: