From 6a96e83ea923ebd0d3a84da218afda020b8b9612 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 25 Oct 2016 19:11:05 -0400 Subject: [PATCH] toolhead: Store both the start and end position in the Move class Store the start position (in addition to the existing end position) in the Move class. The start position can be useful to the kinematic classes. Signed-off-by: Kevin O'Connor --- klippy/cartesian.py | 14 ++++++++------ klippy/extruder.py | 2 +- klippy/toolhead.py | 22 ++++++++++++---------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 860ce9fd..60fe9976 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -67,16 +67,17 @@ class CartKinematics: def query_endstops(self, move_time): return homing.QueryEndstops(["x", "y", "z"], self.steppers) def check_endstops(self, move): + end_pos = move.end_pos for i in StepList: if (move.axes_d[i] - and (move.pos[i] < self.limits[i][0] - or move.pos[i] > self.limits[i][1])): + and (end_pos[i] < self.limits[i][0] + or end_pos[i] > self.limits[i][1])): if self.limits[i][0] > self.limits[i][1]: - raise homing.EndstopError(move.pos, "Must home axis first") - raise homing.EndstopError(move.pos) + raise homing.EndstopError(end_pos, "Must home axis first") + raise homing.EndstopError(end_pos) def check_move(self, move): limits = self.limits - xpos, ypos = move.pos[:2] + xpos, ypos = move.end_pos[:2] if (xpos < limits[0][0] or xpos > limits[0][1] or ypos < limits[1][0] or ypos > limits[1][1]): self.check_endstops(move) @@ -96,7 +97,8 @@ class CartKinematics: inv_accel = 1. / move.accel inv_cruise_v = 1. / move.cruise_v for i in StepList: - new_step_pos = int(move.pos[i]*self.steppers[i].inv_step_dist + 0.5) + new_step_pos = int( + move.end_pos[i]*self.steppers[i].inv_step_dist + 0.5) steps = new_step_pos - self.stepper_pos[i] if not steps: continue diff --git a/klippy/extruder.py b/klippy/extruder.py index 94686fdd..8e9298c5 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -21,7 +21,7 @@ class PrinterExtruder: self.stepper.motor_enable(move_time, 0) def check_move(self, move): if not self.heater.can_extrude: - raise homing.EndstopError(move.pos, "Extrude below minimum temp") + raise homing.EndstopError(move.end_pos, "Extrude below minimum temp") if (not move.do_calc_junction and not move.axes_d[0] and not move.axes_d[1] and not move.axes_d[2]): diff --git a/klippy/toolhead.py b/klippy/toolhead.py index e73a2d15..1cda18df 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -14,12 +14,13 @@ EXTRUDE_DIFF_IGNORE = 1.02 # Class to track each move request class Move: - def __init__(self, toolhead, pos, axes_d, speed, accel): + def __init__(self, toolhead, start_pos, end_pos, speed, accel): self.toolhead = toolhead - self.pos = tuple(pos) - self.axes_d = axes_d + self.start_pos = tuple(start_pos) + self.end_pos = tuple(end_pos) self.accel = accel self.do_calc_junction = True + self.axes_d = axes_d = [end_pos[i] - start_pos[i] for i in (0, 1, 2, 3)] if axes_d[2]: # Move with Z move_d = math.sqrt(sum([d*d for d in axes_d[:3]])) @@ -29,6 +30,10 @@ class Move: if not move_d: # Extrude only move move_d = abs(axes_d[3]) + if not move_d: + # No move + self.move_d = 0. + return self.do_calc_junction = False self.move_d = move_d self.extrude_r = axes_d[3] / move_d @@ -245,15 +250,12 @@ class ToolHead: self.commanded_pos[:] = newpos self.kin.set_position(newpos) def move(self, newpos, speed, sloppy=False): - axes_d = [newpos[i] - self.commanded_pos[i] - for i in (0, 1, 2, 3)] - if axes_d == [0., 0., 0., 0.]: - # No move - return speed = min(speed, self.max_speed) - move = Move(self, newpos, axes_d, speed, self.max_accel) + move = Move(self, self.commanded_pos, newpos, speed, self.max_accel) + if not move.move_d: + return self.kin.check_move(move) - if axes_d[3]: + if move.axes_d[3]: self.extruder.check_move(move) self.commanded_pos[:] = newpos self.move_queue.add_move(move)