Advertisement
shawnp123

printareabedmeshblv500.cfg

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