From 5e8743c33a3a1c57828a3567fb0d706d678b00e0 Mon Sep 17 00:00:00 2001 From: MangaValk Date: Sun, 8 Nov 2026 01:39:15 +0100 Subject: [PATCH] Auto-resume after an AFC buffer fault pause A NOT FEEDING / CLOG pause during a print runs RESUME by itself after 5 s, so the lane check and the purge check decide; a failed check keeps the print paused. At most 2 per print, none within 10 min of printing of the previous one, only between _PRINT_START_FINISH and the print end. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + macros/afc/auto_resume.cfg | 99 ++++++++++++++++++++++++++++++++ macros/klipper-macros.cfg | 1 + macros/print/pause_resume.cfg | 9 +++ macros/print/print_start_end.cfg | 10 +++- 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 macros/afc/auto_resume.cfg diff --git a/README.md b/README.md index 7188400..237cbae 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ everything below, grouped by topic. Comment out what you do not use there. | `lane_tools.cfg` | `LANE_FEED_UNTIL_HUB_OPEN`, `LANE_FEED_ABORT` | AFC | | `purge_check.cfg` | `BLOBIFIER_CHECKED`: checks every AFC purge with bd_pressure (and optionally bdwidth motion); a bd_pressure that does not answer fails the check, `PURGE_CHECK_IGNORE_SENSOR` lets the current print finish without it; when the previous filament (saved `nozzle_last_temp`) needs more than 10°C above the new one, the purge runs at the previous filament's temperature and the nozzle cools back afterwards, so its leftover melts out | Blobifier, AFC, `bdpressure_check.py` from the bd_pressure repo + its load-check firmware, `extras/bdwidth_status.py` | | `flex_lanes.cfg` | Lanes holding TPU/TPE (material from Spoolman) get slower long moves (50 mm/s, AFC's minimum) through the tube; back to the configured speed when the lane holds something else. Polls every 5 s, reapplies after a restart. The last stretch into the extruder (`tool_load_speed`) stays as configured | AFC | +| `auto_resume.cfg` | After an AFC buffer fault pause ("AFC NOT FEEDING", "CLOG DETECTED") during a print, runs `RESUME` by itself after 5 s, so the lane check and the purge check decide; a failed check keeps it paused. At most 2 per print and none within 10 min of printing after the previous one; not during `PRINT_START` or a PA test. Off: `enabled` in `_AUTO_RESUME_CFG` | `print/pause_resume.cfg`, `purge_check.cfg`, AFC | | `purge_until_empty.cfg` | `PURGE_UNTIL_EMPTY`: purges a snapped filament out until there is no more nozzle pressure | same as `purge_check.cfg` | | **pressure_advance/** | | | | `bd_pressure.cfg` | `[bdpressure bd_pa]` (I2C on the Nitehawk) and the vendor macros `PA_CALIBRATE`, `PA_E`, `PA_RESET`, `PA_STATE`; `PA_CALIBRATE` no longer sets Z back to a value read before the test (wrong after a Z hop in `G28 XY`) | `bdpressure.py` from the bd_pressure repo | diff --git a/macros/afc/auto_resume.cfg b/macros/afc/auto_resume.cfg new file mode 100644 index 0000000..c6828ec --- /dev/null +++ b/macros/afc/auto_resume.cfg @@ -0,0 +1,99 @@ +# Automatic resume after an AFC buffer fault ("AFC NOT FEEDING" / "CLOG DETECTED") +# +# When AFC pauses a print because the buffer stayed empty or full too long, +# PAUSE (print/pause_resume.cfg) calls _AUTO_RESUME_ARM. After `delay` seconds +# _AUTO_RESUME runs the normal RESUME: AFC clears its error, the lane check +# runs, and _RESUME_PRINT purges into the Blobifier with the purge check. A +# failed check (or lane check) stops that RESUME as usual, so the print stays +# paused and waits for you. +# +# Limits, so a real problem (tangled spool, grinding extruder, clog) is not +# hidden: at most `max_per_print` automatic resumes per print, and none when +# the previous one was less than `min_interval` minutes of printing ago. After +# that the print stays paused like before. +# +# Only between _PRINT_START_FINISH and the end of the print (`active`): a pause +# during PRINT_START or a PA test needs CLEAR_PAUSE, not RESUME. +# +# Turn off: SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=enabled VALUE=False +# (until the next restart; change `enabled` below to keep it off) + +[gcode_macro _AUTO_RESUME_CFG] +description: Settings and state for the automatic resume after an AFC buffer fault +variable_enabled: True +variable_max_per_print: 2 # automatic resumes per print +variable_min_interval: 10 # minutes of printing since the previous automatic resume +variable_delay: 5 # seconds after the pause (AFC finishes its own pause first) +variable_faults: ['NOT FEEDING', 'CLOG DETECTED'] # text in AFC's error message +# State (set by the macros) +variable_active: False # True from _PRINT_START_FINISH to the end of the print +variable_count: 0 # automatic resumes in this print +variable_last_at: -1.0 # print_duration (s) of the last automatic resume, -1 = none +variable_pending: '' # fault the timer is waiting to resume from +gcode: + RESPOND MSG="Auto-resume: {'on' if enabled else 'off'}, {'active' if active else 'not active'}, {count}/{max_per_print} used in this print" + +# Called by _PRINT_START_FINISH (ON=1) and _PRINT_CLEANUP (ON=0) +[gcode_macro _AUTO_RESUME_ACTIVE] +description: Start (ON=1) or end (ON=0) the automatic resume for a print +gcode: + {% set on = params.ON|default(1)|int %} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=active VALUE={True if on else False} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=count VALUE=0 + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=last_at VALUE=-1.0 + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=pending VALUE="''" + UPDATE_DELAYED_GCODE ID=_AUTO_RESUME DURATION=0 + {% if on and 'AFC' in printer %} + # Old messages would be read as this print's fault: start empty + AFC_CLEAR_ALL_MESSAGES + {% endif %} + +# Called by PAUSE when it pauses a print. AFC's message queue shows its oldest +# message first; _RESUME_PRINT removes a buffer fault message once resumed, so +# the oldest one is this pause's. +[gcode_macro _AUTO_RESUME_ARM] +description: Start the automatic resume timer when AFC paused for a buffer fault and the limits allow it +gcode: + {% set cfg = printer["gcode_macro _AUTO_RESUME_CFG"] %} + {% set has_afc = 'AFC' in printer %} + {% set msg = printer.AFC.message.message|default('') if has_afc else '' %} + {% set fault = (cfg.faults|select('in', msg)|list + [''])[0] %} + {% set now = printer.print_stats.print_duration|float %} + {% if cfg.enabled and cfg.active and has_afc and printer.AFC.error_state and fault %} + {% if cfg.count >= cfg.max_per_print %} + _WARN MSG="Auto-resume: not resuming after AFC {fault}, already {cfg.count} automatic resumes in this print. Check the lane, then RESUME." DISPLAY="AFC {fault}: check, then RESUME" + {% elif cfg.last_at >= 0 and now - cfg.last_at < cfg.min_interval * 60 %} + _WARN MSG="Auto-resume: not resuming after AFC {fault}, the last automatic resume was only {((now - cfg.last_at) / 60)|round(1)} min of printing ago. Check the lane, then RESUME." DISPLAY="AFC {fault} again: check, then RESUME" + {% else %} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=pending VALUE="'{fault}'" + RESPOND MSG="Auto-resume: AFC {fault}, resuming in {cfg.delay} s with the purge check ({cfg.count + 1}/{cfg.max_per_print})" + UPDATE_DELAYED_GCODE ID=_AUTO_RESUME DURATION={cfg.delay} + {% endif %} + {% endif %} + +[delayed_gcode _AUTO_RESUME] +gcode: + {% set cfg = printer["gcode_macro _AUTO_RESUME_CFG"] %} + {% set fault = cfg.pending %} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=pending VALUE="''" + # Only when nothing changed since the pause: still paused, still AFC's + # error (a manual RESUME or CANCEL in the meantime ends it) + {% if fault and cfg.active and printer.print_stats.state == 'paused' + and printer.pause_resume.is_paused and printer.AFC.error_state %} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=count VALUE={cfg.count + 1} + SET_GCODE_VARIABLE MACRO=_AUTO_RESUME_CFG VARIABLE=last_at VALUE={printer.print_stats.print_duration|float} + RESPOND MSG="Auto-resume {cfg.count + 1}/{cfg.max_per_print} after AFC {fault}" + M117 Auto-resume {cfg.count + 1}/{cfg.max_per_print}: AFC {fault} + RESUME + {% endif %} + +# Called by _RESUME_PRINT after a resume: remove a buffer fault message from +# the front of AFC's queue, so the next pause reads its own message +[gcode_macro _AUTO_RESUME_CLEAR_FAULT] +description: Helper: drop AFC's buffer fault message after a resume +gcode: + {% set cfg = printer["gcode_macro _AUTO_RESUME_CFG"] %} + {% set msg = printer.AFC.message.message|default('') if 'AFC' in printer else '' %} + {% if msg and cfg.faults|select('in', msg)|list %} + AFC_CLEAR_MESSAGE + {% endif %} diff --git a/macros/klipper-macros.cfg b/macros/klipper-macros.cfg index a417fc2..cdcc089 100644 --- a/macros/klipper-macros.cfg +++ b/macros/klipper-macros.cfg @@ -37,6 +37,7 @@ [include afc/xy_safety_check.cfg] [include afc/lane_tools.cfg] [include afc/purge_check.cfg] +[include afc/auto_resume.cfg] # resume by itself after an AFC buffer fault (purge check first, limited) [include afc/purge_until_empty.cfg] [include afc/flex_lanes.cfg] # TPU/TPE lanes: slower long moves diff --git a/macros/print/pause_resume.cfg b/macros/print/pause_resume.cfg index 133eed8..5f2c9ef 100644 --- a/macros/print/pause_resume.cfg +++ b/macros/print/pause_resume.cfg @@ -16,6 +16,9 @@ # (the lane AFC was loading when a tool change failed, otherwise the loaded # lane), and RESUME stops with an error when another lane (or none) is loaded. # RESUME LANE_CHECK=0 resumes anyway (e.g. after remapping with SET_MAP). +# An AFC buffer fault pause ("AFC NOT FEEDING" / "CLOG DETECTED") during a +# print runs this RESUME by itself after a few seconds, within limits +# (afc/auto_resume.cfg). # A failed bed check in PRINT_START (calibration/bed_scan_check.cfg) pauses with # _BED_CHECK_STATE.pending set: PAUSE then only pauses, and RESUME runs # PRINT_START again instead of this chain's purge and lane check. @@ -51,6 +54,9 @@ gcode: _STATUS STATE=paused # Set fan to S28 (28/255 ≈ 0.1098) M106 S28 + {% if 'gcode_macro _AUTO_RESUME_ARM' in printer %} + _AUTO_RESUME_ARM ; AFC buffer fault: resume by itself after the purge check (afc/auto_resume.cfg) + {% endif %} {% else %} PAUSE_BASE {% endif %} @@ -103,6 +109,9 @@ gcode: {% endif %} SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=parked VALUE=False SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=expected_lane VALUE="''" + {% if 'gcode_macro _AUTO_RESUME_CLEAR_FAULT' in printer %} + _AUTO_RESUME_CLEAR_FAULT + {% endif %} # Clear the pause reason from the display (no comment on an M117 line: it would show) M117 {% endif %} diff --git a/macros/print/print_start_end.cfg b/macros/print/print_start_end.cfg index 6a5c2fa..efa9337 100644 --- a/macros/print/print_start_end.cfg +++ b/macros/print/print_start_end.cfg @@ -306,6 +306,11 @@ gcode: # ("AFC NOT FEEDING"); the slicer switches it back at layer 2 _FIRST_LAYER_FAULT_DETECTION ON=1 + # From here on an AFC buffer fault pause resumes by itself (afc/auto_resume.cfg) + {% if 'gcode_macro _AUTO_RESUME_ACTIVE' in printer %} + _AUTO_RESUME_ACTIVE ON=1 + {% endif %} + RESPOND MSG="starting" _STATUS STATE=printing @@ -346,7 +351,7 @@ gcode: # End-of-print cleanup shared by PRINT_END and CANCEL_PRINT [gcode_macro _PRINT_CLEANUP] -description: Heaters (incl. chamber heater) and part fan off, flow back to 100%, bdwidth off, mesh and skew cleared, nozzle guard off, AFC runouts cleared +description: Heaters (incl. chamber heater) and part fan off, flow back to 100%, bdwidth off, mesh and skew cleared, nozzle guard off, AFC runouts cleared, auto-resume off gcode: _GUARD_OFF ; a print start that failed while it was armed _BED_CHECK_RESET ; cancelled while the bed check had it paused @@ -364,6 +369,9 @@ gcode: SET_GCODE_VARIABLE MACRO=_PURGE_CHECK_CFG VARIABLE=ignore_missing_sensor VALUE=False {% endif %} _FIRST_LAYER_FAULT_DETECTION ON=0 ; a print that ended during the first layer + {% if 'gcode_macro _AUTO_RESUME_ACTIVE' in printer %} + _AUTO_RESUME_ACTIVE ON=0 ; also stops a pending automatic resume + {% endif %} # Infinite spool is set up per print (SET_RUNOUT): clear every lane's runout {% if 'AFC' in printer %} {% for lane in printer.AFC.lanes|default([]) if printer["AFC_stepper " ~ lane].runout_lane|default(none) %}