Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify kinematic set_position() and clear_homing_state() calls #6782

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions klippy/extras/force_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ def cmd_SET_KINEMATIC_POSITION(self, gcmd):
x = gcmd.get_float('X', curpos[0])
y = gcmd.get_float('Y', curpos[1])
z = gcmd.get_float('Z', curpos[2])
clear = gcmd.get('CLEAR', '').upper()
axes = ['X', 'Y', 'Z']
clear_axes = [axes.index(a) for a in axes if a in clear]
clear = gcmd.get('CLEAR', '').lower()
clear_axes = "".join([a for a in "xyz" if a in clear])
logging.info("SET_KINEMATIC_POSITION pos=%.3f,%.3f,%.3f clear=%s",
x, y, z, ','.join((axes[i] for i in clear_axes)))
toolhead.set_position([x, y, z, curpos[3]], homing_axes=(0, 1, 2))
toolhead.set_position([x, y, z, curpos[3]], homing_axes="xyz")
toolhead.get_kinematics().clear_homing_state(clear_axes)

def load_config(config):
Expand Down
5 changes: 3 additions & 2 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def home_rails(self, rails, forcepos, movepos):
# Notify of upcoming homing operation
self.printer.send_event("homing:home_rails_begin", self, rails)
# Alter kinematics class to think printer is at forcepos
homing_axes = [axis for axis in range(3) if forcepos[axis] is not None]
force_axes = [axis for axis in range(3) if forcepos[axis] is not None]
homing_axes = "".join(["xyz"[i] for i in force_axes])
startpos = self._fill_coord(forcepos)
homepos = self._fill_coord(movepos)
self.toolhead.set_position(startpos, homing_axes=homing_axes)
Expand Down Expand Up @@ -231,7 +232,7 @@ def home_rails(self, rails, forcepos, movepos):
+ self.adjust_pos.get(s.get_name(), 0.))
for s in kin.get_steppers()}
newpos = kin.calc_position(kin_spos)
for axis in homing_axes:
for axis in force_axes:
homepos[axis] = newpos[axis]
self.toolhead.set_position(homepos)

Expand Down
4 changes: 2 additions & 2 deletions klippy/extras/homing_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def cmd_G28(self, gcmd):
# Calculate forced position (if configured)
toolhead = self.printer.lookup_object('toolhead')
pos = toolhead.get_position()
homing_axes = []
homing_axes = ""
for axis, loc in enumerate(self.start_pos):
if loc is not None:
pos[axis] = loc
homing_axes.append(axis)
homing_axes += "xyz"[axis]
toolhead.set_position(pos, homing_axes=homing_axes)
# Perform homing
context = self.template.create_template_context()
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/manual_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def flush_step_generation(self):
self.sync_print_time()
def get_position(self):
return [self.rail.get_commanded_position(), 0., 0., 0.]
def set_position(self, newpos, homing_axes=()):
def set_position(self, newpos, homing_axes=""):
self.do_set_position(newpos[0])
def get_last_move_time(self):
self.sync_print_time()
Expand Down
4 changes: 2 additions & 2 deletions klippy/extras/safe_z_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def cmd_G28(self, gcmd):
if 'z' not in kin_status['homed_axes']:
# Always perform the z_hop if the Z axis is not homed
pos[2] = 0
toolhead.set_position(pos, homing_axes=[2])
toolhead.set_position(pos, homing_axes="z")
toolhead.manual_move([None, None, self.z_hop],
self.z_hop_speed)
toolhead.get_kinematics().clear_homing_state((2,))
toolhead.get_kinematics().clear_homing_state("z")
elif pos[2] < self.z_hop:
# If the Z axis is homed, and below z_hop, lift it to z_hop
toolhead.manual_move([None, None, self.z_hop],
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/stepper_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def motor_off(self):
print_time = toolhead.get_last_move_time()
for el in self.enable_lines.values():
el.motor_disable(print_time)
toolhead.get_kinematics().clear_homing_state("xyz")
self.printer.send_event("stepper_enable:motor_off", print_time)
toolhead.dwell(DISABLE_STALL_TIME)
def motor_debug_enable(self, stepper, enable):
Expand Down
15 changes: 6 additions & 9 deletions klippy/kinematics/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
self.printer.register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat('max_z_velocity', max_velocity,
Expand All @@ -67,16 +65,17 @@ def update_limits(self, i, range):
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):
rail.set_position(newpos)
for axis in homing_axes:
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
if self.dc_module and axis == self.dc_module.axis:
rail = self.dc_module.get_primary_rail().get_rail()
else:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.limits[i] = (1.0, -1.0)
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.limits[axis] = (1.0, -1.0)
def home_axis(self, homing_state, axis, rail):
# Determine movement
position_min, position_max = rail.get_range()
Expand All @@ -97,8 +96,6 @@ def home(self, homing_state):
self.dc_module.home(homing_state)
else:
self.home_axis(homing_state, axis, self.rails[axis])
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def _check_endstops(self, move):
end_pos = move.end_pos
for i in (0, 1, 2):
Expand Down
14 changes: 5 additions & 9 deletions klippy/kinematics/corexy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
config.get_printer().register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
Expand All @@ -41,12 +39,12 @@ def calc_position(self, stepper_positions):
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):
rail.set_position(newpos)
if i in homing_axes:
if "xyz"[i] in homing_axes:
self.limits[i] = rail.get_range()
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.limits[i] = (1.0, -1.0)
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.limits[axis] = (1.0, -1.0)
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
Expand All @@ -63,8 +61,6 @@ def home(self, homing_state):
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
# Perform homing
homing_state.home_rails([rail], forcepos, homepos)
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def _check_endstops(self, move):
end_pos = move.end_pos
for i in (0, 1, 2):
Expand Down
14 changes: 5 additions & 9 deletions klippy/kinematics/corexz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
config.get_printer().register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
Expand All @@ -41,12 +39,12 @@ def calc_position(self, stepper_positions):
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):
rail.set_position(newpos)
if i in homing_axes:
if "xyz"[i] in homing_axes:
self.limits[i] = rail.get_range()
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.limits[i] = (1.0, -1.0)
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.limits[axis] = (1.0, -1.0)
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
Expand All @@ -63,8 +61,6 @@ def home(self, homing_state):
forcepos[axis] += 1.5 * (position_max - hi.position_endstop)
# Perform homing
homing_state.home_rails([rail], forcepos, homepos)
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def _check_endstops(self, move):
end_pos = move.end_pos
for i in (0, 1, 2):
Expand Down
12 changes: 4 additions & 8 deletions klippy/kinematics/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def __init__(self, toolhead, config):
stepper_configs[2], need_position_minmax = False,
default_position_endstop=a_endstop)
self.rails = [rail_a, rail_b, rail_c]
config.get_printer().register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup max velocity
self.max_velocity, self.max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
Expand Down Expand Up @@ -90,7 +88,7 @@ def ratio_to_xy(ratio):
math.sqrt(self.very_slow_xy2)))
self.axes_min = toolhead.Coord(-max_xy, -max_xy, self.min_z, 0.)
self.axes_max = toolhead.Coord(max_xy, max_xy, self.max_z, 0.)
self.set_position([0., 0., 0.], ())
self.set_position([0., 0., 0.], "")
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def _actuator_to_cartesian(self, spos):
Expand All @@ -103,11 +101,11 @@ def set_position(self, newpos, homing_axes):
for rail in self.rails:
rail.set_position(newpos)
self.limit_xy2 = -1.
if tuple(homing_axes) == (0, 1, 2):
if homing_axes == "xyz":
self.need_home = False
def clear_homing_state(self, axes):
def clear_homing_state(self, clear_axes):
# Clearing homing state for each axis individually is not implemented
if 0 in axes or 1 in axes or 2 in axes:
if clear_axes:
self.limit_xy2 = -1
self.need_home = True
def home(self, homing_state):
Expand All @@ -116,8 +114,6 @@ def home(self, homing_state):
forcepos = list(self.home_position)
forcepos[2] = -1.5 * math.sqrt(max(self.arm2)-self.max_xy2)
homing_state.home_rails(self.rails, forcepos, self.home_position)
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def check_move(self, move):
end_pos = move.end_pos
end_xy2 = end_pos[0]**2 + end_pos[1]**2
Expand Down
19 changes: 8 additions & 11 deletions klippy/kinematics/deltesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
config.get_printer().register_event_handler(
"stepper_enable:motor_off", self._motor_off)
self.limits = [(1.0, -1.0)] * 3
# X axis limits
min_angle = config.getfloat('min_angle', MIN_ANGLE,
Expand Down Expand Up @@ -89,7 +87,7 @@ def __init__(self, toolhead, config):
self.axes_min = toolhead.Coord(*[l[0] for l in self.limits], e=0.)
self.axes_max = toolhead.Coord(*[l[1] for l in self.limits], e=0.)
self.homed_axis = [False] * 3
self.set_position([0., 0., 0.], ())
self.set_position([0., 0., 0.], "")
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def _actuator_to_cartesian(self, sp):
Expand All @@ -115,12 +113,13 @@ def calc_position(self, stepper_positions):
def set_position(self, newpos, homing_axes):
for rail in self.rails:
rail.set_position(newpos)
for n in homing_axes:
self.homed_axis[n] = True
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.homed_axis[i] = False
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
self.homed_axis[axis] = True
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.homed_axis[axis] = False
def home(self, homing_state):
homing_axes = homing_state.get_axes()
home_xz = 0 in homing_axes or 2 in homing_axes
Expand All @@ -146,8 +145,6 @@ def home(self, homing_state):
else:
forcepos[1] += 1.5 * (position_max - hi.position_endstop)
homing_state.home_rails([self.rails[2]], forcepos, homepos)
def _motor_off(self, print_time):
self.homed_axis = [False] * 3
def check_move(self, move):
limits = list(map(list, self.limits))
spos, epos = move.start_pos, move.end_pos
Expand Down
15 changes: 6 additions & 9 deletions klippy/kinematics/hybrid_corexy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
self.printer.register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
Expand All @@ -69,16 +67,17 @@ def update_limits(self, i, range):
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):
rail.set_position(newpos)
for axis in homing_axes:
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
if self.dc_module and axis == self.dc_module.axis:
rail = self.dc_module.get_primary_rail().get_rail()
else:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.limits[i] = (1.0, -1.0)
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.limits[axis] = (1.0, -1.0)
def home_axis(self, homing_state, axis, rail):
position_min, position_max = rail.get_range()
hi = rail.get_homing_info()
Expand All @@ -97,8 +96,6 @@ def home(self, homing_state):
self.dc_module.home(homing_state)
else:
self.home_axis(homing_state, axis, self.rails[axis])
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def _check_endstops(self, move):
end_pos = move.end_pos
for i in (0, 1, 2):
Expand Down
15 changes: 6 additions & 9 deletions klippy/kinematics/hybrid_corexz.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def __init__(self, toolhead, config):
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
toolhead.register_step_generator(s.generate_steps)
self.printer.register_event_handler("stepper_enable:motor_off",
self._motor_off)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
Expand All @@ -69,16 +67,17 @@ def update_limits(self, i, range):
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):
rail.set_position(newpos)
for axis in homing_axes:
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
if self.dc_module and axis == self.dc_module.axis:
rail = self.dc_module.get_primary_rail().get_rail()
else:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, axes):
for i, _ in enumerate(self.limits):
if i in axes:
self.limits[i] = (1.0, -1.0)
def clear_homing_state(self, clear_axes):
for axis, axis_name in enumerate("xyz"):
if axis_name in clear_axes:
self.limits[axis] = (1.0, -1.0)
def home_axis(self, homing_state, axis, rail):
position_min, position_max = rail.get_range()
hi = rail.get_homing_info()
Expand All @@ -97,8 +96,6 @@ def home(self, homing_state):
self.dc_module.home(homing_state)
else:
self.home_axis(homing_state, axis, self.rails[axis])
def _motor_off(self, print_time):
self.clear_homing_state((0, 1, 2))
def _check_endstops(self, move):
end_pos = move.end_pos
for i in (0, 1, 2):
Expand Down
2 changes: 1 addition & 1 deletion klippy/kinematics/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def calc_position(self, stepper_positions):
return [0, 0, 0]
def set_position(self, newpos, homing_axes):
pass
def clear_homing_state(self, axes):
def clear_homing_state(self, clear_axes):
pass
def home(self, homing_state):
pass
Expand Down
Loading