homing: Pass list of endstops (not steppers) to the homing code

The homing code wants the list of endstops to enable during a homing
operation - it's confusing to pass the steppers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-12-05 21:51:44 -05:00
parent 31db4cc772
commit 7785d3a87d
6 changed files with 40 additions and 39 deletions

View File

@ -51,14 +51,14 @@ class CartKinematics:
homepos[axis] = s.position_endstop
coord = [None, None, None, None]
coord[axis] = pos
homing_state.home(list(coord), homepos, [s], homing_speed)
homing_state.home(coord, homepos, s.get_endstops(), homing_speed)
# Retract
coord[axis] = rpos
homing_state.retract(list(coord), homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[axis] = r2pos
homing_state.home(
list(coord), homepos, [s], homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, s.get_endstops(),
homing_speed/2.0, second_home=True)
# Set final homed position
coord[axis] = s.position_endstop + s.get_homed_offset()
homing_state.set_homed_position(coord)

View File

@ -59,14 +59,14 @@ class CoreXYKinematics:
homepos[axis] = s.position_endstop
coord = [None, None, None, None]
coord[axis] = pos
homing_state.home(list(coord), homepos, [s], homing_speed)
homing_state.home(coord, homepos, s.get_endstops(), homing_speed)
# Retract
coord[axis] = rpos
homing_state.retract(list(coord), homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[axis] = r2pos
homing_state.home(
list(coord), homepos, [s], homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, s.get_endstops(),
homing_speed/2.0, second_home=True)
if axis == 2:
# Support endstop phase detection on Z axis
coord[axis] = s.position_endstop + s.get_homed_offset()

View File

@ -102,6 +102,7 @@ class DeltaKinematics:
def home(self, homing_state):
# All axes are homed simultaneously
homing_state.set_axes([0, 1, 2])
endstops = [es for s in self.steppers for es in s.get_endstops()]
s = self.steppers[0] # Assume homing speed same for all steppers
self.need_home = False
# Initial homing
@ -109,14 +110,14 @@ class DeltaKinematics:
homepos = [0., 0., self.max_z, None]
coord = list(homepos)
coord[2] = -1.5 * math.sqrt(self.arm_length2-self.max_xy2)
homing_state.home(list(coord), homepos, self.steppers, homing_speed)
homing_state.home(coord, homepos, endstops, homing_speed)
# Retract
coord[2] = homepos[2] - s.homing_retract_dist
homing_state.retract(list(coord), homing_speed)
homing_state.retract(coord, homing_speed)
# Home again
coord[2] -= s.homing_retract_dist
homing_state.home(list(coord), homepos, self.steppers
, homing_speed/2.0, second_home=True)
homing_state.home(coord, homepos, endstops,
homing_speed/2.0, second_home=True)
# Set final homed position
spos = self._cartesian_to_actuator(homepos)
spos = [spos[i] + self.steppers[i].position_endstop - self.max_z

View File

@ -29,58 +29,57 @@ class Homing:
return thcoord
def retract(self, newpos, speed):
self.toolhead.move(self._fill_coord(newpos), speed)
def home(self, forcepos, movepos, steppers, speed, second_home=False):
def home(self, forcepos, movepos, endstops, speed, second_home=False):
# Alter kinematics class to think printer is at forcepos
self.toolhead.set_position(self._fill_coord(forcepos))
# Start homing and issue move
if not second_home:
est_move_d = sum([abs(forcepos[i]-movepos[i])
for i in range(3) if movepos[i] is not None])
est_steps = sum(
[est_move_d / mcu_stepper.get_step_dist()
for s in steppers
for mcu_endstop, mcu_stepper, name in s.get_endstops()])
est_steps = sum([est_move_d / s.get_step_dist()
for es, n in endstops for s in es.get_steppers()])
self.toolhead.dwell(est_steps * HOMING_STEP_DELAY, check_stall=False)
print_time = self.toolhead.get_last_move_time()
endstops = []
for s in steppers:
for mcu_endstop, mcu_stepper, name in s.get_endstops():
mcu_endstop.home_start(
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
mcu_stepper.get_step_dist() / speed)
endstops.append((mcu_endstop, mcu_stepper, name,
mcu_stepper.get_mcu_position()))
start_mcu_pos = [(s, name, s.get_mcu_position())
for es, name in endstops for s in es.get_steppers()]
for mcu_endstop, name in endstops:
min_step_dist = min([s.get_step_dist()
for s in mcu_endstop.get_steppers()])
mcu_endstop.home_start(
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
min_step_dist / speed)
self.toolhead.move(self._fill_coord(movepos), speed)
move_end_print_time = self.toolhead.get_last_move_time()
self.toolhead.reset_print_time(print_time)
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
for mcu_endstop, name in endstops:
mcu_endstop.home_finalize(move_end_print_time)
# Wait for endstops to trigger
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
for mcu_endstop, name in endstops:
try:
mcu_endstop.home_wait()
except mcu_endstop.error as e:
raise EndstopError("Failed to home stepper %s: %s" % (
name, str(e)))
post_home_pos = mcu_stepper.get_mcu_position()
if second_home and self.verify_retract and last_pos == post_home_pos:
raise EndstopError("Endstop %s still triggered after retract" % (
name,))
# Verify retract led to some movement on second home
if second_home and self.verify_retract:
for s, name, pos in start_mcu_pos:
if s.get_mcu_position() == pos:
raise EndstopError(
"Endstop %s still triggered after retract" % (name,))
def set_homed_position(self, pos):
self.toolhead.set_position(self._fill_coord(pos))
def query_endstops(print_time, query_flags, steppers):
if query_flags == "get_mcu_position":
# Only the commanded position is requested
return [(name.upper(), mcu_stepper.get_mcu_position())
for s in steppers
for mcu_endstop, mcu_stepper, name in s.get_endstops()]
return [(s.name.upper(), s.mcu_stepper.get_mcu_position())
for s in steppers]
for s in steppers:
for mcu_endstop, mcu_stepper, name in s.get_endstops():
for mcu_endstop, name in s.get_endstops():
mcu_endstop.query_endstop(print_time)
out = []
for s in steppers:
for mcu_endstop, mcu_stepper, name in s.get_endstops():
for mcu_endstop, name in s.get_endstops():
try:
out.append((name, mcu_endstop.query_endstop_wait()))
except mcu_endstop.error as e:

View File

@ -150,6 +150,8 @@ class MCU_endstop:
if stepper.get_mcu() is not self._mcu:
raise pins.error("Endstop and stepper must be on the same mcu")
self._steppers.append(stepper)
def get_steppers(self):
return list(self._steppers)
def build_config(self):
self._oid = self._mcu.create_oid()
self._mcu.add_config_cmd(

View File

@ -118,7 +118,7 @@ class PrinterHomingStepper(PrinterStepper):
if self.mcu_endstop.get_mcu().is_fileoutput():
self.homing_endstop_accuracy = self.homing_stepper_phases
def get_endstops(self):
return [(self.mcu_endstop, self.mcu_stepper, self.name)]
return [(self.mcu_endstop, self.name)]
def get_homing_speed(self):
# Round the configured homing speed so that it is an even
# number of ticks per step.
@ -162,8 +162,7 @@ class PrinterMultiStepper(PrinterHomingStepper):
if extraendstop is not None:
mcu_endstop = pins.setup_pin(printer, 'endstop', extraendstop)
mcu_endstop.add_stepper(extra.mcu_stepper)
self.endstops.append(
(mcu_endstop, extra.mcu_stepper, extra.name))
self.endstops.append((mcu_endstop, extra.name))
else:
self.mcu_endstop.add_stepper(extra.mcu_stepper)
self.step_const = self.step_multi_const