mirror of
https://github.com/andreili/klipper.git
synced 2025-08-24 03:44:06 +02:00
toolhead: Avoid LookAheadQueue calling back into toolhead class
Avoid lookahead.flush() calling back into toolhead._process_moves(). Instead, rename toolhead._process_moves() to toolhead._process_lookahead(), have it call lookahead.flush(), and consistently use it when flushing the lookahead queue. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
413ff19ea8
commit
6202a0f3bc
@ -1,6 +1,6 @@
|
|||||||
# Code for coordinating events on the printer toolhead
|
# Code for coordinating events on the printer toolhead
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016-2024 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2016-2025 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import math, logging, importlib
|
import math, logging, importlib
|
||||||
@ -115,8 +115,7 @@ LOOKAHEAD_FLUSH_TIME = 0.250
|
|||||||
# Class to track a list of pending move requests and to facilitate
|
# Class to track a list of pending move requests and to facilitate
|
||||||
# "look-ahead" across moves to reduce acceleration between moves.
|
# "look-ahead" across moves to reduce acceleration between moves.
|
||||||
class LookAheadQueue:
|
class LookAheadQueue:
|
||||||
def __init__(self, toolhead):
|
def __init__(self):
|
||||||
self.toolhead = toolhead
|
|
||||||
self.queue = []
|
self.queue = []
|
||||||
self.junction_flush = LOOKAHEAD_FLUSH_TIME
|
self.junction_flush = LOOKAHEAD_FLUSH_TIME
|
||||||
def reset(self):
|
def reset(self):
|
||||||
@ -175,20 +174,19 @@ class LookAheadQueue:
|
|||||||
next_end_v2 = start_v2
|
next_end_v2 = start_v2
|
||||||
next_smoothed_v2 = smoothed_v2
|
next_smoothed_v2 = smoothed_v2
|
||||||
if update_flush_count or not flush_count:
|
if update_flush_count or not flush_count:
|
||||||
return
|
return []
|
||||||
# Generate step times for all moves ready to be flushed
|
|
||||||
self.toolhead._process_moves(queue[:flush_count])
|
|
||||||
# Remove processed moves from the queue
|
# Remove processed moves from the queue
|
||||||
|
res = queue[:flush_count]
|
||||||
del queue[:flush_count]
|
del queue[:flush_count]
|
||||||
|
return res
|
||||||
def add_move(self, move):
|
def add_move(self, move):
|
||||||
self.queue.append(move)
|
self.queue.append(move)
|
||||||
if len(self.queue) == 1:
|
if len(self.queue) == 1:
|
||||||
return
|
return
|
||||||
move.calc_junction(self.queue[-2])
|
move.calc_junction(self.queue[-2])
|
||||||
self.junction_flush -= move.min_move_t
|
self.junction_flush -= move.min_move_t
|
||||||
if self.junction_flush <= 0.:
|
# Check if enough moves have been queued to reach the target flush time.
|
||||||
# Enough moves have been queued to reach the target flush time.
|
return self.junction_flush <= 0.
|
||||||
self.flush(lazy=True)
|
|
||||||
|
|
||||||
BUFFER_TIME_LOW = 1.0
|
BUFFER_TIME_LOW = 1.0
|
||||||
BUFFER_TIME_HIGH = 2.0
|
BUFFER_TIME_HIGH = 2.0
|
||||||
@ -215,7 +213,7 @@ class ToolHead:
|
|||||||
self.all_mcus = [
|
self.all_mcus = [
|
||||||
m for n, m in self.printer.lookup_objects(module='mcu')]
|
m for n, m in self.printer.lookup_objects(module='mcu')]
|
||||||
self.mcu = self.all_mcus[0]
|
self.mcu = self.all_mcus[0]
|
||||||
self.lookahead = LookAheadQueue(self)
|
self.lookahead = LookAheadQueue()
|
||||||
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
||||||
self.commanded_pos = [0., 0., 0., 0.]
|
self.commanded_pos = [0., 0., 0., 0.]
|
||||||
# Velocity and acceleration control
|
# Velocity and acceleration control
|
||||||
@ -334,7 +332,10 @@ class ToolHead:
|
|||||||
self.print_time = min_print_time
|
self.print_time = min_print_time
|
||||||
self.printer.send_event("toolhead:sync_print_time",
|
self.printer.send_event("toolhead:sync_print_time",
|
||||||
curtime, est_print_time, self.print_time)
|
curtime, est_print_time, self.print_time)
|
||||||
def _process_moves(self, moves):
|
def _process_lookahead(self, lazy=False):
|
||||||
|
moves = self.lookahead.flush(lazy=lazy)
|
||||||
|
if not moves:
|
||||||
|
return
|
||||||
# Resync print_time if necessary
|
# Resync print_time if necessary
|
||||||
if self.special_queuing_state:
|
if self.special_queuing_state:
|
||||||
if self.special_queuing_state != "Drip":
|
if self.special_queuing_state != "Drip":
|
||||||
@ -366,7 +367,7 @@ class ToolHead:
|
|||||||
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"
|
||||||
self.lookahead.flush()
|
self._process_lookahead()
|
||||||
self.special_queuing_state = "NeedPrime"
|
self.special_queuing_state = "NeedPrime"
|
||||||
self.need_check_pause = -1.
|
self.need_check_pause = -1.
|
||||||
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
||||||
@ -380,7 +381,7 @@ class ToolHead:
|
|||||||
self._flush_lookahead()
|
self._flush_lookahead()
|
||||||
self._calc_print_time()
|
self._calc_print_time()
|
||||||
else:
|
else:
|
||||||
self.lookahead.flush()
|
self._process_lookahead()
|
||||||
return self.print_time
|
return self.print_time
|
||||||
def _check_pause(self):
|
def _check_pause(self):
|
||||||
eventtime = self.reactor.monotonic()
|
eventtime = self.reactor.monotonic()
|
||||||
@ -478,7 +479,9 @@ class ToolHead:
|
|||||||
if move.axes_d[3]:
|
if move.axes_d[3]:
|
||||||
self.extruder.check_move(move)
|
self.extruder.check_move(move)
|
||||||
self.commanded_pos[:] = move.end_pos
|
self.commanded_pos[:] = move.end_pos
|
||||||
self.lookahead.add_move(move)
|
want_flush = self.lookahead.add_move(move)
|
||||||
|
if want_flush:
|
||||||
|
self._process_lookahead(lazy=True)
|
||||||
if self.print_time > self.need_check_pause:
|
if self.print_time > self.need_check_pause:
|
||||||
self._check_pause()
|
self._check_pause()
|
||||||
def manual_move(self, coord, speed):
|
def manual_move(self, coord, speed):
|
||||||
@ -525,7 +528,7 @@ class ToolHead:
|
|||||||
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)
|
||||||
# Transition from "NeedPrime"/"Priming"/main state to "Drip" state
|
# Transition from "NeedPrime"/"Priming"/main state to "Drip" state
|
||||||
self.lookahead.flush()
|
self._process_lookahead()
|
||||||
self.special_queuing_state = "Drip"
|
self.special_queuing_state = "Drip"
|
||||||
self.need_check_pause = self.reactor.NEVER
|
self.need_check_pause = self.reactor.NEVER
|
||||||
self.reactor.update_timer(self.flush_timer, self.reactor.NEVER)
|
self.reactor.update_timer(self.flush_timer, self.reactor.NEVER)
|
||||||
@ -542,7 +545,7 @@ class ToolHead:
|
|||||||
raise
|
raise
|
||||||
# Transmit move in "drip" mode
|
# Transmit move in "drip" mode
|
||||||
try:
|
try:
|
||||||
self.lookahead.flush()
|
self._process_lookahead()
|
||||||
except DripModeEndSignal as e:
|
except DripModeEndSignal as e:
|
||||||
self.lookahead.reset()
|
self.lookahead.reset()
|
||||||
self.trapq_finalize_moves(self.trapq, self.reactor.NEVER, 0)
|
self.trapq_finalize_moves(self.trapq, self.reactor.NEVER, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user