Skip to content

Commit

Permalink
toolhead: Rename MoveQueue class to LookAheadQueue
Browse files Browse the repository at this point in the history
Rename this class so that is is not confused with the mcu "move
queue".

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Jan 18, 2024
1 parent d633ef2 commit 6cc409f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
36 changes: 19 additions & 17 deletions docs/Code_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def set_junction(self, start_v2, cruise_v2, end_v2):

# 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 = []
Expand Down Expand Up @@ -211,8 +211,8 @@ def __init__(self, config):
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.)
Expand Down Expand Up @@ -354,10 +354,10 @@ def _process_moves(self, moves):
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()
Expand All @@ -368,7 +368,7 @@ def get_last_move_time(self):
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()
Expand Down Expand Up @@ -462,7 +462,7 @@ def move(self, newpos, speed):
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):
Expand Down Expand Up @@ -509,12 +509,12 @@ def _update_drip_move_time(self, next_print_time):
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
Expand All @@ -526,9 +526,9 @@ def drip_move(self, newpos, speed, drip_completion):
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)
Expand All @@ -548,7 +548,7 @@ def stats(self, eventtime):
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
Expand All @@ -566,7 +566,7 @@ def get_status(self, eventtime):
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):
Expand All @@ -583,7 +583,7 @@ def note_step_generation_scan_time(self, delay, old_delay=0.):
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
Expand Down

0 comments on commit 6cc409f

Please sign in to comment.