-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa_cal.cfg
265 lines (251 loc) · 11.3 KB
/
pa_cal.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
[gcode_macro PA_CAL]
# Klipper pressure advance line calibration macro.
# Usage: PA_CAL BED=100 EXTRUDER=240 PA_START=0.0 PA_STOP=0.1 PA_STEPS=20 NOZZLE=0.4
# Or you can execute with no parameters, which will use values from printer.cfg and saved_variables.cfg.
# Based on http://realdeuce.github.io/Voron/PA/pressure_advance.html
# Sourced from u/Deepsiks, assisted by u/imoftendisgruntled, u/scul86, and thanks to u/beansisfat, u/stray_r
# Cleaned up and moved to using saved_variables.cfg by u/jibbsisme
# Fully parameterized and extended by u/ksanislo
description: Tune Pressure Advance
gcode:
# saved_variables.cfg
{% set svv = printer.save_variables.variables %}
# macro parameters
{% set BED = params.BED|default(svv.pa_bed_temp)|int %}
{% set CHAMBER = params.CHAMBER|default(svv.pa_chamber_temp)|int %}
{% set EXTRUDER = params.EXTRUDER|default(svv.pa_extruder_temp)|int %}
{% set PA_START = params.PA_START|default(svv.pa_start)|float %}
{% set PA_STOP = params.PA_STOP|default(svv.pa_stop)|float %}
{% set PA_STEPS = params.PA_STEPS|default(svv.pa_steps)|int %}
{% set NOZZLE = params.NOZZLE|default(printer.configfile.config["extruder"]["nozzle_diameter"])|float %}
# load variables
{% set FD = printer.configfile.config["extruder"]["filament_diameter"]|float %}
{% set AR = svv.pa_accel|default(3000) %}
{% set DR = svv.pa_accel_to_decel|default(1500) %}
{% set SL = svv.pa_slow_length|default(20) %}
{% set FL = svv.pa_fast_length|default(40) %}
{% set BL = svv.pa_between_lines|default(5) %}
{% set MS = svv.pa_move_speed|default(300)*60 %}
{% set SS = svv.pa_slow_speed|default(20)*60 %}
{% set FS = svv.pa_fast_speed|default(120)*60 %}
{% set ZS = svv.pa_z_speed|default(20)*60 %}
{% set RS = svv.pa_retract_speed|default(35)*60 %}
{% set RD = svv.pa_retract_dist|default(0.4) %}
{% set LH = svv.pa_layer_height|default(0.20) %}
{% set LR = svv.pa_line_ratio|default(1.25) %}
{% set ER = svv.pa_extrude_ratio|default(1) %}
{% set BE = svv.pa_bold_extrude|default(1.1)|float %}
{% set EF = svv.pa_enable_frame|default(1) %}
{% set EM = svv.pa_enable_markers|default(1) %}
{% set PV = svv.pa_print_values|default(1) %}
{% set PH = svv.pa_print_height|default(4) %}
{% set ML = svv.pa_marker_length|default(BL*2) %}
{% set DU = svv.pa_draw_underline|default(1) %}
{% set UO = svv.pa_underline_overlap|default(0.25)|float %}
{% set PP = svv.pa_precision|default("%.3f") %}
{% set PX = PH/4 %}
# calculated variables
{% if printer.configfile.config['printer']['kinematics'] == 'delta' %}
{% set X_MID = 0.0|float %}
{% set Y_MID = 0.0|float %}
{% else %}
{% set X_MID = printer.configfile.config["stepper_x"]["position_max"]|float / 2.0 %}
{% set Y_MID = printer.configfile.config["stepper_y"]["position_max"]|float / 2.0 %}
{% endif %}
{% set STARTX = X_MID - (((SL*2)+FL)/2) %}
{% set STARTY = Y_MID - (PA_STEPS * BL / 2.0) %}
{% set PA_STEP = (PA_STOP - PA_START) / PA_STEPS|float %}
{% set LINE_WIDTH = NOZZLE * LR|float %}
{% set ERAT = LINE_WIDTH * LH / ((FD / 2)*(FD / 2) * 3.14159) * ER|float %}
START_PRINT BED={BED} EXTRUDER={EXTRUDER}
PRIME_LINE
G21 ; millimeter units
G90 ; absolute XYZ
M83 ; relative E
SET_VELOCITY_LIMIT ACCEL={AR} ACCEL_TO_DECEL={DR}
G92 E0
M106 S0
# draw framing lines
{% if EF == 1 %} ; only frame if enabled
G1 X{STARTX} Y{STARTY} F{MS} ; move to start position
G1 Z{LH} F{ZS} ; move to layer height
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY+(PA_STEPS*BL)} E{ERAT*(PA_STEPS*BL)*BE} F{SS}; print first frame line
G1 X{STARTX+LINE_WIDTH} ; shift over
G1 Y{STARTY} E{ERAT*(PA_STEPS*BL)*BE} ; print first return frame line
G1 E-{RD} F{RS} ; retract
G1 X{STARTX+FL+(SL*2)} F{MS} ; move to second line start
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY+(PA_STEPS*BL)} E{ERAT*(PA_STEPS*BL)*BE} F{SS}; print second frame line
G1 X{STARTX+FL+(SL*2)-LINE_WIDTH} ; shift over
G1 Y{STARTY} E{ERAT*(PA_STEPS*BL)*BE} ; print second return frame line
G1 E-{RD} F{RS} ; retract
{% endif %}
# draw markers
{% if EM == 1 %} ; only when markers enabled
G1 X{STARTX+SL+FL} Y{STARTY-ML} F{MS} ; marker 1 start
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY} E{ERAT*ML} F{SS} ; marker 1 end
G1 E-{RD} F{RS} ; retract
G1 X{STARTX+SL} Y{STARTY-ML} F{MS} ; marker 2 start
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY} E{ERAT*ML} F{SS} ; marker 2 end
G1 E-{RD} F{RS} ; retract
G1 X{STARTX+SL} Y{STARTY+(PA_STEPS*BL)+ML} F{MS} ; marker 3 start
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY+(PA_STEPS*BL)} E{ERAT*ML} F{SS} ; marker 3 end
G1 E-{RD} F{RS} ; retract
G1 X{STARTX+SL+FL} Y{STARTY+(PA_STEPS*BL)+ML} F{MS} ; marker 4 start
G1 E{RD} F{RS} ; un-retract
G1 Y{STARTY+(PA_STEPS*BL)} E{ERAT*ML} F{SS} ; marker 4 end
G1 E-{RD} F{RS} ; retract
{% endif %}
# draw the actual test lines
{% for i in range(0, PA_STEPS+1) %}
{% set PA_VAL = PA_START + (i * PA_STEP) %}
SET_PRESSURE_ADVANCE ADVANCE={PA_VAL} ; set Pressure Advance
M117 PA={PA_VAL}, STEP={PA_STEP}.
G1 X{STARTX} Y{STARTY+(BL*i)} F{MS} ; move to start position
G1 Z{LH} F{ZS} ; move to layer height
G1 E{RD} F{RS} ; un-retract
G1 X{(STARTX+SL)} Y{STARTY+(BL*i)} E{ERAT*SL} F{SS} ; print line part one
G1 X{(STARTX+SL+FL)} Y{STARTY+(BL*i)} E{ERAT*FL} F{FS} ; print line part two
G1 X{(STARTX+SL+FL+SL)} Y{STARTY+(BL*i)} E{ERAT*SL} F{SS} ; print line part three
G1 E-{RD} F{RS} ; retract
G1 Z{LH*2} F{ZS} ; move above layer height
{% endfor %}
# draw pa value labels
{% if PV == 1 %}
{% for i in range(0, PA_STEPS+1) %}
{% if i is divisibleby(((PH+1)/BL)|round(0,'ceil')|int) %}
{% set PA_VAL = PA_START + (i * PA_STEP) %}
SET_PRESSURE_ADVANCE ADVANCE={PA_VAL} ; set Pressure Advance
M117 PA={PA_VAL}, STEP={PA_STEP}
G1 X{STARTX+FL+(SL*2)+PX} Y{STARTY+(BL*i)} F{MS} ; move to label position
{% for a in PP|format(PA_VAL) %} ; convert float to string with specified precision
G1 Z{LH} F{ZS} ; move to layer height
G91 ; relative positioning
{% if a == "." %}
G1 Y-{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 Y{0.5*PX} E{ERAT*(0.5*PX)}
G1 X{0.5*PX} E{ERAT*(0.5*PX)}
G1 Y-{0.5*PX} E{ERAT*(0.5*PX)}
G1 X-{0.5*PX} E{ERAT*(0.5*PX)}
G1 E-{RD} F{RS} ; retract
G1 X{1.5*PX} Y{2*PX} F{MS}
{% elif a == "0" %}
G1 Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X{2*PX} E{ERAT*2*PX} F{SS}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 Y{4*PX} E{ERAT*4*PX}
G1 E-{RD} F{RS} ; retract
G1 X{3*PX} Y-{2*PX} F{MS}
{% elif a == "1" %}
G1 X{PX} Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 Y-{4*PX} E{ERAT*4*PX} F{SS}
G1 E-{RD} F{RS} ; retract
G1 X{2*PX} Y{2*PX} F{MS}
{% elif a == "2" %}
G1 Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X{2*PX} E{ERAT*2*PX} F{SS}
G1 Y-{2*PX} E{ERAT*2*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 Y-{2*PX} E{ERAT*2*PX}
G1 X{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 X{PX} Y{2*PX} F{MS}
{% elif a == "3" %}
G1 Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X{2*PX} E{ERAT*2*PX} F{SS}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X{2*PX} E{ERAT*2*PX} F{SS}
G1 E-{RD} F{RS} ; retract
G1 X{PX} F{MS}
{% elif a == "4" %}
G1 Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 Y-{2*PX} E{ERAT*2*PX} F{SS}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y{2*PX} F{MS}
G1 Y-{4*PX} E{ERAT*4*PX} F{SS}
G1 E-{RD} F{RS} ; retract
G1 X{PX} Y{2*PX} F{MS}
{% elif a == "5" %}
G1 X{2*PX} Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X-{2*PX} E{ERAT*2*PX} F{SS}
G1 Y-{2*PX} E{ERAT*2*PX}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y-{2*PX} E{ERAT*2*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 X{3*PX} Y{2*PX} F{MS}
{% elif a == "6" %}
G1 X{2*PX} Y{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X-{2*PX} E{ERAT*2*PX} F{SS}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y{2*PX} E{ERAT*2*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 X{3*PX} F{MS}
{% elif a == "7" %}
G1 E{RD} F{RS} ; un-retract
G1 Y{2*PX} E{ERAT*2*PX} F{SS}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 E-{RD} F{RS} ; retract
G1 X{PX} Y{2*PX} F{MS}
{% elif a == "8" %}
G1 E{RD} F{RS} ; un-retract
G1 Y{2*PX} E{ERAT*2*PX} F{SS}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 Y{2*PX} E{ERAT*2*PX}
G1 X{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 X{PX} F{MS}
{% elif a == "9" %}
G1 X{2*PX} F{MS}
G1 E{RD} F{RS} ; un-retract
G1 X-{2*PX} E{ERAT*2*PX} F{SS}
G1 Y{2*PX} E{ERAT*2*PX}
G1 X{2*PX} E{ERAT*2*PX}
G1 Y-{4*PX} E{ERAT*4*PX}
G1 X-{2*PX} E{ERAT*2*PX}
G1 E-{RD} F{RS} ; retract
G1 X{3*PX} Y{2*PX} F{MS}
{% endif %}
G90 ; absolute positioning
G1 Z{LH*2} F{ZS} ; move above layer height
{% endfor %}
{% if DU == 1 %} ; if draw_underline is enabled
G1 X{STARTX+FL+(SL*2)+(PX*2)+(PP|format(PA_VAL)|length-1)*(PX*3)} Y{STARTY+(BL*i)-(PX*2)-(LINE_WIDTH*(1-UO))} F{MS} ; move to underline position
G1 Z{LH} F{ZS} ; move to layer height
G1 E{RD} F{RS} ; un-retract
G1 X{STARTX+FL+(SL*2)} E{ERAT*((PX*2)+(PP|format(PA_VAL)|length-1)*(PX*3))*BE} F{SS} ; draw underline
{% if i == 0 %} ; connect first underline to the frame
G1 Y{STARTY} E{ERAT*((PX*2)+(LINE_WIDTH*(1-UO)))*BE} F{SS}
{% endif %}
G1 E-{RD} F{RS} ; retract
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
END_PRINT
# these may not work, in which case you will need to count and do the math yourself!
#M117 New PA = ({PA_START} + (bestLine * {PA_STEP}) )
M117 Pick your best line and use the printed value.
{action_respond_info ("Pick your best line and use the printed value.")}