From a1dbc53208f5233282892faa3e40bfc5cca2aa70 Mon Sep 17 00:00:00 2001 From: Rob Bricheno Date: Mon, 31 Mar 2025 16:24:11 +0100 Subject: [PATCH 1/3] Allow live update of gcode offsets --- klipper/extras/tool.py | 5 +++++ klipper/extras/tools_calibrate.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/klipper/extras/tool.py b/klipper/extras/tool.py index 58f879f1..4f28565e 100644 --- a/klipper/extras/tool.py +++ b/klipper/extras/tool.py @@ -94,6 +94,11 @@ def get_offset(self): self.gcode_z_offset if self.gcode_z_offset else 0.0, ] + def set_offset(self, [x, y, z]): + self.gcode_x_offset = x + self.gcode_y_offset = y + self.gcode_z_offset = z + cmd_ASSIGN_TOOL_help = 'Assign tool to tool number' def cmd_ASSIGN_TOOL(self, gcmd): self.assign_tool(gcmd.getint('N', minval=0), replace = True) diff --git a/klipper/extras/tools_calibrate.py b/klipper/extras/tools_calibrate.py index 64158415..8be5513b 100644 --- a/klipper/extras/tools_calibrate.py +++ b/klipper/extras/tools_calibrate.py @@ -51,6 +51,9 @@ def __init__(self, config): self.gcode.register_command('TOOL_CALIBRATE_TOOL_OFFSET', self.cmd_TOOL_CALIBRATE_TOOL_OFFSET, desc=self.cmd_TOOL_CALIBRATE_TOOL_OFFSET_help) + self.gcode.register_command('TOOL_CALIBRATE_TOOL_OFFSET_LIVE_UPDATE', + self.cmd_TOOL_CALIBRATE_TOOL_OFFSET_LIVE_UPDATE, + desc=self.cmd_TOOL_CALIBRATE_TOOL_OFFSET_LIVE_UPDATE_help) self.gcode.register_command('TOOL_CALIBRATE_SAVE_TOOL_OFFSET', self.cmd_TOOL_CALIBRATE_SAVE_TOOL_OFFSET, desc=self.cmd_TOOL_CALIBRATE_SAVE_TOOL_OFFSET_help) @@ -132,6 +135,22 @@ def cmd_TOOL_CALIBRATE_TOOL_OFFSET(self, gcmd): % (self.last_result[0], self.last_result[1], self.last_result[2])) + cmd_TOOL_CALIBRATE_TOOL_OFFSET_LIVE_UPDATE_help = "Calibrate current tool offset relative to tool 0 (and apply)" + + def cmd_TOOL_CALIBRATE_TOOL_OFFSET_LIVE_UPDATE(self, gcmd): + if not self.sensor_location: + raise gcmd.error( + "No recorded sensor location, please run TOOL_LOCATE_SENSOR first") + location = self.locate_sensor(gcmd) + self.last_result = [location[i] - self.sensor_location[i] for i in + range(3)] + # set live tool offset using a_tool.set_offset(self.last_result) + self.printer.lookup_object('toolchanger').get_selected_tool().set_offset(self.last_result) + + self.gcode.respond_info("Tool offset is %.6f,%.6f,%.6f" + % (self.last_result[0], self.last_result[1], + self.last_result[2])) + cmd_TOOL_CALIBRATE_SAVE_TOOL_OFFSET_help = "Save tool offset calibration to config" def cmd_TOOL_CALIBRATE_SAVE_TOOL_OFFSET(self, gcmd): From 72662ad36929a75267d97ece3e6c5e72295d2813 Mon Sep 17 00:00:00 2001 From: noobydp Date: Fri, 2 May 2025 14:54:48 +0800 Subject: [PATCH 2/3] fix tupple error --- klipper/extras/tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/klipper/extras/tool.py b/klipper/extras/tool.py index 4f28565e..8b4be825 100644 --- a/klipper/extras/tool.py +++ b/klipper/extras/tool.py @@ -94,7 +94,8 @@ def get_offset(self): self.gcode_z_offset if self.gcode_z_offset else 0.0, ] - def set_offset(self, [x, y, z]): + def set_offset(self, offset): + x, y, z = offset self.gcode_x_offset = x self.gcode_y_offset = y self.gcode_z_offset = z From a6cbbc28b1e3e986df751444b463ff269fbfb03d Mon Sep 17 00:00:00 2001 From: noobydp Date: Fri, 2 May 2025 19:59:39 +0800 Subject: [PATCH 3/3] replicated jwellman80:patch-1 --- klipper/extras/tool_probe.py | 3 ++- klipper/extras/tool_probe_endstop.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/klipper/extras/tool_probe.py b/klipper/extras/tool_probe.py index 607858dd..6f3848cb 100644 --- a/klipper/extras/tool_probe.py +++ b/klipper/extras/tool_probe.py @@ -122,7 +122,8 @@ def _probe(self, speed): pos = toolhead.get_position() pos[2] = self.z_position try: - epos = self.mcu_probe.probing_move(pos, speed) + phoming = self.printer.lookup_object('homing') + epos = phoming.probing_move(self.mcu_probe, pos, speed) except self.printer.command_error as e: reason = str(e) if "Timeout during endstop homing" in reason: diff --git a/klipper/extras/tool_probe_endstop.py b/klipper/extras/tool_probe_endstop.py index b8cd0093..331f6be2 100644 --- a/klipper/extras/tool_probe_endstop.py +++ b/klipper/extras/tool_probe_endstop.py @@ -209,7 +209,7 @@ def set_active_mcu(self, mcu_probe): self.home_wait = self.active_mcu.home_wait self.multi_probe_begin = self.active_mcu.multi_probe_begin self.multi_probe_end = self.active_mcu.multi_probe_end - self.probing_move = self.active_mcu.probing_move + # self.probing_move = self.active_mcu.probing_move self.probe_prepare = self.active_mcu.probe_prepare self.probe_finish = self.active_mcu.probe_finish else: @@ -218,7 +218,7 @@ def set_active_mcu(self, mcu_probe): self.home_wait = self.on_error self.multi_probe_begin = self.on_error self.multi_probe_end = self.on_error - self.probing_move = self.on_error + # self.probing_move = self.on_error self.probe_prepare = self.on_error self.probe_finish = self.on_error