-
Notifications
You must be signed in to change notification settings - Fork 102
/
homing.cfg
107 lines (103 loc) · 5.56 KB
/
homing.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
#####################################################################
# Homing definition
#####################################################################
[homing_override]
axes: z
set_position_z: 0
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
{% set home_x, home_y, home_z = False, False, False %} ; define what axes need to be homed
{% if params.X is not defined and params.Y is not defined and params.Z is not defined %} ; G28
{% set home_x, home_y, home_z = True, True, True %}
{% else %}
{% if params.X is defined %}{% set home_x = True %}{% endif %}
{% if params.Y is defined %}{% set home_y = True %}{% endif %}
{% if params.Z is defined %}
{% if 'x' not in printer.toolhead.homed_axes %}{% set home_x = True %}{% endif %} ; check if homed
{% if 'y' not in printer.toolhead.homed_axes %}{% set home_y = True %}{% endif %} ; check if homed
{% set home_z = True %}
{% endif %}
{% endif %}
{% if user.hw.mag_probe.ena %} _MAG_PROBE ACTION=GET_STATUS RESPOND=0 {% endif %} ; generate probe state
_SET_ACC VAL=HOME ; reduce accel and accel_to_decel
G0 Z{user.homing.z_endstop.hop} F{user.speed.z_hop} ; lift nozzle
{% if home_x %} G28 X {% endif %} ; home X
{% if home_y %} G28 Y {% endif %} ; home Y
{% if home_z %} _HOME_Z {% endif %} ; home Z
_SET_ACC ; set accel and accel_to_decel back to cfg value
[gcode_macro _HOME_Z]
description: Helper: z homing
variable_calibrate_z_next: False
gcode:
{% set user = printer['gcode_macro _USER_VARIABLE'] %}
; use -10 as default to insure it error out in case the variable is not existing
{% set z_endstop = user.homing.z_endstop|default({'x':-10,'y':-10,'z':0, 'hop':0}) %}
{% if user.hw.mag_probe.ena %}
{% set probe = printer['gcode_macro _MAG_PROBE'].state|default('unknown')|lower %} ; get probe state
{% set error = "run \"_MAG_PROBE ACTION=GET_STATUS\"" if probe == 'unknown'
else "last dock or undock failed" if probe == 'error'
else "not valid" if probe is not in ['docked','attached']
else "" %}
{% if error|length > 0 %}
{action_raise_error("Home&Probe: MagProbe state %s %s" % (error,probe|upper))}
{% endif %}
{% endif %}
{% if user.hw.mag_probe.ena and probe == 'attached' %}
{action_respond_info("Home&Probe: Probe docked, remove probe first")}
DETACH_PROBE ; detach probe
{% endif %}
_SET_Z_CURRENT VAL=HOME ; reduce Z current
G90 ; absolute position
G0 X{z_endstop.x} Y{z_endstop.y} F{user.speed.travel} ; move to endstop position
G28 Z ; home Z
G0 Z{z_endstop.z} F{user.speed.z_hop/3} ; lift toolhead to stop pressing on the pin
{% if calibrate_z_next %}
SET_GCODE_VARIABLE MACRO=_HOME_Z VARIABLE=calibrate_z_next VALUE=False
{% else %}
_SET_Z_CURRENT ; set Z current back to cfg value
G0 Z{user.z_hop} F{user.speed.z_hop} ; lift toolhead
{% endif %}
{% if not printer.gcode_move.absolute_coordinates %} G91 {% endif %} ; set it back to relative
#####################################################################
# Macros
#####################################################################
## conditional home
[gcode_macro _CG28]
description: Helper: Conditional homing
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %} G28 {% endif %}
[gcode_macro _SET_Z_CURRENT]
description: Helper: Set Z-drive motor current
variable_last_val: 'CONFIG'
gcode:
{% set val = params.VAL|default('CONFIG') %}
{% set z_run = printer['gcode_macro _USER_VARIABLE'].homing.z_current if val == 'HOME'
else printer.configfile.settings['tmc2209 stepper_z'].run_current if 'tmc2209 stepper_z' in printer.configfile.settings
else printer.configfile.settings['tmc5160 stepper_z'].run_current if 'tmc5160 stepper_z' in printer.configfile.settings %}
{% if val != last_val %}
SET_GCODE_VARIABLE MACRO=_SET_Z_CURRENT VARIABLE=last_val VALUE='"{val}"'
{% if params.RESPOND|default(printer['gcode_macro _USER_VARIABLE'].respond.z_current)|int == 1 %}
{action_respond_info("Home&Probe: RunCur %.2fA rms" % z_run|float)}
{% endif %}
SET_TMC_CURRENT STEPPER=stepper_z CURRENT={z_run}
SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT={z_run}
SET_TMC_CURRENT STEPPER=stepper_z2 CURRENT={z_run}
SET_TMC_CURRENT STEPPER=stepper_z3 CURRENT={z_run}
M400
{% endif %}
[gcode_macro _SET_ACC]
description: Helper: Set accel and accel_to_decel value
variable_last_val: 'CONFIG'
gcode:
{% set val = params.VAL|default('CONFIG') %}
{% set accel = printer['gcode_macro _USER_VARIABLE'].homing.accel if val == 'HOME'
else printer.configfile.settings.printer.max_accel %}
{% set accel_to_decel = printer['gcode_macro _USER_VARIABLE'].homing.accel|int / 2 if val == 'HOME'
else printer.configfile.settings.printer.max_accel_to_decel %}
{% if val != last_val %}
SET_GCODE_VARIABLE MACRO=_SET_ACC VARIABLE=last_val VALUE='"{val}"'
{% if params.RESPOND|default(printer['gcode_macro _USER_VARIABLE'].respond.acc)|int == 1 %}
{action_respond_info("Home&Probe: ACCEL: %d ACCEL_TO_DECEL: %d" % (accel|int, accel_to_decel|int))}
{% endif %}
SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel_to_decel}
{% endif %}