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

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