# Bed check: scan the bed and warn about bumps, dips or too much height range # (needs extras/mesh_check.py, which explains the method and the limits) # # BED_SCAN_CHECK [BUMP=0.03] [RANGE=0.30] # Scan now and report. Warns only, for use between prints. No heating and # no contact: X and Y home if needed, Z homes with the Beacon's proximity # mode. Replaces the active mesh, like any scan. # # BED_MESH_CHECK [BUMP=0.03] [RANGE=0.30] (extras/mesh_check.py) # Only check the mesh that is loaded now. # # In PRINT_START a failed check pauses the print before the nozzle heats up: # the toolhead goes up and out of the way so the plate can be cleaned. # Resume levels, homes and scans again, and checks again # BED_CHECK_IGNORE then Resume: the next failed check only warns # Cancel works as usual. # # How the retry works: a PAUSE in a macro only stops the print file, the rest # of the macro still runs, so everything after the check sits in # _PRINT_START_FINISH and is only called when the check allows it. While a # line of the file runs, virtual_sdcard.file_position is the start of that # line. Resume sets the file back there (M26) and resumes, so the file runs # PRINT_START again, as normal print file G-code: an error stops the print as # it always does, which an error in a delayed_gcode would not (the file would # carry on with the first layer). # # The pause goes through PAUSE, so through AFC_PAUSE: AFC_RESUME always restores # AFC's saved position after a pause. Without saving it here, that could be a # stale position from an earlier print, or X0 Y0 (seen after HEAT_SOAK). # RESET_FAILURE first, because AFC does not save over a position it still holds. # PAUSE sees _BED_CHECK_STATE.pending and only pauses: no retract, no park at # the bucket, and RESUME skips _RESUME_PRINT and its purge (the filament is not # loaded yet at this point). [mesh_check] bump_limit: 0.03 range_limit: 0.30 [gcode_macro _BED_CHECK_STATE] description: Variables of the print start bed check variable_pending: False # paused by the check, the next RESUME retries variable_ignore: False # BED_CHECK_IGNORE: the next failed check only warns variable_file_position: 0 # start of the PRINT_START line in the print file variable_park_z: 100 # room to reach the plate; free of the bucket above Z10 gcode: [gcode_macro _BED_CHECK_RESET] description: Forget a pending bed check (start and end of a print) gcode: SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=pending VALUE=False SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=ignore VALUE=False [gcode_macro BED_SCAN_CHECK] description: Scan the bed and warn about bumps, dips or too much height range (not during a print) gcode: {% set state = printer.print_stats.state %} {% if state in ('printing', 'paused') %} _ERROR MSG="BED_SCAN_CHECK: not during a print ({state})" DISPLAY="Bed scan: not during a print" {% else %} SAVE_GCODE_STATE NAME=_bed_scan_check G90 {% if 'xy' not in printer.toolhead.homed_axes %} _GUARD_ON PHASE=bed_check_home_xy G28 X Y _GUARD_OFF {% endif %} {% if 'z' not in printer.toolhead.homed_axes %} _GUARD_ON PHASE=bed_check_home_z G28 Z METHOD=PROXIMITY _GUARD_OFF {% endif %} _GUARD_ON PHASE=bed_check_qgl QUAD_GANTRY_LEVEL _GUARD_ON PHASE=bed_check_z G28 Z METHOD=PROXIMITY _GUARD_ON PHASE=bed_check_mesh BED_MESH_CALIBRATE RUNS=2 G1 Z10 F1200 _GUARD_OFF RESTORE_GCODE_STATE NAME=_bed_scan_check BED_MESH_CHECK {rawparams} _BED_SCAN_CHECK_REPORT {% endif %} # Separate macro: rendered after BED_MESH_CHECK has run [gcode_macro _BED_SCAN_CHECK_REPORT] description: Helper for BED_SCAN_CHECK: warn when the check failed gcode: {% set check = printer.mesh_check %} {% if check.result == 'fail' %} _WARN MSG="Bed check: {check.summary}. A bump usually means something on the plate: clean it and scan again." DISPLAY="Bed check failed, see console" {% elif check.result == 'none' %} _WARN MSG="Bed check not done: {check.summary}" DISPLAY="Bed check not done" {% else %} M117 Bed check OK {% endif %} [gcode_macro BED_CHECK_IGNORE] description: After the print start bed check paused the print: the next failed check only warns (press Resume after this) gcode: {% if printer["gcode_macro _BED_CHECK_STATE"].pending %} SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=ignore VALUE=True RESPOND MSG="Bed check: press Resume. It scans once more and continues even if the check still fails." {% else %} RESPOND MSG="Bed check: the print is not paused by the check, nothing to ignore" {% endif %} # Called by _PRINT_START_GATE. FILE_POS: start of the PRINT_START line. [gcode_macro _BED_CHECK_PAUSE] description: Helper for PRINT_START: move away from the plate and pause, RESUME scans again gcode: {% set cfg = printer["gcode_macro _BED_CHECK_STATE"] %} {% set summary = printer.mesh_check.summary %} SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=pending VALUE=True SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=file_position VALUE={params.FILE_POS|int} G90 _GUARD_ON PHASE=bed_check_park G1 Z{[cfg.park_z, printer.toolhead.axis_maximum.z - 5]|min} F1200 G1 X175 Y340 F6000 _GUARD_OFF RESET_FAILURE PAUSE _STATUS STATE=paused _WARN MSG="Bed check failed, print paused: {summary}. Clean the plate and press Resume to scan again. To print anyway: BED_CHECK_IGNORE, then Resume." DISPLAY="Bed check failed: clean plate, Resume" # Called by RESUME instead of its normal chain while a check is pending. # AFC_RESUME then restores the position that AFC_PAUSE saved in _BED_CHECK_PAUSE. [gcode_macro _BED_CHECK_RETRY] description: Helper for RESUME: go back to the PRINT_START line of the print file and resume gcode: {% set cfg = printer["gcode_macro _BED_CHECK_STATE"] %} SET_GCODE_VARIABLE MACRO=_BED_CHECK_STATE VARIABLE=pending VALUE=False # Clear the pause reason from the display M117 RESPOND MSG="Bed check: levelling and scanning again" M26 S{cfg.file_position|int} RESUME_BASE