-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_area-mesh.cfg
141 lines (112 loc) · 13.9 KB
/
print_area-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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Setting based on kamp.
# Thank you kyleisah for contributing to the Moment 3D printer.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: _BED_MESH_CALIBRATE
gcode:
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %} # Gather all object points
{% 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 meshing_settings = printer["gcode_macro _meshing_Settings"] %} # Pull variables from _meshing_Settings
{% set mesh_margin = meshing_settings.mesh_margin | float %} # Pull mesh margin setting from _meshing_Settings
{% set fuzz_amount = meshing_settings.fuzz_amount | float %} # Pull fuzz amount setting from _meshing_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
{% set x_min = all_points | map(attribute=0) | min | default(bed_mesh_min[0]) %} # Set x_min from smallest object x point
{% set y_min = all_points | map(attribute=1) | min | default(bed_mesh_min[1]) %} # Set y_min from smallest object y point
{% set x_max = all_points | map(attribute=0) | max | default(bed_mesh_max[0]) %} # Set x_max from largest object x point
{% 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 = 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
{% set adapted_x_max = [adapted_x_max , bed_mesh_max[0]] | min %} # Compare adjustments to defaults and choose min
{% set adapted_y_max = [adapted_y_max , bed_mesh_max[1]] | min %} # Compare adjustments to defaults and choose min
{% set points_x = (((adapted_x_max - adapted_x_min) / max_probe_point_distance_x) | round(method='ceil') | int) + 1 %} # Define probe_count's x point count and round up
{% set points_y = (((adapted_y_max - adapted_y_min) / max_probe_point_distance_y) | round(method='ceil') | int) + 1 %} # Define probe_count's y point count and round up
{% if (([points_x, points_y]|max) > 6) %} #
{% set algorithm = "bicubic" %} #
{% set min_points = 4 %} #
{% else %} # Calculate if algorithm should be bicubic or lagrange
{% set algorithm = "lagrange" %} #
{% set min_points = 3 %} #
{% endif %} #
{% set points_x = [points_x , min_points]|max %} # Set probe_count's x points to fit the calculated algorithm
{% set points_y = [points_y , min_points]|max %} # Set probe_count's y points to fit the calculated algorithm
{% set points_x = [points_x , probe_count[0]]|min %}
{% set points_y = [points_y , probe_count[1]]|min %}
{% if verbose_enable == True %} # If verbose is enabled, print information about meshing's calculations
{% 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("meshing adjustments successful!")}
{% 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 %}
{% if probe_dock_enable == True %}
{attach_macro} # Attach/deploy a probe if the probe is stored somewhere outside of the print area
{% endif %}
_BED_MESH_CALIBRATE mesh_min={adapted_x_min},{adapted_y_min} mesh_max={adapted_x_max},{adapted_y_max} ALGORITHM={algorithm} PROBE_COUNT={points_x},{points_y}
{% 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 _meshing_Settings]
description: This macro contains all adjustable settings for meshing
# The following variables are settings for meshing as a whole.
variable_verbose_enable: True # Set to True to enable meshing information output when running. This is useful for debugging.
# The following variables are for adjusting adaptive mesh settings for meshing.
variable_mesh_margin: 0 # Expands the mesh size in millimeters if desired. Leave at 0 to disable.
variable_fuzz_amount: 0 # Slightly randomizes mesh points to spread out wear from nozzle-based probes. Leave at 0 to disable.
# The following variables are for those with a dockable probe like Klicky, Euclid, etc. # ---------------- Attach Macro | Detach Macro
variable_probe_dock_enable: False # Set to True to enable the usage of a dockable probe. # ---------------------------------------------
variable_attach_macro: 'Attach_Probe' # The macro that is used to attach the probe. # Klicky Probe: 'Attach_Probe' | 'Dock_Probe'
variable_detach_macro: 'Dock_Probe' # The macro that is used to store the probe. # Euclid Probe: 'Deploy_Probe' | 'Stow_Probe'
# Legacy Gcode: 'M401' | 'M402'
# The following variables are for adjusting adaptive purge settings for meshing.
variable_purge_height: 0.8 # Z position of nozzle during purge, default is 0.8.
variable_tip_distance: 0 # Distance between tip of filament and nozzle before purge. Should be similar to PRINT_END final retract amount.
variable_purge_margin: 10 # Distance the purge will be in front of the print area, default is 10.
variable_purge_amount: 30 # Amount of filament to be purged prior to printing.
variable_flow_rate: 12 # Flow rate of purge in mm3/s. Default is 12.
# The following variables are for adjusting the Smart Park feature for meshing, which will park the printhead near the print area at a specified height.
variable_smart_park_height: 10 # Z position for Smart Park, default is 10.
gcode: # Gcode section left intentionally blank. Do not disturb.
{action_respond_info(" Running the meshing_Settings macro does nothing, it is only used for storing meshing settings. ")}