From 815c0182275a47a3be0286678a3b0c99c4b7b8a4 Mon Sep 17 00:00:00 2001 From: Jonas Damtoft Date: Mon, 2 Dec 2024 19:51:04 +0100 Subject: [PATCH] feat: support cartographer (#7) --- macros/z_tramming.cfg | 37 +++++++++++++++++++++------------- macros/z_tramming_settings.cfg | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/macros/z_tramming.cfg b/macros/z_tramming.cfg index cc9b525..20e4e54 100644 --- a/macros/z_tramming.cfg +++ b/macros/z_tramming.cfg @@ -2,25 +2,35 @@ [gcode_macro Z_TRAMMING] gcode: - # We need a probe definition in printer.cfg - {% set probe = printer.configfile.settings.probe %} - {% if probe is undefined %} - {action_raise_error("Missing probe settings")} - {% endif %} - {% set config = printer["gcode_macro _Z_TRAMMING_SETTINGS"] | default({}) %} - {% set speed = config.speed | default(printer.configfile.settings.bed_mesh.speed) * 60 %} {% set stepper_x = printer.configfile.settings.stepper_x %} {% set x_min = stepper_x.position_min | float %} - {% set left = config.left | default(x_min if probe.x_offset >= 0 else (x_min - (probe.x_offset * 2))) %} - {% set x_max = stepper_x.position_max | float %} - {% set right = config.right | default(x_max if probe.x_offset <= 0 else (x_max - (probe.x_offset * 2))) %} + + # We need a probe or scanner definition in printer.cfg + {% set probe = printer.configfile.settings.probe %} + {% set scanner = printer.configfile.settings.scanner %} + + {% if probe is defined %} + {% set default_left = x_min if probe.x_offset >= 0 else (x_min - (probe.x_offset * 2)) %} + {% set default_right = x_max if probe.x_offset <= 0 else (x_max - (probe.x_offset * 2)) %} + {% set y_offset = probe.y_offset %} + {% elif scanner is defined %} + {% set margin = 15 %} + {% set default_left = (x_min if scanner.x_offset >= 0 else (x_min - (scanner.x_offset * 2))) + margin %} + {% set default_right = (x_max if scanner.x_offset <= 0 else (x_max - (scanner.x_offset * 2))) - margin %} + {% set y_offset = scanner.y_offset %} + {% else %} + {action_raise_error("No probe or scanner defined")} + {% endif %} + + {% set left = config.left | default(default_left) %} + {% set right = config.right | default(default_right) %} {% set stepper_y = printer.configfile.settings.stepper_y %} - {% set center = config.y_position | default((stepper_y.position_min + stepper_y.position_max) / 2 - probe.y_offset) %} + {% set center = config.y_position | default((stepper_y.position_min + stepper_y.position_max) / 2 - y_offset) %} # Home all axes if not already homed {% if printer.toolhead.homed_axes != "xyz" %} @@ -52,8 +62,7 @@ variable_left: 0 variable_right: 0 gcode: {% set config = printer["gcode_macro _Z_TRAMMING_SETTINGS"] | default({}) %} - {% set probe = printer.configfile.settings.probe %} - {% set tolerance = config.tolerance | default(probe.samples_tolerance * 2)%} + {% set tolerance = config.tolerance | default(0.04) %} {% set screw_lead = printer.configfile.settings.stepper_z.rotation_distance | float %} {% set lift_direction = config.lift_direction | default("CW") | upper %} @@ -109,7 +118,7 @@ gcode: [gcode_macro _Z_TRAMMING_SAVE_RESULT] gcode: - SET_GCODE_VARIABLE MACRO=_Z_TRAMMING_EVALUATE VARIABLE={params.SIDE} VALUE={printer.probe.last_z_result} + SET_GCODE_VARIABLE MACRO=_Z_TRAMMING_EVALUATE VARIABLE={params.SIDE} VALUE={printer.toolhead.position.z} [gcode_macro _Z_TRAMMING_ERROR] gcode: diff --git a/macros/z_tramming_settings.cfg b/macros/z_tramming_settings.cfg index bacaa76..9aa9d43 100644 --- a/macros/z_tramming_settings.cfg +++ b/macros/z_tramming_settings.cfg @@ -1,6 +1,6 @@ # This macro contains the configuration variables for the Z Tramming macro [gcode_macro _Z_TRAMMING_SETTINGS] -# variable_tolerance: 0.04 # Defaults to double the probe.samples_tolerance +# variable_tolerance: 0.04 # Defaults to 0.04 # variable_y_position: 51 # Defaults to probe at the center of bed # variable_left: 0 # Defaults to minmum position accounting for probe offset # variable_right: 169.5 # Defaults to minmum position accounting for probe offset