From 6e8c10ebb3e635535f9654b36737c2f9c0754e41 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Tue, 12 Sep 2023 13:39:54 +0200 Subject: [PATCH] force_move: implement CLEAR for SET_KINEMATIC_POSITION `CLEAR` clears the homing status (resets the axis limits) without turning off the motors. This is particularly useful when implementing safe Z homing in `[homing_override]` on printers with multiple independent Z steppers (where `FORCE_MOVE` can't be used). Signed-off-by: Dennis Marttinen --- docs/G-Codes.md | 19 ++++++++++--------- klippy/extras/force_move.py | 7 +++++-- klippy/toolhead.py | 3 ++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 1f466dcd3eb1..e8ed28aff9d4 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -540,15 +540,16 @@ state; issue a G28 afterwards to reset the kinematics. This command is intended for low-level diagnostics and debugging. #### SET_KINEMATIC_POSITION -`SET_KINEMATIC_POSITION [X=] [Y=] [Z=]`: Force -the low-level kinematic code to believe the toolhead is at the given -cartesian position. This is a diagnostic and debugging command; use -SET_GCODE_OFFSET and/or G92 for regular axis transformations. If an -axis is not specified then it will default to the position that the -head was last commanded to. Setting an incorrect or invalid position -may lead to internal software errors. This command may invalidate -future boundary checks; issue a G28 afterwards to reset the -kinematics. +`SET_KINEMATIC_POSITION [X=] [Y=] [Z=] +[CLEAR=<[X][Y][Z]>]`: Force the low-level kinematic code to believe the +toolhead is at the given cartesian position. This is a diagnostic and +debugging command; use SET_GCODE_OFFSET and/or G92 for regular axis +transformations. If an axis is not specified then it will default to the +position that the head was last commanded to. Setting an incorrect or +invalid position may lead to internal software errors. Use the CLEAR +parameter to forget the homing state for the given axes. This command +may invalidate future boundary checks; issue a G28 afterwards to reset +the kinematics. ### [gcode] diff --git a/klippy/extras/force_move.py b/klippy/extras/force_move.py index 3c05843b23bd..0939572cb8f9 100644 --- a/klippy/extras/force_move.py +++ b/klippy/extras/force_move.py @@ -129,8 +129,11 @@ def cmd_SET_KINEMATIC_POSITION(self, gcmd): x = gcmd.get_float('X', curpos[0]) y = gcmd.get_float('Y', curpos[1]) z = gcmd.get_float('Z', curpos[2]) - logging.info("SET_KINEMATIC_POSITION pos=%.3f,%.3f,%.3f", x, y, z) - toolhead.set_position([x, y, z, curpos[3]], homing_axes=(0, 1, 2)) + axes = ['X', 'Y', 'Z'] + clear_axes = [axes.index(a) for a in axes if a in gcmd.get('CLEAR', '').upper()] + logging.info("SET_KINEMATIC_POSITION pos=%.3f,%.3f,%.3f clear=%s", + x, y, z, ','.join((axes[i] for i in clear_axes))) + toolhead.set_position([x, y, z, curpos[3]], homing_axes=(0, 1, 2), clear_axes=clear_axes) def load_config(config): return ForceMove(config) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index d8b9382570b6..833bfe252ec5 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -406,13 +406,14 @@ def _flush_handler(self, eventtime): # Movement commands def get_position(self): return list(self.commanded_pos) - def set_position(self, newpos, homing_axes=()): + def set_position(self, newpos, homing_axes=(), clear_axes=()): self.flush_step_generation() ffi_main, ffi_lib = chelper.get_ffi() ffi_lib.trapq_set_position(self.trapq, self.print_time, newpos[0], newpos[1], newpos[2]) self.commanded_pos[:] = newpos self.kin.set_position(newpos, homing_axes) + self.kin.clear_homing_state(clear_axes) self.printer.send_event("toolhead:set_position") def move(self, newpos, speed): move = Move(self, self.commanded_pos, newpos, speed)