-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Adaptive_Mesh.cfg
100 lines (80 loc) · 5.85 KB
/
Adaptive_Mesh.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# # # 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: True # 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: True # 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 those using a dockable probe that is stored outside of the print area. ###
variable_probe_dock_enable: True # 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'
gcode:
{% 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 max_probe_point_distance_x = ( bed_mesh_max[0] - bed_mesh_min[0] ) / (printer.configfile.settings.bed_mesh.probe_count[0]-2) %}
{% set max_probe_point_distance_y = ( bed_mesh_max[1] - bed_mesh_min[1] ) / (printer.configfile.settings.bed_mesh.probe_count[1]-2) %}
{% set x_min = bed_mesh_min[0] %}
{% set y_min = bed_mesh_min[1] %}
{% set x_max = bed_mesh_max[0] %}
{% set y_max = bed_mesh_max[1] %}
{ action_respond_info("{} points, clamping to mesh [{!r} {!r}]".format(
all_points | count,
bed_mesh_min,
bed_mesh_max,
)) }
{% if fuzz_enable == True %}
{% if all_points %}
{% set fuzz_range = range(fuzz_min * 100 | int, fuzz_max * 100 | int) %}
{% set x_min = ( bed_mesh_min[0], ((all_points | map(attribute=0) | min - (fuzz_range | random / 100.0)) | default(bed_mesh_min[0])) ) | max %}
{% set y_min = ( bed_mesh_min[1], ((all_points | map(attribute=1) | min - (fuzz_range | random / 100.0)) | default(bed_mesh_min[1])) ) | max %}
{% set x_max = ( bed_mesh_max[0], ((all_points | map(attribute=0) | max + (fuzz_range | random / 100.0)) | default(bed_mesh_max[0])) ) | min %}
{% set y_max = ( bed_mesh_max[1], ((all_points | map(attribute=1) | max + (fuzz_range | random / 100.0)) | default(bed_mesh_max[1])) ) | min %}
{% endif %}
{% else %}
{% set x_min = [ bed_mesh_min[0], (all_points | map(attribute=0) | min | default(bed_mesh_min[0])) ] | max %}
{% set y_min = [ bed_mesh_min[1], (all_points | map(attribute=1) | min | default(bed_mesh_min[1])) ] | max %}
{% set x_max = [ bed_mesh_max[0], (all_points | map(attribute=0) | max | default(bed_mesh_max[0])) ] | min %}
{% set y_max = [ bed_mesh_max[1], (all_points | map(attribute=1) | max | default(bed_mesh_max[1])) ] | 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) | int) + 2 %}
{% set points_y = (((y_max - y_min) / max_probe_point_distance_y) | int) + 2 %}
{% 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 %}