From 1f3a160f47175c44722a3ce1e58e90c359b99c99 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 3 Sep 2020 16:22:54 -0400 Subject: [PATCH] toolhead: Add a move.move_error() helper Move the EndstopMoveError() code from homing.py to a new method in the toolhead Move class. Signed-off-by: Kevin O'Connor --- klippy/homing.py | 4 ---- klippy/kinematics/cartesian.py | 5 ++--- klippy/kinematics/corexy.py | 5 ++--- klippy/kinematics/corexz.py | 5 ++--- klippy/kinematics/delta.py | 4 ++-- klippy/kinematics/extruder.py | 3 +-- klippy/kinematics/polar.py | 13 ++++++------- klippy/kinematics/rotary_delta.py | 4 ++-- klippy/toolhead.py | 4 ++++ 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/klippy/homing.py b/klippy/homing.py index cc808cc1..ce9a3de8 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -164,8 +164,4 @@ class CommandError(Exception): class EndstopError(CommandError): pass -def EndstopMoveError(pos, msg="Move out of range"): - return EndstopError("%s: %.3f %.3f %.3f [%.3f]" % ( - msg, pos[0], pos[1], pos[2], pos[3])) - Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e')) diff --git a/klippy/kinematics/cartesian.py b/klippy/kinematics/cartesian.py index 3dfd8fc5..073b0b3d 100644 --- a/klippy/kinematics/cartesian.py +++ b/klippy/kinematics/cartesian.py @@ -100,9 +100,8 @@ class CartKinematics: 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.EndstopMoveError( - end_pos, "Must home axis first") - raise homing.EndstopMoveError(end_pos) + raise move.move_error("Must home axis first") + raise move.move_error() def check_move(self, move): limits = self.limits xpos, ypos = move.end_pos[:2] diff --git a/klippy/kinematics/corexy.py b/klippy/kinematics/corexy.py index f04b3009..47b766b0 100644 --- a/klippy/kinematics/corexy.py +++ b/klippy/kinematics/corexy.py @@ -77,9 +77,8 @@ class CoreXYKinematics: 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.EndstopMoveError( - end_pos, "Must home axis first") - raise homing.EndstopMoveError(end_pos) + raise move.move_error("Must home axis first") + raise move.move_error() def check_move(self, move): limits = self.limits xpos, ypos = move.end_pos[:2] diff --git a/klippy/kinematics/corexz.py b/klippy/kinematics/corexz.py index 8addecf7..6cc21624 100644 --- a/klippy/kinematics/corexz.py +++ b/klippy/kinematics/corexz.py @@ -76,9 +76,8 @@ class CoreXZKinematics: 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.EndstopMoveError( - end_pos, "Must home axis first") - raise homing.EndstopMoveError(end_pos) + raise move.move_error("Must home axis first") + raise move.move_error() def check_move(self, move): limits = self.limits xpos, ypos = move.end_pos[:2] diff --git a/klippy/kinematics/delta.py b/klippy/kinematics/delta.py index 885ce940..427fabda 100644 --- a/klippy/kinematics/delta.py +++ b/klippy/kinematics/delta.py @@ -118,7 +118,7 @@ class DeltaKinematics: # Normal XY move return if self.need_home: - raise homing.EndstopMoveError(end_pos, "Must home first") + raise move.move_error("Must home first") end_z = end_pos[2] limit_xy2 = self.max_xy2 if end_z > self.limit_z: @@ -127,7 +127,7 @@ class DeltaKinematics: # Move out of range - verify not a homing move if (end_pos[:2] != self.home_position[:2] or end_z < self.min_z or end_z > self.home_position[2]): - raise homing.EndstopMoveError(end_pos) + raise move.move_error() limit_xy2 = -1. if move.axes_d[2]: move.limit_speed(self.max_z_velocity, move.accel) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 3a03b606..28bd59a2 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -217,8 +217,7 @@ class DummyExtruder: def update_move_time(self, flush_time): pass def check_move(self, move): - raise homing.EndstopMoveError( - move.end_pos, "Extrude when no extruder present") + raise move.move_error("Extrude when no extruder present") def calc_junction(self, prev_move, move): return move.max_cruise_v2 def get_name(self): diff --git a/klippy/kinematics/polar.py b/klippy/kinematics/polar.py index 904ccf55..93ab59d2 100644 --- a/klippy/kinematics/polar.py +++ b/klippy/kinematics/polar.py @@ -94,18 +94,17 @@ class PolarKinematics: xy2 = end_pos[0]**2 + end_pos[1]**2 if xy2 > self.limit_xy2: if self.limit_xy2 < 0.: - raise homing.EndstopMoveError(end_pos, "Must home axis first") - raise homing.EndstopMoveError(end_pos) + raise move.move_error("Must home axis first") + raise move.move_error() if move.axes_d[2]: if end_pos[2] < self.limit_z[0] or end_pos[2] > self.limit_z[1]: if self.limit_z[0] > self.limit_z[1]: - raise homing.EndstopMoveError( - end_pos, "Must home axis first") - raise homing.EndstopMoveError(end_pos) + raise move.move_error("Must home axis first") + raise move.move_error() # Move with Z - update velocity and accel for slower Z axis z_ratio = move.move_d / abs(move.axes_d[2]) - move.limit_speed( - self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio) + move.limit_speed(self.max_z_velocity * z_ratio, + self.max_z_accel * z_ratio) def get_status(self, eventtime): xy_home = "xy" if self.limit_xy2 >= 0. else "" z_home = "z" if self.limit_z[0] <= self.limit_z[1] else "" diff --git a/klippy/kinematics/rotary_delta.py b/klippy/kinematics/rotary_delta.py index 415a2e7f..41cae032 100644 --- a/klippy/kinematics/rotary_delta.py +++ b/klippy/kinematics/rotary_delta.py @@ -106,7 +106,7 @@ class RotaryDeltaKinematics: # Normal XY move return if self.need_home: - raise homing.EndstopMoveError(end_pos, "Must home first") + raise move.move_error("Must home first") end_z = end_pos[2] limit_xy2 = self.max_xy2 if end_z > self.limit_z: @@ -115,7 +115,7 @@ class RotaryDeltaKinematics: # Move out of range - verify not a homing move if (end_pos[:2] != self.home_position[:2] or end_z < self.min_z or end_z > self.home_position[2]): - raise homing.EndstopMoveError(end_pos) + raise move.move_error() limit_xy2 = -1. if move.axes_d[2]: move.limit_speed(self.max_z_velocity, move.accel) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index ae668429..c6797942 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -54,6 +54,10 @@ class Move: self.accel = min(self.accel, accel) self.delta_v2 = 2.0 * self.move_d * self.accel self.smooth_delta_v2 = min(self.smooth_delta_v2, self.delta_v2) + def move_error(self, msg="Move out of range"): + pos = self.end_pos + return homing.EndstopError("%s: %.3f %.3f %.3f [%.3f]" + % (msg, pos[0], pos[1], pos[2], pos[3])) def calc_junction(self, prev_move): if not self.is_kinematic_move or not prev_move.is_kinematic_move: return