Skip to content

Commit 6cc409f

Browse files
committed
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>
1 parent d633ef2 commit 6cc409f

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

docs/Code_Overview.md

+19-17
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ provides further information on the mechanics of moves.
136136

137137
* The ToolHead class (in toolhead.py) handles "look-ahead" and tracks
138138
the timing of printing actions. The main codepath for a move is:
139-
`ToolHead.move() -> MoveQueue.add_move() -> MoveQueue.flush() ->
140-
Move.set_junction() -> ToolHead._process_moves()`.
139+
`ToolHead.move() -> LookAheadQueue.add_move() ->
140+
LookAheadQueue.flush() -> Move.set_junction() ->
141+
ToolHead._process_moves()`.
141142
* ToolHead.move() creates a Move() object with the parameters of the
142143
move (in cartesian space and in units of seconds and millimeters).
143144
* The kinematics class is given the opportunity to audit each move
@@ -146,10 +147,10 @@ provides further information on the mechanics of moves.
146147
may raise an error if the move is not valid. If check_move()
147148
completes successfully then the underlying kinematics must be able
148149
to handle the move.
149-
* MoveQueue.add_move() places the move object on the "look-ahead"
150-
queue.
151-
* MoveQueue.flush() determines the start and end velocities of each
152-
move.
150+
* LookAheadQueue.add_move() places the move object on the
151+
"look-ahead" queue.
152+
* LookAheadQueue.flush() determines the start and end velocities of
153+
each move.
153154
* Move.set_junction() implements the "trapezoid generator" on a
154155
move. The "trapezoid generator" breaks every move into three parts:
155156
a constant acceleration phase, followed by a constant velocity
@@ -170,17 +171,18 @@ provides further information on the mechanics of moves.
170171
placed on a "trapezoid motion queue": `ToolHead._process_moves() ->
171172
trapq_append()` (in klippy/chelper/trapq.c). The step times are then
172173
generated: `ToolHead._process_moves() ->
173-
ToolHead._update_move_time() -> MCU_Stepper.generate_steps() ->
174-
itersolve_generate_steps() -> itersolve_gen_steps_range()` (in
175-
klippy/chelper/itersolve.c). The goal of the iterative solver is to
176-
find step times given a function that calculates a stepper position
177-
from a time. This is done by repeatedly "guessing" various times
178-
until the stepper position formula returns the desired position of
179-
the next step on the stepper. The feedback produced from each guess
180-
is used to improve future guesses so that the process rapidly
181-
converges to the desired time. The kinematic stepper position
182-
formulas are located in the klippy/chelper/ directory (eg,
183-
kin_cart.c, kin_corexy.c, kin_delta.c, kin_extruder.c).
174+
ToolHead._advance_move_time() -> ToolHead._advance_flush_time() ->
175+
MCU_Stepper.generate_steps() -> itersolve_generate_steps() ->
176+
itersolve_gen_steps_range()` (in klippy/chelper/itersolve.c). The
177+
goal of the iterative solver is to find step times given a function
178+
that calculates a stepper position from a time. This is done by
179+
repeatedly "guessing" various times until the stepper position
180+
formula returns the desired position of the next step on the
181+
stepper. The feedback produced from each guess is used to improve
182+
future guesses so that the process rapidly converges to the desired
183+
time. The kinematic stepper position formulas are located in the
184+
klippy/chelper/ directory (eg, kin_cart.c, kin_corexy.c,
185+
kin_delta.c, kin_extruder.c).
184186

185187
* Note that the extruder is handled in its own kinematic class:
186188
`ToolHead._process_moves() -> PrinterExtruder.move()`. Since

klippy/toolhead.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def set_junction(self, start_v2, cruise_v2, end_v2):
110110

111111
# Class to track a list of pending move requests and to facilitate
112112
# "look-ahead" across moves to reduce acceleration between moves.
113-
class MoveQueue:
113+
class LookAheadQueue:
114114
def __init__(self, toolhead):
115115
self.toolhead = toolhead
116116
self.queue = []
@@ -211,8 +211,8 @@ def __init__(self, config):
211211
self.all_mcus = [
212212
m for n, m in self.printer.lookup_objects(module='mcu')]
213213
self.mcu = self.all_mcus[0]
214-
self.move_queue = MoveQueue(self)
215-
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
214+
self.lookahead = LookAheadQueue(self)
215+
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
216216
self.commanded_pos = [0., 0., 0., 0.]
217217
# Velocity and acceleration control
218218
self.max_velocity = config.getfloat('max_velocity', above=0.)
@@ -354,10 +354,10 @@ def _process_moves(self, moves):
354354
self._advance_move_time(next_move_time)
355355
def _flush_lookahead(self):
356356
# Transit from "NeedPrime"/"Priming"/"Drip"/main state to "NeedPrime"
357-
self.move_queue.flush()
357+
self.lookahead.flush()
358358
self.special_queuing_state = "NeedPrime"
359359
self.need_check_pause = -1.
360-
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
360+
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
361361
self.check_stall_time = 0.
362362
def flush_step_generation(self):
363363
self._flush_lookahead()
@@ -368,7 +368,7 @@ def get_last_move_time(self):
368368
self._flush_lookahead()
369369
self._calc_print_time()
370370
else:
371-
self.move_queue.flush()
371+
self.lookahead.flush()
372372
return self.print_time
373373
def _check_pause(self):
374374
eventtime = self.reactor.monotonic()
@@ -462,7 +462,7 @@ def move(self, newpos, speed):
462462
if move.axes_d[3]:
463463
self.extruder.check_move(move)
464464
self.commanded_pos[:] = move.end_pos
465-
self.move_queue.add_move(move)
465+
self.lookahead.add_move(move)
466466
if self.print_time > self.need_check_pause:
467467
self._check_pause()
468468
def manual_move(self, coord, speed):
@@ -509,12 +509,12 @@ def _update_drip_move_time(self, next_print_time):
509509
def drip_move(self, newpos, speed, drip_completion):
510510
self.dwell(self.kin_flush_delay)
511511
# Transition from "NeedPrime"/"Priming"/main state to "Drip" state
512-
self.move_queue.flush()
512+
self.lookahead.flush()
513513
self.special_queuing_state = "Drip"
514514
self.need_check_pause = self.reactor.NEVER
515515
self.reactor.update_timer(self.flush_timer, self.reactor.NEVER)
516516
self.do_kick_flush_timer = False
517-
self.move_queue.set_flush_time(BUFFER_TIME_HIGH)
517+
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
518518
self.check_stall_time = 0.
519519
self.drip_completion = drip_completion
520520
# Submit move
@@ -526,9 +526,9 @@ def drip_move(self, newpos, speed, drip_completion):
526526
raise
527527
# Transmit move in "drip" mode
528528
try:
529-
self.move_queue.flush()
529+
self.lookahead.flush()
530530
except DripModeEndSignal as e:
531-
self.move_queue.reset()
531+
self.lookahead.reset()
532532
self.trapq_finalize_moves(self.trapq, self.reactor.NEVER, 0)
533533
# Exit "Drip" state
534534
self.reactor.update_timer(self.flush_timer, self.reactor.NOW)
@@ -548,7 +548,7 @@ def stats(self, eventtime):
548548
self.print_time, max(buffer_time, 0.), self.print_stall)
549549
def check_busy(self, eventtime):
550550
est_print_time = self.mcu.estimated_print_time(eventtime)
551-
lookahead_empty = not self.move_queue.queue
551+
lookahead_empty = not self.lookahead.queue
552552
return self.print_time, est_print_time, lookahead_empty
553553
def get_status(self, eventtime):
554554
print_time = self.print_time
@@ -566,7 +566,7 @@ def get_status(self, eventtime):
566566
return res
567567
def _handle_shutdown(self):
568568
self.can_pause = False
569-
self.move_queue.reset()
569+
self.lookahead.reset()
570570
def get_kinematics(self):
571571
return self.kin
572572
def get_trapq(self):
@@ -583,7 +583,7 @@ def note_step_generation_scan_time(self, delay, old_delay=0.):
583583
new_delay = max(self.kin_flush_times + [SDS_CHECK_TIME])
584584
self.kin_flush_delay = new_delay
585585
def register_lookahead_callback(self, callback):
586-
last_move = self.move_queue.get_last()
586+
last_move = self.lookahead.get_last()
587587
if last_move is None:
588588
callback(self.get_last_move_time())
589589
return

0 commit comments

Comments
 (0)