-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauto_z_offset.cfg
250 lines (226 loc) · 11.5 KB
/
auto_z_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
# Copyright © 2023 Jose Jaramillo
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[gcode_macro RatOS]
variable_z_probe: "static"
variable_safe_home_x: 0
variable_safe_home_y: 0
variable_homing_z_hop: 10
variable_after_attach_z_hop: 20
variable_stowable_probe_position_preflight: [ 34, 72 ]
variable_stowable_probe_position_side: [ 34, 3 ]
variable_stowable_probe_position_dock: [ 4, 3 ]
# exit/re-entry staging
variable_stowable_probe_position_exit: [ 4, 72 ]
variable_macro_z_speed: 5
variable_euclid_xy_speed: 80
variable_homing: "endstops"
variable_nozzle_prime_direction: "forwards"
[z_calibration]
nozzle_xy_position: 0, 0
switch_xy_position: 27, 24
bed_xy_position: 250, 250
switch_offset: 0.42
max_deviation: 5.0
clearance: 20
lift_speed: 8
samples: 5
samples_tolerance: 0.01
samples_result: median
before_switch_gcode: CALIBRATE_EUCLID
# Macro to perform a modified z_tilt
[gcode_macro Z_TILT_ADJUST]
rename_existing: EUCLID_Z_TILT
gcode:
QUERY_PROBE ; check Euclid probe status
DEPLOY_PROBE ; deploy Euclid Probe if needed
EUCLID_Z_TILT ; check bed level
STOW_PROBE ; dock Euclid Probe
[ratos_homing]
axes: xyz
z_hop: 15
z_hop_speed: 15
gcode:
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %}
{% endif %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %}
{% endif %}
{% set home_middle_x = printer.toolhead.axis_maximum.x / 2 %}
{% set home_middle_y = printer.toolhead.axis_maximum.y / 2 %}
{% set z_probe = printer["gcode_macro RatOS"].z_probe|lower %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %}
{% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %}
{% set homing_x = printer["gcode_macro RatOS"].homing_x|lower %}
{% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %}
{% set homing = printer["gcode_macro RatOS"].homing|lower %}
{% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %}
# Make stowable probe assertion failures cause an emergency stop
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True
M400 # Wait for moves to finish
G90 # Absolute positioning
{% if params.X is defined or params.Y is not defined and params.Z is not defined %}
{% if homing_x == 'endstop' or homing == 'endstops' %}
G28 X
{% elif homing_x == 'sensorless' or homing == 'sensorless' %}
HOME_X_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_x to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_x, homing)) }
{% endif %}
{% set x_homed = True %}
G0 X{home_middle_x} F{speed}
{% endif %}
{% if params.Y is defined or params.X is not defined and params.Z is not defined %}
{% if homing_y == 'endstop' or homing == 'endstops' %}
G28 Y
{% elif homing_y == 'sensorless' or homing == 'sensorless' %}
HOME_Y_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_y to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_y, homing)) }
{% endif %}
{% set y_homed = True %}
G0 Y{home_middle_y} F{speed}
{% endif %}
{% if params.Z is defined or params.Y is not defined and params.X is not defined %}
RESPOND MSG="Homing Z"
M118 Homing Z
{% if x_homed == False or y_homed == False %}
M118 X and Y must be homed before homing Z
{ action_emergency_stop("X and Y must be homed before homing Z") }
{% else %}
{% if z_probe == "stowable" %}
DEPLOY_PROBE
G0 X{safe_home_x} Y{safe_home_y} F{speed}
G28 Z
G0 Z{z_hop} F{z_hop_speed}
STOW_PROBE
{% else %}
M118 z_home_else
# G0 X{safe_home_x} Y{safe_home_y} F{speed}
# G28 Z
# G0 Z{z_hop} F{z_hop_speed}
QUERY_PROBE
STOW_IF_DEPLOYED
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_side[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_side[1] } F{ speed }
G0 X{safe_home_x} Y{safe_home_y} F{speed}
G28 Z
G0 Z{z_hop} F{z_speed}
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_side[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_side[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[1] } F{ speed }
{% endif %}
{% endif %}
{% endif %}
# Reset stowable probe stop on error state
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error}
[gcode_macro CALIBRATE_Z]
rename_existing: BASE_CALIBRATE_Z
gcode:
{% set bed_position = params.BED_POSITION|default('None') %}
M118 E1 Starting Calibrate Z
{% if bed_position != 'None' %}
BASE_CALIBRATE_Z BED_POSITION={bed_position}
{% else %}
BASE_CALIBRATE_Z
{% endif %}
STOW_PROBE # and parking it afterwards (or DOCK_PROBE in klicky macros)
M118 E1 Finished Calibrate Z
M117
[gcode_macro STOW_IF_DEPLOYED]
description: if deployed, then stow it
gcode:
QUERY_PROBE
# {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set speed = printer["gcode_macro RatOS"].euclid_xy_speed|float * 60 %}
{% if not printer.probe.last_query %}
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_exit[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_exit[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_dock[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_dock[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_side[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_side[1] } F{ speed }
error_if_probe_deployed ; error trapping
{% endif %}
# error trapping macro
[gcode_macro error_if_probe_not_deployed]
gcode:
QUERY_PROBE ; check Euclid probe status
ASSERT_PROBE_STATE MUST_BE=deployed ; pass if deployed
# error trapping macro
[gcode_macro error_if_probe_deployed]
gcode:
QUERY_PROBE ; check Euclid probe status
ASSERT_PROBE_STATE MUST_BE=stowed ; pass if not deployed
; basically do nothing, magic is in the action_respond_info line...
[gcode_macro RETURN_EUCLID_TO_DOCK]
gcode:
M118 Returning Euclid to dock...
QUERY_PROBE
STOW_PROBE
[gcode_macro CALIBRATE_EUCLID]
gcode:
# {% set speed = printer["gcode_macro RatOS"].euclid_xy_speed|float * 60 %}
# {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set after_attach_z_hop = printer.configfile.config.ratos_homing.z_hop|float %}
M118 Picking up Euclid for calibration...
# this ensures that if the toolhead is over the Euclid probe dock that it doesn't accidently remove it when moving away.
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_side[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_side[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_side[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_side[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_dock[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_dock[1] } F{ speed }
G4 P500
M118 after_attach_z_hop: { after_attach_z_hop } z_speed: { z_speed }
G0 Z{ after_attach_z_hop } F{ z_speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_exit[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_exit[1] } F{ speed }
G0 X{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[0] } Y{ printer["gcode_macro RatOS"].stowable_probe_position_preflight[1] } F{ speed }
[gcode_macro START_PRINT]
gcode:
CLEAR_PAUSE
SAVE_GCODE_STATE NAME=start_print_state
# Metric values
G21
# Absolute positioning
G90
# Set extruder to absolute mode
M82
# Home
G28
M117 Heating bed...
# Wait for bed to heat up
M190 S{params.BED_TEMP|default(printer.heater_bed.target, true) }
# Run the customizable "AFTER_HEATING_BED" macro.
_START_PRINT_AFTER_HEATING_BED
# Run the customizable "BED_MESH" macro
_START_PRINT_BED_MESH
RESTORE_GCODE_STATE NAME=start_print_state
# Calibrate Z-Offset
CALIBRATE_Z
# Start heating extruder
M104 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) }
# Run the customizable "PARK" macro
_START_PRINT_PARK
# Wait for extruder to heat up
M109 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) }
# Run the customizable "AFTER_HEATING_EXTRUDER" macro.
_START_PRINT_AFTER_HEATING_EXTRUDER
M117 Printing...
# Set extrusion mode based on user configuration
{% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %}
M83
{% else %}
M82
{% endif %}
SKEW_PROFILE LOAD=ratos
{% if params.Z_ADJUST %}
# Adjust the G-Code Z offset if needed
SET_GCODE_OFFSET Z_ADJUST={params.Z_ADJUST|default(0.0)|float} MOVE=1
{% endif %}
G92 E0