I recently discovered nonlinear pressure advance through the Kalico fork and became interested in implementing a more sophisticated PA algorithm for Klipper.
Taking inspiration from the nonlinear PA implementation in @dmbutyugin’s repository, I’ve developed my own implementation that adds nonlinear correction methods
The implementation introduces 5 different nonlinear methods:
-
Linear (default) - Standard
Klipperbehavior -
Tanh - Hyperbolic tangent with saturation at high velocities
-
Exp - Exponential response for quick transitions
-
Recip - Reciprocal function for gradual saturation
-
Sigmoid - S-curve response for smooth transitions
New Configuration Parameters
[extruder]
pressure_advance_method: tanh # Algorithm selection
pressure_advance_offset: 0.3 # Nonlinear correction magnitude (-1.0 to 1.0)
pressure_advance_linv: 50.0 # Velocity normalization factor (0.001 to 1000.0)
G-code Commands
# Set nonlinear PA parameters
SET_PRESSURE_ADVANCE ADVANCE=0.05 METHOD=tanh OFFSET=0.3 LINV=50
Technical Approach
The implementation works by:
-
Computing smoothed velocity through time integration over the smoothing window
-
Applying the selected (non)linear function to the normalized velocity
-
Adding the (non)linear correction to the base position
The mathematical foundation:
position = base + (linear_pa(v) || nonlinear_pa(v))
This is where I need your help! ![]()
While I believe the algorithm is mathematically sound, I haven’t conducted extensive print testing yet. I’m particularly concerned about:
-
Implementation correctness - Are there edge cases I missed?
-
Performance impact - Does the additional computation significantly affect print performance?
-
Memory management - Is the PA parameter cleanup logic robust?
Implementation Details
The complete implementation is available in my GitHub fork:
Repository: GitHub - loss-and-quick/klipper at feat/nonlinear-pa
I’m excited about the potential of this enhancement but want to make sure it’s implemented correctly and safely before broader testing. Any feedback, concerns, or suggestions would be greatly appreciated!