forked from jschuh/klipper-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpark.cfg
69 lines (60 loc) · 2.46 KB
/
park.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
# Copyright (C) 2022 Justin Schuh <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
[gcode_macro park]
description: Park the toolhead
Usage: PARK [P=<0|1|2>] [X=<pos>] [Y=<pos>] [Z=<pos>]
gcode:
{% set toolhead = printer.toolhead %}
{% if toolhead.homed_axes != "xyz" %}
{action_respond_info("Must home axes first.")}
{% endif %}
{% set km = printer["gcode_macro _km_globals"] %}
{% set max_z = toolhead.axis_maximum.z %}
{% set min_z = toolhead.axis_minimum.z %}
{% set travel_speed_xy = km.travel_speed_xy %}
{% set travel_speed_z = km.travel_speed_z %}
# Z position type from G27 (if below, absolute, relative)
{% set P = (params.P|default(2))|int %} # Default to 2 because it's sanest.
{% set X = params.X|default(km.park_x)|float %}
{% set Y = params.Y|default(km.park_x)|float %}
{% set Z = params.Z|default(km.park_z)|float %}
_CHECK_KINEMATIC_LIMITS X="{X}" Y="{Y}" Z="{Z}"
# Use the taller of the highest printed layer or the current Z height, which
# should helps crashes e.g. when a sequential print in progress.
{% set clearance_z = (printer["gcode_macro _km_layer_run"].clearance_z,
printer.gcode_move.gcode_position.z) | max %}
# Convert everything to absolute coordinates.
# P == 1 is absolute, so needs no adjustment.
{% if P == 0 %} # Move absolute to Z if below current Z
{% if clearance_z > Z %}
{% set Z = clearance_z %}
{% endif %}
{% elif P == 2 %} # Move Z relative
{% set Z = Z + clearance_z %}
{% elif P != 1 %}
{action_raise_error("Invalid parameter P=%i. Value must be 0, 1, or 2." |
format(P)) }
{% endif %}
# Clamp to the printer limits.
{% set Z = ((Z, max_z)|min, min_z)|max %}
SAVE_GCODE_STATE NAME=PARK
G90
G0 Z{Z} F{travel_speed_z}
G0 X{X} Y{Y} F{travel_speed_xy}
RESTORE_GCODE_STATE NAME=PARK MOVE=0
# Dummy argument block for Mainsail
{% set dummy = None if True else "
{% set dummy = params.P|default(mode=<0|1|2>)|int %}
{% set dummy = params.X|default(X position)|int %}
{% set dummy = params.Y|default(Y position)|int %}
{% set dummy = params.Z|default(Z position)|int %}
" %} # End argument block for Mainsail
[gcode_macro g27]
description: Parks the toolhead.
Usage: G27 [P=<0|1|2>]
gcode:
# Wraps any arguments for the PARK macro and defaults P=0 for Marlin compat.
PARK P={params.P|default(0)} {% for k in params|reject("in", "GP") %}{
' '~k~'="'~params[k]~'"'
}{% endfor %}