|
| 1 | +## Client klipper macro definitions |
| 2 | +## |
| 3 | +## Copyright (C) 2022 Alex Zellner <[email protected]> |
| 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 | +#variable_idle_timeout : 0 ; time in sec until idle_timeout kicks in. Value 0 means that no value will be set or restored |
| 40 | +#gcode: |
| 41 | + |
| 42 | +[virtual_sdcard] |
| 43 | +path: ~/printer_data/gcodes |
| 44 | +on_error_gcode: CANCEL_PRINT |
| 45 | + |
| 46 | +[pause_resume] |
| 47 | + |
| 48 | +[display_status] |
| 49 | + |
| 50 | +[respond] |
| 51 | + |
| 52 | +[gcode_macro CANCEL_PRINT] |
| 53 | +description: Cancel the actual running print |
| 54 | +rename_existing: CANCEL_PRINT_BASE |
| 55 | +gcode: |
| 56 | + ##### get user parameters or use default ##### |
| 57 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 58 | + {% set allow_park = client.park_at_cancel | default(false) | lower == 'true' %} |
| 59 | + {% set retract = client.cancel_retract | default(5.0) | abs %} |
| 60 | + ##### define park position ##### |
| 61 | + {% set park_x = "" if (client.park_at_cancel_x | default(none) is none) |
| 62 | + else "X=" ~ client.park_at_cancel_x %} |
| 63 | + {% set park_y = "" if (client.park_at_cancel_y | default(none) is none) |
| 64 | + else "Y=" ~ client.park_at_cancel_y %} |
| 65 | + {% set custom_park = park_x | length > 0 or park_y | length > 0 %} |
| 66 | + ##### end of definitions ##### |
| 67 | + # restore idle_timeout time if needed |
| 68 | + {% if printer['gcode_macro PAUSE'].restore_idle_timeout > 0 %} |
| 69 | + SET_IDLE_TIMEOUT TIMEOUT={printer['gcode_macro PAUSE'].restore_idle_timeout} |
| 70 | + {% endif %} |
| 71 | + {% if (custom_park or not printer.pause_resume.is_paused) and allow_park %} _TOOLHEAD_PARK_PAUSE_CANCEL {park_x} {park_y} {% endif %} |
| 72 | + _CLIENT_RETRACT LENGTH={retract} |
| 73 | + TURN_OFF_HEATERS |
| 74 | + M106 S0 |
| 75 | + # clear pause_next_layer and pause_at_layer as preparation for next print |
| 76 | + SET_PAUSE_NEXT_LAYER ENABLE=0 |
| 77 | + SET_PAUSE_AT_LAYER ENABLE=0 LAYER=0 |
| 78 | + CANCEL_PRINT_BASE |
| 79 | + |
| 80 | +[gcode_macro PAUSE] |
| 81 | +description: Pause the actual running print |
| 82 | +rename_existing: PAUSE_BASE |
| 83 | +variable_restore_idle_timeout: 0 |
| 84 | +gcode: |
| 85 | + ##### get user parameters or use default ##### |
| 86 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 87 | + {% set idle_timeout = client.idle_timeout | default(0) %} |
| 88 | + {% set temp = printer[printer.toolhead.extruder].target if printer.toolhead.extruder != '' else 0 %} |
| 89 | + {% set restore = printer.toolhead.extruder != '' and params.RESTORE | default(1) | int == 1 %} |
| 90 | + ##### end of definitions ##### |
| 91 | + SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=last_extruder_temp VALUE="{{'restore': restore, 'temp': temp}}" |
| 92 | + # set a new idle_timeout value |
| 93 | + {% if idle_timeout > 0 %} |
| 94 | + SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=restore_idle_timeout VALUE={printer.configfile.settings.idle_timeout.timeout} |
| 95 | + SET_IDLE_TIMEOUT TIMEOUT={idle_timeout} |
| 96 | + {% endif %} |
| 97 | + PAUSE_BASE |
| 98 | + _TOOLHEAD_PARK_PAUSE_CANCEL {rawparams} |
| 99 | + |
| 100 | +[gcode_macro RESUME] |
| 101 | +description: Resume the actual running print |
| 102 | +rename_existing: RESUME_BASE |
| 103 | +variable_last_extruder_temp: {'restore': False, 'temp': 0} |
| 104 | +gcode: |
| 105 | + ##### get user parameters or use default ##### |
| 106 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 107 | + {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %} |
| 108 | + {% set sp_move = client.speed_move | default(velocity) %} |
| 109 | + ##### end of definitions ##### |
| 110 | + # restore idle_timeout time if needed |
| 111 | + {% if printer['gcode_macro PAUSE'].restore_idle_timeout > 0 %} |
| 112 | + SET_IDLE_TIMEOUT TIMEOUT={printer['gcode_macro PAUSE'].restore_idle_timeout} |
| 113 | + {% endif %} |
| 114 | + {% if printer.idle_timeout.state | upper == "IDLE" and last_extruder_temp.restore %} |
| 115 | + M109 S{last_extruder_temp.temp} |
| 116 | + {% endif %} |
| 117 | + _CLIENT_EXTRUDE |
| 118 | + RESUME_BASE VELOCITY={params.VELOCITY | default(sp_move)} |
| 119 | + |
| 120 | +# Usage: SET_PAUSE_NEXT_LAYER [ENABLE=[0 | 1]] [MACRO=<name>] |
| 121 | +[gcode_macro SET_PAUSE_NEXT_LAYER] |
| 122 | +description: Enable a pause if the next layer is reached |
| 123 | +gcode: |
| 124 | + {% set pause_next_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_next_layer %} |
| 125 | + {% set ENABLE = params.ENABLE | default(1) | int != 0 %} |
| 126 | + {% set MACRO = params.MACRO | default(pause_next_layer.call, True) %} |
| 127 | + SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_next_layer VALUE="{{ 'enable': ENABLE, 'call': MACRO }}" |
| 128 | + |
| 129 | +# Usage: SET_PAUSE_AT_LAYER [ENABLE=[0 | 1]] [LAYER=<number>] [MACRO=<name>] |
| 130 | +[gcode_macro SET_PAUSE_AT_LAYER] |
| 131 | +description: Enable/disable a pause if a given layer number is reached |
| 132 | +gcode: |
| 133 | + {% set pause_at_layer = printer['gcode_macro SET_PRINT_STATS_INFO'].pause_at_layer %} |
| 134 | + {% set ENABLE = params.ENABLE | int != 0 if params.ENABLE is defined |
| 135 | + else params.LAYER is defined %} |
| 136 | + {% set LAYER = params.LAYER | default(pause_at_layer.layer) | int %} |
| 137 | + {% set MACRO = params.MACRO | default(pause_at_layer.call, True) %} |
| 138 | + SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_at_layer VALUE="{{ 'enable': ENABLE, 'layer': LAYER, 'call': MACRO }}" |
| 139 | + |
| 140 | +# Usage: SET_PRINT_STATS_INFO [TOTAL_LAYER=<total_layer_count>] [CURRENT_LAYER= <current_layer>] |
| 141 | +[gcode_macro SET_PRINT_STATS_INFO] |
| 142 | +rename_existing: SET_PRINT_STATS_INFO_BASE |
| 143 | +description: Overwrite, to get pause_next_layer and pause_at_layer feature |
| 144 | +variable_pause_next_layer: { 'enable': False, 'call': "PAUSE" } |
| 145 | +variable_pause_at_layer : { 'enable': False, 'layer': 0, 'call': "PAUSE" } |
| 146 | +gcode: |
| 147 | + {% if pause_next_layer.enable %} |
| 148 | + RESPOND TYPE=echo MSG='{"%s, forced by pause_next_layer" % pause_next_layer.call}' |
| 149 | + {pause_next_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE |
| 150 | + SET_PAUSE_NEXT_LAYER ENABLE=0 |
| 151 | + {% elif pause_at_layer.enable and params.CURRENT_LAYER is defined and params.CURRENT_LAYER | int == pause_at_layer.layer %} |
| 152 | + RESPOND TYPE=echo MSG='{"%s, forced by pause_at_layer [%d]" % (pause_at_layer.call, pause_at_layer.layer)}' |
| 153 | + {pause_at_layer.call} ; execute the given gcode to pause, should be either M600 or PAUSE |
| 154 | + SET_PAUSE_AT_LAYER ENABLE=0 |
| 155 | + {% endif %} |
| 156 | + SET_PRINT_STATS_INFO_BASE {rawparams} |
| 157 | + |
| 158 | +##### internal use ##### |
| 159 | +[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL] |
| 160 | +description: Helper: park toolhead used in PAUSE and CANCEL_PRINT |
| 161 | +gcode: |
| 162 | + ##### get user parameters or use default ##### |
| 163 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 164 | + {% set velocity = printer.configfile.settings.pause_resume.recover_velocity %} |
| 165 | + {% set use_custom = client.use_custom_pos | default(false) | lower == 'true' %} |
| 166 | + {% set custom_park_x = client.custom_park_x | default(0.0) %} |
| 167 | + {% set custom_park_y = client.custom_park_y | default(0.0) %} |
| 168 | + {% set park_dz = client.custom_park_dz | default(2.0) | abs %} |
| 169 | + {% set sp_hop = client.speed_hop | default(15) * 60 %} |
| 170 | + {% set sp_move = client.speed_move | default(velocity) * 60 %} |
| 171 | + ##### get config and toolhead values ##### |
| 172 | + {% set origin = printer.gcode_move.homing_origin %} |
| 173 | + {% set act = printer.gcode_move.gcode_position %} |
| 174 | + {% set max = printer.toolhead.axis_maximum %} |
| 175 | + {% set cone = printer.toolhead.cone_start_z | default(max.z) %} ; height as long the toolhead can reach max and min of an delta |
| 176 | + {% set round_bed = True if printer.configfile.settings.printer.kinematics is in ['delta','polar','rotary_delta','winch'] |
| 177 | + else False %} |
| 178 | + ##### define park position ##### |
| 179 | + {% set z_min = params.Z_MIN | default(0) | float %} |
| 180 | + {% set z_park = [[(act.z + park_dz), z_min] | max, (max.z - origin.z)] | min %} |
| 181 | + {% set x_park = params.X if params.X is defined |
| 182 | + else custom_park_x if use_custom |
| 183 | + else 0.0 if round_bed |
| 184 | + else (max.x - 5.0) %} |
| 185 | + {% set y_park = params.Y if params.Y is defined |
| 186 | + else custom_park_y if use_custom |
| 187 | + else (max.y - 5.0) if round_bed and z_park < cone |
| 188 | + else 0.0 if round_bed |
| 189 | + else (max.y - 5.0) %} |
| 190 | + ##### end of definitions ##### |
| 191 | + _CLIENT_RETRACT |
| 192 | + {% if "xyz" in printer.toolhead.homed_axes %} |
| 193 | + G90 |
| 194 | + G1 Z{z_park} F{sp_hop} |
| 195 | + G1 X{x_park} Y{y_park} F{sp_move} |
| 196 | + {% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} |
| 197 | + {% else %} |
| 198 | + RESPOND TYPE=echo MSG='Printer not homed' |
| 199 | + {% endif %} |
| 200 | + |
| 201 | +[gcode_macro _CLIENT_EXTRUDE] |
| 202 | +description: Extrudes, if the extruder is hot enough |
| 203 | +gcode: |
| 204 | + ##### get user parameters or use default ##### |
| 205 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 206 | + {% set use_fw_retract = (client.use_fw_retract | default(false) | lower == 'true') and (printer.firmware_retraction is defined) %} |
| 207 | + {% set length = params.LENGTH | default(client.unretract) | default(1.0) | float %} |
| 208 | + {% set speed = params.SPEED | default(client.speed_unretract) | default(35) %} |
| 209 | + {% set absolute_extrude = printer.gcode_move.absolute_extrude %} |
| 210 | + ##### end of definitions ##### |
| 211 | + {% if printer.toolhead.extruder != '' %} |
| 212 | + {% if printer[printer.toolhead.extruder].can_extrude %} |
| 213 | + {% if use_fw_retract %} |
| 214 | + {% if length < 0 %} |
| 215 | + G10 |
| 216 | + {% else %} |
| 217 | + G11 |
| 218 | + {% endif %} |
| 219 | + {% else %} |
| 220 | + M83 |
| 221 | + G1 E{length} F{(speed | float | abs) * 60} |
| 222 | + {% if absolute_extrude %} |
| 223 | + M82 |
| 224 | + {% endif %} |
| 225 | + {% endif %} |
| 226 | + {% else %} |
| 227 | + RESPOND TYPE=echo MSG='Extruder not hot enough' |
| 228 | + {% endif %} |
| 229 | + {% endif %} |
| 230 | + |
| 231 | +[gcode_macro _CLIENT_RETRACT] |
| 232 | +description: Retracts, if the extruder is hot enough |
| 233 | +gcode: |
| 234 | + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] | default({}) %} |
| 235 | + {% set length = params.LENGTH | default(client.retract) | default(1.0) | float %} |
| 236 | + {% set speed = params.SPEED | default(client.speed_retract) | default(35) %} |
| 237 | + |
| 238 | + _CLIENT_EXTRUDE LENGTH=-{length | float | abs} SPEED={speed | float | abs} |
0 commit comments