Add a bed check: warn about bumps and flatness, pause PRINT_START on a failure

BED_SCAN_CHECK levels, scans and warns, without heating or touching the bed.
extras/mesh_check.py fits a smooth surface to the mesh and reports areas more
than 0.03 mm from it, and a range over 0.30 mm.

In PRINT_START a failed check pauses before the nozzle heats. Resume sets the
print file back to the PRINT_START line (M26), so it runs again as normal file
G-code. BED_CHECK_IGNORE lets the next failed check only warn.

Tested on saved scans and rendered macros only, not yet on the printer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-06 16:16:36 +01:00
1 parent e540e40cf7
commit 99b7109b5b
7 files changed
+358 -5

No files matched your search

+11 -2
View File
@@ -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).
# 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.
# https://klipperscreen.readthedocs.io/en/latest/macros/#recommended
[gcode_macro PAUSE]
@@ -25,7 +28,9 @@ variable_saved_fan_speed: 0.0
variable_parked: False # set by PAUSE, used by _RESUME_PRINT
variable_expected_lane: '' # AFC lane the print needs after RESUME ('' = no check)
gcode:
{% if not printer.pause_resume.is_paused %}
{% if printer["gcode_macro _BED_CHECK_STATE"].pending %}
PAUSE_BASE
{% elif not printer.pause_resume.is_paused %}
# AFC sets next_lane during a tool change and still has it when a failed
# change pauses the print; it clears it once CHANGE_TOOL returns
{% if 'AFC' in printer %}
@@ -54,7 +59,11 @@ gcode:
description: Resume the print (while HEAT_SOAK runs: skip the soak phase)
rename_existing: RESUME_BASE
gcode:
HEAT_SOAK_RESUME ON_RESUME=_RESUME_PRINT {rawparams}
{% if printer["gcode_macro _BED_CHECK_STATE"].pending %}
_BED_CHECK_RETRY
{% else %}
HEAT_SOAK_RESUME ON_RESUME=_RESUME_PRINT {rawparams}
{% endif %}
[gcode_macro _RESUME_PRINT]
description: Resume after PAUSE: purge and check (or unretract), restore the part fan, continue the print
+40 -3
View File
@@ -9,8 +9,10 @@
# PRINT_START runs on a soaked bed:
# PRINT_WARMUP bed heats while the nozzle cools and the printer homes,
# wait for the bed, HEAT_SOAK
# PRINT_START QGL, Z, contact Z calibration, mesh, load the initial tool,
# PA for all lanes, XY reference
# PRINT_START QGL, Z, contact Z calibration, mesh, bed check (a failed
# check pauses, RESUME runs PRINT_START again, see
# calibration/bed_scan_check.cfg), then _PRINT_START_FINISH:
# load the initial tool, PA for all lanes, XY reference
# The filament is loaded after the Z calibration, so the contact always
# touches a clean nozzle that has not been oozing at 150C for minutes.
# Chamber prints are the exception: PRINT_WARMUP loads and purges the first
@@ -26,6 +28,7 @@ gcode:
RESET_FAILURE
CLEAR_PAUSE
_BED_CHECK_RESET
# Clear what an earlier print or error left on the display
M117
@@ -193,10 +196,14 @@ gcode:
RESUME_BASE
[gcode_macro PRINT_START]
description: Print start after HEAT_SOAK: QGL, Z calibration, mesh, load the initial tool, PA
description: Print start after HEAT_SOAK: QGL, Z calibration, mesh, bed check, then _PRINT_START_FINISH
gcode:
{% set target_extruder = params.EXTRUDER|int %}
{% set initial_tool = params.TOOL|default("0")|int %}
# Rendered while this line of the print file runs: the start of the line,
# where a retry after a failed bed check goes back to. -1: not from a file.
{% set sd = printer.virtual_sdcard %}
{% set file_pos = sd.file_position if sd.is_active else -1 %}
RESPOND MSG="print start macro continued"
_LIGHTS_ON
@@ -235,6 +242,35 @@ gcode:
# From here on the nozzle extrudes and AFC cuts and loads: guard off
_GUARD_OFF
BED_MESH_CHECK
_PRINT_START_GATE EXTRUDER={target_extruder} TOOL={initial_tool} FILE_POS={file_pos}
# Separate macro: rendered after BED_MESH_CHECK has run. Pausing does not stop
# a running macro, so what follows the check must not be in PRINT_START itself.
[gcode_macro _PRINT_START_GATE]
description: Helper for PRINT_START: pause when the bed check failed, else go on with _PRINT_START_FINISH
gcode:
{% set check = printer.mesh_check %}
{% set ignore = printer["gcode_macro _BED_CHECK_STATE"].ignore %}
{% set file_pos = params.FILE_POS|int %}
{% if check.result == 'fail' and not ignore and file_pos >= 0 %}
_BED_CHECK_PAUSE FILE_POS={file_pos}
{% else %}
{% if check.result == 'fail' %}
_WARN MSG="Bed check failed, continuing: {check.summary}" DISPLAY="Bed check failed, continuing"
{% elif check.result != 'ok' %}
_WARN MSG="Bed check not done, continuing: {check.summary}" DISPLAY="Bed check not done"
{% endif %}
_BED_CHECK_RESET
_PRINT_START_FINISH EXTRUDER={params.EXTRUDER} TOOL={params.TOOL}
{% endif %}
[gcode_macro _PRINT_START_FINISH]
description: Helper for PRINT_START after the bed check: load the initial tool, PA, XY reference
gcode:
{% set target_extruder = params.EXTRUDER|int %}
{% set initial_tool = params.TOOL|default("0")|int %}
# Heat over the bucket, then undo the retracts of the previous PRINT_END
_STATUS STATE=heating_extruder
BLOBIFIER_PARK
@@ -310,6 +346,7 @@ gcode:
description: Heaters (incl. chamber heater) and part fan off, flow back to 100%, bdwidth off, mesh and skew cleared, nozzle guard off
gcode:
_GUARD_OFF ; a print start that failed while it was armed
_BED_CHECK_RESET ; cancelled while the bed check had it paused
TURN_OFF_HEATERS
iHEATER_OFF ; stops the chamber heater control loop too
M107