toolhead: Rename MoveQueue class to LookAheadQueue

Rename this class so that is is not confused with the mcu "move
queue".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2024-01-18 12:16:47 -05:00
parent d633ef2cfc
commit 6cc409f6fb
2 changed files with 33 additions and 31 deletions

View File

@ -136,8 +136,9 @@ provides further information on the mechanics of moves.
* The ToolHead class (in toolhead.py) handles "look-ahead" and tracks
the timing of printing actions. The main codepath for a move is:
`ToolHead.move() -> MoveQueue.add_move() -> MoveQueue.flush() ->
Move.set_junction() -> ToolHead._process_moves()`.
`ToolHead.move() -> LookAheadQueue.add_move() ->
LookAheadQueue.flush() -> Move.set_junction() ->
ToolHead._process_moves()`.
* ToolHead.move() creates a Move() object with the parameters of the
move (in cartesian space and in units of seconds and millimeters).
* The kinematics class is given the opportunity to audit each move
@ -146,10 +147,10 @@ provides further information on the mechanics of moves.
may raise an error if the move is not valid. If check_move()
completes successfully then the underlying kinematics must be able
to handle the move.
* MoveQueue.add_move() places the move object on the "look-ahead"
queue.
* MoveQueue.flush() determines the start and end velocities of each
move.
* LookAheadQueue.add_move() places the move object on the
"look-ahead" queue.
* LookAheadQueue.flush() determines the start and end velocities of
each move.
* Move.set_junction() implements the "trapezoid generator" on a
move. The "trapezoid generator" breaks every move into three parts:
a constant acceleration phase, followed by a constant velocity
@ -170,17 +171,18 @@ provides further information on the mechanics of moves.
placed on a "trapezoid motion queue": `ToolHead._process_moves() ->
trapq_append()` (in klippy/chelper/trapq.c). The step times are then
generated: `ToolHead._process_moves() ->
ToolHead._update_move_time() -> MCU_Stepper.generate_steps() ->
itersolve_generate_steps() -> itersolve_gen_steps_range()` (in
klippy/chelper/itersolve.c). The goal of the iterative solver is to
find step times given a function that calculates a stepper position
from a time. This is done by repeatedly "guessing" various times
until the stepper position formula returns the desired position of
the next step on the stepper. The feedback produced from each guess
is used to improve future guesses so that the process rapidly
converges to the desired time. The kinematic stepper position
formulas are located in the klippy/chelper/ directory (eg,
kin_cart.c, kin_corexy.c, kin_delta.c, kin_extruder.c).
ToolHead._advance_move_time() -> ToolHead._advance_flush_time() ->
MCU_Stepper.generate_steps() -> itersolve_generate_steps() ->
itersolve_gen_steps_range()` (in klippy/chelper/itersolve.c). The
goal of the iterative solver is to find step times given a function
that calculates a stepper position from a time. This is done by
repeatedly "guessing" various times until the stepper position
formula returns the desired position of the next step on the
stepper. The feedback produced from each guess is used to improve
future guesses so that the process rapidly converges to the desired
time. The kinematic stepper position formulas are located in the
klippy/chelper/ directory (eg, kin_cart.c, kin_corexy.c,
kin_delta.c, kin_extruder.c).
* Note that the extruder is handled in its own kinematic class:
`ToolHead._process_moves() -> PrinterExtruder.move()`. Since

View File

@ -110,7 +110,7 @@ LOOKAHEAD_FLUSH_TIME = 0.250
# Class to track a list of pending move requests and to facilitate
# "look-ahead" across moves to reduce acceleration between moves.
class MoveQueue:
class LookAheadQueue:
def __init__(self, toolhead):
self.toolhead = toolhead
self.queue = []
@ -211,8 +211,8 @@ class ToolHead:
self.all_mcus = [
m for n, m in self.printer.lookup_objects(module='mcu')]
self.mcu = self.all_mcus[0]
self.move_queue = MoveQueue(self)
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
self.lookahead = LookAheadQueue(self)
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
self.commanded_pos = [0., 0., 0., 0.]
# Velocity and acceleration control
self.max_velocity = config.getfloat('max_velocity', above=0.)
@ -354,10 +354,10 @@ class ToolHead:
self._advance_move_time(next_move_time)
def _flush_lookahead(self):
# Transit from "NeedPrime"/"Priming"/"Drip"/main state to "NeedPrime"
self.move_queue.flush()
self.lookahead.flush()
self.special_queuing_state = "NeedPrime"
self.need_check_pause = -1.
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
self.check_stall_time = 0.
def flush_step_generation(self):
self._flush_lookahead()
@ -368,7 +368,7 @@ class ToolHead:
self._flush_lookahead()
self._calc_print_time()
else:
self.move_queue.flush()
self.lookahead.flush()
return self.print_time
def _check_pause(self):
eventtime = self.reactor.monotonic()
@ -462,7 +462,7 @@ class ToolHead:
if move.axes_d[3]:
self.extruder.check_move(move)
self.commanded_pos[:] = move.end_pos
self.move_queue.add_move(move)
self.lookahead.add_move(move)
if self.print_time > self.need_check_pause:
self._check_pause()
def manual_move(self, coord, speed):
@ -509,12 +509,12 @@ class ToolHead:
def drip_move(self, newpos, speed, drip_completion):
self.dwell(self.kin_flush_delay)
# Transition from "NeedPrime"/"Priming"/main state to "Drip" state
self.move_queue.flush()
self.lookahead.flush()
self.special_queuing_state = "Drip"
self.need_check_pause = self.reactor.NEVER
self.reactor.update_timer(self.flush_timer, self.reactor.NEVER)
self.do_kick_flush_timer = False
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
self.check_stall_time = 0.
self.drip_completion = drip_completion
# Submit move
@ -526,9 +526,9 @@ class ToolHead:
raise
# Transmit move in "drip" mode
try:
self.move_queue.flush()
self.lookahead.flush()
except DripModeEndSignal as e:
self.move_queue.reset()
self.lookahead.reset()
self.trapq_finalize_moves(self.trapq, self.reactor.NEVER, 0)
# Exit "Drip" state
self.reactor.update_timer(self.flush_timer, self.reactor.NOW)
@ -548,7 +548,7 @@ class ToolHead:
self.print_time, max(buffer_time, 0.), self.print_stall)
def check_busy(self, eventtime):
est_print_time = self.mcu.estimated_print_time(eventtime)
lookahead_empty = not self.move_queue.queue
lookahead_empty = not self.lookahead.queue
return self.print_time, est_print_time, lookahead_empty
def get_status(self, eventtime):
print_time = self.print_time
@ -566,7 +566,7 @@ class ToolHead:
return res
def _handle_shutdown(self):
self.can_pause = False
self.move_queue.reset()
self.lookahead.reset()
def get_kinematics(self):
return self.kin
def get_trapq(self):
@ -583,7 +583,7 @@ class ToolHead:
new_delay = max(self.kin_flush_times + [SDS_CHECK_TIME])
self.kin_flush_delay = new_delay
def register_lookahead_callback(self, callback):
last_move = self.move_queue.get_last()
last_move = self.lookahead.get_last()
if last_move is None:
callback(self.get_last_move_time())
return