homing: Create Homing class from gcode

Create the Homing class in the gcode handler instead of in the
kinematic classes.  This will make it easier to pass error messages
back to the user.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-18 11:27:16 -05:00
parent 9e1059afb4
commit 781cf608d7
5 changed files with 20 additions and 19 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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)