Skip to content

Instantly share code, notes, and snippets.

@JeremyKennedy
Last active March 9, 2023 05:48
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save JeremyKennedy/c214edc291d4beb6354895c05e019a05 to your computer and use it in GitHub Desktop.
Save JeremyKennedy/c214edc291d4beb6354895c05e019a05 to your computer and use it in GitHub Desktop.
Klipper Pressure Advance Line Calibration Macro
[gcode_macro PA_CAL]
# Klipper pressure advance line calibration macro.
# Usage: PA_CAL BED=100 NOZZLE=240 PA_START=0.0 PA_STOP=0.1 NZL=0.4
# Or you can execute with no parameters, which will use values from printer.cfg and saved_variables.cfg.
# First prints a line with current set PA, then prints 21 additional line segments starting with PA_START, and increasing to PA_STOP.
# Based on http://realdeuce.github.io/Voron/PA/pressure_advance.html
# Cleaned up and moved to using saved_variables.cfg by u/jibbsisme
# Sourced from u/Deepsiks, assisted by u/imoftendisgruntled, u/scul86, and thanks to u/beansisfat, u/stray_r
description: Tune Pressure Advance
gcode:
# saved_variables.cfg
{% set speed = printer.save_variables.variables.speed %}
{% set nozzle_temp = printer.save_variables.variables.nozzle_temp %}
{% set bed_temp = printer.save_variables.variables.bed_temp %}
# macro parameters
{% set BED = params.BED|default(bed_temp)|float %}
{% set NOZZLE = params.NOZZLE|default(nozzle_temp)|float %}
{% set PA_START = params.PA_START|default(0.0)|float %}
{% set PA_STOP = params.PA_STOP|default(0.1)|float %}
{% set NZL = params.NZL|default(printer.configfile.config["extruder"]["nozzle_diameter"])|float %}
# calculated variables
{% set PA_STEP = (PA_STOP - PA_START) / 20 |float %}
{% set E20 = (0.1147475 * NZL) * 20|float %}
{% set E40 = (0.1147475 * NZL) * 40|float %}
{% set X_MID = printer.configfile.config["stepper_x"]["position_max"]|float / 2.0 %}
{% set Y_MID = printer.configfile.config["stepper_y"]["position_max"]|float / 2.0 %}
START_PRINT BED_TEMP={BED} NOZZLE_TEMP={NOZZLE}
G21 ; millimeter units
G90 ; absolute XYZ
M83 ; relative E
SET_VELOCITY_LIMIT ACCEL=3000 ACCEL_TO_DECEL=1500
G92 E0
M106 S0
G1 X{(X_MID-40)} Y{(Y_MID-65)} F{speed} ; move to start position
G1 Z0.25 F300 ; move to layer height
G1 E0.75 F1800 ; un-retract
G1 X{(X_MID-20)} Y{(Y_MID-65)} E{E20} F300 ; print line part one
G1 X{(X_MID+20)} Y{(Y_MID-65)} E{E40} F3000 ; print line part two
G1 X{(X_MID+40)} Y{(Y_MID-65)} E{E20} F300 ; print line part three
G1 E-0.75 F1800 ; retract
G1 Z1 F300 ; move above layer height
{% for i in range(0, 21) %}
SET_PRESSURE_ADVANCE ADVANCE={PA_START + (i * PA_STEP)} ; set Pressure Advance
M117 PA={PA_START + (i * PA_STEP)}, STEP={PA_STEP}.
G1 X{(X_MID-40)} Y{(Y_MID-35)+(5*i)} F30000 ; move to start position
G1 Z0.25 F300 ; move to layer height
G1 E0.75 F1800 ; un-retract
G1 X{(X_MID-20)} Y{(Y_MID-35)+(5*i)} E{E20} F300 ; print line part one
G1 X{(X_MID+20)} Y{(Y_MID-35)+(5*i)} E{E40} F3000 ; print line part two
G1 X{(X_MID+40)} Y{(Y_MID-35)+(5*i)} E{E20} F300 ; print line part three
G1 E-0.75 F1800 ; retract
G1 Z1 F300 ; move above layer height
{% endfor %}
END_PRINT
# these may not work, in which case you will need to count and do the math yourself!
M117 New PA = ({PA_START} + (bestLine * {PA_STEP}) )
{action_respond_info ("Find best line and multiply it by (" + PA_START|string + " + (bestLine * " + PA_STEP|string + ") ) to find your PA setting.")}
[save_variables]
filename: ~/klipper_config/saved_variables.cfg
[Variables]
speed = 9000
nozzle_temp = 215
bed_temp = 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment