mainsail.cfg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. ## Client klipper macro definitions
  2. ##
  3. ## Copyright (C) 2022 Alex Zellner <alexander.zellner@googlemail.com>
  4. ##
  5. ## This file may be distributed under the terms of the GNU GPLv3 license
  6. ##
  7. ## !!! This file is read-only. Maybe the used editor indicates that. !!!
  8. ##
  9. ## Customization:
  10. ## 1) copy the gcode_macro _CLIENT_VARIABLE (see below) to your printer.cfg
  11. ## 2) remove the comment mark (#) from all lines
  12. ## 3) change any value in there to your needs
  13. ##
  14. ## Use the PAUSE macro direct in your M600:
  15. ## e.g. with a different park position front left and a minimal height of 50
  16. ## [gcode_macro M600]
  17. ## description: Filament change
  18. ## gcode: PAUSE X=10 Y=10 Z_MIN=50
  19. ## Z_MIN will park the toolhead at a minimum of 50 mm above to bed to make it easier for you to swap filament.
  20. ##
  21. ## Client variable macro for your printer.cfg
  22. #[gcode_macro _CLIENT_VARIABLE]
  23. #variable_use_custom_pos : False ; use custom park coordinates for x,y [True/False]
  24. #variable_custom_park_x : 0.0 ; custom x position; value must be within your defined min and max of X
  25. #variable_custom_park_y : 0.0 ; custom y position; value must be within your defined min and max of Y
  26. #variable_custom_park_dz : 2.0 ; custom dz value; the value in mm to lift the nozzle when move to park position
  27. #variable_retract : 1.0 ; the value to retract while PAUSE
  28. #variable_cancel_retract : 5.0 ; the value to retract while CANCEL_PRINT
  29. #variable_speed_retract : 35.0 ; retract speed in mm/s
  30. #variable_unretract : 1.0 ; the value to unretract while RESUME
  31. #variable_speed_unretract : 35.0 ; unretract speed in mm/s
  32. #variable_speed_hop : 15.0 ; z move speed in mm/s
  33. #variable_speed_move : 100.0 ; move speed in mm/s
  34. #variable_park_at_cancel : False ; allow to move the toolhead to park while execute CANCEL_PRINT [True/False]
  35. #variable_park_at_cancel_x : None ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True
  36. #variable_park_at_cancel_y : None ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True
  37. ## !!! Caution [firmware_retraction] must be defined in the printer.cfg if you set use_fw_retract: True !!!
  38. #variable_use_fw_retract : False ; use fw_retraction instead of the manual version [True/False]
  39. #gcode:
  40. [virtual_sdcard]
  41. path: ~/printer_data/gcodes
  42. on_error_gcode: CANCEL_PRINT
  43. [pause_resume]
  44. [display_status]
  45. [gcode_macro CANCEL_PRINT]
  46. description: Cancel the actual running print
  47. rename_existing: CANCEL_PRINT_BASE
  48. gcode:
  49. ##### get user parameters or use default #####
  50. {% set macro_found = True if printer['gcode_macro _CLIENT_VARIABLE'] is defined else False %}
  51. {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
  52. {% set allow_park = False if not macro_found
  53. else False if client.park_at_cancel is not defined
  54. else True if client.park_at_cancel|lower == 'true'
  55. else False %}
  56. {% set retract = 5.0 if not macro_found else client.cancel_retract|default(5.0)|abs %}
  57. ##### define park position #####
  58. {% set park_x = "" if not macro_found
  59. else "" if client.park_at_cancel_x is not defined
  60. else "X=" + client.park_at_cancel_x|string if client.park_at_cancel_x is not none %}
  61. {% set park_y = "" if not macro_found
  62. else "" if client.park_at_cancel_y is not defined
  63. else "Y=" + client.park_at_cancel_y|string if client.park_at_cancel_y is not none %}
  64. {% set custom_park = True if (park_x|length > 0 or park_y|length > 0) else False %}
  65. ##### end of definitions #####
  66. {% if (custom_park or not printer.pause_resume.is_paused) and allow_park %} _TOOLHEAD_PARK_PAUSE_CANCEL {park_x} {park_y} {% endif %}
  67. _CLIENT_RETRACT LENGTH={retract}
  68. TURN_OFF_HEATERS
  69. M106 S0
  70. # clear pause_next_layer and pause_at_layer as preparation for next print
  71. SET_PAUSE_NEXT_LAYER ENABLE=0
  72. SET_PAUSE_AT_LAYER ENABLE=0 LAYER=0
  73. CANCEL_PRINT_BASE
  74. [gcode_macro PAUSE]
  75. description: Pause the actual running print
  76. rename_existing: PAUSE_BASE
  77. gcode:
  78. SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=last_extruder_temp VALUE="{printer[printer.toolhead.extruder].target}"
  79. PAUSE_BASE
  80. _TOOLHEAD_PARK_PAUSE_CANCEL {rawparams}
  81. [gcode_macro RESUME]
  82. description: Resume the actual running print
  83. rename_existing: RESUME_BASE
  84. variable_last_extruder_temp: 0
  85. gcode:
  86. ##### get user parameters or use default #####
  87. {% set macro_found = True if printer['gcode_macro _CLIENT_VARIABLE'] is defined else False %}
  88. {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
  89. {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %}
  90. {% set sp_move = velocity if not macro_found else client.speed_move|default(velocity) %}
  91. ##### end of definitions #####
  92. M109 S{last_extruder_temp}
  93. _CLIENT_EXTRUDE
  94. RESUME_BASE VELOCITY={params.VELOCITY|default(sp_move)}
  95. # Usage: SET_PAUSE_NEXT_LAYER [ENABLE=[0|1]] [MACRO=<name>]
  96. [gcode_macro SET_PAUSE_NEXT_LAYER]
  97. description: Enable a pause if the next layer is reached
  98. gcode:
  99. {% set pause_next_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_next_layer %}
  100. {% set ENABLE = params.ENABLE | default(1) | int != 0 %}
  101. {% set MACRO = params.MACRO | default(pause_next_layer.call, True) %}
  102. SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_next_layer VALUE="{{ 'enable': ENABLE, 'call': MACRO }}"
  103. # Usage: SET_PAUSE_AT_LAYER [ENABLE=[0|1]] [LAYER=<number>] [MACRO=<name>]
  104. [gcode_macro SET_PAUSE_AT_LAYER]
  105. description: Enable/disable a pause if a given layer number is reached
  106. gcode:
  107. {% set pause_at_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_at_layer %}
  108. {% set ENABLE = params.ENABLE | int != 0 if params.ENABLE is defined
  109. else params.LAYER is defined %}
  110. {% set LAYER = params.LAYER | default(pause_at_layer.layer) | int %}
  111. {% set MACRO = params.MACRO | default(pause_at_layer.call, True) %}
  112. SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_at_layer VALUE="{{ 'enable': ENABLE, 'layer': LAYER, 'call': MACRO }}"
  113. # Usage: SET_PRINT_STATS_INFO [TOTAL_LAYER=<total_layer_count>] [CURRENT_LAYER= <current_layer>]
  114. [gcode_macro SET_PRINT_STATS_INFO]
  115. rename_existing: SET_PRINT_STATS_INFO_BASE
  116. description: Overwrite, to get pause_next_layer and pause_at_layer feature
  117. variable_pause_next_layer: { 'enable': False, 'call': "PAUSE" }
  118. variable_pause_at_layer : { 'enable': False, 'layer': 0, 'call': "PAUSE" }
  119. gcode:
  120. {% if pause_next_layer.enable %}
  121. {action_respond_info("%s, forced by pause_next_layer" % pause_next_layer.call)}
  122. {pause_next_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE
  123. SET_PAUSE_NEXT_LAYER ENABLE=0
  124. {% elif pause_at_layer.enable and params.CURRENT_LAYER is defined and params.CURRENT_LAYER|int == pause_at_layer.layer %}
  125. {action_respond_info("%s, forced by pause_at_layer [%d]" % (pause_at_layer.call, pause_at_layer.layer))}
  126. {pause_at_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE
  127. SET_PAUSE_AT_LAYER ENABLE=0
  128. {% endif %}
  129. SET_PRINT_STATS_INFO_BASE {rawparams}
  130. ##### internal use #####
  131. [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
  132. description: Helper: park toolhead used in PAUSE and CANCEL_PRINT
  133. gcode:
  134. ##### get user parameters or use default #####
  135. {% set macro_found = True if printer['gcode_macro _CLIENT_VARIABLE'] is defined else False %}
  136. {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
  137. {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %}
  138. {% set use_custom = False if not macro_found
  139. else False if client.use_custom_pos is not defined
  140. else True if client.use_custom_pos|lower == 'true'
  141. else False %}
  142. {% set custom_park_x = 0.0 if not macro_found else client.custom_park_x|default(0.0) %}
  143. {% set custom_park_y = 0.0 if not macro_found else client.custom_park_y|default(0.0) %}
  144. {% set park_dz = 2.0 if not macro_found else client.custom_park_dz|default(2.0)|abs %}
  145. {% set sp_hop = 900 if not macro_found else client.speed_hop|default(15) * 60 %}
  146. {% set sp_move = velocity * 60 if not macro_found else client.speed_move|default(velocity) * 60 %}
  147. ##### get config and toolhead values #####
  148. {% set origin = printer.gcode_move.homing_origin %}
  149. {% set act = printer.gcode_move.gcode_position %}
  150. {% set max = printer.toolhead.axis_maximum %}
  151. {% set cone = printer.toolhead.cone_start_z|default(max.z) %} ; height as long the toolhead can reach max and min of an delta
  152. {% set round_bed = True if printer.configfile.settings.printer.kinematics is in ['delta','polar','rotary_delta','winch']
  153. else False %}
  154. ##### define park position #####
  155. {% set z_min = params.Z_MIN|default(0)|float %}
  156. {% set z_park = [[(act.z + park_dz), z_min]|max, (max.z - origin.z)]|min %}
  157. {% set x_park = params.X if params.X is defined
  158. else custom_park_x if use_custom
  159. else 0.0 if round_bed
  160. else (max.x - 5.0) %}
  161. {% set y_park = params.Y if params.Y is defined
  162. else custom_park_y if use_custom
  163. else (max.y - 5.0) if round_bed and z_park < cone
  164. else 0.0 if round_bed
  165. else (max.y - 5.0) %}
  166. ##### end of definitions #####
  167. _CLIENT_RETRACT
  168. {% if "xyz" in printer.toolhead.homed_axes %}
  169. G90
  170. G1 Z{z_park} F{sp_hop}
  171. G1 X{x_park} Y{y_park} F{sp_move}
  172. {% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %}
  173. {% else %}
  174. {action_respond_info("Printer not homed")}
  175. {% endif %}
  176. [gcode_macro _CLIENT_EXTRUDE]
  177. description: Extrudes, if the extruder is hot enough
  178. gcode:
  179. {% set macro_found = True if printer['gcode_macro _CLIENT_VARIABLE'] is defined else False %}
  180. {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
  181. {% set use_fw_retract = False if not macro_found
  182. else False if client.use_fw_retract is not defined
  183. else True if client.use_fw_retract|lower == 'true' and printer.firmware_retraction is defined
  184. else False %}
  185. {% set length = (params.LENGTH|float) if params.LENGTH is defined
  186. else 1.0 if not macro_found
  187. else client.unretract|default(1.0) %}
  188. {% set speed = params.SPEED if params.SPEED is defined
  189. else 35 if not macro_found
  190. else client.speed_unretract|default(35) %}
  191. {% set absolute_extrude = printer.gcode_move.absolute_extrude %}
  192. {% if printer.extruder.can_extrude %}
  193. {% if use_fw_retract %}
  194. {% if length < 0 %}
  195. G10
  196. {% else %}
  197. G11
  198. {% endif %}
  199. {% else %}
  200. M83
  201. G1 E{length} F{(speed|float|abs) * 60}
  202. {% if absolute_extrude %}
  203. M82
  204. {% endif %}
  205. {% endif %}
  206. {% else %}
  207. {action_respond_info("Extruder not hot enough")}
  208. {% endif %}
  209. [gcode_macro _CLIENT_RETRACT]
  210. description: Retracts, if the extruder is hot enough
  211. gcode:
  212. {% set macro_found = True if printer['gcode_macro _CLIENT_VARIABLE'] is defined else False %}
  213. {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
  214. {% set length = (params.LENGTH|float) if params.LENGTH is defined
  215. else 1.0 if not macro_found
  216. else client.retract|default(1.0) %}
  217. {% set speed = params.SPEED if params.SPEED is defined
  218. else 35 if not macro_found
  219. else client.speed_retract|default(35) %}
  220. _CLIENT_EXTRUDE LENGTH=-{length|float|abs} SPEED={speed|float|abs}