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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-09-03 16:22:54 -04:00
parent d0ed6e5705
commit 1f3a160f47
9 changed files with 21 additions and 26 deletions

View File

@ -164,8 +164,4 @@ class CommandError(Exception):
class EndstopError(CommandError): class EndstopError(CommandError):
pass 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')) Coord = collections.namedtuple('Coord', ('x', 'y', 'z', 'e'))

View File

@ -100,9 +100,8 @@ class CartKinematics:
and (end_pos[i] < self.limits[i][0] and (end_pos[i] < self.limits[i][0]
or end_pos[i] > self.limits[i][1])): or end_pos[i] > self.limits[i][1])):
if self.limits[i][0] > self.limits[i][1]: if self.limits[i][0] > self.limits[i][1]:
raise homing.EndstopMoveError( raise move.move_error("Must home axis first")
end_pos, "Must home axis first") raise move.move_error()
raise homing.EndstopMoveError(end_pos)
def check_move(self, move): def check_move(self, move):
limits = self.limits limits = self.limits
xpos, ypos = move.end_pos[:2] xpos, ypos = move.end_pos[:2]

View File

@ -77,9 +77,8 @@ class CoreXYKinematics:
and (end_pos[i] < self.limits[i][0] and (end_pos[i] < self.limits[i][0]
or end_pos[i] > self.limits[i][1])): or end_pos[i] > self.limits[i][1])):
if self.limits[i][0] > self.limits[i][1]: if self.limits[i][0] > self.limits[i][1]:
raise homing.EndstopMoveError( raise move.move_error("Must home axis first")
end_pos, "Must home axis first") raise move.move_error()
raise homing.EndstopMoveError(end_pos)
def check_move(self, move): def check_move(self, move):
limits = self.limits limits = self.limits
xpos, ypos = move.end_pos[:2] xpos, ypos = move.end_pos[:2]

View File

@ -76,9 +76,8 @@ class CoreXZKinematics:
and (end_pos[i] < self.limits[i][0] and (end_pos[i] < self.limits[i][0]
or end_pos[i] > self.limits[i][1])): or end_pos[i] > self.limits[i][1])):
if self.limits[i][0] > self.limits[i][1]: if self.limits[i][0] > self.limits[i][1]:
raise homing.EndstopMoveError( raise move.move_error("Must home axis first")
end_pos, "Must home axis first") raise move.move_error()
raise homing.EndstopMoveError(end_pos)
def check_move(self, move): def check_move(self, move):
limits = self.limits limits = self.limits
xpos, ypos = move.end_pos[:2] xpos, ypos = move.end_pos[:2]

View File

@ -118,7 +118,7 @@ class DeltaKinematics:
# Normal XY move # Normal XY move
return return
if self.need_home: if self.need_home:
raise homing.EndstopMoveError(end_pos, "Must home first") raise move.move_error("Must home first")
end_z = end_pos[2] end_z = end_pos[2]
limit_xy2 = self.max_xy2 limit_xy2 = self.max_xy2
if end_z > self.limit_z: if end_z > self.limit_z:
@ -127,7 +127,7 @@ class DeltaKinematics:
# Move out of range - verify not a homing move # Move out of range - verify not a homing move
if (end_pos[:2] != self.home_position[:2] if (end_pos[:2] != self.home_position[:2]
or end_z < self.min_z or end_z > 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. limit_xy2 = -1.
if move.axes_d[2]: if move.axes_d[2]:
move.limit_speed(self.max_z_velocity, move.accel) move.limit_speed(self.max_z_velocity, move.accel)

View File

@ -217,8 +217,7 @@ class DummyExtruder:
def update_move_time(self, flush_time): def update_move_time(self, flush_time):
pass pass
def check_move(self, move): def check_move(self, move):
raise homing.EndstopMoveError( raise move.move_error("Extrude when no extruder present")
move.end_pos, "Extrude when no extruder present")
def calc_junction(self, prev_move, move): def calc_junction(self, prev_move, move):
return move.max_cruise_v2 return move.max_cruise_v2
def get_name(self): def get_name(self):

View File

@ -94,18 +94,17 @@ class PolarKinematics:
xy2 = end_pos[0]**2 + end_pos[1]**2 xy2 = end_pos[0]**2 + end_pos[1]**2
if xy2 > self.limit_xy2: if xy2 > self.limit_xy2:
if self.limit_xy2 < 0.: if self.limit_xy2 < 0.:
raise homing.EndstopMoveError(end_pos, "Must home axis first") raise move.move_error("Must home axis first")
raise homing.EndstopMoveError(end_pos) raise move.move_error()
if move.axes_d[2]: if move.axes_d[2]:
if end_pos[2] < self.limit_z[0] or end_pos[2] > self.limit_z[1]: 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]: if self.limit_z[0] > self.limit_z[1]:
raise homing.EndstopMoveError( raise move.move_error("Must home axis first")
end_pos, "Must home axis first") raise move.move_error()
raise homing.EndstopMoveError(end_pos)
# Move with Z - update velocity and accel for slower Z axis # Move with Z - update velocity and accel for slower Z axis
z_ratio = move.move_d / abs(move.axes_d[2]) z_ratio = move.move_d / abs(move.axes_d[2])
move.limit_speed( move.limit_speed(self.max_z_velocity * z_ratio,
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio) self.max_z_accel * z_ratio)
def get_status(self, eventtime): def get_status(self, eventtime):
xy_home = "xy" if self.limit_xy2 >= 0. else "" xy_home = "xy" if self.limit_xy2 >= 0. else ""
z_home = "z" if self.limit_z[0] <= self.limit_z[1] else "" z_home = "z" if self.limit_z[0] <= self.limit_z[1] else ""

View File

@ -106,7 +106,7 @@ class RotaryDeltaKinematics:
# Normal XY move # Normal XY move
return return
if self.need_home: if self.need_home:
raise homing.EndstopMoveError(end_pos, "Must home first") raise move.move_error("Must home first")
end_z = end_pos[2] end_z = end_pos[2]
limit_xy2 = self.max_xy2 limit_xy2 = self.max_xy2
if end_z > self.limit_z: if end_z > self.limit_z:
@ -115,7 +115,7 @@ class RotaryDeltaKinematics:
# Move out of range - verify not a homing move # Move out of range - verify not a homing move
if (end_pos[:2] != self.home_position[:2] if (end_pos[:2] != self.home_position[:2]
or end_z < self.min_z or end_z > 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. limit_xy2 = -1.
if move.axes_d[2]: if move.axes_d[2]:
move.limit_speed(self.max_z_velocity, move.accel) move.limit_speed(self.max_z_velocity, move.accel)

View File

@ -54,6 +54,10 @@ class Move:
self.accel = min(self.accel, accel) self.accel = min(self.accel, accel)
self.delta_v2 = 2.0 * self.move_d * self.accel self.delta_v2 = 2.0 * self.move_d * self.accel
self.smooth_delta_v2 = min(self.smooth_delta_v2, self.delta_v2) 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): def calc_junction(self, prev_move):
if not self.is_kinematic_move or not prev_move.is_kinematic_move: if not self.is_kinematic_move or not prev_move.is_kinematic_move:
return return