Skip to content

Commit

Permalink
Merge pull request kyleisah#88 from kyleisah/revert-87-dev
Browse files Browse the repository at this point in the history
Revert "Total ovarhaul of KAMP to improve verbosity, usability, and prevent several error states"
  • Loading branch information
kyleisah authored Jun 30, 2023
2 parents a6504c5 + d204c8d commit 4a7569e
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 437 deletions.
1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

139 changes: 139 additions & 0 deletions Configuration/Adaptive_Mesh.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# # # Klipper Adaptive Meshing # # #

# Heads up! If you have any other BED_MESH_CALIBRATE macros defined elsewhere in your config, you will need to comment out / remove them for this to work. (Klicky/Euclid Probe)
# You will also need to be sure that [exclude_object] is defined in printer.cfg, and your slicer is labeling objects.
# This macro will parse information from objects in your gcode to define a min and max mesh area to probe, creating an adaptive mesh!
# This macro will not increase probe_count values in your [bed_mesh] config. If you want richer meshes, be sure to increase probe_count. We recommend at least 5,5.

[gcode_macro BED_MESH_CALIBRATE]
rename_existing: _BED_MESH_CALIBRATE

### This section allows control of status LEDs your printer may have.

variable_led_enable: False # Enables/disables the use of status LEDs in this macro.
variable_status_macro: 'status_meshing' # If you have status LEDs in your printer (StealthBurner), you can use the macro that changes their status here.

### This section configures mesh point fuzzing, which allows probe points to be varied slightly if printing multiples of the same G-code file.

variable_fuzz_enable: False # Enables/disables the use of mesh point fuzzing to slightly randomize probing points to spread out wear on a build surface, default is False.
variable_fuzz_min: 0 # If enabled, the minimum amount in mm a probe point can be randomized, default is 0.
variable_fuzz_max: 4 # If enabled, the maximum amount in mm a probe point can be randomized, default is 4.

### This section is for configuring a mesh margin, which allows the probed mesh to be expanded outwards from the print area.

variable_margin_enable: False # Enables/disables adding a margin to the meshed area to pad a mesh out for specific needs, default is False.
variable_margin_size: 5 # Size in millimeters to expand the mesh outwards from the print area in all directions.

### This section is for those using a dockable probe that is stored outside of the print area. ###

variable_probe_dock_enable: False # Enables/disables the use of a dockable probe that is stored outside of the print area, default is False.
variable_attach_macro: 'Attach_Probe' # Here is where you define the macro that ATTACHES the probe to the printhead. E.g. 'Attach_Probe'
variable_detach_macro: 'Dock_Probe' # Here is where you define the macro that DETACHES the probe from the printhead. E.g. 'Dock_Probe'

### This section is for those who are using Moonraker's Update Manager for KAMP, or want a more verbose macro. ###

variable_display_parameters: True # Display macro paramters in the console, useful for debugging the SETUP_KAMP_MESHING call, or more verbosity.

gcode:

{% if display_parameters == True %}
{ action_respond_info("led_enable : %d" % (led_enable)) }
{ action_respond_info("status_macro: \'%s\'" % (status_macro)) }
{ action_respond_info("fuzz_enable : %d" % (fuzz_enable)) }
{ action_respond_info("fuzz_min : %f" % (fuzz_min)) }
{ action_respond_info("fuzz_max : %f" % (fuzz_max)) }
{ action_respond_info("probe_dock_enable: %d" % (probe_dock_enable)) }
{ action_respond_info("attach_macro: \'%s\'" % (attach_macro)) }
{ action_respond_info("detach_macro: \'%s\'" % (detach_macro)) }
{% endif %}

{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
{% set bed_mesh_min = printer.configfile.settings.bed_mesh.mesh_min %}
{% set bed_mesh_max = printer.configfile.settings.bed_mesh.mesh_max %}
{% set probe_count = printer.configfile.settings.bed_mesh.probe_count %}
{% set probe_count = probe_count if probe_count|length > 1 else probe_count * 2 %}
{% set max_probe_point_distance_x = ( bed_mesh_max[0] - bed_mesh_min[0] ) / (probe_count[0] - 1) %}
{% set max_probe_point_distance_y = ( bed_mesh_max[1] - bed_mesh_min[1] ) / (probe_count[1] - 1) %}
{% set x_min = all_points | map(attribute=0) | min | default(bed_mesh_min[0]) %}
{% set y_min = all_points | map(attribute=1) | min | default(bed_mesh_min[1]) %}
{% set x_max = all_points | map(attribute=0) | max | default(bed_mesh_max[0]) %}
{% set y_max = all_points | map(attribute=1) | max | default(bed_mesh_max[1]) %}

{% if margin_enable == False %}
{% set margin_size = 0 %}
{% endif %}

{ action_respond_info("{} object points, clamping to bed mesh [{!r} {!r}]".format(
all_points | count,
bed_mesh_min,
bed_mesh_max,
)) }

{% if fuzz_enable == True %}
{% set fuzz_range = range((fuzz_min * 100) | int, (fuzz_max * 100) | int + 1) %}
{% set x_min = (bed_mesh_min[0] + fuzz_max - margin_size, x_min) | max - (fuzz_range | random / 100.0) %}
{% set y_min = (bed_mesh_min[1] + fuzz_max - margin_size, y_min) | max - (fuzz_range | random / 100.0) %}
{% set x_max = (bed_mesh_max[0] - fuzz_max + margin_size, x_max) | min + (fuzz_range | random / 100.0) %}
{% set y_max = (bed_mesh_max[1] - fuzz_max + margin_size, y_max) | min + (fuzz_range | random / 100.0) %}
{% else %}
{% set x_min = [ bed_mesh_min[0], x_min - margin_size ] | max %}
{% set y_min = [ bed_mesh_min[1], y_min - margin_size ] | max %}
{% set x_max = [ bed_mesh_max[0], x_max + margin_size ] | min %}
{% set y_max = [ bed_mesh_max[1], y_max + margin_size ] | min %}
{% endif %}

{ action_respond_info("Object bounds, clamped to the bed_mesh: {!r}, {!r}".format(
(x_min, y_min),
(x_max, y_max),
)) }

{% set points_x = (((x_max - x_min) / max_probe_point_distance_x) | round(method='ceil') | int) + 1 %}
{% set points_y = (((y_max - y_min) / max_probe_point_distance_y) | round(method='ceil') | int) + 1 %}

{% if (([points_x, points_y]|max) > 6) %}
{% set algorithm = "bicubic" %}
{% set min_points = 4 %}
{% else %}
{% set algorithm = "lagrange" %}
{% set min_points = 3 %}
{% endif %}
{ action_respond_info( "Algorithm: {}".format(algorithm)) }

{% set points_x = [points_x, min_points]|max %}
{% set points_y = [points_y, min_points]|max %}
{ action_respond_info( "Points: x: {}, y: {}".format(points_x, points_y) ) }

{% if printer.configfile.settings.bed_mesh.relative_reference_index is defined %}
{% set ref_index = (points_x * points_y / 2) | int %}
{ action_respond_info( "Reference index: {}".format(ref_index) ) }
{% else %}
{% set ref_index = -1 %}
{% endif %}

{% if probe_dock_enable == True %}
{attach_macro} # Attach/deploy a probe if the probe is stored somewhere outside of the print area
{% endif %}

{% if led_enable == True %}
{status_macro} # Set status LEDs
{% endif %}

_BED_MESH_CALIBRATE mesh_min={x_min},{y_min} mesh_max={x_max},{y_max} ALGORITHM={algorithm} PROBE_COUNT={points_x},{points_y} RELATIVE_REFERENCE_INDEX={ref_index}

{% if probe_dock_enable == True %}
{detach_macro} # Detach/stow a probe if the probe is stored somewhere outside of the print area
{% endif %}

[gcode_macro SETUP_KAMP_MESHING]
gcode:
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=display_parameters VALUE={params.DISPLAY_PARAMETERS|default(True)|int}
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=led_enable VALUE={params.LED_ENABLE|default(False)|int}
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=status_macro VALUE='"{params.STATUS_MACRO|default('status_meshing')|string}"'

SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_enable VALUE={params.FUZZ_ENABLE|default(False)|int}
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_min VALUE={params.FUZZ_MIN|default(0)|float}
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_max VALUE={params.FUZZ_MAX|default(4)|float}

SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=probe_dock_enable VALUE={params.PROBE_DOCK_ENABLE|default(False)|int}
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=attach_macro VALUE='"{params.ATTACH_MACRO|default('Attach_Probe')|string}"'
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=detach_macro VALUE='"{params.DETACH_MACRO|default('Dock_Probe')|string}"'
Loading

0 comments on commit 4a7569e

Please sign in to comment.