From 2843c850198010b1948a578a1b1421ee81be36b7 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 13 Nov 2019 23:34:21 -0500 Subject: [PATCH] toolhead: Rename _full_flush() to flush_step_generation() and use globally Update code that modifies the low-level kinematics handlers to first call toolhead.flush_step_generation(). Signed-off-by: Kevin O'Connor --- klippy/extras/bltouch.py | 2 ++ klippy/extras/force_move.py | 3 ++- klippy/extras/manual_probe.py | 2 +- klippy/extras/z_tilt.py | 4 ++++ klippy/homing.py | 5 ++++- klippy/kinematics/cartesian.py | 2 +- klippy/toolhead.py | 13 +++++++------ 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/klippy/extras/bltouch.py b/klippy/extras/bltouch.py index f45b966c..f372b1ab 100644 --- a/klippy/extras/bltouch.py +++ b/klippy/extras/bltouch.py @@ -144,6 +144,8 @@ class BLTouchEndstopWrapper: self.send_cmd(None) self.sync_print_time() self.mcu_endstop.home_prepare() + toolhead = self.printer.lookup_object('toolhead') + toolhead.flush_step_generation() self.start_mcu_pos = [(s, s.get_mcu_position()) for s in self.mcu_endstop.get_steppers()] def home_finalize(self): diff --git a/klippy/extras/force_move.py b/klippy/extras/force_move.py index 187ba91b..12707f4c 100644 --- a/klippy/extras/force_move.py +++ b/klippy/extras/force_move.py @@ -71,10 +71,11 @@ class ForceMove: toolhead.dwell(STALL_TIME) def manual_move(self, stepper, dist, speed, accel=0.): toolhead = self.printer.lookup_object('toolhead') - print_time = toolhead.get_last_move_time() + toolhead.flush_step_generation() prev_sk = stepper.set_stepper_kinematics(self.stepper_kinematics) stepper.set_position((0., 0., 0.)) axis_r, accel_t, cruise_t, cruise_v = calc_move_time(dist, speed, accel) + print_time = toolhead.get_last_move_time() self.trapq_append(self.trapq, print_time, accel_t, cruise_t, accel_t, 0., 0., 0., axis_r, 0., 0., 0., cruise_v, accel) print_time += accel_t + cruise_t + accel_t diff --git a/klippy/extras/manual_probe.py b/klippy/extras/manual_probe.py index c3fcadb9..0dfba2ff 100644 --- a/klippy/extras/manual_probe.py +++ b/klippy/extras/manual_probe.py @@ -82,7 +82,7 @@ class ManualProbeHelper: toolhead_pos = self.toolhead.get_position() if toolhead_pos == self.last_toolhead_pos: return self.last_kinematics_pos - self.toolhead.get_last_move_time() + self.toolhead.flush_step_generation() kin = self.toolhead.get_kinematics() for s in kin.get_steppers(): s.set_tag_position(s.get_commanded_position()) diff --git a/klippy/extras/z_tilt.py b/klippy/extras/z_tilt.py index 6bccfe37..e6680a75 100644 --- a/klippy/extras/z_tilt.py +++ b/klippy/extras/z_tilt.py @@ -35,6 +35,7 @@ class ZAdjustHelper: msg = "Making the following Z adjustments:\n%s" % ("\n".join(stepstrs),) gcode.respond_info(msg) # Disable Z stepper movements + toolhead.flush_step_generation() for s in self.z_steppers: s.set_trapq(None) # Move each z stepper (sorted from lowest to highest) until they match @@ -45,6 +46,7 @@ class ZAdjustHelper: for i in range(len(positions)-1): stepper_offset, stepper = positions[i] next_stepper_offset, next_stepper = positions[i+1] + toolhead.flush_step_generation() stepper.set_trapq(toolhead.get_trapq()) curpos[2] = z_low + next_stepper_offset try: @@ -52,11 +54,13 @@ class ZAdjustHelper: toolhead.set_position(curpos) except: logging.exception("ZAdjustHelper adjust_steppers") + toolhead.flush_step_generation() for s in self.z_steppers: s.set_trapq(toolhead.get_trapq()) raise # Z should now be level - do final cleanup last_stepper_offset, last_stepper = positions[-1] + toolhead.flush_step_generation() last_stepper.set_trapq(toolhead.get_trapq()) curpos[2] += first_stepper_offset toolhead.set_position(curpos) diff --git a/klippy/homing.py b/klippy/homing.py index 48dadaf5..11b6e152 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -41,13 +41,14 @@ class Homing: for mcu_endstop, name in endstops: mcu_endstop.home_prepare() # Note start location - print_time = self.toolhead.get_last_move_time() + self.toolhead.flush_step_generation() kin = self.toolhead.get_kinematics() for s in kin.get_steppers(): s.set_tag_position(s.get_commanded_position()) start_mcu_pos = [(s, name, s.get_mcu_position()) for es, name in endstops for s in es.get_steppers()] # Start endstop checking + print_time = self.toolhead.get_last_move_time() self.endstops_pending = len(endstops) for mcu_endstop, name in endstops: min_step_dist = min([s.get_step_dist() @@ -71,6 +72,7 @@ class Homing: if error is None: error = "Failed to home %s: %s" % (name, str(e)) # Determine stepper halt positions + self.toolhead.flush_step_generation() end_mcu_pos = [(s, name, spos, s.get_mcu_position()) for s, name, spos in start_mcu_pos] if probe_pos: @@ -123,6 +125,7 @@ class Homing: self.homing_move(movepos, endstops, hi.second_homing_speed, verify_movement=self.verify_retract) # Signal home operation complete + self.toolhead.flush_step_generation() kin = self.toolhead.get_kinematics() for s in kin.get_steppers(): s.set_tag_position(s.get_commanded_position()) diff --git a/klippy/kinematics/cartesian.py b/klippy/kinematics/cartesian.py index 7eded6e9..ee65d4ba 100644 --- a/klippy/kinematics/cartesian.py +++ b/klippy/kinematics/cartesian.py @@ -123,7 +123,7 @@ class CartKinematics: # Dual carriage support def _activate_carriage(self, carriage): toolhead = self.printer.lookup_object('toolhead') - toolhead.get_last_move_time() + toolhead.flush_step_generation() dc_rail = self.dual_carriage_rails[carriage] dc_axis = self.dual_carriage_axis self.rails[dc_axis].set_trapq(None) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 2d302a7b..140f1f6b 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -320,7 +320,7 @@ class ToolHead: self._update_drip_move_time(next_move_time) else: self._update_move_time(next_move_time) - def _full_flush(self): + def flush_step_generation(self): # Transition from "Flushed"/"Priming"/main state to "Flushed" state self.move_queue.flush() self.special_queuing_state = "Flushed" @@ -331,7 +331,7 @@ class ToolHead: self._update_move_time(self.print_time, lazy=False) def _flush_lookahead(self): if self.special_queuing_state: - return self._full_flush() + return self.flush_step_generation() self.move_queue.flush() def get_last_move_time(self): self._flush_lookahead() @@ -374,7 +374,7 @@ class ToolHead: # Running normally - reschedule check return eventtime + buffer_time - self.buffer_time_low # Under ran low buffer mark - flush lookahead queue - self._full_flush() + self.flush_step_generation() if print_time != self.print_time: self.idle_flush_print_time = self.print_time except: @@ -385,7 +385,8 @@ class ToolHead: def get_position(self): return list(self.commanded_pos) def set_position(self, newpos, homing_axes=()): - self._flush_lookahead() + self.flush_step_generation() + self.trapq_free_moves(self.trapq, self.reactor.NEVER) self.commanded_pos[:] = newpos self.kin.set_position(newpos, homing_axes) def move(self, newpos, speed): @@ -445,7 +446,7 @@ class ToolHead: try: self.move(newpos, speed) except homing.CommandError as e: - self._full_flush() + self.flush_step_generation() raise # Transmit move in "drip" mode try: @@ -454,7 +455,7 @@ class ToolHead: self.move_queue.reset() self.trapq_free_moves(self.trapq, self.reactor.NEVER) # Exit "Drip" state - self._full_flush() + self.flush_step_generation() def signal_drip_mode_end(self): self.drip_completion.complete(True) # Misc commands