forked from zellneralex/klipper_config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pressure_advance.cfg
185 lines (182 loc) · 9.66 KB
/
pressure_advance.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
#####################################################################
# Preperation
#####################################################################
# copy this file in the same directory as your printer.cfg
# add
# [include pressure_advance.cfg]
# to your printer.cfg
#
# A [save_variables] block is needed since a printer save variable needs to be used to have it available after power up.
# You can skip this if you already have an [save_variables] config block
# e.g:
# [save_variables]
# filename: /home/pi/klipper_config/.variables.stb
# I like to hide that file as there is nothing in that should be modified by the user.
# Do a klipper restart after adding the stuff above
#
# After klipper is back you need define your first filament id e.g.
# PRESSURE_ADVANCE_ADD FILAMENT=ABS
#
#####################################################################
# Macro for the print start or filament gcode section of your slicer
#####################################################################
# PRESSURE_ADVANCE_SELECT [FILAMENT=<id>] [NOZZLE=<value>] : Set pressure advanve and smooth
# time for the different filaments and nozzles combinations. If no combo is found
# the cfg values are used.
#
# For SuperSlicer/PrusaSlicer this could look like
# PRESSURE_ADVANCE_SELECT NOZZLE=[nozzle_diameter] FILAMENT=[filament_settings_id]
#
#####################################################################
# Console ussage
#####################################################################
# PRESSURE_ADVANCE_LIST: List all pressure advanve and smooth
# time for the different filaments and nozzles
#
# PRESSURE_ADVANCE_ADD FILAMENT=<id> [NOZZLE=<value>] [PRESSURE_ADVANCE=<value>] [SMOOTH_TIME=<value>]:
# Add new filaments, or nozzle to an existing filament or change pa settings for
# for an existing filament nozzle combination.
# Nozzle is defaulted to 0.4 and preasure advance/smoth time to the cfg values if not defined at the call
# !!! Caution do not use special characters like äüö or anything else in the name !!!
#
# PRESSURE_ADVANCE_REMOVE FILAMENT=<id> [NOZZLE=<value>]: Remove a definition
# If FILAMENT/NOZZLE is defined then only the coresponding nozzle setup will removed otherwise the complete
# filament.
#
#####################################################################
[gcode_macro PRESSURE_ADVANCE_LIST]
description: List all filament pressure advance settings
gcode:
{% if not printer.save_variables.variables.pressure_advance %}
{action_respond_info("PRESSURE ADVANCE: No filament defined ABORDED")}
{% else %}
{% set pa_dic = printer.save_variables.variables.pressure_advance %}
{% set out = ["PRESSURE ADVANCE: Defined filaments"] %}
{% for filament in pa_dic|sort(attribute='id') %}
{% set _dummy = out.append("%s" % filament.id) %}
{% for setup in filament.val|sort(attribute='nozzle') %}
{% set _dummy = out.append("Nozzle: %1.02f | Pressure Advance: %1.03f | Smooth Time: %1.03f" %
(setup.nozzle, setup.pa, setup.st)) %}
{% endfor %}
{% endfor %}
{action_respond_info(out|join("\n"))}
{% endif %}
[gcode_macro PRESSURE_ADVANCE_ADD]
description: Add or change pressure advance settings
gcode:
{% if 'FILAMENT' not in params|upper %}
{action_respond_info("PRESSURE ADVANCE: FILAMENT must be defined use \"PRESSURE_ADVANCE_ADD FILAMENT=id\" as a minimum")}
{% else %}
{% set cfg = printer.configfile.settings.extruder %}
{% set id = params.FILAMENT|string %}
{% set nozzle = params.NOZZLE|default(0.40)|float|round(2) %}
{% if not printer.save_variables.variables.pressure_advance %} # add first entry
{action_respond_info("PRESSURE ADVANCE: Initialize with Filament %s" % (id))}
{% set pa_dic = [{'id' : id,
'val': [{'nozzle': nozzle,
'pa' : params.PRESSURE_ADVANCE|default(cfg.pressure_advance)|float|round(3),
'st' : params.SMOOTH_TIME|default(cfg.pressure_advance_smooth_time)|float|round(3)}]}] %}
{% else %}
{% set pa_dic = printer.save_variables.variables.pressure_advance %}
{% for filament in pa_dic %}
{% if id == filament.id %}
{% set id_index = loop.index0 %}
{% for setup in filament.val %}
{% if nozzle == setup.nozzle %} # change value of an existing nozzle st an existing filament
{% set change_txt = [] %}
{% if 'PRESSURE_ADVANCE' in params|upper %}
{% set _dummy = change_txt.append("PRESSURE ADVANCE") %}
{% set _dummy = pa_dic[id_index].val[loop.index0].update({'pa': params.PRESSURE_ADVANCE|float|round(3)}) %}
{% endif %}
{% if 'SMOOTH_TIME' in params|upper %}
{% set _dummy = change_txt.append("SMOOTH TIME") %}
{% set _dummy = pa_dic[id_index].val[loop.index0].update({'st': params.SMOOTH_TIME|float|round(3)}) %}
{% endif %}
{% if change_txt|length > 0 %}
{action_respond_info("PRESSURE ADVANCE: Changed %s at Filament %s Nozzle %s" % (change_txt|join(" and "),id,nozzle))}
{% else %}
{action_respond_info("PRESSURE ADVANCE: Nothing changed at Filament %s Nozzle %s" % (id,nozzle))}
{% endif %}
{% elif loop.last %} # add a new nozzle to an existing filament
{action_respond_info("PRESSURE ADVANCE: Add setup for Nozzle %s at Filament %s" % (nozzle,id))}
{% set _dummy = pa_dic[id_index].val.append({'nozzle': nozzle,
'pa' : params.PRESSURE_ADVANCE|default(cfg.pressure_advance)|float|round(3),
'st' : params.SMOOTH_TIME|default(cfg.pressure_advance_smooth_time)|float|round(3)}) %}
{% endif%}
{% endfor %}
{% elif loop.last %} # add a new filament
{action_respond_info("PRESSURE ADVANCE: Add setup for Filament %s" % (id))}
{% set _dummy = pa_dic.append({'id' : id,
'val': [{'nozzle': nozzle,
'pa' : params.PRESSURE_ADVANCE|default(cfg.pressure_advance)|float|round(3),
'st' : params.SMOOTH_TIME|default(cfg.pressure_advance_smooth_time)|float|round(3)}]}) %}
{% endif %}
{% endfor %}
{% endif %}
SAVE_VARIABLE VARIABLE=pressure_advance VALUE="{pa_dic}"
{% endif %}
[gcode_macro PRESSURE_ADVANCE_REMOVE]
description: Remove a filament or a nezzle setup
gcode:
{% if 'FILAMENT' not in params|upper %}
{action_respond_info("PRESSURE ADVANCE: FILAMENT must be defined use \"PRESSURE_ADVANCE_REMOVE FILAMENT=id\" as a minimum")}
{% else %}
{% if not printer.save_variables.variables.pressure_advance %} # nothing setup'ed yet
{action_respond_info("PRESSURE ADVANCE: Nothing to remove, no save_variable defined yet")}
{% else %}
{% set id = params.FILAMENT|string %}
{% set pa_dic = printer.save_variables.variables.pressure_advance %}
{% for filament in pa_dic %}
{% if id == filament.id %}
{% if 'NOZZLE' in params|upper %}
{% set nozzle = params.NOZZLE|float|round(2) %}
{% set id_index = loop.index0 %}
{% for setup in filament.val %}
{% if nozzle == setup.nozzle %} # remove nozzle
{action_respond_info("PRESSURE ADVANCE: Remove Nozzle %s at Filament %s" % (nozzle,id))}
{% set _dummy = pa_dic[id_index].val.pop(loop.index0) %}
{% elif loop.last %} # nozzle not found
{action_respond_info("PRESSURE ADVANCE: Nothing to remove, Nozzle %s at Filament %s not defined" % (nozzle,id))}
{% endif%}
{% endfor %}
{% else %} # remove filament
{action_respond_info("PRESSURE ADVANCE: Remove Filament %s" % id)}
{% set _dummy = pa_dic.pop(loop.index0) %}
{% endif %}
{% elif loop.last %} # filament not found
{action_respond_info("PRESSURE ADVANCE: Nothing to remove, Filament %s not defined" % id)}
{% endif %}
{% endfor %}
{% endif %}
SAVE_VARIABLE VARIABLE=pressure_advance VALUE="{pa_dic}"
{% endif %}
[gcode_macro PRESSURE_ADVANCE_SELECT]
description: Set PA depending on nozzle and filament
gcode:
{% if not printer.save_variables.variables.pressure_advance %}
{action_respond_info("PRESSURE ADVANCE: No filament defined ABORDED")}
{% else %}
{% set nozzle = params.NOZZLE|default(0.4)|float %}
{% set id = params.FILAMENT|default('None')|string %}
{% set pa_dic = printer.save_variables.variables.pressure_advance %}
{% set found = {'id' : 'default',
'nozzle': 0.4,
'pa' : printer.configfile.settings.extruder.pressure_advance,
'st' : printer.configfile.settings.extruder.pressure_advance_smooth_time} %}
{% for filament in pa_dic %}
{% if id == filament.id %}
{% for setup in filament.val %}
{% if nozzle == setup.nozzle %}
{% set _dummy = found.update({'id': filament.id}) %}
{% set _dummy = found.update({'nozzle': setup.nozzle}) %}
{% set _dummy = found.update({'pa': setup.pa}) %}
{% set _dummy = found.update({'st': setup.st}) %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
SET_PRESSURE_ADVANCE ADVANCE={found.pa} SMOOTH_TIME={found.st}
{action_respond_info("PRESSURE ADVANCE:
Filament: %s Nozzle: %1.02f
Pressure Advance: %1.03f Smooth Time: %1.03f" % (found.id, found.nozzle, found.pa, found.st))}
{% endif %}