From a16b57a0a9d53069a687e367ac6cc4a23265a7da Mon Sep 17 00:00:00 2001 From: MangaValk Date: Sun, 18 Oct 2026 23:11:02 +0200 Subject: [PATCH] Move bd_pressure.cfg and TEST_SPEED into the repo All macros now come from this repo. bd_pressure.cfg ([bdpressure bd_pa] and the vendor PA_CALIBRATE macros) and Macros/TEST_SPEED.cfg were loose files in ~/printer_data/config. PA_CALIBRATE no longer sets Z back to z_current at the end: it was read before the test ran, so a Z hop in the G28 XY (Beacon home_z_hop) would leave Klipper believing the nozzle is lower than it is. Z is never switched off or moved by the test, so it keeps its position without that line. The ACC_WALL bug (read from ACCEL_TO_DECEL, always 4000) is documented, not fixed: the cached PA values were measured at 4000. printer.cfg must drop [include bd_pressure.cfg] and Macros/macros.cfg its TEST_SPEED include, else the old copies (included later) still win. Reference values from the load-check-afc branch and from the guard and Z check tests added to CLAUDE.md. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 7 +- README.md | 4 + macros/klipper-macros.cfg | 2 + macros/pressure_advance/bd_pressure.cfg | 164 ++++++++++++++++++++++++ macros/print/test_speed.cfg | 127 ++++++++++++++++++ 5 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 macros/pressure_advance/bd_pressure.cfg create mode 100644 macros/print/test_speed.cfg diff --git a/CLAUDE.md b/CLAUDE.md index 13206b0..009f3e6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -94,7 +94,12 @@ detection, `filament_error_sensitivity`), iHeater chamber heater. ## Reference values - Purge check (150 mm Blobifier purge): good load = longest pressure - 13-18 s, peak 64-181; empty nozzle about 30 ms. + 13-18 s, peak 64-181; empty nozzle about 30 ms. A real failed load in a + print start (AFC reported the lane loaded, nothing reached the nozzle): + longest 1915 ms, peak 45, caught by the 5000 ms limit. +- Nozzle guard (bdp_guard): reading at rest and in travel peaks about 2; a + light finger push on the cold nozzle gives 41 (threshold 30). +- Z check after a contact homing: Beacon vs Klipper Z about 0.06 mm. - XY drift check: endstop noise about 0.01-0.02 mm; limit 0.1 mm (one motor skipping one cycle = 0.4 mm shows as 0.2 mm in X and Y). diff --git a/README.md b/README.md index 22432ca..d59471b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ everything below, grouped by topic. Comment out what you do not use there. | `filament.cfg` | `LOAD_FILAMENT`, `UNLOAD_FILAMENT` | — | | `homing.cfg` | `HOME`: X/Y, then Z always with Beacon contact (also when already homed); `_Z_CHECK`: stops the print when Klipper's Z and the Beacon reading differ (run in `PRINT_START` after the soak) | Beacon | | `nozzle_guard.cfg` | `[bdp_guard]`, `_GUARD_ON PHASE=`, `_GUARD_OFF`: bd_pressure watches the nozzle force during print-start moves where nothing should touch it (QGL, Z homing, mesh); `mode: log` only reports the peak per phase, `mode: stop` shuts Klipper down on a touch | `extras/bdp_guard.py` + bd_pressure load-check firmware | +| `test_speed.cfg` | `TEST_SPEED`: skipped-steps test for speed and acceleration | — | | `idle_timeout.cfg` | `[idle_timeout]`: heaters, chamber heater and motors off | iHeater macros | | **heating/** | | | | `heat_soak.cfg` | `HEAT_SOAK`, `STOP_HEAT_SOAK`, `CANCEL_HEAT_SOAK`, `HEAT_SOAK_RESUME`, `RESUME` | — | @@ -39,6 +40,7 @@ everything below, grouped by topic. Comment out what you do not use there. | `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 | Blobifier, AFC, `extras/bdpressure_check.py` + bd_pressure load-check firmware, `extras/bdwidth_status.py` | | `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 | | `bd_pa_spoolman.cfg` + `bd_pa_*.sh` | `LANE_CALIBRATE_PA`, `PA_CALIBRATE_ALL_LANES`, `LANE_RECAL_PA`, `SET_SPOOL_ID`, `PA_STATUS`: pressure advance per lane/spool, cached locally and in Spoolman; a calibration with no result, a pause during the test or too few/stuck sensor readings is rejected and not saved | bd_pressure, AFC, Spoolman, `gcode_shell_command` | | **spoolman/** | | | | `active_spool.cfg` | `SET_ACTIVE_SPOOL`, `CLEAR_ACTIVE_SPOOL` | Spoolman in Moonraker | @@ -160,6 +162,8 @@ original licenses apply to those parts: | `heating/heat_soak.cfg` | community `HEAT_SOAK` macro | | `heating/chamber_iheater.cfg` | iHeater vendor configuration | | `heating/filament_drying.cfg` | community filament drying macro | +| `pressure_advance/bd_pressure.cfg` | [bd_pressure](https://github.com/markniu/bd_pressure) `klipper/bd_pressure.cfg` | +| `print/test_speed.cfg` | [Ellis' TEST_SPEED](https://ellis3dp.com/Print-Tuning-Guide/articles/determining_max_speeds_accels.html) | | `print/pause_resume.cfg`, `print/filament.cfg` | [KlipperScreen recommended macros](https://klipperscreen.readthedocs.io/en/latest/macros/#recommended) | | `scripts/` | [Voron docs: automating MCU updates](https://docs.vorondesign.com/community/howto/drachenkatze/automating_klipper_mcu_updates.html), [Esoterical's CANBus guide](https://canbus.esoterical.online/) | diff --git a/macros/klipper-macros.cfg b/macros/klipper-macros.cfg index fd23d20..e73feca 100644 --- a/macros/klipper-macros.cfg +++ b/macros/klipper-macros.cfg @@ -24,6 +24,7 @@ [include print/homing.cfg] [include print/idle_timeout.cfg] [include print/print_start_end.cfg] +[include print/test_speed.cfg] # TEST_SPEED: skipped-steps test # Heating [include heating/bed_fans.cfg] @@ -39,6 +40,7 @@ [include afc/purge_until_empty.cfg] # Pressure advance per lane/spool (bd_pressure + Spoolman) +[include pressure_advance/bd_pressure.cfg] # [bdpressure bd_pa] and the vendor PA_CALIBRATE macros [include pressure_advance/bd_pa_spoolman.cfg] # Spoolman diff --git a/macros/pressure_advance/bd_pressure.cfg b/macros/pressure_advance/bd_pressure.cfg new file mode 100644 index 0000000..63c3764 --- /dev/null +++ b/macros/pressure_advance/bd_pressure.cfg @@ -0,0 +1,164 @@ +# bd_pressure (strain gauge on the nozzle): sensor and the vendor's PA +# calibration macros, from the bd_pressure repo (klipper/bd_pressure.cfg), +# moved here from ~/printer_data/config/bd_pressure.cfg. +# +# Connected over I2C (software I2C on the Nitehawk). Its endstop output is +# not wired; Beacon does the Z probing. Used by: LANE_CALIBRATE_PA +# (bd_pa_spoolman.cfg), the purge check (bdpressure_check.py) and the +# nozzle guard (bdp_guard.py). +# +# PA_CALIBRATE: SET_BDPRESSURE START switches the X and Y drivers off, so +# the X/Y moves of the test only happen on paper (the nozzle stays where +# LANE_CALIBRATE_PA put it) and X/Y are homed again at the end. +# Known: ACC_WALL is read from the ACCEL_TO_DECEL parameter (vendor bug), so +# the test always runs at 4000 mm/s^2; the cached PA values were measured +# like that. The acceleration and square corner velocity it sets are not +# restored (the slicer sets them again per feature). + +[bdpressure bd_pa] +port: i2c +i2c_mcu: nhk +i2c_software_scl_pin: nhk:PB3 +i2c_software_sda_pin: nhk:PB4 +thrhold: 5 # probe trigger value, recommended 3 to 10; bdp_guard and the load check read it as THRHOLD_Z + +[gcode_macro PA_RESET] +gcode: + M400 + G4 P200 + SET_BDPRESSURE NAME=bd_pa COMMAND=RESET_PROBE + G4 P200 + + +[gcode_macro PA_STATE] +gcode: + {% set status = printer["bdpressure bd_pa"].state %} + { action_respond_info("status:%s %d"%(status,params.T|int)) } + + +[gcode_macro PA_E] +gcode: + {% set status = printer["bdpressure bd_pa"].state %} + {% set i = params.I|int %} + #{ action_respond_info("status:%f %d"%(params.STEP|float,i)) } + {% if status=='START' %} + {% set pressure_ad = 0 + i*(params.STEP|float) %} + SET_PRESSURE_ADVANCE ADVANCE={pressure_ad} + {% set y_step =38.75 + i*3.5 %} + G1 X78 Y{y_step} F{params.T_SPEED|int} + G1 F{params.L_SPEED|int} + G1 X98 Y{y_step} E.92643 + G1 F{params.H_SPEED|int} + G1 X138 Y{y_step} E1.85285 + G1 F{params.L_SPEED|int} + G1 X158 Y{y_step} E.92643 + M400 + SET_BDPRESSURE NAME=bd_pa COMMAND=READ VALUE={pressure_ad} + {% endif %} + + +[gcode_macro PA_CALIBRATE] +gcode: + # PA_CALIBRATE NOZZLE_TEMP=[first_layer_temperature] MAX_VOLUMETRIC=[filament_max_volumetric_speed] ACC_WALL=[outer_wall_acceleration] + # TRAVEL_SPEED=[travel_speed] ACC_TO_DECEL_FACTOR=[accel_to_decel_factor] + + ### temperature=210,ACCEL_TO_DECEL=10000,ACCEL=8000,SQUARE_CORNER_VELOCITY=5 + {% set NOZZLE_TEMP = 210 %} + {% if params.NOZZLE_TEMP %} + { action_respond_info("nozzle TEMPERATURE %s "%params.NOZZLE_TEMP) } + {% set NOZZLE_TEMP = params.NOZZLE_TEMP|default(210)|float %} + {% endif %} + {% set ACC_WALL = 4000 %} + {% if params.ACC_WALL %} + { action_respond_info("ACC_out_WALL %s "%params.ACC_WALL) } + {% set ACC_WALL = params.ACCEL_TO_DECEL|default(4000)|float %} + {% endif %} + + {% set SQUARE_CORNER_SPEED = 9 %} + {% if params.SQUARE_CORNER_VELOCITY %} + { action_respond_info("SQUARE_CORNER_VELOCITY %s "%params.SQUARE_CORNER_VELOCITY) } + {% set SQUARE_CORNER_SPEED = params.SQUARE_CORNER_VELOCITY|default(9)|float %} + {% endif %} + ### travel_speed=400, max_volumetric_speed = [filament_max_volumetric_speed] + ## low_speed = (1020/20)*max_volumetric_speed + ## high_speed = (10740/20)*max_volumetric_speed + {% set ACC_TO_DECEL_FAC = 0.5 %} + {% set MIN_CRUISE = 0.5 %} + {% if params.ACC_TO_DECEL_FACTOR %} + { action_respond_info("accel_to_decel_factor %s "%params.ACC_TO_DECEL_FACTOR) } + {% set ACC_TO_DECEL_FAC = params.ACC_TO_DECEL_FACTOR.replace("%", "").strip() | float / 100 %} + {% set MIN_CRUISE = 1-ACC_TO_DECEL_FAC|float %} + { action_respond_info("ACC_TO_DECEL_FACTOR %s "%ACC_TO_DECEL_FAC) } + {% endif %} + {% if params.MINIMUM_CRUISE_RATIO %} + {% set MIN_CRUISE = params.MINIMUM_CRUISE_RATIO|default(0.5)|float %} + {% endif %} + { action_respond_info("MIN_CRUISE %s "%MIN_CRUISE) } + {% set ACC_TO_DEC = ACC_TO_DECEL_FAC*ACC_WALL %} + + {% set TRAVEL_SPEED = 400 %} + {% if params.TRAVEL_SPEED %} + {% set TRAVEL_SPEED = params.TRAVEL_SPEED|default(400)|float * 60 %} + { action_respond_info("travel_speed %s/60 "%TRAVEL_SPEED) } + {% endif %} + {% set MAX_VOLUMETRIC = 20 %} + {% if params.MAX_VOLUMETRIC %} + { action_respond_info("filament_max_volumetric_speed %s "%params.MAX_VOLUMETRIC) } + {% set MAX_VOLUMETRIC = params.MAX_VOLUMETRIC|default(20)|float %} + {% endif %} + {% set low_speed = 51*MAX_VOLUMETRIC %} + { action_respond_info("low_speed %f "%low_speed) } + {% set high_speed = 537*MAX_VOLUMETRIC %} + { action_respond_info("high_speed %f "%high_speed) } + + # volum=[filament_max_volumetric_speed] + # travel=[travel_speed] [accel_to_decel_factor] acc=[outer_wall_acceleration] temper=[first_layer_temperature] + G90 + G21 + M83 + M109 S{NOZZLE_TEMP} + G1 E4 + SET_PRESSURE_ADVANCE ADVANCE=0.04; Override pressure advance value + SET_VELOCITY_LIMIT ACCEL={ACC_WALL} ACCEL_TO_DECEL={ACC_TO_DEC} + SET_VELOCITY_LIMIT ACCEL={ACC_WALL} MINIMUM_CRUISE_RATIO={MIN_CRUISE} + SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={SQUARE_CORNER_SPEED} + + + SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=1 + SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=1 + SET_BDPRESSURE NAME=bd_pa COMMAND=START + M400 + G4 P1000 + {% set y_step = 38.75 %} + {% set pressure_ad = 0 %} + {% set pressure_step = 0.002 %} + + G1 F{high_speed} + G1 X78 Y{y_step} E9.92204 + M400 + G4 P4000 + G1 F{low_speed} + G1 X98 Y{y_step} E.92643 + G1 X138 Y{y_step} E1.85285 + G1 X158 Y{y_step} E.92643 + G1 X78 Y{y_step} F{TRAVEL_SPEED} + ###### + M400 + {% for i in range(50) %} + PA_E STEP={pressure_step} T_SPEED={TRAVEL_SPEED} H_SPEED={high_speed} L_SPEED={low_speed} I={i} + {% endfor %} + M400 + SET_BDPRESSURE NAME=bd_pa COMMAND=STOP + G4 P500 + SET_BDPRESSURE NAME=bd_pa COMMAND=RESET_PROBE + G4 P500 + + SET_KINEMATIC_POSITION X=0 Y=0 + G28 XY + # Z was not switched off and not moved: it keeps its position. The + # vendor macro set Z back to z_current, read before any of this ran: + # a Z hop in G28 XY (Beacon home_z_hop) would then leave Klipper + # believing the nozzle is lower than it is. + G4 P200 + + #G28 Z diff --git a/macros/print/test_speed.cfg b/macros/print/test_speed.cfg new file mode 100644 index 0000000..3af05d3 --- /dev/null +++ b/macros/print/test_speed.cfg @@ -0,0 +1,127 @@ +# TEST_SPEED: skipped-steps test for speed and acceleration (common Voron +# macro, moved here from ~/printer_data/config/Macros/TEST_SPEED.cfg) + +[gcode_macro TEST_SPEED] +# Home, get position, throw around toolhead, home again. +# If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured. +# We only measure to a full step to accomodate for endstop variance. +# Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10, ZHEIGHT=20 + +description: Test for max speed and acceleration parameters for the printer. Procedure: Home -> ReadPositionFromMCU -> MovesToolhead@Vel&Accel -> Home -> ReadPositionfromMCU + +gcode: + # Speed + {% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %} + # Iterations + {% set iterations = params.ITERATIONS|default(5)|int %} + # Acceleration + {% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %} + # Minimum Cruise Ratio + {% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0.5)|float %} + # Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions) + {% set bound = params.BOUND|default(20)|int %} + {% set zHeight = params.ZHEIGHT|default(20)|int %} + # Size for small pattern box + {% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %} + + # Large pattern + # Max positions, inset by BOUND + {% set x_min = printer.toolhead.axis_minimum.x + bound %} + {% set x_max = printer.toolhead.axis_maximum.x - bound %} + {% set y_min = printer.toolhead.axis_minimum.y + bound %} + {% set y_max = printer.toolhead.axis_maximum.y - bound %} + + # Small pattern at center + # Find X/Y center point + {% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %} + {% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %} + + # Set small pattern box around center point + {% set x_center_min = x_center - (smallpatternsize/2) %} + {% set x_center_max = x_center + (smallpatternsize/2) %} + {% set y_center_min = y_center - (smallpatternsize/2) %} + {% set y_center_max = y_center + (smallpatternsize/2) %} + + # Save current gcode state (absolute/relative, etc) + SAVE_GCODE_STATE NAME=TEST_SPEED + + # Output parameters to g-code terminal + { action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) } + + # Home and get position for comparison later: + M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 + G28 + # QGL if not already QGLd (only if QGL section exists in config) + {% if printer.configfile.settings.quad_gantry_level %} + {% if printer.quad_gantry_level.applied == False %} + QUAD_GANTRY_LEVEL + G28 Z + {% endif %} + {% endif %} + # Move 50mm away from max position and home again (to help with hall effect endstop accuracy - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/24) + G90 + G1 X{printer.toolhead.axis_maximum.x-50} Y{printer.toolhead.axis_maximum.y-50} F{30*60} + M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 + G28 X Y + G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60} + G4 P1000 + GET_POSITION + + # Go to starting position + G0 X{x_min} Y{y_min} Z{zHeight + 10} F{speed*60} + + # Set new limits + {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %} + SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MINIMUM_CRUISE_RATIO={min_cruise_ratio} + {% else %} + SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2} + {% endif %} + + {% for i in range(iterations) %} + # Large pattern diagonals + G0 X{x_min} Y{y_min} F{speed*60} + G0 X{x_max} Y{y_max} F{speed*60} + G0 X{x_min} Y{y_min} F{speed*60} + G0 X{x_max} Y{y_min} F{speed*60} + G0 X{x_min} Y{y_max} F{speed*60} + G0 X{x_max} Y{y_min} F{speed*60} + + # Large pattern box + G0 X{x_min} Y{y_min} F{speed*60} + G0 X{x_min} Y{y_max} F{speed*60} + G0 X{x_max} Y{y_max} F{speed*60} + G0 X{x_max} Y{y_min} F{speed*60} + + # Small pattern diagonals + G0 X{x_center_min} Y{y_center_min} F{speed*60} + G0 X{x_center_max} Y{y_center_max} F{speed*60} + G0 X{x_center_min} Y{y_center_min} F{speed*60} + G0 X{x_center_max} Y{y_center_min} F{speed*60} + G0 X{x_center_min} Y{y_center_max} F{speed*60} + G0 X{x_center_max} Y{y_center_min} F{speed*60} + + # Small pattern box + G0 X{x_center_min} Y{y_center_min} F{speed*60} + G0 X{x_center_min} Y{y_center_max} F{speed*60} + G0 X{x_center_max} Y{y_center_max} F{speed*60} + G0 X{x_center_max} Y{y_center_min} F{speed*60} + {% endfor %} + + # Restore max speed/accel/accel_to_decel to their configured values + {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %} + SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio} + {% else %} + SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel} + {% endif %} + + # Re-home and get position again for comparison: + M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66 + G28 # This is a full G28 to fix an issue with CoreXZ - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/12 + # Go to XY home positions (in case your homing override leaves it elsewhere) + G90 + G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60} + G4 P1000 + GET_POSITION + + # Restore previous gcode state (absolute/relative, etc) + RESTORE_GCODE_STATE NAME=TEST_SPEED