forked from viesturz/klipper-toolchanger
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtoolchanger-fan-stall-detect.cfg
More file actions
81 lines (71 loc) · 4.34 KB
/
toolchanger-fan-stall-detect.cfg
File metadata and controls
81 lines (71 loc) · 4.34 KB
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
## Toolchanger fan stall detect (tachometer/rpm):
# Written by: MikeyMike (github: MikeYankeeOscarBeta) (Discord: dubiousmnemonic)
# Original single hotend fan rpm macro written by: alch3my#9819
# link to original: https://github.com/AndrewEllis93/Print-Tuning-Guide/blob/main/macros/fan_tach_monitor.cfg
# Requires a 3-wire fan with tachometer_pin defined. https://www.klipper3d.org/Config_Reference.html#heater_fan
# The tach wire can be connected to a spare endstop pin.
# Depending on what board you connect it to you might need to set pullup (^) on the tach pin (example: tachometer_pin: ^P1.29)
# Klipper Docs for DELAYED_GCODE https://www.klipper3d.org/Command_Templates.html#delayed-gcodes
# & UPDATE_DELAYED_GCODE: https://www.klipper3d.org/G-Codes.html#update_delayed_gcode
# Monitoring loop. Begins at Klipper start.
[delayed_gcode CHECK_ALL_FANS] ## starts the hotend fan check
initial_duration: 1 # start automatically when klipper starts, comment out to not-autostart (if you want to start it manually instead)
gcode:
HOTEND_FAN_CHECK
UPDATE_DELAYED_GCODE ID=CHECK_ALL_FANS DURATION=3
[gcode_macro HOTEND_FAN_CHECK_CANCEL] ## cancels the check (stops checking fan rpm)
gcoode:
UPDATE_DELAYED_GCODE ID=CHECK_ALL_FANS DURATION=0 ## setting it to 0 cancels the pending gcode from executing
# Change max_consecutive_stops and hotend_fan_min_rpm per tool to your desired values.
[gcode_macro HOTEND_FAN_CHECK]
gcode:
{% set max_consecutive_stops = 3 %}
{% for tool_name in printer.toolchanger.tool_names %}
{% set tn = tool_name.split(' ')[1] %}
{% set tool = printer['tool ' + tn] %}
{% set hotend_fan_name = 'heater_fan '+tn+'_hotend_fan'|string|lower %}
{% set rpm = printer[hotend_fan_name].rpm|float %}
{% set he_target = printer[tool.extruder].target|float %}
{% set he_temp = printer[tool.extruder].temperature|float %}
{% set fan_on_temp = printer['configfile'].settings[hotend_fan_name|string|lower].heater_temp|float %}
{% set hotend_fan_stop_count = printer["gcode_macro "+tn].hotend_fan_stop_count|int %}
{% set hotend_fan_min_rpm = printer["gcode_macro "+tn].hotend_fan_min_rpm|int %}
{% if (he_target >= fan_on_temp) and (rpm < hotend_fan_min_rpm) and (he_temp >= fan_on_temp) %}
SET_GCODE_VARIABLE MACRO={tn} VARIABLE=hotend_fan_stop_count VALUE={hotend_fan_stop_count + 1}
M118 WARNING: Fan stoppage on {tn} detected ({hotend_fan_stop_count+1}/{max_consecutive_stops}). ##DONE?: add tool name to the error message
M400
{% if printer["gcode_macro "+tn].hotend_fan_stop_count|int >= max_consecutive_stops-1 %}
FAN_STOPPAGE_ROUTINE
{% endif %}
{% else %}
SET_GCODE_VARIABLE MACRO={tn} VARIABLE=hotend_fan_stop_count VALUE=0 ## DONE?: check the toolname macro instead (AVR0, AVR1, etc)
{% endif %}
{% endfor %}
# Insert the gcode that you want to run when a fan stoppage is detected.
# This runs every ~3 seconds until the stop conditions are cleared and the user resumes print
[gcode_macro FAN_STOPPAGE_ROUTINE]
gcode:
# If not already paused
#{% if printer['pause_resume'].is_paused|int == 0 %}
{% if not printer.pause_resume.is_paused %}
M117 !!ERROR: FAN STOPPAGE ON TOOL: {tn}!!
M118 FAN STOPPAGE DETECTED. PAUSING...
# TODO: figure out how to pause properly and save tool temperatures so they can be re-set once resumed
#PAUSE
#_TOOLCHANGER_CRASH_PAUSE ##
# Turn off all hotends.
# TODO: !! Don't forget to check if hotend gets turned back on before resume. !!
{% set temps = [] %}
SET_GCODE_VARIABLE MACRO=_TOOLCHANGER_CRASH_PAUSE VARIABLE=crashed VALUE=1
SET_GCODE_VARIABLE MACRO=_TOOLCHANGER_CRASH_RESUME VARIABLE=active_tool VALUE={printer.tool_probe_endstop.active_tool_number}
{% for tool_nr in printer.toolchanger.tool_numbers %}
{% set toolname = printer.toolchanger.tool_names[tool_nr] %}
{% set extruder = printer[toolname].extruder %}
{% set temp = printer[extruder].target|default(0.0)|float %}
{% set temps = temps.append(temp) %}
M104 T{tool_nr} S0
{% endfor %}
SET_GCODE_VARIABLE MACRO=_TOOLCHANGER_CRASH_RESUME VARIABLE=tool_temps VALUE='{temps}'
PAUSE
M117 paused
{% endif %}