-
Notifications
You must be signed in to change notification settings - Fork 9
/
bed_offset.cfg
308 lines (266 loc) · 13.2 KB
/
bed_offset.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
##
# Strayr's bed management
# saves all state in a separate local file
# considered experimental
# GPL 3, see license.txt, section 15 disclaimer of warranty applies. You have been warned.
# USE AT YOUR OWN RISK. Improper use may distroy your printbed or worse.
#
# requires [save_variables]
#
###
# Usage:
# _INIT_BED to set up variables
# BED_DETAILS for info
# Do a PROBE_CALIBRATE on a bed SAVE_CONFIG
# SAVE_BED NAME="My Shiny New Bed" to save the bed in the current slot, or specify a different number
# repeat the PROBE_CALIBRATE for all your beds, saving them to different slots
#
# NOTE bed temperature doesn't matter when you probe calibrate so long as you are making a mesh with the bed
# at print temerature. HOWEVER nozzle temperature does matter. I run PROBE_CALIBRATE at 180C which is enough
# to soften any filamant blobs and it's close enough with smooth PEI at 200-300C with v6/revo. If you have
# issues with hotend expansion and do very high temp printing, save the same bed with nozzle temperature
# variations, eg 1 "Smooth PEI 200", 2 "Smooth PEI 400" etc.
#
# Shim thickness is hard coded into _INIT_BED, you can change this there or by editing the value in your saved
# varibles if required.
#
# When you swap in a bed you have already saved, use LOAD_BED SLOT=n where n is the slot you saved it to
# SAVE_CONFIG to apply
#
# Add _BED_START_PRINT_OFFSETS and _BED_END_PRINT_OFFSETS to you START/END_print macros to use
# fine adjust/systematic offset system
#
# Use BED_FINE_ADJUST to tweak Z height, it's persistent but not saved to a slot untill you use SAVE_BED
# This should only be needed to set some squish.
#
# When you change a nozzle, put in a bed that has good saved values. PROBE_CALIBRATE and SAVE_CONFIG,
# check with a test print. If it's good do BED_RECALCULATE_NOZZLE_OFFSET, specify a SLOT if you forgot to
# load the bed slot before doing the nozzle calibration. The change in probe offset will be applied to all
# defined beds.
#
# TODO: make this work for endstop + probe printers which are a right headache here.
#
# TODO: systematic offset adjust to move the same amount from every slot fine adjust to systematic offset
# TODO: provide a way to edit shim thickness.
####
# Saved variables#
#
# bed_probe_offset: LIST should be the value measured using probe valibrate with a 0.1mm shim, this should not change if you have a mechanical probe
# bed_endstop_offset: LIST not used if your probe is a virtual endstop.
# bed_fine_adjust: LIST should be where any fine adjust is stored, mostly for squish
# bed_name: LIST of familar names for beds
# bed_shim_thickness: Use to remove systematic errors, 0.1 for paper
# bed_age: LIST the print count when the bed was calibrated.
# bed_virtual_endstop: set to 1 if using virtual endstop, will look at doing this programtiavly
# bed_slot: index of the bed in use
[gcode_macro BED_DETAILS]
description: use SLOT parameter to get info on a different bed.
variable_version: 0.501
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
{% if SVV.bed_version|float < version|float %}
{ action_raise_error("Setup data is older than macro version You should check the values in _INIT_BED and run it to update.")}
{% endif %}
{% if printer.save_variables.variables.setup_use_bed_offset == 0 %}
{ action_respond_info("BED OFFSET DISABLED")}
{% endif %}
{%set slot = params.SLOT|default(printer.save_variables.variables.bed_slot)|int %}
{ action_respond_info("Bed " + slot|string + " " + SVV.bed_name[slot]|string )}
{ action_respond_info("Slot Probe Offset " + SVV.bed_probe_offset[slot]|string )}
{ action_respond_info("Used Probe Offset " + PCS.probe.z_offset|string )}
{ action_respond_info("Fine Adjust " + SVV.bed_fine_adjust[slot]|string )}
{ action_respond_info("Bed Age " + SVV.bed_age[slot]|string )}
{% if SVV.bed_virtual_endstop == 1 %}
{ action_respond_info("You have a virtual endstop")}
{% else %}
{ action_respond_info("Endsop Offset " + SVV.bed_endstop_offset[slot]|default("virtual")|string )}
{% endif %}
[gcode_macro BED_LIST]
description: List all beds
variable_version: 0.501
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
{% if SVV.bed_version|float < version|float %}
{ action_raise_error("Setup data is older than macro version You should check the values in _INIT_BED and run it to update.")}
{% endif %}
{% for i in range(SVV.bed_probe_offset|count)%}
{% if i == SVV.bed_slot|int %}
{% set highlight = "* "%}
{% else %}
{% set highlight = " "%}
{% endif %}
{ action_respond_info(highlight + i|string + " " + SVV.bed_name[i] )}
{% endfor %}
[gcode_macro BED_OFFSET_DISABLE]
description: turn this system off
variable_version: 0.501
gcode:
SAVE_VARIABLE VARIABLE=setup_use_bed_offset VALUE=0
{ action_respond_info("BED OFFSET DISABLED")}
[gcode_macro BED_OFFSET_ENABLE]
description: turn this system on
variable_version: 0.501
gcode:
SAVE_VARIABLE VARIABLE=setup_use_bed_offset VALUE=1
{ action_respond_info("BED OFFSET ENABLED")}
[gcode_macro BED_SAVE]
description: Saves offset to slot, use PROBE to set probe offset and NAME to set bed name, SLOT to set a value, this doesn't error check, be warned.
variable_version: 0.501
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
{% set slot = params.SLOT|default(SVV.bed_slot)|int %}
{% set probe_offset = params.PROBE|default(PCS.probe.z_offset)|float %}
{% set name = params.NAME|default(SVV.bed_name[slot])|string %}
{% set probe_offsets = SVV.bed_probe_offset|list %}
{% set new_probe_offsets = probe_offsets[0:slot]|list + [probe_offset] + probe_offsets[slot+1:]|list %}
{% set new_fine_adjust = SVV.bed_fine_adjust[0:slot]|list + [SVV.setup_nozzle_offset] + SVV.bed_fine_adjust[slot+1:]|list %}
{% set new_names = SVV.bed_name[0:slot]|list + [name] + SVV.bed_name[slot+1:]|list %}
#TODO bed_age
#TODO bed_maxtemp
SAVE_VARIABLE VARIABLE=bed_probe_offset VALUE="{new_probe_offsets|string}"
{% if ('RECALCULATE' not in params) %}
{ action_respond_info("Probe Offsets" + new_probe_offsets|string )}
{ action_respond_info("Fine Adjust" + new_fine_adjust|string )}
{ action_respond_info("Names" + new_names|string )}
SAVE_VARIABLE VARIABLE=bed_slot VALUE={slot}
SAVE_VARIABLE VARIABLE=bed_fine_adjust VALUE="{new_fine_adjust|string}"
SAVE_VARIABLE VARIABLE=bed_name VALUE="{new_names|string}"
{% endif %}
[gcode_macro ZERO_OFFSET]
description: get rid of probe offset
gcode:
SET_GCODE_OFFSET Z={-(printer.configfile.settings.probe.z_offset)}
Z_OFFSET_APPLY_PROBE
[gcode_macro BED_LOAD]
description: Load a saved bed
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
{% set slot = params.SLOT|default(SVV.bed_slot)|int %}
{% set probe_offset = SVV.bed_probe_offset[slot]|float %}
# ZERO_OFFSET
{ action_respond_info("New Probe Offset " + probe_offset|string )}
{ action_respond_info("Old Probe Offset " + PCS.probe.z_offset|string )}
{% set z_adjust =(PCS.probe.z_offset|float) - probe_offset %}
{ action_respond_info("Z Adjust " + z_adjust|string )}
SET_GCODE_OFFSET Z={(z_adjust)|string}
Z_OFFSET_APPLY_PROBE
{ action_respond_info("Stored " + slot|string + " " + SVV.bed_name[slot]|string )}
BED_FINE_ADJUST ZOFFSET={SVV.bed_fine_adjust[slot]}
SAVE_VARIABLE VARIABLE=bed_slot VALUE={slot}
SAVE_CONFIG
[gcode_macro BED_RECALCULATE_NOZZLE_OFFSET]
description: Run this after nozzle change procedure to apply changes to all beds
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
{% set slot = params.SLOT|default(SVV.bed_slot)|int %}
{% set new_offset = params.PROBE|default(PCS.probe.z_offset)|float %}
{% set old_offset = SVV.bed_probe_offset[slot]|float %}
{% set offset_adjust = new_offset - old_offset %}
{action_respond_info("Offsetting beds by " + offset_adjust|string) }
{% for i in range(SVV.bed_probe_offset|count)%}
{% set new = SVV.bed_probe_offset[i]|float + offset_adjust %}
BED_SAVE SLOT={i} PROBE={new} RECALCULATE=1
{% endfor %}
{ action_respond_info(offset_list|string) }
SAVE_VARIABLE VARIABLE=bed_slot VALUE={slot}
#BED_LIST
[gcode_macro _INIT_BED]
description: Creates required variblaes if the don't already exist.
variable_version: 0.501
gcode:
{% set SVV = printer.save_variables.variables %}
{% set PCS = printer.configfile.settings %}
SAVE_VARIABLE VARIABLE=bed_version VALUE="{version}"
{% if (not SVV.bed_slot) %}
{ action_respond_info("Using bed_slot 0")}
SAVE_VARIABLE VARIABLE=bed_slot VALUE=0
{% else %}
{ action_respond_info("bed_slot already exists")}
{% endif %}
{% if (not SVV.bed_shim_thickness) %}
{ action_respond_info("Using bed_shim_thickness 0.1 mmm")}
SAVE_VARIABLE VARIABLE=bed_shim_thickness VALUE=0.1
{% else %}
{ action_respond_info("bed_shim_thickness already exists")}
{% endif %}
{% if (not SVV.bed_probe_offset) %}
{%set poffset = PCS.probe.z_offset|float %}
{% set bed_offset_array=[poffset,poffset,poffset] %}
{ action_respond_info( bed_offset_array|string )}
SAVE_VARIABLE VARIABLE=bed_probe_offset VALUE="{bed_offset_array|string}"
{% else %}
{ action_respond_info("bed_probe_offset already exists")}
{% endif %}
{% if (not SVV.bed_virtual_endstop) %}
{% if (not PCS.stepper_z.position_endstop) %}
{ action_respond_info( "We think you are using a virtual endstop, set bed_virtual_endstop manually if this is incorrect" ) }
SAVE_VARIABLE VARIABLE=bed_virtual_endstop VALUE=1
{% else %}
{ action_respond_info("We think you are using a physical, set bed_virtual_endstop manually if this is incorrect" ) }
SAVE_VARIABLE VARIABLE=bed_virtual_endstop VALUE=0
{% endif %}
{% else %}
{ action_respond_info("bed_virtual_endstop already exists")}
{% endif %}
# TODO test this on the other printer
{% if (SVV.bed_virtual_endstop == 0) and (not SVV.bed_endstop_offset) %}
{% set eoffset = PCS.stepper_z.position_endstop|float %}
{% set bed_offset_array=[eoffset, eoffset, eoffset] %}
{ action_respond_info( bed_offset_array|string )}
SAVE_VARIABLE VARIABLE=bed_endstop_offset VALUE="{bed_offset_array|string}"
{% else %}
{ action_respond_info("bed_endstop_offset unchanged")}
{% endif %}
{% if (not SVV.bed_fine_adjust) %}
{% set bed_fine_array=[0,0,0] %}
{ action_respond_info("offset fine adjust zeroed")}
SAVE_VARIABLE VARIABLE=bed_fine_adjust VALUE="{bed_fine_array|string}"
{% else %}
{ action_respond_info("bed_probe_offset already exists")}
{% endif %}
{% if (not SVV.bed_name) %}
{% set bed_name_array=["Sample PEI", "Sample textured", "Sample number 3"] %}
{ action_respond_info("sample bed names loaded")}
SAVE_VARIABLE VARIABLE=bed_name VALUE="{bed_name_array|string}"
{% else %}
{ action_respond_info("bed_name already exists")}
{% endif %}
{% if( not SVV.bed_age) %}
{% set bed_age_array=[0,0,0] %}
{ action_respond_info("bed age zeroed")}
SAVE_VARIABLE VARIABLE=bed_age VALUE="{bed_age_array|string}"
{% else %}
{ action_respond_info("bed age already exists")}
{% endif %}
[gcode_macro _BED_START_PRINT_OFFSETS]
description: Applies systematic and fine adjust offsets in start print
gcode:
# TODO check we didn't turn this off
{% set SVV = printer.save_variables.variables %}
SET_GCODE_OFFSET Z=-{SVV.bed_shim_thickness|string} # Don't forget the -here
SET_GCODE_OFFSET Z_ADJUST={SVV.setup_nozzle_offset|string}
# TODO put print count increment in here
# We remove systematic effects so we can save our in use offset to fine adjust
[gcode_macro _BED_END_PRINT_OFFSETS]
description: Applies systematic and fine adjust offsets in start print
gcode:
# TODO check we didn't turn this off
{% set SVV = printer.save_variables.variables %}
SET_GCODE_OFFSET Z_ADJUST={SVV.bed_shim_thickness|string} # This is +VE as we subtract to apply
# use this to set an offset to the gcode that remains in place, usually represents a systematic error in PROBE_CALIBRATE
# this looks like the thickness of the shim i use, but I can't be certain it's just that.
[gcode_macro BED_FINE_ADJUST]
description: Set ZOFFSET parameter to the static adjustment you need for the printer, independent of bed offsets
gcode:
{% if "ZOFFSET" in params %}
{ action_respond_info("Nozzle offset was " + printer.save_variables.variables.setup_nozzle_offset|string )}
SAVE_VARIABLE VARIABLE=setup_nozzle_offset VALUE={params.ZOFFSET|default(0)|float}
{ action_respond_info("Nozzle offset set to " + params.ZOFFSET|default(0)|string )}
{% else %}
{ action_respond_info("Nozzle offset is " + printer.save_variables.variables.setup_nozzle_offset|string )}
{% endif %}