From 9dde27aef3a78af0b9db35a014b44a0dfaa4eb6b Mon Sep 17 00:00:00 2001 From: Nick Weedon Date: Wed, 29 Jan 2025 10:44:52 -0500 Subject: [PATCH] probe_as_z_home: Added g28_probe_cmd_args configuration option * Added the optional g28_probe_cmd_args configuration option to [probe_as_z_home] to allow gcode command arguments to be passed to the PROBE command during homing. * Updated documentation to 'Config_Reference.md'. Signed-off-by: Nick Weedon --- docs/Config_Reference.md | 7 ++++++- klippy/extras/probe_as_z_home.py | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 53d3409f7..1af68b54e 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -2095,7 +2095,7 @@ sensor_type: ldc1612 This tool allows the homing procedure (```G28```) to use probing (i.e. the same as the ```PROBE``` command) so that in some cases the Z axis can be more accurately probed. -You should only use this option if you are occasionally experiencing innacurate homing. +You should use this option if you are occasionally experiencing innacurate homing. Configuring this tool will also cause the ```G28``` G-Code to emit a console message stating the correction that was performed. You can use this to measure the level of benefit that the tool is providing. @@ -2107,6 +2107,11 @@ See [command reference](G-Codes.md#G-Code_commands) for further information. ``` [probe_as_z_home] +#g28_probe_cmd_args: +# Optional command arguments passed to the PROBE command while homing. +# See [g-code PROBE command](G-Codes.md#probe). +# Example: +# g28_probe_cmd_args: SAMPLES=3 SAMPLES_TOLERANCE_RETRIES=5 ``` _Note: The standing homing procedure is still perofrmed before probing since this is required to ensure safety and compatibility with the probing method since probing requires homing to first be performed_ diff --git a/klippy/extras/probe_as_z_home.py b/klippy/extras/probe_as_z_home.py index eb0a84649..73eafc5e6 100644 --- a/klippy/extras/probe_as_z_home.py +++ b/klippy/extras/probe_as_z_home.py @@ -17,6 +17,7 @@ class ProbeAsZHome: self.printer.load_object(config, 'homing') self.prev_G28 = self.gcode.register_command("G28", None) self.gcode.register_command("G28", self.cmd_G28) + self.g28_probe_cmd_args = config.get("g28_probe_cmd_args", None) def cmd_G28(self, gcmd): logging.debug("Probe As Home: Performing G28") @@ -61,10 +62,21 @@ class ProbeAsZHome: current_pos[2] += retract_dist self.toolhead.move(current_pos, lift_speed) - # Use the probe options from the configuration here - g28_gcmd = self.gcode.create_gcode_command("PROBE", "PROBE", {}) - probe_session = probe.start_probe_session(gcmd) - probe_session.run_probe(gcmd) + # Parse and pass any arguments defined in the g28_probe_cmd_args + # configuration to the PROBE command. + probe_args_dict = {} + + if self.g28_probe_cmd_args is not None: + probe_arg_tokens = self.g28_probe_cmd_args.split(" ") + probe_arg_tokens = filter(lambda token: token.strip() != "", + probe_arg_tokens) + probe_args_dict = { operand[0]: operand[1] for operand in \ + [arg.split("=") for arg in probe_arg_tokens]} + + probe_gcmd = self.gcode.create_gcode_command( + "PROBE", "PROBE", probe_args_dict) + probe_session = probe.start_probe_session(probe_gcmd) + probe_session.run_probe(probe_gcmd) probed_pos = probe_session.pull_probed_results()[0] current_pos = self.toolhead.get_position() z_error_delta = probed_pos[2] - current_pos[2]