-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmacros.cfg
211 lines (175 loc) · 11.2 KB
/
macros.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
[gcode_macro PRINT_START]
gcode:
{% set bed_temp = params.BED | default(60) | float %}
{% set extruder_temp = params.EXTRUDER | default(220) | float %}
CLEAR_PAUSE ; Clear Pause
M190 S{bed_temp} ; Heat bed_temp and wait
M104 S150 ; Preheat extruder to 150°C
G28 ; Home all axes
M104 S{extruder_temp} ; Set final extruder temperature
BED_MESH_CALIBRATE ADAPTIVE=1 ADAPTIVE_MARGIN=5 ; Start Adaptive Bed Leveling
G0 X1 Y1 Z1 F5000 ; Move to front-left to heat nozzle
M109 S{extruder_temp} ; Set extruder temp and wait
ADAPTIVE_LINE_PURGE ; Adaptive Purge
[gcode_macro PRINT_END]
gcode:
G91 ; Relative positionning
G1 E-2 F2700 ; Retract a bit
G1 E-2 Z0.2 F2400 ; Retract and raise Z
G0 X5 Y5 F3000 ; Wipe out
G0 Z10 ; Raise Z more
G90 ; Absolute positionning
G0 X0 Y220 ; Present print
M106 S0 ; Turn-off fan
M104 S0 ; Turn-off hotend
M140 S0 ; Turn-off bed_temp
M84 ; Disable stepper motors
[gcode_macro LINE_PURGE]
gcode:
G92 E0 ; Reset Extruder
G1 Z2 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X1 Y20 Z0.4 F5000 ; Move to start position
G1 X1 Y145 Z0.4 E15 F1500 ; Draw the first line
G1 X1.3 Y145 Z0.4 F5000 ; Move to side a little
G1 X1.3 Y20 Z0.4 E30 F1500 ; Draw the second line
G92 E0 ; Reset Extruder
G1 E-1 F1800 ; Retract a bit
G0 Z2 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 E0 F1800 ; Unretract/Reset Extruder
############################################################################################################
# Adaptive Line Purge Macro (Modified from https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging)
############################################################################################################
[gcode_macro ADAPTIVE_LINE_PURGE]
variable_purge_height: 0.8 # Z position of nozzle during purge, default is 0.8 mm.
variable_tip_distance: 4 # Distance in mm 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 mm.
variable_purge_amount: 20 # Amount of filament in mm to be purged prior to printing.
variable_flow_rate: 12 # Flow rate of purge in mm3/s. Default is 12.
gcode:
{% set travel_speed = printer.toolhead.max_velocity * 60 %}
{% set cross_section = printer.configfile.settings.extruder.max_extrude_cross_section | float %}
{% set RETRACT = 'G10' if printer.firmware_retraction is defined else 'G1 E-0.5 F2100' %}
{% set UNRETRACT = 'G11' if printer.firmware_retraction is defined else 'G1 E0.5 F2100' %}
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %} ; Get all object points
{% set x_min = (all_points | map(attribute=0) | min | default(0)) %} ; Object x min
{% set x_max = (all_points | map(attribute=0) | max | default(0)) %} ; Object x max
{% set y_min = (all_points | map(attribute=1) | min | default(0)) %} ; Object y min
{% set y_max = (all_points | map(attribute=1) | max | default(0)) %} ; Object y max
{% set x_center = ([((x_max + x_min) / 2) - (purge_amount / 2), 0] | max) %} ; Create center point of purge line relative to print on X axis
{% set y_center = ([((y_max + y_min) / 2) - (purge_amount / 2), 0] | max) %} ; Create center point of purge line relative to print on Y axis
{% set x_origin = ([x_min - purge_margin, 0] | max) %} ; Add margin to x min, compare to 0, and choose the larger
{% set y_origin = ([y_min - purge_margin, 0] | max) %} ; Add margin to y min, compare to 0, and choose the larger
# Calculate purge speed
{% set purge_move_speed = (flow_rate / 5.0) * 60 | float %}
{% if cross_section < 5 %}
{action_respond_info("[Extruder] max_extrude_cross_section is insufficient for purge. Set it to 5 or greater. Purge skipped.")}
{% else %}
SAVE_GCODE_STATE NAME=prepurge_state ; Create gcode state
G92 E0 ; Reset extruder
G0 F{travel_speed} ; Set travel speed
G90 ; Absolute positioning
G0 X{x_center if y_origin > 0 else x_origin} Y{y_origin if y_origin > 0 else y_center} ; Move to purge position
G0 Z{purge_height} ; Move to purge Z height
M83 ; Relative extrusion mode
G1 E{tip_distance} F{purge_move_speed} ; Move filament tip
{% if y_origin > 0 %} ; If there's room on Y, purge along X axis in front of print area
G1 X{x_center + purge_amount} E{purge_amount} F{purge_move_speed} ; Purge line
{RETRACT} ; Retract
G0 X{x_center + purge_amount + 10} F{travel_speed} ; Rapid move to break string
{% else %} ; If there's room on X, purge along Y axis to the left of print area
G1 Y{y_center + purge_amount} E{purge_amount} F{purge_move_speed} ; Purge line
{RETRACT} ; Retract
G0 Y{y_center + purge_amount + 10} F{travel_speed} ; Rapid move to break string
{% endif %}
G0 Z{purge_height * 2} F{travel_speed} ; Z hop
{UNRETRACT} ; Unretract, Prepeare For Extrusion
G92 E0 ; Reset extruder distance
M82 ; Absolute extrusion mode
RESTORE_GCODE_STATE NAME=prepurge_state ; Restore gcode state
{% endif %}
[gcode_macro LOAD_FILAMENT]
variable_load_distance = 40 # Distance to load filament into the extruder
variable_purge_distance = 30 # Distance to purge filament after loading
gcode:
{% set load_speed = params.LOAD_SPEED | default(1500) | float %}
{% set purge_speed = params.PURGE_SPEED | default(300) | float %}
{% set min_temp = params.MIN_TEMP | default(220) | float %}
{% set turn_off_extruder = params.TURN_OFF_EXTRUDER | default(1) | int %} ; Turn off extruder after loading (0/1)
SAVE_GCODE_STATE NAME=load_state ; Create gcode state
# Heat extruder to the minimum required temperature if necessary
{% if printer.extruder.temperature < min_temp %}
M109 S{min_temp} ; Set extruder temp and wait
{% endif %}
G91 ; Relative positioning
G92 E0 ; Reset extruder
G1 E{load_distance} F{load_speed} ; Load filament quickly
G1 E{purge_distance} F{purge_speed} ; Purge filament
# Optionally turn off the extruder heater after loading
{% if turn_off_extruder %}
M104 S0 ; Turn off extruder heater
{% endif %}
RESTORE_GCODE_STATE NAME=load_state ; Restore gcode state
M118 Filament Loaded ; Notify completion
[gcode_macro UNLOAD_FILAMENT]
variable_unload_distance: 80 # Distance to retract filament from the extruder
variable_purge_distance: 20 # Distance to purge filament before unloading
gcode:
{% set unload_speed = params.UNLOAD_SPEED | default(1500) | float %}
{% set purge_speed = params.PURGE_SPEED | default(300) | float %}
{% set min_temp = params.MIN_TEMP | default(220) | float %}
{% set turn_off_extruder = params.TURN_OFF_EXTRUDER | default(1) | int %} ; Turn off extruder after unloading (0/1)
SAVE_GCODE_STATE NAME=unload_state ; Save current printer state
# Heat extruder to the minimum required temperature if necessary
{% if printer.extruder.temperature < min_temp %}
M109 S{min_temp} ; Set extruder temp and wait
{% endif %}
G91 ; Enable relative positioning
G92 E0 ; Reset extruder position
G1 E{purge_distance} F{purge_speed} ; Purge filament
G1 E-{unload_distance} F{unload_speed} ; Unload filament
# Optionally turn off the extruder heater after unloading
{% if turn_off_extruder %}
M104 S0 ; Turn off extruder heater
{% endif %}
RESTORE_GCODE_STATE NAME=unload_state ; Restore saved printer state
M118 Filament Unloaded ; Notify completion
[gcode_macro BEEP]
gcode:
{% set duration = params.P | default(100) | float %}
SET_PIN PIN=beeper VALUE=1
G4 P{duration}
SET_PIN PIN=beeper VALUE=0
[gcode_macro OFF]
gcode:
M84 ; Turn steppers off
TURN_OFF_HEATERS ; Turn bed_temp / hotend off
M107 ; Turn print cooling fan off
[gcode_macro PID_EXTRUDER]
gcode:
{% set target = params.TARGET | default(220) | float %}
PID_CALIBRATE HEATER=extruder TARGET={target}
SAVE_CONFIG
[gcode_macro PID_BED]
gcode:
{% set target = params.TARGET | default(60) | float %}
PID_CALIBRATE HEATER=heater_bed TARGET={target}
SAVE_CONFIG
#####################################################################
# Klipper G-Code Overrides
#####################################################################
[gcode_macro M109]
rename_existing: M99109
gcode:
{% set s = params.S | float %}
M104 {% for p in params %} {'%s%s' % (p, params[p])} {% endfor %} ; Set hotend temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s} MAXIMUM={s+1} ; Wait for hotend temp (within 1 degree)
{% endif %}
[gcode_macro M190]
rename_existing: M99190
gcode:
{% set s = params.S | float %}
M140 {% for p in params %} {'%s%s' % (p, params[p])} {% endfor %} ; Set bed temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={s} MAXIMUM={s+1} ; Wait for bed temp (within 1 degree)
{% endif %}