diff --git a/klippy/cartesian.py b/klippy/cartesian.py index b7b4a9ab..c1cddc7d 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -31,10 +31,9 @@ class CartKinematics: def get_homed_position(self): return [s.position_endstop + s.get_homed_offset()*s.step_dist for s in self.steppers] - def home(self, toolhead, axes): + def home(self, homing_state): # Each axis is homed independently and in order - homing_state = homing.Homing(toolhead, axes) - for axis in axes: + for axis in homing_state.get_axes(): s = self.steppers[axis] self.limits[axis] = (s.position_min, s.position_max) # Determine moves @@ -60,7 +59,6 @@ class CartKinematics: # Home again coord[axis] = r2pos homing_state.plan_home(list(coord), homepos, [s], s.homing_speed/2.0) - return homing_state def motor_off(self, move_time): self.limits = [(1.0, -1.0)] * 3 for stepper in self.steppers: diff --git a/klippy/delta.py b/klippy/delta.py index 8f5bd409..34b5a9e2 100644 --- a/klippy/delta.py +++ b/klippy/delta.py @@ -83,9 +83,9 @@ class DeltaKinematics: * self.steppers[i].step_dist for i in StepList] return self.actuator_to_cartesian(pos) - def home(self, toolhead, axes): + def home(self, homing_state): # All axes are homed simultaneously - homing_state = homing.Homing(toolhead, [0, 1, 2]) + homing_state.set_axes([0, 1, 2]) s = self.steppers[0] # Assume homing parameters same for all steppers self.limit_xy2 = self.max_xy2 # Initial homing @@ -101,7 +101,6 @@ class DeltaKinematics: coord[2] -= s.homing_retract_dist homing_state.plan_home(list(coord), homepos, self.steppers , s.homing_speed/2.0) - return homing_state def motor_off(self, move_time): self.limit_xy2 = -1. for stepper in self.steppers: diff --git a/klippy/gcode.py b/klippy/gcode.py index 97f88563..5262676a 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -250,14 +250,15 @@ class GCodeParser: axes.append(self.axis2pos[axis]) if not axes: axes = [0, 1, 2] - busy_handler = self.toolhead.home(axes) - def axes_update(axes): + homing_state = homing.Homing(self.toolhead, axes) + self.toolhead.home(homing_state) + def axes_update(homing_state): newpos = self.toolhead.get_position() - for axis in axes: + for axis in homing_state.get_axes(): self.last_position[axis] = newpos[axis] self.base_position[axis] = -self.homing_add[axis] - busy_handler.plan_axes_update(axes_update) - self.set_busy(busy_handler) + homing_state.plan_axes_update(axes_update) + self.set_busy(homing_state) def cmd_G90(self, params): # Use absolute coordinates self.absolutecoord = True diff --git a/klippy/homing.py b/klippy/homing.py index 117080f1..29c1a48f 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -14,13 +14,17 @@ class Homing: self.eventtime = 0. self.states = [] self.endstops = [] + def set_axes(self, axes): + self.changed_axes = axes + def get_axes(self): + return self.changed_axes def plan_home(self, forcepos, movepos, steppers, speed): self.states.append((self.do_home, (forcepos, movepos, steppers, speed))) self.states.append((self.do_wait_endstop, ())) def plan_move(self, newpos, speed): self.states.append((self.do_move, (newpos, speed))) def plan_axes_update(self, callback): - self.states.append((callback, (self.changed_axes,))) + self.states.append((callback, (self,))) def check_busy(self, eventtime): self.eventtime = eventtime while self.states: diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 91bcd87f..bc0356dc 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -259,16 +259,15 @@ class ToolHead: self.extruder.check_move(move) self.commanded_pos[:] = newpos self.move_queue.add_move(move) - def home(self, axes): - homing = self.kin.home(self, axes) - def axes_update(axes): + def home(self, homing_state): + self.kin.home(homing_state) + def axes_update(homing_state): pos = self.get_position() homepos = self.kin.get_homed_position() - for axis in axes: + for axis in homing_state.get_axes(): pos[axis] = homepos[axis] self.set_position(pos) - homing.plan_axes_update(axes_update) - return homing + homing_state.plan_axes_update(axes_update) def dwell(self, delay): self.get_last_move_time() self.update_move_time(delay)