cribbageSTARSHIP

print_area_bed_mesh.cfg_M8P_CB1_E3Max

Jul 12th, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. [gcode_macro BED_MESH_CALIBRATE]
  2. # print surface bed mesh calibrate
  3. # Works with Klicky Probe on Voron
  4. # November 24, 2021
  5. # Steve Turgeon
  6. rename_existing: _BED_MESH_CALIBRATE
  7.  
  8. variable_buffer: 20
  9.  
  10. ; Do not change any of the existing values below.
  11. variable_last_area_start_x: -1 ; Do not change
  12. variable_last_area_start_y: -1 ; Do not change
  13. variable_last_area_end_x: -1 ; Do not change
  14. variable_last_area_end_y: -1 ; Do not change
  15.  
  16. gcode:
  17.  
  18. {% if params.FORCE_NEW_MESH != null %}
  19. { action_respond_info("Force New Mesh: %s" % (params.FORCE_NEW_MESH)) }
  20. {% endif %}
  21. {% if printer["bed_mesh"].profile_name == '' %}
  22. { action_respond_info("No existing bed mesh found.") }
  23. {% set last_area_end_x=-1 %}
  24. {% endif %}
  25.  
  26. {% if printer.toolhead.homed_axes != "xyz" %}
  27. G28
  28. {% endif %}
  29.  
  30. {% set klicky_available = printer['gcode_macro _Probe_Variables'] != null %}
  31. {% set euclid_available = printer['gcode_macro EuclidProbe'] != null %}; Requires v5 macros https://github.com/nionio6915/Euclid_Probe/blob/main/Firmware_Examples/Klipper/00-euclid_exampleV5.cfg
  32. {% if params.PRINT_MIN %}
  33. { action_respond_info("print_min: %s" % params.PRINT_MIN) }
  34. { action_respond_info("print_max: %s" % params.PRINT_MAX) }
  35.  
  36. {% set blTouchConfig = printer['configfile'].config["bltouch"] %}
  37. {% if blTouchConfig %}
  38. {% set OffsetX = blTouchConfig.x_offset|default(0)|float %}
  39. {% set OffsetY = blTouchConfig.y_offset|default(0)|float %}
  40. {% endif %}
  41.  
  42. {% set probeConfig = printer['configfile'].config["probe"] %}
  43. {% if probeConfig %}
  44. {% set OffsetX = probeConfig.x_offset|default(0)|float %}
  45. {% set OffsetY = probeConfig.y_offset|default(0)|float %}
  46. {% endif %}
  47.  
  48. {% set print_min_x = params.PRINT_MIN.split(",")[0]|float %}
  49. {% set print_min_y = params.PRINT_MIN.split(",")[1]|float %}
  50. {% set print_max_x = params.PRINT_MAX.split(",")[0]|float %}
  51. {% set print_max_y = params.PRINT_MAX.split(",")[1]|float %}
  52.  
  53. {% if last_area_start_x > 0 %}
  54. { action_respond_info("last_bed_mesh: %s,%s %s,%s" % (last_area_start_x, last_area_start_y, last_area_end_x, last_area_end_y)) }
  55. {% endif %}
  56.  
  57. {% if (params.FORCE_NEW_MESH != null) or (print_min_x < last_area_start_x) or (print_max_x > last_area_end_x) or (print_min_y < last_area_start_y) or (print_max_y > last_area_end_y) %}
  58. {% if klicky_available %}
  59. _CheckProbe action=query
  60. Attach_Probe
  61. {% elif euclid_available %}
  62. DEPLOY_PROBE
  63. {% endif %}
  64. {% if (print_min_x < print_max_x) and (print_min_y < print_max_y) %}
  65.  
  66. # Get bed_mesh config (probe count, mesh_min and mesh_max for x and y
  67. {% set bedMeshConfig = printer['configfile'].config["bed_mesh"] %}
  68. {% set minimum_probe_count = 3 %}
  69. {% if bedMeshConfig.algorithm == "bicubic" %}
  70. {% set minimum_probe_count = 5 %}
  71. {% endif %}
  72. {% set probe_count = bedMeshConfig.probe_count.split(",") %}
  73. {% set probe_count_x = probe_count[0]|int %}
  74. {% if probe_count.__len__() > 1 %}
  75. {% set probe_count_y = probe_count[1]|int %}
  76. {% else %}
  77. {% set probe_count_y = probe_count_x|int %}
  78. {% endif %}
  79. {% set relative_reference_index = bedMeshConfig.relative_reference_index %}
  80. {% set mesh_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
  81. {% set mesh_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
  82. {% set mesh_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
  83. {% set mesh_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}
  84.  
  85. # If print area X is smaller than 50% of the bed size, change to to 3 probe counts for X instead of the default
  86. {% if print_max_x - print_min_x < (mesh_max_x - mesh_min_x) * 0.50 %}
  87. {% set probe_count_x = minimum_probe_count %}
  88. {% endif %}
  89.  
  90. # If print area Y is smaller than 50% of the bed size, change to to 3 probe counts for Y instead of the default
  91. {% if print_max_y - print_min_y < (mesh_max_y - mesh_min_y) * 0.50 %}
  92. {% set probe_count_y = minimum_probe_count %}
  93. {% endif %}
  94.  
  95. {% if print_min_x - buffer >= mesh_min_x %}
  96. {% set mesh_min_x = print_min_x - buffer %}
  97. {% endif %}
  98.  
  99. {% if print_min_y - buffer >= mesh_min_y %}
  100. {% set mesh_min_y = print_min_y - buffer %}
  101. {% endif %}
  102.  
  103. {% if print_max_x + buffer <= mesh_max_x %}
  104. {% set mesh_max_x = print_max_x + buffer %}
  105. {% endif %}
  106.  
  107. {% if print_max_y + buffer <= mesh_max_y %}
  108. {% set mesh_max_y = print_max_y + buffer %}
  109. {% endif %}
  110.  
  111. { action_respond_info("mesh_min: %s,%s" % (mesh_min_x, mesh_min_y)) }
  112. { action_respond_info("mesh_max: %s,%s" % (mesh_max_x, mesh_max_y)) }
  113. { action_respond_info("probe_count: %s,%s" % (probe_count_x,probe_count_y)) }
  114.  
  115. ; Set variables so they're available outside of macro
  116. SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=last_area_start_x VALUE={print_min_x}
  117. SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=last_area_start_y VALUE={print_min_y}
  118. SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=last_area_end_x VALUE={print_max_x}
  119. SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=last_area_end_y VALUE={print_max_y}
  120.  
  121. {% if printer["gcode_macro status_meshing"] != null %}
  122. status_meshing
  123. {% endif %}
  124.  
  125. {% if relative_reference_index == 0 or relative_reference_index == null %}
  126. _BED_MESH_CALIBRATE mesh_min={mesh_min_x},{mesh_min_y} mesh_max={mesh_max_x},{mesh_max_y} probe_count={probe_count_x},{probe_count_y}
  127. {% else %}
  128. {% set relative_reference_index = ((probe_count_x * probe_count_y - 1) / 2)|int %}
  129. { action_respond_info("relative_reference_index: %s" % relative_reference_index) }
  130. _BED_MESH_CALIBRATE mesh_min={mesh_min_x},{mesh_min_y} mesh_max={mesh_max_x},{mesh_max_y} probe_count={probe_count_x},{probe_count_y} relative_reference_index={relative_reference_index}
  131. {% endif %}
  132. {% else %}
  133. {% if printer["gcode_macro status_meshing"] != null %}
  134. status_meshing
  135. {% endif %}
  136. _BED_MESH_CALIBRATE
  137. {% endif %}
  138. {% if klicky_available %}
  139. Dock_Probe
  140. {% elif euclid_available %}
  141. STOW_PROBE
  142. {% endif %}
  143. {% else %}
  144. { action_respond_info("No need to recreate Bed Mesh since it's same as current mesh or smaller") }
  145. {% endif %}
  146. {% else %}
  147. {% if klicky_available %}
  148. _CheckProbe action=query
  149. Attach_Probe
  150. {% elif euclid_available %}
  151. STOW_PROBE
  152. {% endif %}
  153. {% if printer["gcode_macro status_meshing"] != null %}
  154. status_meshing
  155. {% endif %}
  156. _BED_MESH_CALIBRATE
  157. {% if klicky_available %}
  158. Dock_Probe
  159. {% endif %}
  160. {% if euclid_available %}
  161. STOW_PROBE
  162. {% endif %}
  163. {% endif %}
  164. {% if printer["gcode_macro status_ready"] != null %}
  165. status_ready
  166. {% endif %}
  167.  
Advertisement
Add Comment
Please, Sign In to add comment