toolhead: Fix _calc_print_time() after G4 and SET_PRESSURE_ADVANCE

Commit b7b13588 changed the internal flush time tracking, but
introduced the possibility of motion restart occurring too close to
the last motion end in some rare cases.  This could result in
internal stepcompress errors.

Track the last step generation flush time (last_sg_flush_time) and use
when recalculating the next print_time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-12-26 11:18:40 -05:00
parent 77619e912c
commit fe56bf36c9
1 changed files with 4 additions and 2 deletions

View File

@ -238,7 +238,8 @@ class ToolHead:
# Flush tracking # Flush tracking
self.flush_timer = self.reactor.register_timer(self._flush_handler) self.flush_timer = self.reactor.register_timer(self._flush_handler)
self.do_kick_flush_timer = True self.do_kick_flush_timer = True
self.last_flush_time = self.need_flush_time = self.step_gen_time = 0. self.last_flush_time = self.last_sg_flush_time = 0.
self.need_flush_time = self.step_gen_time = 0.
# Kinematic step generation scan window time tracking # Kinematic step generation scan window time tracking
self.kin_flush_delay = SDS_CHECK_TIME self.kin_flush_delay = SDS_CHECK_TIME
self.kin_flush_times = [] self.kin_flush_times = []
@ -286,6 +287,7 @@ class ToolHead:
sg_flush_time = min(flush_time + STEPCOMPRESS_FLUSH_TIME, sg_flush_ceil) sg_flush_time = min(flush_time + STEPCOMPRESS_FLUSH_TIME, sg_flush_ceil)
for sg in self.step_generators: for sg in self.step_generators:
sg(sg_flush_time) sg(sg_flush_time)
self.last_sg_flush_time = sg_flush_time
# Free trapq entries that are no longer needed # Free trapq entries that are no longer needed
free_time = sg_flush_time - self.kin_flush_delay free_time = sg_flush_time - self.kin_flush_delay
self.trapq_finalize_moves(self.trapq, free_time) self.trapq_finalize_moves(self.trapq, free_time)
@ -307,7 +309,7 @@ class ToolHead:
def _calc_print_time(self): def _calc_print_time(self):
curtime = self.reactor.monotonic() curtime = self.reactor.monotonic()
est_print_time = self.mcu.estimated_print_time(curtime) est_print_time = self.mcu.estimated_print_time(curtime)
kin_time = max(est_print_time + MIN_KIN_TIME, self.last_flush_time) kin_time = max(est_print_time + MIN_KIN_TIME, self.last_sg_flush_time)
kin_time += self.kin_flush_delay kin_time += self.kin_flush_delay
min_print_time = max(est_print_time + BUFFER_TIME_START, kin_time) min_print_time = max(est_print_time + BUFFER_TIME_START, kin_time)
if min_print_time > self.print_time: if min_print_time > self.print_time: