toolhead: Track separate time for flush_step_generation() and need_flush_time

Introduce a new step_gen_time variable for flush_step_generation().
This allows need_flush_time to be set to future times without
interfering with flush_step_generation().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-12-11 12:42:11 -05:00
parent f0753bd338
commit 19862bc3b7
1 changed files with 9 additions and 5 deletions

View File

@ -238,7 +238,7 @@ 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 = 0. self.last_flush_time = 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 = []
@ -341,7 +341,8 @@ class ToolHead:
# Generate steps for moves # Generate steps for moves
if self.special_queuing_state: if self.special_queuing_state:
self._update_drip_move_time(next_move_time) self._update_drip_move_time(next_move_time)
self.note_kinematic_activity(next_move_time + self.kin_flush_delay) self.note_kinematic_activity(next_move_time + self.kin_flush_delay,
set_step_gen_time=True)
self._advance_move_time(next_move_time) self._advance_move_time(next_move_time)
def _flush_lookahead(self): def _flush_lookahead(self):
# Transit from "NeedPrime"/"Priming"/"Drip"/main state to "NeedPrime" # Transit from "NeedPrime"/"Priming"/"Drip"/main state to "NeedPrime"
@ -352,7 +353,7 @@ class ToolHead:
self.check_stall_time = 0. self.check_stall_time = 0.
def flush_step_generation(self): def flush_step_generation(self):
self._flush_lookahead() self._flush_lookahead()
self._advance_flush_time(self.need_flush_time) self._advance_flush_time(self.step_gen_time)
def get_last_move_time(self): def get_last_move_time(self):
if self.special_queuing_state: if self.special_queuing_state:
self._flush_lookahead() self._flush_lookahead()
@ -492,7 +493,8 @@ class ToolHead:
self.drip_completion.wait(curtime + wait_time) self.drip_completion.wait(curtime + wait_time)
continue continue
npt = min(self.print_time + DRIP_SEGMENT_TIME, next_print_time) npt = min(self.print_time + DRIP_SEGMENT_TIME, next_print_time)
self.note_kinematic_activity(npt + self.kin_flush_delay) self.note_kinematic_activity(npt + self.kin_flush_delay,
set_step_gen_time=True)
self._advance_move_time(npt) self._advance_move_time(npt)
def drip_move(self, newpos, speed, drip_completion): def drip_move(self, newpos, speed, drip_completion):
self.dwell(self.kin_flush_delay) self.dwell(self.kin_flush_delay)
@ -574,8 +576,10 @@ class ToolHead:
callback(self.get_last_move_time()) callback(self.get_last_move_time())
return return
last_move.timing_callbacks.append(callback) last_move.timing_callbacks.append(callback)
def note_kinematic_activity(self, kin_time): def note_kinematic_activity(self, kin_time, set_step_gen_time=False):
self.need_flush_time = max(self.need_flush_time, kin_time) self.need_flush_time = max(self.need_flush_time, kin_time)
if set_step_gen_time:
self.step_gen_time = max(self.step_gen_time, kin_time)
if self.do_kick_flush_timer: if self.do_kick_flush_timer:
self.do_kick_flush_timer = False self.do_kick_flush_timer = False
self.reactor.update_timer(self.flush_timer, self.reactor.NOW) self.reactor.update_timer(self.flush_timer, self.reactor.NOW)