From f34103183453093f432b8d5565068cdd5b2c7999 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 15 Sep 2025 13:42:32 -0400 Subject: [PATCH] motion_queuing: Try harder to use next_batch_time when flushing Use the next_batch_time even if it is slightly past or before the ideal flushing window. This should improve run to run reproducibility of flush timing. Signed-off-by: Kevin O'Connor --- klippy/extras/motion_queuing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/klippy/extras/motion_queuing.py b/klippy/extras/motion_queuing.py index a22598093..c2b306436 100644 --- a/klippy/extras/motion_queuing.py +++ b/klippy/extras/motion_queuing.py @@ -187,12 +187,13 @@ class PrinterMotionQueuing: if self.last_step_gen_time < aggr_sg_time: # Actively stepping - want more aggressive flushing want_sg_time = est_print_time + BGFLUSH_SG_HIGH_TIME - want_sg_time = min(want_sg_time, aggr_sg_time) - # Try improving run-to-run reproducibility by batching from last batch_time = BGFLUSH_SG_HIGH_TIME - BGFLUSH_SG_LOW_TIME next_batch_time = self.last_step_gen_time + batch_time - if next_batch_time > est_print_time + BGFLUSH_SG_LOW_TIME: - want_sg_time = min(want_sg_time, next_batch_time) + if (next_batch_time > est_print_time + and next_batch_time < want_sg_time + 0.005): + # Improve run-to-run reproducibility by batching from last + want_sg_time = next_batch_time + want_sg_time = min(want_sg_time, aggr_sg_time) # Flush motion queues (if needed) if want_sg_time > self.last_step_gen_time: self._advance_flush_time(0., want_sg_time)