Skip to content

Commit

Permalink
Small fixes and improvements (#216)
Browse files Browse the repository at this point in the history
* Update Smart_Park.cfg

- fixed smart park not obeying the purge_margin adjustment properly

- added logic to check the XY axes minimums so the park location will always obey the bounds of the machine

* Update Smart_Park.cfg

- added check for current Z position before z_height move. If current Z position is less than z_height, move Z before XY

* Update README.md

- Fix weird spacing with moonraker.conf update_manager config block

* Add files via upload

* Update README.md

- added include tutorial gif and adjusted some verbiage I felt was odd

* Update Voron_Purge.cfg

- fixed purge not using firmware retraction if it's defined

* Update README.md

fixed typo

* Correct calculations for margins and fuzzing (#201)

* Update Adaptive_Meshing.cfg

- employ simpler variable pulling
- add error message if no objects are found, with a 5 second pause

* tweak readme layout

---------

Co-authored-by: Garth Snyder <garth@garthsnyder.com>
  • Loading branch information
kyleisah and GarthSnyder authored Nov 2, 2023
1 parent 2389a99 commit 128142b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 99 deletions.
114 changes: 61 additions & 53 deletions Configuration/Adaptive_Meshing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ gcode:
{% set bed_mesh_min = printer.configfile.settings.bed_mesh.mesh_min %} # Get bed mesh min from printer.cfg
{% set bed_mesh_max = printer.configfile.settings.bed_mesh.mesh_max %} # Get bed mesh max from printer.cfg
{% set probe_count = printer.configfile.settings.bed_mesh.probe_count %} # Get probe count from printer.cfg
{% set verbose_enable = printer["gcode_macro _KAMP_Settings"].verbose_enable | abs %} # Pull verbose setting from _KAMP_Settings
{% set probe_dock_enable = printer["gcode_macro _KAMP_Settings"].probe_dock_enable | abs %} # Pull probe dockable probe settings from _KAMP_Settings
{% set attach_macro = printer["gcode_macro _KAMP_Settings"].attach_macro | string %} # Pull attach probe command from _KAMP_Settings
{% set detach_macro = printer["gcode_macro _KAMP_Settings"].detach_macro | string %} # Pull detach probe command from _KAMP_Settings
{% set mesh_margin = printer["gcode_macro _KAMP_Settings"].mesh_margin | float %} # Pull mesh margin setting from _KAMP_Settings
{% set fuzz_amount = printer["gcode_macro _KAMP_Settings"].fuzz_amount | float %} # Pull fuzz amount setting from _KAMP_Settings
{% set kamp_settings = printer["gcode_macro _KAMP_Settings"] %} # Pull variables from _KAMP_Settings
{% set verbose_enable = kamp_settings.verbose_enable | abs %} # Pull verbose setting from _KAMP_Settings
{% set probe_dock_enable = kamp_settings.probe_dock_enable | abs %} # Pull probe dockable probe settings from _KAMP_Settings
{% set attach_macro = kamp_settings.attach_macro | string %} # Pull attach probe command from _KAMP_Settings
{% set detach_macro = kamp_settings.detach_macro | string %} # Pull detach probe command from _KAMP_Settings
{% set mesh_margin = kamp_settings.mesh_margin | float %} # Pull mesh margin setting from _KAMP_Settings
{% set fuzz_amount = kamp_settings.fuzz_amount | float %} # Pull fuzz amount setting from _KAMP_Settings
{% set probe_count = probe_count if probe_count|length > 1 else probe_count * 2 %} # If probe count is only a single number, convert it to 2. E.g. probe_count:7 = 7,7
{% set max_probe_point_distance_x = ( bed_mesh_max[0] - bed_mesh_min[0] ) / (probe_count[0] - 1) %} # Determine max probe point distance
{% set max_probe_point_distance_y = ( bed_mesh_max[1] - bed_mesh_min[1] ) / (probe_count[1] - 1) %} # Determine max probe point distance
Expand All @@ -28,10 +29,10 @@ gcode:
{% set y_max = all_points | map(attribute=1) | max | default(bed_mesh_max[1]) %} # Set y_max from largest object y point

{% set fuzz_range = range((0) | int, (fuzz_amount * 100) | int + 1) %} # Set fuzz_range between 0 and fuzz_amount
{% set adapted_x_min = (bed_mesh_min[0] + fuzz_amount - mesh_margin, x_min) | max - (fuzz_range | random / 100.0) %} # Adapt x_min to margin and fuzz constraints
{% set adapted_y_min = (bed_mesh_min[1] + fuzz_amount - mesh_margin, y_min) | max - (fuzz_range | random / 100.0) %} # Adapt y_min to margin and fuzz constraints
{% set adapted_x_max = (bed_mesh_max[0] - fuzz_amount + mesh_margin, x_max) | min + (fuzz_range | random / 100.0) %} # Adapt x_max to margin and fuzz constraints
{% set adapted_y_max = (bed_mesh_max[1] - fuzz_amount + mesh_margin, y_max) | min + (fuzz_range | random / 100.0) %} # Adapt y_max to margin and fuzz constraints
{% set adapted_x_min = x_min - mesh_margin - (fuzz_range | random / 100.0) %} # Adapt x_min to margin and fuzz constraints
{% set adapted_y_min = y_min - mesh_margin - (fuzz_range | random / 100.0) %} # Adapt y_min to margin and fuzz constraints
{% set adapted_x_max = x_max + mesh_margin + (fuzz_range | random / 100.0) %} # Adapt x_max to margin and fuzz constraints
{% set adapted_y_max = y_max + mesh_margin + (fuzz_range | random / 100.0) %} # Adapt y_max to margin and fuzz constraints

{% set adapted_x_min = [adapted_x_min , bed_mesh_min[0]] | max %} # Compare adjustments to defaults and choose max
{% set adapted_y_min = [adapted_y_min , bed_mesh_min[1]] | max %} # Compare adjustments to defaults and choose max
Expand All @@ -55,49 +56,56 @@ gcode:
{% set points_y = [points_y , probe_count[1]]|min %}

{% if verbose_enable == True %} # If verbose is enabled, print information about KAMP's calculations

{ action_respond_info( "Algorithm: {}.".format(
(algorithm),
)) }

{ action_respond_info("Default probe count: {},{}.".format(
(probe_count[0]),
(probe_count[1]),
)) }

{ action_respond_info("Adapted probe count: {},{}.".format(
(points_x),
(points_y),
)) }

{action_respond_info("Default mesh bounds: {}, {}.".format(
(bed_mesh_min[0],bed_mesh_min[1]),
(bed_mesh_max[0],bed_mesh_max[1]),
)) }

{% if mesh_margin > 0 %}
{action_respond_info("Mesh margin is {}, mesh bounds extended by {}mm.".format(
(mesh_margin),
(mesh_margin),
)) }
{% else %}
{action_respond_info("Mesh margin is 0, margin not increased.")}
{% endif %}

{% if fuzz_amount > 0 %}
{action_respond_info("Mesh point fuzzing enabled, points fuzzed up to {}mm.".format(
(fuzz_amount),
)) }
{% else %}
{action_respond_info("Fuzz amount is 0, mesh points not fuzzed.")}
{% endif %}

{ action_respond_info("Adapted mesh bounds: {}, {}.".format(
(adapted_x_min, adapted_y_min),
(adapted_x_max, adapted_y_max),
)) }

{action_respond_info("KAMP adjustments successful. Happy KAMPing!")}
{% if printer.exclude_object.objects != [] %}

{ action_respond_info( "Algorithm: {}.".format(
(algorithm),
)) }

{ action_respond_info("Default probe count: {},{}.".format(
(probe_count[0]),
(probe_count[1]),
)) }

{ action_respond_info("Adapted probe count: {},{}.".format(
(points_x),
(points_y),
)) }

{action_respond_info("Default mesh bounds: {}, {}.".format(
(bed_mesh_min[0],bed_mesh_min[1]),
(bed_mesh_max[0],bed_mesh_max[1]),
)) }

{% if mesh_margin > 0 %}
{action_respond_info("Mesh margin is {}, mesh bounds extended by {}mm.".format(
(mesh_margin),
(mesh_margin),
)) }
{% else %}
{action_respond_info("Mesh margin is 0, margin not increased.")}
{% endif %}

{% if fuzz_amount > 0 %}
{action_respond_info("Mesh point fuzzing enabled, points fuzzed up to {}mm.".format(
(fuzz_amount),
)) }
{% else %}
{action_respond_info("Fuzz amount is 0, mesh points not fuzzed.")}
{% endif %}

{ action_respond_info("Adapted mesh bounds: {}, {}.".format(
(adapted_x_min, adapted_y_min),
(adapted_x_max, adapted_y_max),
)) }

{action_respond_info("KAMP adjustments successful. Happy KAMPing!")}

{% else %}

{action_respond_info("No objects detected! Check your gcode and make sure that EXCLUDE_OBJECT_DEFINE is happening before BED_MESH_CALIBRATE is called. Defaulting to regular meshing.")}
G4 P5000 # Wait 5 seconds to make error more visible
{% endif %}

{% endif %}

Expand Down
11 changes: 9 additions & 2 deletions Configuration/Smart_Park.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ gcode:
{% set verbose_enable = kamp_settings.verbose_enable | abs %} # Set verbosity
{% set center_x = printer.toolhead.axis_maximum.x / 2 | float %} # Create center point of x for fallback
{% set center_y = printer.toolhead.axis_maximum.y / 2 | float %} # Create center point of y for fallback
{% set axis_minimum_x = printer.toolhead.axis_minimum.x | float %}
{% set axis_minimum_y = printer.toolhead.axis_minimum.y | float %}
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %} # Gather all object points
{% set x_min = all_points | map(attribute=0) | min | default(center_x) %} # Set x_min from smallest object x point
{% set y_min = all_points | map(attribute=1) | min | default(center_y) %} # Set y_min from smallest object y point
{% set travel_speed = (printer.toolhead.max_velocity) * 60 | float %} # Set travel speed from config

{% if purge_margin > 0 and x_min != center_x and y_min != center_y %} # If objects are detected and purge margin
{% set x_min = [ x_min - purge_margin , x_min ] | max %} # value is greater than 0, move
{% set y_min = [ y_min - purge_margin , y_min ] | max %} # to purge location + margin
{% set x_min = [ x_min - purge_margin , x_min ] | min %} # value is greater than 0, move
{% set y_min = [ y_min - purge_margin , y_min ] | min %} # to purge location + margin
{% set x_min = [ x_min , axis_minimum_x ] | max %}
{% set y_min = [ y_min , axis_minimum_y ] | max %}
{% endif %}

# Verbose park location
Expand All @@ -28,5 +32,8 @@ gcode:

{% endif %}

{% if printer.toolhead.position.z < z_height %}
G0 Z{z_height} # Move Z to park height if current Z position is lower than z_height
{% endif %}
G0 X{x_min} Y{y_min} F{travel_speed} # Move near object area
G0 Z{z_height} # Move Z to park height
Loading

0 comments on commit 128142b

Please sign in to comment.