From 6d03dee104531cc174b8ed8a0886768956bade31 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 20 Apr 2018 19:58:37 -0400 Subject: [PATCH] gcode: Add a SET_GCODE_OFFSET command The M206 command is confusing (it uses negative offsets) and isn't very flexible. Add a new SET_GCODE_OFFSET command to make it easier to add virtual offsets to gcode commands. Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 11 ++++++++++- docs/Todo.md | 4 ---- klippy/gcode.py | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 37a72717..716ff47a 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -25,7 +25,6 @@ Klipper supports the following standard G-Code commands: - Emergency stop: `M112` - Get current position: `M114` - Get firmware version: `M115` -- Set home offset: `M206 [X] [Y] [Z]` For further details on the above commands see the [RepRap G-Code documentation](http://reprap.org/wiki/G-code). @@ -64,6 +63,16 @@ The following standard commands are supported: verify that an endstop is working correctly. - `GET_POSITION`: Return information on the current location of the toolhead. +- `SET_GCODE_OFFSET [X=|X_ADJUST=] + [Y=|Y_ADJUST=] [Z=|Z_ADJUST=]`: Set a + positional offset to apply to future G-Code commands. This is + commonly used to virtually change the Z bed offset or to set nozzle + XY offsets when switching extruders. For example, if + "SET_GCODE_OFFSET Z=0.2" is sent, then future G-Code moves will + have 0.2mm added to their Z height. If the X_ADJUST style parameters + are used, then the adjustment will be added to any existing offset + (eg, "SET_GCODE_OFFSET Z=-0.2" followed by "SET_GCODE_OFFSET + Z_ADJUST=0.3" would result in a total Z offset of 0.1). - `PID_CALIBRATE HEATER= TARGET= [WRITE_FILE=1]`: Perform a PID calibration test. The specified heater will be enabled until the specified target temperature is diff --git a/docs/Todo.md b/docs/Todo.md index 2c9be3c5..2d9bbae9 100644 --- a/docs/Todo.md +++ b/docs/Todo.md @@ -11,10 +11,6 @@ Host user interaction * Improve gcode interface: - * Provide a better way to handle print nozzle z offsets. The M206 - command is cryptic to use and it is too easy to set the value - incorrectly or to forget to set it. - * Provide a way to temporarily disable endstop checks so that a user can issue commands that potentially move the head past position_min/position_max. diff --git a/klippy/gcode.py b/klippy/gcode.py index 99969d1d..84a3ad88 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -367,7 +367,8 @@ class GCodeParser: self.run_script(self.extruder.get_activate_gcode(True)) all_handlers = [ 'G1', 'G4', 'G28', 'M18', 'M400', - 'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M220', 'M221', 'M206', + 'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M220', 'M221', + 'SET_GCODE_OFFSET', 'M206', 'M105', 'M104', 'M109', 'M140', 'M190', 'M106', 'M107', 'M112', 'M115', 'IGNORE', 'QUERY_ENDSTOPS', 'GET_POSITION', 'RESTART', 'FIRMWARE_RESTART', 'ECHO', 'STATUS', 'HELP'] @@ -484,6 +485,18 @@ class GCodeParser: e_value = (last_e_pos - self.base_position[3]) / self.extrude_factor self.base_position[3] = last_e_pos - e_value * new_extrude_factor 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): + for axis, pos in self.axis2pos.items(): + if axis in params: + offset = self.get_float(axis, params) + elif axis + '_ADJUST' in params: + offset = self.homing_position[pos] + offset += self.get_float(axis + '_ADJUST', params) + else: + continue + self.base_position[pos] += offset - self.homing_position[pos] + self.homing_position[pos] = offset def cmd_M206(self, params): # Offset axes offsets = { self.axis2pos[a]: self.get_float(a, params)