From 36832739369ab2f66beb1bad732523b5c3687ff7 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 24 Nov 2019 19:16:21 -0500 Subject: [PATCH] toolhead: Report which axes are homed via get_status() Signed-off-by: Kevin O'Connor --- docs/Command_Templates.md | 3 +++ klippy/extras/safe_z_home.py | 6 +++--- klippy/kinematics/cartesian.py | 7 +++---- klippy/kinematics/corexy.py | 7 +++---- klippy/kinematics/delta.py | 4 ++-- klippy/kinematics/none.py | 2 +- klippy/kinematics/polar.py | 7 ++++--- klippy/kinematics/winch.py | 4 ++-- klippy/toolhead.py | 12 +++++++----- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/docs/Command_Templates.md b/docs/Command_Templates.md index 07026093..c95ebea4 100644 --- a/docs/Command_Templates.md +++ b/docs/Command_Templates.md @@ -157,6 +157,9 @@ The following are common printer attributes: extruder. For example, one could use `printer[printer.toolhead.extruder].target` to get the target temperature of the current extruder. +- `printer.toolhead.homed_axes`: The current cartesian axes considered + to be in a "homed" state. This is a string containing one or more of + "x", "y", "z". The above list is subject to change - if using an attribute be sure to review the [Config Changes document](Config_Changes.md) when upgrading diff --git a/klippy/extras/safe_z_home.py b/klippy/extras/safe_z_home.py index a392535b..a49f6b9a 100644 --- a/klippy/extras/safe_z_home.py +++ b/klippy/extras/safe_z_home.py @@ -30,14 +30,14 @@ class SafeZHoming: def cmd_G28(self, params): toolhead = self.printer.lookup_object('toolhead') - kinematics = toolhead.get_kinematics() # Perform Z Hop if necessary if self.z_hop != 0.0: pos = toolhead.get_position() - kin_status = kinematics.get_status() + curtime = self.printer.get_reactor().monotonic() + kin_status = toolhead.get_kinematics().get_status(curtime) # Check if Z axis is homed or has a known position - if 'Z' in kin_status['homed_axes']: + if 'z' in kin_status['homed_axes']: # Check if the zhop would exceed the printer limits if pos[2] + self.z_hop > self.max_z: self.gcode.respond_info( diff --git a/klippy/kinematics/cartesian.py b/klippy/kinematics/cartesian.py index ee65d4ba..c44ad857 100644 --- a/klippy/kinematics/cartesian.py +++ b/klippy/kinematics/cartesian.py @@ -116,10 +116,9 @@ class CartKinematics: 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) - def get_status(self): - return {'homed_axes': "".join([a - for a, (l, h) in zip("XYZ", self.limits) if l <= h]) - } + def get_status(self, eventtime): + axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h] + return { 'homed_axes': "".join(axes) } # Dual carriage support def _activate_carriage(self, carriage): toolhead = self.printer.lookup_object('toolhead') diff --git a/klippy/kinematics/corexy.py b/klippy/kinematics/corexy.py index aa88406d..98c66dd5 100644 --- a/klippy/kinematics/corexy.py +++ b/klippy/kinematics/corexy.py @@ -93,10 +93,9 @@ class CoreXYKinematics: 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) - def get_status(self): - return {'homed_axes': "".join([a - for a, (l, h) in zip("XYZ", self.limits) if l <= h]) - } + def get_status(self, eventtime): + axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h] + return {'homed_axes': "".join(axes)} def load_kinematics(toolhead, config): return CoreXYKinematics(toolhead, config) diff --git a/klippy/kinematics/delta.py b/klippy/kinematics/delta.py index ee01be56..73a987d3 100644 --- a/klippy/kinematics/delta.py +++ b/klippy/kinematics/delta.py @@ -144,8 +144,8 @@ class DeltaKinematics: move.limit_speed(max_velocity * r, self.max_accel * r) limit_xy2 = -1. self.limit_xy2 = min(limit_xy2, self.slow_xy2) - def get_status(self): - return {'homed_axes': '' if self.need_home else 'XYZ'} + def get_status(self, eventtime): + return {'homed_axes': '' if self.need_home else 'xyz'} # Helper function for DELTA_CALIBRATE script def get_calibrate_params(self): diff --git a/klippy/kinematics/none.py b/klippy/kinematics/none.py index 6fe9884f..7df1010a 100644 --- a/klippy/kinematics/none.py +++ b/klippy/kinematics/none.py @@ -17,7 +17,7 @@ class NoneKinematics: pass def check_move(self, move): pass - def get_status(self): + def get_status(self, eventtime): return {'homed_axes': ''} def load_kinematics(toolhead, config): diff --git a/klippy/kinematics/polar.py b/klippy/kinematics/polar.py index 3a043ab3..4201978d 100644 --- a/klippy/kinematics/polar.py +++ b/klippy/kinematics/polar.py @@ -104,9 +104,10 @@ class PolarKinematics: 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) - def get_status(self): - return {'homed_axes': (("XY" if self.limit_xy2 >= 0. else "") + - ("Z" if self.limit_z[0] <= self.limit_z[1] else ""))} + 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 "" + return {'homed_axes': xy_home + z_home} def load_kinematics(toolhead, config): return PolarKinematics(toolhead, config) diff --git a/klippy/kinematics/winch.py b/klippy/kinematics/winch.py index 6792dbd7..37494c4e 100644 --- a/klippy/kinematics/winch.py +++ b/klippy/kinematics/winch.py @@ -45,9 +45,9 @@ class WinchKinematics: def check_move(self, move): # XXX - boundary checks and speed limits not implemented pass - def get_status(self): + def get_status(self, eventtime): # XXX - homed_checks and rail limits not implemented - return {'homed_axes': 'XYZ'} + return {'homed_axes': 'xyz'} def load_kinematics(toolhead, config): return WinchKinematics(toolhead, config) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 55f1bb36..51d39148 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -482,11 +482,13 @@ class ToolHead: status = "Printing" else: status = "Ready" - return { 'status': status, 'print_time': print_time, - 'estimated_print_time': estimated_print_time, - 'extruder': self.extruder.get_name(), - 'position': homing.Coord(*self.commanded_pos), - 'printing_time': print_time - last_print_start_time } + res = dict(self.kin.get_status(eventtime)) + res.update({ 'status': status, 'print_time': print_time, + 'estimated_print_time': estimated_print_time, + 'extruder': self.extruder.get_name(), + 'position': homing.Coord(*self.commanded_pos), + 'printing_time': print_time - last_print_start_time }) + return res def _handle_shutdown(self): self.can_pause = False self.move_queue.reset()