Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions overlays/firmware-extended/20-klipper-patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This overlay integrates upstream klipper changes

## Upstream commmits:

1. [toolhead: Reduce LOOKAHEAD_FLUSH_TIME to 0.150 seconds](https://github.com/Klipper3d/klipper/commit/16fc46fe5)
1. [resonance_tester: Fix chips selection, add accel_per_hz selection](https://github.com/Klipper3d/klipper/commit/6d1256ddc)
1. [resonance_tester: Added a new sweeping_vibrations resonance test method](https://github.com/Klipper3d/klipper/commit/16b4b6b30)

## Formatting of patches

Patches are ordered, they are stripped of config changes, and minimal amount of amendments are done
to make them as close to upstream as possible.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 16fc46fe5ff0dbbc5188ee6a7829eee5976c1eb9 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Tue, 30 Sep 2025 19:32:49 -0400
Subject: [PATCH] toolhead: Reduce LOOKAHEAD_FLUSH_TIME to 0.150 seconds

The current code is likely to perform a lazy flush of the lookahead
queue around 4 times a second. Increase that to around 6-7 times a
second. This change may slightly improve the responsiveness to user
requests mid-print (eg, changing extrusion ratio) and may make a
"print stall" less likely in some corner cases.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
klippy/toolhead.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 9163e82cc7a8..da297e966be4 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -113,7 +113,7 @@ def set_junction(self, start_v2, cruise_v2, end_v2):
self.cruise_t = cruise_d / cruise_v
self.decel_t = decel_d / ((end_v + cruise_v) * 0.5)

-LOOKAHEAD_FLUSH_TIME = 0.250
+LOOKAHEAD_FLUSH_TIME = 0.150

# Class to track a list of pending move requests and to facilitate
# "look-ahead" across moves to reduce acceleration between moves.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 6d1256ddcc51cc62ab403fdc29d0b2688116a29e Mon Sep 17 00:00:00 2001
From: MRX8024 <57844100+MRX8024@users.noreply.github.com>
Date: Wed, 13 Nov 2024 02:55:32 +0200
Subject: [PATCH] resonance_tester: Fix chips selection, add accel_per_hz
selection (#6726)

Corrected issue where accelerometer names were incorrectly prefixed
with "adxl345", preventing the selection of other chip types when running TEST_RESONANCES.

Implemented support for selecting the `accel_per_hz` parameter when running TEST_RESONANCES.

docs: Update TEST_RESONANCES + SHAPER_CALIBRATE with missing parameters and bracket corrections

Signed-off-by: Maksim Bolgov <maksim8024@gmail.com>
---
docs/Config_Changes.md | 4 ++++
docs/G-Codes.md | 18 +++++++++---------
klippy/extras/resonance_tester.py | 8 +++-----
3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/klippy/extras/resonance_tester.py b/klippy/extras/resonance_tester.py
index fe8717d58545..e9d4e9d92c53 100644
--- a/klippy/extras/resonance_tester.py
+++ b/klippy/extras/resonance_tester.py
@@ -65,6 +65,8 @@ def prepare_test(self, gcmd):
self.freq_start = gcmd.get_float("FREQ_START", self.min_freq, minval=1.)
self.freq_end = gcmd.get_float("FREQ_END", self.max_freq,
minval=self.freq_start, maxval=300.)
+ self.accel_per_hz = gcmd.get_float("ACCEL_PER_HZ",
+ self.accel_per_hz, above=0.)
self.hz_per_sec = gcmd.get_float("HZ_PER_SEC", self.hz_per_sec,
above=0., maxval=2.)
def run_test(self, axis, gcmd):
@@ -212,11 +214,7 @@ def _run_test(self, gcmd, axes, helper, raw_name_suffix=None,
def _parse_chips(self, accel_chips):
parsed_chips = []
for chip_name in accel_chips.split(','):
- if "adxl345" in chip_name:
- chip_lookup_name = chip_name.strip()
- else:
- chip_lookup_name = "adxl345 " + chip_name.strip();
- chip = self.printer.lookup_object(chip_lookup_name)
+ chip = self.printer.lookup_object(chip_name.strip())
parsed_chips.append(chip)
return parsed_chips
def _get_max_calibration_freq(self):
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 8291788f40a677b11d6e0e0283411bc5f96936f7 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Wed, 27 Nov 2024 22:45:27 -0500
Subject: [PATCH] toolhead: Use delta_v2 when calculating centripetal force

As a minor math optimization, it's possible to calculate:
.5 * self.move_d * self.accel * tan_theta_d2
using:
self.delta_v2 * .25 * tan_theta_d2
because self.delta_v2 is "2. * self.move_d * self.accel".

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
klippy/toolhead.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 4149d53b12f6..948ea974fd70 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -76,10 +76,11 @@ def calc_junction(self, prev_move):
sin_theta_d2 = math.sqrt(0.5*(1.0-junction_cos_theta))
R_jd = sin_theta_d2 / (1. - sin_theta_d2)
# Approximated circle must contact moves no further away than mid-move
- tan_theta_d2 = sin_theta_d2 / math.sqrt(0.5*(1.0+junction_cos_theta))
- move_centripetal_v2 = .5 * self.move_d * tan_theta_d2 * self.accel
- prev_move_centripetal_v2 = (.5 * prev_move.move_d * tan_theta_d2
- * prev_move.accel)
+ # centripetal_v2 = .5 * self.move_d * self.accel * tan_theta_d2
+ cos_theta_d2 = math.sqrt(0.5*(1.0+junction_cos_theta))
+ quarter_tan_theta_d2 = .25 * sin_theta_d2 / cos_theta_d2
+ move_centripetal_v2 = self.delta_v2 * quarter_tan_theta_d2
+ prev_move_centripetal_v2 = prev_move.delta_v2 * quarter_tan_theta_d2
# Apply limits
self.max_start_v2 = min(
R_jd * self.junction_deviation * self.accel,
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From 847331260c84e9de00404aa98f0029184150a897 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin@koconnor.net>
Date: Wed, 27 Nov 2024 22:34:17 -0500
Subject: [PATCH] toolhead: Remove arbitrary constants controlling junction
deviation

When calculating the junction speed between two moves the code checked
for angles greater than 0.999999 or less than -0.999999 to avoid math
issues (sqrt of a negative number and/or divide by zero). However,
these arbitrary constants could unnecessarily pessimize junction
speeds when angles are close to 180 or 0 degrees.

Change the code to explicitly check for negative numbers during sqrt
and to explicilty check for zero values prior to division. This
simplifies the code and avoids unnecessarily reducing some junction
speeds.

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
klippy/toolhead.py | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 948ea974fd70..ed26092f651d 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -64,33 +64,33 @@ def calc_junction(self, prev_move):
return
# Allow extruder to calculate its maximum junction
extruder_v2 = self.toolhead.extruder.calc_junction(prev_move, self)
+ max_start_v2 = min(
+ extruder_v2, self.max_cruise_v2, prev_move.max_cruise_v2,
+ prev_move.max_start_v2 + prev_move.delta_v2)
# Find max velocity using "approximated centripetal velocity"
axes_r = self.axes_r
prev_axes_r = prev_move.axes_r
junction_cos_theta = -(axes_r[0] * prev_axes_r[0]
+ axes_r[1] * prev_axes_r[1]
+ axes_r[2] * prev_axes_r[2])
- if junction_cos_theta > 0.999999:
- return
- junction_cos_theta = max(junction_cos_theta, -0.999999)
- sin_theta_d2 = math.sqrt(0.5*(1.0-junction_cos_theta))
- R_jd = sin_theta_d2 / (1. - sin_theta_d2)
- # Approximated circle must contact moves no further away than mid-move
- # centripetal_v2 = .5 * self.move_d * self.accel * tan_theta_d2
- cos_theta_d2 = math.sqrt(0.5*(1.0+junction_cos_theta))
- quarter_tan_theta_d2 = .25 * sin_theta_d2 / cos_theta_d2
- move_centripetal_v2 = self.delta_v2 * quarter_tan_theta_d2
- prev_move_centripetal_v2 = prev_move.delta_v2 * quarter_tan_theta_d2
+ sin_theta_d2 = math.sqrt(max(0.5*(1.0-junction_cos_theta), 0.))
+ cos_theta_d2 = math.sqrt(max(0.5*(1.0+junction_cos_theta), 0.))
+ one_minus_sin_theta_d2 = 1. - sin_theta_d2
+ if one_minus_sin_theta_d2 > 0. and cos_theta_d2 > 0.:
+ R_jd = sin_theta_d2 / one_minus_sin_theta_d2
+ move_jd_v2 = R_jd * self.junction_deviation * self.accel
+ pmove_jd_v2 = R_jd * prev_move.junction_deviation * prev_move.accel
+ # Approximated circle must contact moves no further than mid-move
+ # centripetal_v2 = .5 * self.move_d * self.accel * tan_theta_d2
+ quarter_tan_theta_d2 = .25 * sin_theta_d2 / cos_theta_d2
+ move_centripetal_v2 = self.delta_v2 * quarter_tan_theta_d2
+ pmove_centripetal_v2 = prev_move.delta_v2 * quarter_tan_theta_d2
+ max_start_v2 = min(max_start_v2, move_jd_v2, pmove_jd_v2,
+ move_centripetal_v2, pmove_centripetal_v2)
# Apply limits
- self.max_start_v2 = min(
- R_jd * self.junction_deviation * self.accel,
- R_jd * prev_move.junction_deviation * prev_move.accel,
- move_centripetal_v2, prev_move_centripetal_v2,
- extruder_v2, self.max_cruise_v2, prev_move.max_cruise_v2,
- prev_move.max_start_v2 + prev_move.delta_v2)
+ self.max_start_v2 = max_start_v2
self.max_smoothed_v2 = min(
- self.max_start_v2
- , prev_move.max_smoothed_v2 + prev_move.smooth_delta_v2)
+ max_start_v2, prev_move.max_smoothed_v2 + prev_move.smooth_delta_v2)
def set_junction(self, start_v2, cruise_v2, end_v2):
# Determine accel, cruise, and decel portions of the move distance
half_inv_accel = .5 / self.accel
Loading