PA values per nozzle: SET_NOZZLE, slicer check, no Spoolman write
A PA value only holds for the nozzle it was measured with, so values are saved per nozzle and spool (pa_value_0_4_spool_<id>). SET_NOZZLE sets the fitted size; a different NOZZLE= from the slicer on PRINT_WARMUP stops the print before anything heats. The existing values are copied to 0.4 once at the first start; the old variables stay in the file, unread. Each nozzle has its own test flow and PA range (0.2: 5 mm3/s, 0-0.196, starting estimates, about 9 min a lane). The test primes at the test flow instead of 120 mm3/s. Remove the Spoolman write: it went to localhost and never arrived, and nothing read the values back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1dcbc50bf6
commit
b415cbebf4
7 files changed
+108
-133
No files matched your search
@@ -63,6 +63,9 @@ detection, `filament_error_sensitivity`), iHeater chamber heater.
|
|||||||
line (`M26`) and resumes. Everything after the check belongs in
|
line (`M26`) and resumes. Everything after the check belongs in
|
||||||
`_PRINT_START_FINISH`: a pause does not stop a running macro.
|
`_PRINT_START_FINISH`: a pause does not stop a running macro.
|
||||||
- Only one `[save_variables]`, in `macros/save_variables.cfg`.
|
- Only one `[save_variables]`, in `macros/save_variables.cfg`.
|
||||||
|
- PA values are saved per nozzle and spool (`pa_value_0_4_spool_<id>`), the fitted
|
||||||
|
size in `pa_nozzle` (`SET_NOZZLE`). The slicer's `NOZZLE=` on `PRINT_WARMUP` must
|
||||||
|
match, or the print stops. A new size needs an entry in `_PA_CFG.nozzle_test`.
|
||||||
- `PRINT_END` and `CANCEL_PRINT` share `_PRINT_CLEANUP` (heaters including
|
- `PRINT_END` and `CANCEL_PRINT` share `_PRINT_CLEANUP` (heaters including
|
||||||
`iHEATER_OFF`, fan, `M221 S100`, bdwidth off). Anything that must happen
|
`iHEATER_OFF`, fan, `M221 S100`, bdwidth off). Anything that must happen
|
||||||
at the end of every print goes there. `RESTORE_GCODE_STATE` restores the
|
at the end of every print goes there. `RESTORE_GCODE_STATE` restores the
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ everything below, grouped by topic. Comment out what you do not use there.
|
|||||||
| `purge_until_empty.cfg` | `PURGE_UNTIL_EMPTY`: purges a snapped filament out until there is no more nozzle pressure | same as `purge_check.cfg` |
|
| `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/** | | |
|
| **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_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; before a calibration the lane's spool is assigned again so a temperature just changed in Spoolman is used; flexible materials (TPU/TPE) calibrate at a lower flow (8 mm³/s) and over a wider PA range (0–0.196 in 0.004 steps instead of 0–0.098); 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` |
|
| `bd_pa_spoolman.cfg` | `LANE_CALIBRATE_PA`, `PA_CALIBRATE_ALL_LANES`, `LANE_RECAL_PA`, `SET_SPOOL_ID`, `PA_STATUS`, `SET_NOZZLE`: pressure advance per nozzle and spool, saved on the printer; run `SET_NOZZLE SIZE=0.2` after a swap (a print start stops if the slicer profile has another size); each nozzle has its own test flow and PA range (0.4: 25 mm³/s, 0–0.098, about 2 min a lane; 0.2: 5 mm³/s, 0–0.196, about 9 min, not measured yet); before a calibration the lane's spool is assigned again so a temperature just changed in Spoolman is used; flexible materials (TPU/TPE) calibrate at a lower flow (8 mm³/s) and over a wider PA range (0–0.196 in 0.004 steps instead of 0–0.098); 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 through AFC |
|
||||||
| **spoolman/** | | |
|
| **spoolman/** | | |
|
||||||
| `active_spool.cfg` | `SET_ACTIVE_SPOOL`, `CLEAR_ACTIVE_SPOOL` | Spoolman in Moonraker |
|
| `active_spool.cfg` | `SET_ACTIVE_SPOOL`, `CLEAR_ACTIVE_SPOOL` | Spoolman in Moonraker |
|
||||||
| **leds/** | | |
|
| **leds/** | | |
|
||||||
@@ -143,7 +143,7 @@ These are the settings of one printer. Before using a file, check:
|
|||||||
- **Settings at the top of a file** (`variable_...`): `afc/purge_check.cfg`
|
- **Settings at the top of a file** (`variable_...`): `afc/purge_check.cfg`
|
||||||
(`mode: "enforce"`, `motion_check: False` because this printer's bdwidth
|
(`mode: "enforce"`, `motion_check: False` because this printer's bdwidth
|
||||||
motion reading is unreliable), `pressure_advance/bd_pa_spoolman.cfg`
|
motion reading is unreliable), `pressure_advance/bd_pa_spoolman.cfg`
|
||||||
(`spoolman_url`), `heating/bed_fans.cfg`, `heating/filament_drying.cfg`.
|
(`nozzle_test`), `heating/bed_fans.cfg`, `heating/filament_drying.cfg`.
|
||||||
- `xy_drift.py` is for CoreXY only.
|
- `xy_drift.py` is for CoreXY only.
|
||||||
|
|
||||||
Comment out files you do not need in `klipper-macros.cfg`.
|
Comment out files you do not need in `klipper-macros.cfg`.
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
BASE_URL=$1
|
|
||||||
FIELD=$2
|
|
||||||
curl -sf -X POST "${BASE_URL}/api/v1/field/spool/${FIELD}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"name\": \"Pressure Advance\", \"field_type\": \"float\", \"default_value\": \"0\"}" \
|
|
||||||
> /tmp/pa_setup_result 2>&1
|
|
||||||
@@ -171,6 +171,9 @@
|
|||||||
# To see what's cached, and which lanes are missing a tracked
|
# To see what's cached, and which lanes are missing a tracked
|
||||||
# spool_id:
|
# spool_id:
|
||||||
# PA_STATUS
|
# PA_STATUS
|
||||||
|
#
|
||||||
|
# After fitting another nozzle (values are saved per nozzle):
|
||||||
|
# SET_NOZZLE SIZE=0.2
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
# [save_variables] is defined once in ../save_variables.cfg (shared with Blobifier)
|
# [save_variables] is defined once in ../save_variables.cfg (shared with Blobifier)
|
||||||
@@ -190,18 +193,24 @@ variable_lane_names: "lane1,lane2,lane3,lane4,lane5"
|
|||||||
variable_fallback_nozzle_temp: 260
|
variable_fallback_nozzle_temp: 260
|
||||||
# bd_pressure PA_CALIBRATE parameters -- tune to your printer/filament.
|
# bd_pressure PA_CALIBRATE parameters -- tune to your printer/filament.
|
||||||
# See https://pandapi3d.cn/bdpressure/home for guidance on these values.
|
# See https://pandapi3d.cn/bdpressure/home for guidance on these values.
|
||||||
variable_max_volumetric: 25
|
# Per nozzle, and only these sizes are accepted by SET_NOZZLE:
|
||||||
|
# max_volumetric: test flow (mm3/s). The test time follows it: about 2 min a
|
||||||
|
# lane at 25, 9 min at 5.
|
||||||
|
# pa_step: PA_CALIBRATE tests 50 values, 0..49 x step (0.002: 0-0.098,
|
||||||
|
# 0.004: 0-0.196).
|
||||||
|
# The 0.2 values are starting estimates, not measured yet.
|
||||||
|
variable_nozzle_test: {"0.4": {"max_volumetric": 25, "pa_step": 0.002}, "0.2": {"max_volumetric": 5, "pa_step": 0.004}}
|
||||||
# Lower test flow (mm3/s) for materials that cannot extrude max_volumetric:
|
# Lower test flow (mm3/s) for materials that cannot extrude max_volumetric:
|
||||||
# soft TPU buckles or slips in the extruder at 25. A key contained in the
|
# soft TPU buckles or slips in the extruder at 25. A key contained in the
|
||||||
# lane's material (any case) applies; with several matches the lowest wins.
|
# lane's material (any case) applies; the lowest of these and the nozzle's
|
||||||
|
# flow wins.
|
||||||
variable_material_max_volumetric: {"tpu": 8, "tpe": 8, "flex": 8}
|
variable_material_max_volumetric: {"tpu": 8, "tpe": 8, "flex": 8}
|
||||||
variable_acc_wall: 5000
|
variable_acc_wall: 5000
|
||||||
variable_travel_speed: 300
|
variable_travel_speed: 300
|
||||||
variable_acc_to_decel_factor: 50
|
variable_acc_to_decel_factor: 50
|
||||||
# Minimum PA delta before we bother re-saving the cached value
|
# Minimum PA delta before we bother re-saving the cached value
|
||||||
variable_write_threshold: 0.002
|
variable_write_threshold: 0.002
|
||||||
# A calibration is rejected (nothing cached or written to Spoolman, the
|
# A calibration is rejected (nothing saved, the previous PA is kept) when:
|
||||||
# previous PA is kept) when:
|
|
||||||
# - its result is the last PA_CALIBRATE test value: bdpressure.py found no
|
# - its result is the last PA_CALIBRATE test value: bdpressure.py found no
|
||||||
# result and left the extruder at the end of its scan (0..49 x the PA
|
# result and left the extruder at the end of its scan (0..49 x the PA
|
||||||
# step: 0.098 at the default step, 0.196 for flexibles),
|
# step: 0.098 at the default step, 0.196 for flexibles),
|
||||||
@@ -209,94 +218,74 @@ variable_write_threshold: 0.002
|
|||||||
# - bd_pressure gave fewer than min_points readings or fewer than
|
# - bd_pressure gave fewer than min_points readings or fewer than
|
||||||
# min_distinct different ones (sensor silent or hung; needs
|
# min_distinct different ones (sensor silent or hung; needs
|
||||||
# bdpressure_check.py, otherwise this check is skipped).
|
# bdpressure_check.py, otherwise this check is skipped).
|
||||||
variable_pa_step: 0.002 # PA_CALIBRATE tests 50 values: 0..49 x step
|
|
||||||
# Wider range for materials whose PA can be above 0.098 (soft TPU measured
|
# Wider range for materials whose PA can be above 0.098 (soft TPU measured
|
||||||
# 0.094): same 50 lines and test time, coarser steps. Key contained in the
|
# 0.094): same 50 lines and test time, coarser steps. Key contained in the
|
||||||
# lane's material (any case); with several matches the largest step wins.
|
# lane's material (any case); the largest of these and the nozzle's step wins.
|
||||||
variable_material_pa_step: {"tpu": 0.004, "tpe": 0.004, "flex": 0.004}
|
variable_material_pa_step: {"tpu": 0.004, "tpe": 0.004, "flex": 0.004}
|
||||||
variable_min_points: 10
|
variable_min_points: 10
|
||||||
variable_min_distinct: 8
|
variable_min_distinct: 8
|
||||||
# PA applied when a rejected lane has no earlier cached value
|
# PA applied when a rejected lane has no earlier cached value
|
||||||
variable_fallback_pa: 0.04
|
variable_fallback_pa: 0.04
|
||||||
# Spoolman URL and the custom "extra" field name used to push calibrated
|
|
||||||
# PA values back to the spool record (so the value travels with the
|
|
||||||
# spool, not just with this printer's local save_variables cache).
|
|
||||||
# Create the field once with: _PA_SETUP_SPOOLMAN_FIELD (see below).
|
|
||||||
variable_spoolman_url: "http://localhost:7912"
|
|
||||||
variable_spoolman_field: "pa_value"
|
|
||||||
gcode: # intentionally empty -- variables only
|
gcode: # intentionally empty -- variables only
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Spoolman write-back: push a calibrated PA value to a spool's "extra"
|
# Fitted nozzle. A PA value only holds for the nozzle it was measured with, so
|
||||||
# field, so the value travels with the spool (e.g. if you move it to a
|
# values are saved per nozzle and spool: pa_value_0_4_spool_15. The size is the
|
||||||
# different printer, or reinstall save_variables from scratch).
|
# saved variable pa_nozzle, set by SET_NOZZLE after a swap. The slicer sends the
|
||||||
#
|
# size of its profile to PRINT_WARMUP, and a mismatch stops the print before
|
||||||
# Requires the custom field to exist once -- run _PA_SETUP_SPOOLMAN_FIELD
|
# anything heats. G-code without a size uses the saved one.
|
||||||
# (below) a single time, or create it manually:
|
|
||||||
# curl -X POST http://<spoolman_ip>:7912/api/v1/field/spool/pa_value -H "Content-Type: application/json" -d '{"name": "Pressure Advance", "field_type": "float", "default_value": "0"}'
|
|
||||||
#
|
|
||||||
# UNVERIFIED -- needs live testing the same way everything else in this
|
|
||||||
# file has needed it. In particular: confirm curl and python3 are both
|
|
||||||
# available in the shell shell_command runs in (they're standard on
|
|
||||||
# MainsailOS/FluiddOS, but worth confirming), and confirm the merge-write
|
|
||||||
# below doesn't clobber any other custom Spoolman fields you may have.
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
[gcode_shell_command _pa_write_spoolman]
|
[gcode_macro SET_NOZZLE]
|
||||||
# HISTORICAL NOTE ON ARGUMENT OFFSET (no longer applicable here, kept
|
description: Set the fitted nozzle size, which selects its saved PA values (without SIZE: show it)
|
||||||
# for context): an earlier version of this command ran the script
|
# [SIZE=<mm>]
|
||||||
# inline via `bash -c '<script>' arg1 arg2 ...`, which makes the FIRST
|
|
||||||
# argument after the script string become $0 inside the script, not $1
|
|
||||||
# -- a well-known bash gotcha, confirmed empirically while building
|
|
||||||
# this file:
|
|
||||||
# bash -c 'echo "0=$0 1=$1 2=$2"' alpha beta gamma
|
|
||||||
# -> 0=alpha 1=beta 2=gamma (gamma, the 3rd arg, never reaches $3)
|
|
||||||
# This command now invokes a real .sh FILE instead (`bash script.sh
|
|
||||||
# arg1 arg2 ...`), which does NOT have this offset -- $1 really is the
|
|
||||||
# first argument in that invocation form (also confirmed empirically).
|
|
||||||
# So RUN_SHELL_COMMAND ... PARAMS="a b c d" maps cleanly to $1-$4 in
|
|
||||||
# the script with no placeholder needed.
|
|
||||||
#
|
|
||||||
# WHY THIS CALLS AN EXTERNAL .sh FILE INSTEAD OF EMBEDDING PYTHON
|
|
||||||
# INLINE: Klipper's config parser (Python's configparser) requires
|
|
||||||
# EVERY physical line of a multi-line value to be indented, and strips
|
|
||||||
# that indentation uniformly before passing the value to the shell.
|
|
||||||
# Confirmed empirically while building this file: this dedenting
|
|
||||||
# flattens ALL lines to the same level, which destroys the relative
|
|
||||||
# indentation Python's try/except blocks need to remain valid syntax --
|
|
||||||
# there is no way to embed multi-line, block-structured Python directly
|
|
||||||
# inside a Klipper command: value. Putting the logic in a separate .sh
|
|
||||||
# file sidesteps this entirely, since that file is never touched by
|
|
||||||
# Klipper's config parser.
|
|
||||||
#
|
|
||||||
# The script ships in this folder (klipper-macros/pressure_advance/bd_pa_write_spoolman.sh);
|
|
||||||
# install.sh makes it executable.
|
|
||||||
command: bash ~/printer_data/config/klipper-macros/pressure_advance/bd_pa_write_spoolman.sh
|
|
||||||
verbose: False
|
|
||||||
|
|
||||||
|
|
||||||
[gcode_shell_command _pa_create_spoolman_field]
|
|
||||||
# Same reasoning as _pa_write_spoolman above for using an external
|
|
||||||
# script file -- see the note there. This one has no embedded Python,
|
|
||||||
# so the only real issue was the closing quote sitting at column 0
|
|
||||||
# (un-indented), which is also a config parsing error in Klipper's
|
|
||||||
# parser -- every line of a multi-line value must be indented,
|
|
||||||
# including the very last line.
|
|
||||||
command: bash ~/printer_data/config/klipper-macros/pressure_advance/bd_pa_create_spoolman_field.sh
|
|
||||||
verbose: False
|
|
||||||
|
|
||||||
|
|
||||||
[gcode_macro _PA_SETUP_SPOOLMAN_FIELD]
|
|
||||||
description: One-time setup -- creates the pa_value custom field in Spoolman
|
|
||||||
# REQUIRES bd_pa_create_spoolman_field.sh to already exist on disk at
|
|
||||||
# ~/printer_data/config/ -- see the one-time SSH setup instructions
|
|
||||||
# given alongside this file. This macro just invokes that script; it
|
|
||||||
# does not create it.
|
|
||||||
gcode:
|
gcode:
|
||||||
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
||||||
{action_respond_info("Creating Spoolman field '%s' at %s ..." % (cfg.spoolman_field, cfg.spoolman_url))}
|
{% set vars = printer.save_variables.variables %}
|
||||||
RUN_SHELL_COMMAND CMD=_pa_create_spoolman_field PARAMS="{cfg.spoolman_url} {cfg.spoolman_field}"
|
{% set current = "%g" % vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
{action_respond_info("Done. Verify with: curl %s/api/v1/field/spool" % cfg.spoolman_url)}
|
{% if not params.SIZE %}
|
||||||
|
RESPOND MSG="Nozzle set: {current} mm. Change it with SET_NOZZLE SIZE=<mm>, sizes: {cfg.nozzle_test.keys()|join(', ')}"
|
||||||
|
{% else %}
|
||||||
|
{% set size = "%g" % params.SIZE|float %}
|
||||||
|
{% if size not in cfg.nozzle_test %}
|
||||||
|
_ERROR MSG="SET_NOZZLE: no PA test settings for {size} mm. Sizes: {cfg.nozzle_test.keys()|join(', ')} (variable_nozzle_test in _PA_CFG)" DISPLAY="Unknown nozzle size"
|
||||||
|
{% elif printer.print_stats.state in ("printing", "paused") %}
|
||||||
|
_ERROR MSG="SET_NOZZLE: not during a print, the nozzle stays {current} mm" DISPLAY="No SET_NOZZLE in a print"
|
||||||
|
{% else %}
|
||||||
|
SAVE_VARIABLE VARIABLE=pa_nozzle VALUE={size}
|
||||||
|
RESPOND MSG="Nozzle set: {size} mm (was {current} mm)"
|
||||||
|
_PA_APPLY_LOADED_LANE
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
[gcode_macro _PA_CHECK_NOZZLE]
|
||||||
|
description: Stop the print when the size from the slicer is not the fitted nozzle
|
||||||
|
# NOZZLE=<mm>
|
||||||
|
gcode:
|
||||||
|
{% set vars = printer.save_variables.variables %}
|
||||||
|
{% set fitted = vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
|
{% set sliced = params.NOZZLE|float %}
|
||||||
|
{% if (sliced - fitted)|abs > 0.001 %}
|
||||||
|
_ERROR MSG="Print stopped: sliced for a {'%g' % sliced} mm nozzle, the printer is set to {'%g' % fitted} mm. Slice with the matching profile, or fit that nozzle and run SET_NOZZLE SIZE={'%g' % sliced}" DISPLAY="Nozzle mismatch, print stopped"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# Once: values saved before there were per-nozzle values were all measured with
|
||||||
|
# the 0.4 nozzle. Copied at the first start with this macro, so the first print
|
||||||
|
# does not calibrate every lane again. The old pa_value_spool_<id> lines stay in
|
||||||
|
# the variables file; nothing reads them any more.
|
||||||
|
[delayed_gcode _PA_MIGRATE_NOZZLE]
|
||||||
|
initial_duration: 1
|
||||||
|
gcode:
|
||||||
|
{% set vars = printer.save_variables.variables %}
|
||||||
|
{% if "pa_nozzle" not in vars %}
|
||||||
|
{% for name, value in vars.items() %}
|
||||||
|
{% if name.startswith("pa_value_spool_") and ("pa_value_0_4_spool_" ~ name[15:]) not in vars %}
|
||||||
|
SAVE_VARIABLE VARIABLE={"pa_value_0_4_spool_" ~ name[15:]} VALUE={value}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
SAVE_VARIABLE VARIABLE=pa_nozzle VALUE=0.4
|
||||||
|
RESPOND MSG="PA values moved to the 0.4 mm nozzle. Nozzle set: 0.4 mm"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -375,7 +364,7 @@ gcode:
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# PA cache, keyed by spool_id, stored via Klipper's own save_variables.
|
# PA cache, keyed by nozzle and spool_id, stored via Klipper's own save_variables.
|
||||||
# Requires [save_variables] (save_variables.cfg, see header notes).
|
# Requires [save_variables] (save_variables.cfg, see header notes).
|
||||||
#
|
#
|
||||||
# IMPORTANT: printer.save_variables.variables is read DIRECTLY inline in
|
# IMPORTANT: printer.save_variables.variables is read DIRECTLY inline in
|
||||||
@@ -392,12 +381,13 @@ gcode:
|
|||||||
# value set earlier in the same template render.
|
# value set earlier in the same template render.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
[gcode_macro _PA_CACHE_SET]
|
[gcode_macro _PA_CACHE_SET]
|
||||||
description: Internal -- stores a PA value for a spool_id
|
description: Internal -- stores a PA value for a nozzle and spool_id
|
||||||
# SPOOL_ID=<int> PA=<float>
|
# SPOOL_ID=<int> NOZZLE=<mm> PA=<float>
|
||||||
gcode:
|
gcode:
|
||||||
{% set spool_id = params.SPOOL_ID|default(0)|int %}
|
{% set spool_id = params.SPOOL_ID|default(0)|int %}
|
||||||
|
{% set nozzle = "%g" % params.NOZZLE|float %}
|
||||||
{% set pa = params.PA|default(0.0)|float %}
|
{% set pa = params.PA|default(0.0)|float %}
|
||||||
{% set varname = "pa_value_spool_" ~ spool_id %}
|
{% set varname = "pa_value_" ~ nozzle|replace(".", "_") ~ "_spool_" ~ spool_id %}
|
||||||
SAVE_VARIABLE VARIABLE={varname} VALUE={pa}
|
SAVE_VARIABLE VARIABLE={varname} VALUE={pa}
|
||||||
|
|
||||||
|
|
||||||
@@ -418,7 +408,8 @@ gcode:
|
|||||||
{% set force = params.FORCE|default(0)|int %}
|
{% set force = params.FORCE|default(0)|int %}
|
||||||
{% set vars = printer.save_variables.variables %}
|
{% set vars = printer.save_variables.variables %}
|
||||||
{% set spool_id = vars["pa_lane_" ~ lane ~ "_spool_id"]|default(0)|int %}
|
{% set spool_id = vars["pa_lane_" ~ lane ~ "_spool_id"]|default(0)|int %}
|
||||||
{% set cached = ("pa_value_spool_" ~ spool_id) in vars %}
|
{% set nozzle = "%g" % vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
|
{% set cached = ("pa_value_" ~ nozzle|replace(".", "_") ~ "_spool_" ~ spool_id) in vars %}
|
||||||
{% set key = "AFC_stepper " ~ lane %}
|
{% set key = "AFC_stepper " ~ lane %}
|
||||||
{% set afc_spool = printer[key].spool_id|default(none, true) if key in printer else none %}
|
{% set afc_spool = printer[key].spool_id|default(none, true) if key in printer else none %}
|
||||||
{% if lane and spool_id > 0 and (force or not cached) and afc_spool %}
|
{% if lane and spool_id > 0 and (force or not cached) and afc_spool %}
|
||||||
@@ -443,12 +434,14 @@ gcode:
|
|||||||
{% elif spool_id == 0 %}
|
{% elif spool_id == 0 %}
|
||||||
{action_respond_info("LANE_CALIBRATE_PA: no spool_id recorded for %s yet. Run SET_SPOOL_ID LANE=%s SPOOL_ID=<id> then _PA_TRACK_LANE_SPOOL LANE=%s SPOOL_ID=<id>." % (lane, lane, lane))}
|
{action_respond_info("LANE_CALIBRATE_PA: no spool_id recorded for %s yet. Run SET_SPOOL_ID LANE=%s SPOOL_ID=<id> then _PA_TRACK_LANE_SPOOL LANE=%s SPOOL_ID=<id>." % (lane, lane, lane))}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set pa_varname = "pa_value_spool_" ~ spool_id %}
|
{% set nozzle = "%g" % vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
|
{% set test = cfg.nozzle_test[nozzle] %}
|
||||||
|
{% set pa_varname = "pa_value_" ~ nozzle|replace(".", "_") ~ "_spool_" ~ spool_id %}
|
||||||
{% set cache_found = pa_varname in vars %}
|
{% set cache_found = pa_varname in vars %}
|
||||||
{% set cached_pa = vars[pa_varname]|float if cache_found else 0.0 %}
|
{% set cached_pa = vars[pa_varname]|float if cache_found else 0.0 %}
|
||||||
|
|
||||||
{% if cache_found and force == 0 %}
|
{% if cache_found and force == 0 %}
|
||||||
{action_respond_info("Using cached PA=%.4f for %s (spool %d)" % (cached_pa, lane, spool_id))}
|
{action_respond_info("Using cached PA=%.4f for %s (spool %d, %s mm nozzle)" % (cached_pa, lane, spool_id, nozzle))}
|
||||||
SET_PRESSURE_ADVANCE ADVANCE={cached_pa}
|
SET_PRESSURE_ADVANCE ADVANCE={cached_pa}
|
||||||
{% else %}
|
{% else %}
|
||||||
CHANGE_TOOL LANE={lane}
|
CHANGE_TOOL LANE={lane}
|
||||||
@@ -462,21 +455,21 @@ gcode:
|
|||||||
{% set target = printer.extruder.target|default(0)|float %}
|
{% set target = printer.extruder.target|default(0)|float %}
|
||||||
{% set nozzle_temp = lane_temp if lane_temp > 0 else (target if target > 0 else cfg.fallback_nozzle_temp|float) %}
|
{% set nozzle_temp = lane_temp if lane_temp > 0 else (target if target > 0 else cfg.fallback_nozzle_temp|float) %}
|
||||||
{% set material = lane_obj.material|default("", true)|string|lower %}
|
{% set material = lane_obj.material|default("", true)|string|lower %}
|
||||||
{% set vol = namespace(max=cfg.max_volumetric|float) %}
|
{% set vol = namespace(max=test.max_volumetric|float) %}
|
||||||
{% for key, flow in cfg.material_max_volumetric.items() %}
|
{% for key, flow in cfg.material_max_volumetric.items() %}
|
||||||
{% if key in material and flow|float < vol.max %}
|
{% if key in material and flow|float < vol.max %}
|
||||||
{% set vol.max = flow|float %}
|
{% set vol.max = flow|float %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% set step = namespace(pa=cfg.pa_step|float) %}
|
{% set step = namespace(pa=test.pa_step|float) %}
|
||||||
{% for key, s in cfg.material_pa_step.items() %}
|
{% for key, s in cfg.material_pa_step.items() %}
|
||||||
{% if key in material and s|float > step.pa %}
|
{% if key in material and s|float > step.pa %}
|
||||||
{% set step.pa = s|float %}
|
{% set step.pa = s|float %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{action_respond_info("Calibrating PA for %s (spool %d) at %.0fC, %g mm3/s, PA 0-%.3f..." % (lane, spool_id, nozzle_temp, vol.max, 49 * step.pa))}
|
{action_respond_info("Calibrating PA for %s (spool %d, %s mm nozzle) at %.0fC, %g mm3/s, PA 0-%.3f..." % (lane, spool_id, nozzle, nozzle_temp, vol.max, 49 * step.pa))}
|
||||||
M117 Calibrating PA: {lane}
|
M117 Calibrating PA: {lane}
|
||||||
|
|
||||||
G1 Z50 F3000
|
G1 Z50 F3000
|
||||||
@@ -505,7 +498,7 @@ gcode:
|
|||||||
# triggered (and its own template is rendered), PA_CALIBRATE
|
# triggered (and its own template is rendered), PA_CALIBRATE
|
||||||
# above has already finished and printer.extruder.pressure_advance
|
# above has already finished and printer.extruder.pressure_advance
|
||||||
# is current.
|
# is current.
|
||||||
_PA_AFTER_CALIBRATE LANE={lane} SPOOL_ID={spool_id} CACHE_FOUND={1 if cache_found else 0} CACHED_PA={cached_pa} SWEEP_END={49 * step.pa}
|
_PA_AFTER_CALIBRATE LANE={lane} SPOOL_ID={spool_id} NOZZLE={nozzle} CACHE_FOUND={1 if cache_found else 0} CACHED_PA={cached_pa} SWEEP_END={49 * step.pa}
|
||||||
BLOBIFIER_CLEAN
|
BLOBIFIER_CLEAN
|
||||||
G4 P400
|
G4 P400
|
||||||
G1 Z10 F3000
|
G1 Z10 F3000
|
||||||
@@ -516,14 +509,15 @@ gcode:
|
|||||||
|
|
||||||
[gcode_macro _PA_AFTER_CALIBRATE]
|
[gcode_macro _PA_AFTER_CALIBRATE]
|
||||||
description: Internal -- runs immediately after PA_CALIBRATE completes; reads the fresh PA value and caches it
|
description: Internal -- runs immediately after PA_CALIBRATE completes; reads the fresh PA value and caches it
|
||||||
# LANE=<lane_name> SPOOL_ID=<int> CACHE_FOUND=<0|1> CACHED_PA=<float> SWEEP_END=<last PA tested>
|
# LANE=<lane_name> SPOOL_ID=<int> NOZZLE=<mm> CACHE_FOUND=<0|1> CACHED_PA=<float> SWEEP_END=<last PA tested>
|
||||||
gcode:
|
gcode:
|
||||||
{% set lane = params.LANE|default("")|string %}
|
{% set lane = params.LANE|default("")|string %}
|
||||||
{% set spool_id = params.SPOOL_ID|default(0)|int %}
|
{% set spool_id = params.SPOOL_ID|default(0)|int %}
|
||||||
{% set cache_found = params.CACHE_FOUND|default(0)|int %}
|
{% set cache_found = params.CACHE_FOUND|default(0)|int %}
|
||||||
{% set cached_pa = params.CACHED_PA|default(0.0)|float %}
|
{% set cached_pa = params.CACHED_PA|default(0.0)|float %}
|
||||||
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
||||||
{% set sweep_end = params.SWEEP_END|default(49 * cfg.pa_step|float)|float %}
|
{% set sweep_end = params.SWEEP_END|float %}
|
||||||
|
{% set nozzle = "%g" % params.NOZZLE|float %}
|
||||||
|
|
||||||
# This template is evaluated only once this macro is actually
|
# This template is evaluated only once this macro is actually
|
||||||
# triggered -- which happens after PA_CALIBRATE (queued earlier by
|
# triggered -- which happens after PA_CALIBRATE (queued earlier by
|
||||||
@@ -556,16 +550,14 @@ gcode:
|
|||||||
_WARN MSG="PA calibration for {lane} (spool {spool_id}) rejected: {problems|join('; ')}. Nothing saved; using PA={'%.4f' % keep} ({'cached' if use_cache else 'fallback'}). Fix the cause, then LANE_CALIBRATE_PA LANE={lane} FORCE=1" DISPLAY="PA cal rejected: {lane}, see console"
|
_WARN MSG="PA calibration for {lane} (spool {spool_id}) rejected: {problems|join('; ')}. Nothing saved; using PA={'%.4f' % keep} ({'cached' if use_cache else 'fallback'}). Fix the cause, then LANE_CALIBRATE_PA LANE={lane} FORCE=1" DISPLAY="PA cal rejected: {lane}, see console"
|
||||||
SET_PRESSURE_ADVANCE ADVANCE={keep}
|
SET_PRESSURE_ADVANCE ADVANCE={keep}
|
||||||
{% else %}
|
{% else %}
|
||||||
{action_respond_info("Calibration complete for %s: PA=%.4f" % (lane, new_pa))}
|
{action_respond_info("Calibration complete for %s (%s mm nozzle): PA=%.4f" % (lane, nozzle, new_pa))}
|
||||||
M117 PA cal done: {new_pa|round(4)}
|
M117 PA cal done: {new_pa|round(4)}
|
||||||
|
|
||||||
{% set delta = (new_pa - cached_pa)|abs if cache_found else 999 %}
|
{% set delta = (new_pa - cached_pa)|abs if cache_found else 999 %}
|
||||||
{% if delta > cfg.write_threshold|float %}
|
{% if delta > cfg.write_threshold|float %}
|
||||||
_PA_CACHE_SET SPOOL_ID={spool_id} PA={new_pa}
|
_PA_CACHE_SET SPOOL_ID={spool_id} NOZZLE={nozzle} PA={new_pa}
|
||||||
{action_respond_info("Writing PA=%.4f to Spoolman spool %d" % (new_pa, spool_id))}
|
|
||||||
RUN_SHELL_COMMAND CMD=_pa_write_spoolman PARAMS="{spool_id} {cfg.spoolman_url} {cfg.spoolman_field} {new_pa}"
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{action_respond_info("PA change below threshold (%.4f), skipping cache/Spoolman write" % cfg.write_threshold|float)}
|
{action_respond_info("PA change below threshold (%.4f), keeping the saved value" % cfg.write_threshold|float)}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -691,14 +683,15 @@ gcode:
|
|||||||
{% set spool_id = vars[lane_varname]|default(0)|int if lane_varname in vars else 0 %}
|
{% set spool_id = vars[lane_varname]|default(0)|int if lane_varname in vars else 0 %}
|
||||||
|
|
||||||
{% if spool_id > 0 %}
|
{% if spool_id > 0 %}
|
||||||
{% set pa_varname = "pa_value_spool_" ~ spool_id %}
|
{% set nozzle = "%g" % vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
|
{% set pa_varname = "pa_value_" ~ nozzle|replace(".", "_") ~ "_spool_" ~ spool_id %}
|
||||||
{% if pa_varname in vars %}
|
{% if pa_varname in vars %}
|
||||||
{% set cached_pa = vars[pa_varname]|float %}
|
{% set cached_pa = vars[pa_varname]|float %}
|
||||||
SET_PRESSURE_ADVANCE ADVANCE={cached_pa}
|
SET_PRESSURE_ADVANCE ADVANCE={cached_pa}
|
||||||
{action_respond_info("Lane %s loaded: applied cached PA=%.4f (spool %d)" % (lane, cached_pa, spool_id))}
|
{action_respond_info("Lane %s loaded: applied cached PA=%.4f (spool %d, %s mm nozzle)" % (lane, cached_pa, spool_id, nozzle))}
|
||||||
M117 PA: {lane} = {cached_pa|round(4)}
|
M117 PA: {lane} = {cached_pa|round(4)}
|
||||||
{% else %}
|
{% else %}
|
||||||
{action_respond_info("Lane %s loaded: spool %d has no cached PA yet. Run LANE_CALIBRATE_PA LANE=%s or PA_CALIBRATE_ALL_LANES." % (lane, spool_id, lane))}
|
{action_respond_info("Lane %s loaded: spool %d has no PA for the %s mm nozzle yet, PA stays %.4f. Run LANE_CALIBRATE_PA LANE=%s or PA_CALIBRATE_ALL_LANES; a print start does this itself." % (lane, spool_id, nozzle, printer.extruder.pressure_advance|float, lane))}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{action_respond_info("Lane %s loaded: no spool_id recorded yet (run SET_SPOOL_ID first)." % lane)}
|
{action_respond_info("Lane %s loaded: no spool_id recorded yet (run SET_SPOOL_ID first)." % lane)}
|
||||||
@@ -726,15 +719,16 @@ gcode:
|
|||||||
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
{% set cfg = printer["gcode_macro _PA_CFG"] %}
|
||||||
{% set lane_list = cfg.lane_names.split(",") %}
|
{% set lane_list = cfg.lane_names.split(",") %}
|
||||||
{% set vars = printer.save_variables.variables %}
|
{% set vars = printer.save_variables.variables %}
|
||||||
|
{% set nozzle = "%g" % vars["pa_nozzle"]|default(0.4)|float %}
|
||||||
|
|
||||||
{action_respond_info("=== PA Status ===")}
|
{action_respond_info("=== PA Status, %s mm nozzle ===" % nozzle)}
|
||||||
{% for lane in lane_list %}
|
{% for lane in lane_list %}
|
||||||
{% set lane = lane.strip() %}
|
{% set lane = lane.strip() %}
|
||||||
{% if lane != "" %}
|
{% if lane != "" %}
|
||||||
{% set spool_varname = "pa_lane_" ~ lane ~ "_spool_id" %}
|
{% set spool_varname = "pa_lane_" ~ lane ~ "_spool_id" %}
|
||||||
{% set spool_id = vars[spool_varname]|default(0)|int if spool_varname in vars else 0 %}
|
{% set spool_id = vars[spool_varname]|default(0)|int if spool_varname in vars else 0 %}
|
||||||
{% if spool_id > 0 %}
|
{% if spool_id > 0 %}
|
||||||
{% set pa_varname = "pa_value_spool_" ~ spool_id %}
|
{% set pa_varname = "pa_value_" ~ nozzle|replace(".", "_") ~ "_spool_" ~ spool_id %}
|
||||||
{% if pa_varname in vars %}
|
{% if pa_varname in vars %}
|
||||||
{action_respond_info(" %s (spool %d): PA=%.4f cached" % (lane, spool_id, vars[pa_varname]|float))}
|
{action_respond_info(" %s (spool %d): PA=%.4f cached" % (lane, spool_id, vars[pa_varname]|float))}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
SPOOL_ID=$1
|
|
||||||
BASE_URL=$2
|
|
||||||
FIELD=$3
|
|
||||||
PA_VALUE=$4
|
|
||||||
CURRENT=$(curl -sf "${BASE_URL}/api/v1/spool/${SPOOL_ID}" 2>/dev/null)
|
|
||||||
EXTRA=$(echo "$CURRENT" | python3 -c "
|
|
||||||
import sys, json
|
|
||||||
try:
|
|
||||||
d = json.load(sys.stdin)
|
|
||||||
e = d.get('extra', {})
|
|
||||||
e['$FIELD'] = '$PA_VALUE'
|
|
||||||
print(json.dumps(e))
|
|
||||||
except Exception:
|
|
||||||
print(json.dumps({'$FIELD': '$PA_VALUE'}))
|
|
||||||
" 2>/dev/null)
|
|
||||||
if [ -z "$EXTRA" ]; then
|
|
||||||
EXTRA="{\"$FIELD\": \"$PA_VALUE\"}"
|
|
||||||
fi
|
|
||||||
curl -sf -X PATCH "${BASE_URL}/api/v1/spool/${SPOOL_ID}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"extra\": $EXTRA}" > /tmp/pa_spoolman_write_result 2>&1
|
|
||||||
@@ -117,7 +117,9 @@ gcode:
|
|||||||
G21
|
G21
|
||||||
M83
|
M83
|
||||||
M109 S{NOZZLE_TEMP}
|
M109 S{NOZZLE_TEMP}
|
||||||
G1 E4
|
# At the test flow. Without F this ran at the speed of the move before
|
||||||
|
# (F3000 in LANE_CALIBRATE_PA: 120 mm3/s), too much for a small nozzle.
|
||||||
|
G1 E4 F{MAX_VOLUMETRIC / 2.405 * 60}
|
||||||
SET_PRESSURE_ADVANCE ADVANCE=0.04; Override pressure advance value
|
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} ACCEL_TO_DECEL={ACC_TO_DEC}
|
||||||
SET_VELOCITY_LIMIT ACCEL={ACC_WALL} MINIMUM_CRUISE_RATIO={MIN_CRUISE}
|
SET_VELOCITY_LIMIT ACCEL={ACC_WALL} MINIMUM_CRUISE_RATIO={MIN_CRUISE}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ gcode:
|
|||||||
{% set target_chamber = params.CHAMBER|default("0")|int %}
|
{% set target_chamber = params.CHAMBER|default("0")|int %}
|
||||||
{% set initial_tool = params.TOOL|default("0")|int %}
|
{% set initial_tool = params.TOOL|default("0")|int %}
|
||||||
|
|
||||||
|
# First, so a wrong nozzle stops the print before anything heats
|
||||||
|
{% if params.NOZZLE %}
|
||||||
|
_PA_CHECK_NOZZLE NOZZLE={params.NOZZLE}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
RESET_FAILURE
|
RESET_FAILURE
|
||||||
CLEAR_PAUSE
|
CLEAR_PAUSE
|
||||||
_BED_CHECK_RESET
|
_BED_CHECK_RESET
|
||||||
|
|||||||
Reference in new issue
Block a user