From 4f30dce64f16ad17ba471538fa3abe0e63f5b91f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 18 Nov 2016 12:42:39 -0500 Subject: [PATCH] homing: Add EndstopMoveError wrapper around EndstopError Allow an EndstopError to be raised without a destination position. Introduce EndstopMoveError wrapper so that current callers can continue to pass in a move destination. Signed-off-by: Kevin O'Connor --- klippy/cartesian.py | 5 +++-- klippy/delta.py | 6 +++--- klippy/extruder.py | 3 ++- klippy/homing.py | 12 +++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 706ebc5e..f6dc3685 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -84,8 +84,9 @@ 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.EndstopError(end_pos, "Must home axis first") - raise homing.EndstopError(end_pos) + raise homing.EndstopMoveError( + end_pos, "Must home axis first") + raise homing.EndstopMoveError(end_pos) def check_move(self, move): limits = self.limits xpos, ypos = move.end_pos[:2] diff --git a/klippy/delta.py b/klippy/delta.py index d54c0a3c..40df8ab6 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -118,11 +118,11 @@ class DeltaKinematics: xy2 = end_pos[0]**2 + end_pos[1]**2 if xy2 > self.limit_xy2 or end_pos[2] < 0.: if self.limit_xy2 < 0.: - raise homing.EndstopError(end_pos, "Must home first") - raise homing.EndstopError(end_pos) + raise homing.EndstopMoveError(end_pos, "Must home first") + raise homing.EndstopMoveError(end_pos) if end_pos[2] > self.limit_z: if end_pos[2] > self.max_z or xy2 > (self.max_z - end_pos[2])**2: - raise homing.EndstopError(end_pos) + raise homing.EndstopMoveError(end_pos) def move_z(self, move_time, move): if not move.axes_d[2]: return diff --git a/klippy/extruder.py b/klippy/extruder.py index 451aebb0..823ed599 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -23,7 +23,8 @@ class PrinterExtruder: self.need_motor_enable = True def check_move(self, move): if not self.heater.can_extrude: - raise homing.EndstopError(move.end_pos, "Extrude below minimum temp") + raise homing.EndstopMoveError( + 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/homing.py b/klippy/homing.py index b4c5290f..fb0f4ca7 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -104,9 +104,11 @@ class QueryEndstops: return False class EndstopError(Exception): - def __init__(self, pos, msg="Move out of range"): - self.pos = pos - self.msg = msg + def __init__(self, msg="Endstop error"): + self._msg = msg def __str__(self): - return "%s: %.3f %.3f %.3f [%.3f]" % ( - self.msg, self.pos[0], self.pos[1], self.pos[2], self.pos[3]) + return self._msg + +def EndstopMoveError(pos, msg="Move out of range"): + return EndstopError("%s: %.3f %.3f %.3f [%.3f]" % ( + msg, pos[0], pos[1], pos[2], pos[3]))