Skip to content

Commit

Permalink
toolhead: Make sure to flush history when in debug output mode
Browse files Browse the repository at this point in the history
When in debugging "batch mode", use the existing method of keeping the
last 30 seconds of history from the furthest planned move time.  This
avoids keeping all moves in memory during a batch test.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Dec 30, 2023
1 parent 9847b44 commit 25bc649
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(self, config):
self.flush_timer = self.reactor.register_timer(self._flush_handler)
self.do_kick_flush_timer = True
self.last_flush_time = self.last_sg_flush_time = 0.
self.need_flush_time = self.step_gen_time = 0.
self.need_flush_time = self.step_gen_time = self.clear_history_time = 0.
# Kinematic step generation scan window time tracking
self.kin_flush_delay = SDS_CHECK_TIME
self.kin_flush_times = []
Expand Down Expand Up @@ -281,7 +281,7 @@ def __init__(self, config):
for module_name in modules:
self.printer.load_object(config, module_name)
# Print time and flush tracking
def _advance_flush_time(self, flush_time, clear_history_time):
def _advance_flush_time(self, flush_time):
flush_time = max(flush_time, self.last_flush_time)
# Generate steps via itersolve
sg_flush_want = min(flush_time + STEPCOMPRESS_FLUSH_TIME,
Expand All @@ -291,6 +291,9 @@ def _advance_flush_time(self, flush_time, clear_history_time):
sg(sg_flush_time)
self.last_sg_flush_time = sg_flush_time
# Free trapq entries that are no longer needed
clear_history_time = self.clear_history_time
if not self.can_pause:
clear_history_time = flush_time - MOVE_HISTORY_EXPIRE
free_time = sg_flush_time - self.kin_flush_delay
self.trapq_finalize_moves(self.trapq, free_time, clear_history_time)
self.extruder.update_move_time(free_time, clear_history_time)
Expand All @@ -303,11 +306,9 @@ def _advance_move_time(self, next_print_time):
flush_time = max(self.last_flush_time, self.print_time - pt_delay)
self.print_time = max(self.print_time, next_print_time)
want_flush_time = max(flush_time, self.print_time - pt_delay)
clear_history_time = self.mcu.estimated_print_time(
self.reactor.monotonic()) - MOVE_HISTORY_EXPIRE
while 1:
flush_time = min(flush_time + MOVE_BATCH_TIME, want_flush_time)
self._advance_flush_time(flush_time, clear_history_time)
self._advance_flush_time(flush_time)
if flush_time >= want_flush_time:
break
def _calc_print_time(self):
Expand Down Expand Up @@ -359,7 +360,7 @@ def _flush_lookahead(self):
self.check_stall_time = 0.
def flush_step_generation(self):
self._flush_lookahead()
self._advance_flush_time(self.step_gen_time, 0.)
self._advance_flush_time(self.step_gen_time)
def get_last_move_time(self):
if self.special_queuing_state:
self._flush_lookahead()
Expand Down Expand Up @@ -433,8 +434,7 @@ def _flush_handler(self, eventtime):
if buffer_time > BGFLUSH_LOW_TIME:
return eventtime + buffer_time - BGFLUSH_LOW_TIME
ftime = est_print_time + BGFLUSH_LOW_TIME + BGFLUSH_BATCH_TIME
self._advance_flush_time(min(self.need_flush_time, ftime),
est_print_time - MOVE_HISTORY_EXPIRE)
self._advance_flush_time(min(self.need_flush_time, ftime))
except:
logging.exception("Exception in flush_handler")
self.printer.invoke_shutdown("Exception in flush_handler")
Expand Down Expand Up @@ -535,7 +535,9 @@ def stats(self, eventtime):
max_queue_time = max(self.print_time, self.last_flush_time)
for m in self.all_mcus:
m.check_active(max_queue_time, eventtime)
buffer_time = self.print_time - self.mcu.estimated_print_time(eventtime)
est_print_time = self.mcu.estimated_print_time(eventtime)
self.clear_history_time = est_print_time - MOVE_HISTORY_EXPIRE
buffer_time = self.print_time - est_print_time
is_active = buffer_time > -60. or not self.special_queuing_state
if self.special_queuing_state == "Drip":
buffer_time = 0.
Expand Down

0 comments on commit 25bc649

Please sign in to comment.