2016-05-25 17:37:40 +02:00
|
|
|
# Code for state tracking during homing operations
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
import logging
|
|
|
|
|
|
|
|
class Homing:
|
2016-07-26 05:47:30 +02:00
|
|
|
def __init__(self, toolhead, changed_axes):
|
2016-07-07 20:23:48 +02:00
|
|
|
self.toolhead = toolhead
|
2016-07-26 05:47:30 +02:00
|
|
|
self.changed_axes = changed_axes
|
2016-11-28 17:23:26 +01:00
|
|
|
self.verify_retract = True
|
|
|
|
def set_no_verify_retract(self):
|
|
|
|
self.verify_retract = False
|
2016-11-18 17:27:16 +01:00
|
|
|
def set_axes(self, axes):
|
|
|
|
self.changed_axes = axes
|
|
|
|
def get_axes(self):
|
|
|
|
return self.changed_axes
|
2016-12-09 00:12:20 +01:00
|
|
|
def _fill_coord(self, coord):
|
2016-07-26 05:47:30 +02:00
|
|
|
# Fill in any None entries in 'coord' with current toolhead position
|
2016-11-18 17:49:05 +01:00
|
|
|
thcoord = list(self.toolhead.get_position())
|
2016-07-26 05:47:30 +02:00
|
|
|
for i in range(len(coord)):
|
2016-11-18 17:49:05 +01:00
|
|
|
if coord[i] is not None:
|
|
|
|
thcoord[i] = coord[i]
|
|
|
|
return thcoord
|
2016-12-09 00:12:20 +01:00
|
|
|
def retract(self, newpos, speed):
|
|
|
|
self.toolhead.move(self._fill_coord(newpos), speed)
|
|
|
|
def home(self, forcepos, movepos, steppers, speed, second_home=False):
|
2016-07-26 05:47:30 +02:00
|
|
|
# Alter kinematics class to think printer is at forcepos
|
2016-12-09 00:12:20 +01:00
|
|
|
self.toolhead.set_position(self._fill_coord(forcepos))
|
2016-05-25 17:37:40 +02:00
|
|
|
# Start homing and issue move
|
2016-07-07 20:23:48 +02:00
|
|
|
print_time = self.toolhead.get_last_move_time()
|
2016-12-09 00:12:20 +01:00
|
|
|
endstops = []
|
2016-07-26 05:47:30 +02:00
|
|
|
for s in steppers:
|
2016-08-24 22:42:25 +02:00
|
|
|
es = s.enable_endstop_checking(print_time, s.step_dist / speed)
|
2016-12-09 00:12:20 +01:00
|
|
|
endstops.append((s, es, s.mcu_stepper.get_mcu_position()))
|
|
|
|
self.toolhead.move(self._fill_coord(movepos), speed)
|
2016-11-18 19:03:40 +01:00
|
|
|
move_end_print_time = self.toolhead.get_last_move_time()
|
2016-07-07 20:23:48 +02:00
|
|
|
self.toolhead.reset_print_time()
|
2016-12-09 00:12:20 +01:00
|
|
|
for s, es, last_pos in endstops:
|
2016-11-18 19:03:40 +01:00
|
|
|
es.home_finalize(es.print_to_mcu_time(move_end_print_time))
|
2016-12-09 00:12:20 +01:00
|
|
|
# Wait for endstops to trigger
|
|
|
|
for s, es, last_pos in endstops:
|
2016-11-18 19:03:40 +01:00
|
|
|
try:
|
2016-12-09 00:12:20 +01:00
|
|
|
es.home_wait()
|
2017-06-10 05:32:49 +02:00
|
|
|
except es.error as e:
|
2016-11-18 19:03:40 +01:00
|
|
|
raise EndstopError("Failed to home stepper %s: %s" % (
|
2016-12-09 00:12:20 +01:00
|
|
|
s.name, str(e)))
|
|
|
|
post_home_pos = s.mcu_stepper.get_mcu_position()
|
|
|
|
if second_home and self.verify_retract and last_pos == post_home_pos:
|
2016-11-18 19:39:48 +01:00
|
|
|
raise EndstopError("Endstop %s still triggered after retract" % (
|
2016-12-09 00:12:20 +01:00
|
|
|
s.name,))
|
|
|
|
def set_homed_position(self, pos):
|
|
|
|
self.toolhead.set_position(self._fill_coord(pos))
|
2016-09-22 17:09:20 +02:00
|
|
|
|
2016-09-30 22:00:32 +02:00
|
|
|
class EndstopError(Exception):
|
2016-11-30 00:27:48 +01:00
|
|
|
pass
|
2016-11-18 18:42:39 +01:00
|
|
|
|
|
|
|
def EndstopMoveError(pos, msg="Move out of range"):
|
|
|
|
return EndstopError("%s: %.3f %.3f %.3f [%.3f]" % (
|
|
|
|
msg, pos[0], pos[1], pos[2], pos[3]))
|