Skip to content

Commit

Permalink
feat: support cartographer (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jomik authored Dec 2, 2024
1 parent be96fbf commit 815c018
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
37 changes: 23 additions & 14 deletions macros/z_tramming.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}
Expand Down Expand Up @@ -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 %}

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion macros/z_tramming_settings.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 815c018

Please sign in to comment.