homing: Make sure to clean up homing state even if homing fails
Make sure to always call MCU_endstop.home_wait() if MCU_endstop.home_start() is invoked. Rename MCU_stepper.note_homing_triggered() to note_homing_end() and make sure it is always called if MCU_stepper.note_homing_start() is invoked. With these changes, MCU_endstop.home_finalize() is no longer needed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
7785d3a87d
commit
b340fdcc4a
|
@ -29,61 +29,69 @@ class Homing:
|
||||||
return thcoord
|
return thcoord
|
||||||
def retract(self, newpos, speed):
|
def retract(self, newpos, speed):
|
||||||
self.toolhead.move(self._fill_coord(newpos), speed)
|
self.toolhead.move(self._fill_coord(newpos), speed)
|
||||||
def home(self, forcepos, movepos, endstops, speed, second_home=False):
|
def set_homed_position(self, pos):
|
||||||
# Alter kinematics class to think printer is at forcepos
|
self.toolhead.set_position(self._fill_coord(pos))
|
||||||
self.toolhead.set_position(self._fill_coord(forcepos))
|
def homing_move(self, movepos, endstops, speed):
|
||||||
# Start homing and issue move
|
# Start endstop checking
|
||||||
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 / 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()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
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:
|
for mcu_endstop, name in endstops:
|
||||||
min_step_dist = min([s.get_step_dist()
|
min_step_dist = min([s.get_step_dist()
|
||||||
for s in mcu_endstop.get_steppers()])
|
for s in mcu_endstop.get_steppers()])
|
||||||
mcu_endstop.home_start(
|
mcu_endstop.home_start(
|
||||||
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
||||||
min_step_dist / speed)
|
min_step_dist / speed)
|
||||||
self.toolhead.move(self._fill_coord(movepos), speed)
|
# Issue move
|
||||||
|
error = None
|
||||||
|
try:
|
||||||
|
self.toolhead.move(self._fill_coord(movepos), speed)
|
||||||
|
except EndstopError as e:
|
||||||
|
error = "Error during homing move: %s" % (str(e),)
|
||||||
|
# Wait for endstops to trigger
|
||||||
move_end_print_time = self.toolhead.get_last_move_time()
|
move_end_print_time = self.toolhead.get_last_move_time()
|
||||||
self.toolhead.reset_print_time(print_time)
|
self.toolhead.reset_print_time(print_time)
|
||||||
for mcu_endstop, name in endstops:
|
|
||||||
mcu_endstop.home_finalize(move_end_print_time)
|
|
||||||
# Wait for endstops to trigger
|
|
||||||
for mcu_endstop, name in endstops:
|
for mcu_endstop, name in endstops:
|
||||||
try:
|
try:
|
||||||
mcu_endstop.home_wait()
|
mcu_endstop.home_wait(move_end_print_time)
|
||||||
except mcu_endstop.error as e:
|
except mcu_endstop.TimeoutError as e:
|
||||||
raise EndstopError("Failed to home stepper %s: %s" % (
|
if error is None:
|
||||||
name, str(e)))
|
error = "Failed to home %s: %s" % (name, str(e))
|
||||||
|
if error is not None:
|
||||||
|
raise EndstopError(error)
|
||||||
|
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))
|
||||||
|
# Add a CPU delay when homing a large axis
|
||||||
|
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 / 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)
|
||||||
|
# Setup for retract verification
|
||||||
|
self.toolhead.get_last_move_time()
|
||||||
|
start_mcu_pos = [(s, name, s.get_mcu_position())
|
||||||
|
for es, name in endstops for s in es.get_steppers()]
|
||||||
|
# Issue homing move
|
||||||
|
self.homing_move(movepos, endstops, speed)
|
||||||
# Verify retract led to some movement on second home
|
# Verify retract led to some movement on second home
|
||||||
if second_home and self.verify_retract:
|
if second_home and self.verify_retract:
|
||||||
for s, name, pos in start_mcu_pos:
|
for s, name, pos in start_mcu_pos:
|
||||||
if s.get_mcu_position() == pos:
|
if s.get_mcu_position() == pos:
|
||||||
raise EndstopError(
|
raise EndstopError(
|
||||||
"Endstop %s still triggered after retract" % (name,))
|
"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):
|
def query_endstops(print_time, query_flags, steppers):
|
||||||
if query_flags == "get_mcu_position":
|
if query_flags == "get_mcu_position":
|
||||||
# Only the commanded position is requested
|
# Only the commanded position is requested
|
||||||
return [(s.name.upper(), s.mcu_stepper.get_mcu_position())
|
return [(s.name.upper(), s.mcu_stepper.get_mcu_position())
|
||||||
for s in steppers]
|
for s in steppers]
|
||||||
for s in steppers:
|
|
||||||
for mcu_endstop, name in s.get_endstops():
|
|
||||||
mcu_endstop.query_endstop(print_time)
|
|
||||||
out = []
|
out = []
|
||||||
for s in steppers:
|
for s in steppers:
|
||||||
for mcu_endstop, name in s.get_endstops():
|
for mcu_endstop, name in s.get_endstops():
|
||||||
try:
|
mcu_endstop.query_endstop(print_time)
|
||||||
out.append((name, mcu_endstop.query_endstop_wait()))
|
for s in steppers:
|
||||||
except mcu_endstop.error as e:
|
for mcu_endstop, name in s.get_endstops():
|
||||||
raise EndstopError(str(e))
|
out.append((name, mcu_endstop.query_endstop_wait()))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
class EndstopError(Exception):
|
class EndstopError(Exception):
|
||||||
|
|
|
@ -79,14 +79,17 @@ class MCU_stepper:
|
||||||
self._stepqueue, homing_clock)
|
self._stepqueue, homing_clock)
|
||||||
if ret:
|
if ret:
|
||||||
raise error("Internal error in stepcompress")
|
raise error("Internal error in stepcompress")
|
||||||
def note_homing_finalized(self):
|
def note_homing_end(self, did_trigger=False):
|
||||||
ret = self._ffi_lib.stepcompress_set_homing(self._stepqueue, 0)
|
ret = self._ffi_lib.stepcompress_set_homing(self._stepqueue, 0)
|
||||||
if ret:
|
if ret:
|
||||||
raise error("Internal error in stepcompress")
|
raise error("Internal error in stepcompress")
|
||||||
|
if not did_trigger:
|
||||||
|
return
|
||||||
ret = self._ffi_lib.stepcompress_reset(self._stepqueue, 0)
|
ret = self._ffi_lib.stepcompress_reset(self._stepqueue, 0)
|
||||||
if ret:
|
if ret:
|
||||||
raise error("Internal error in stepcompress")
|
raise error("Internal error in stepcompress")
|
||||||
def note_homing_triggered(self):
|
if self._mcu.is_fileoutput():
|
||||||
|
return
|
||||||
cmd = self._get_position_cmd.encode(self._oid)
|
cmd = self._get_position_cmd.encode(self._oid)
|
||||||
params = self._mcu.send_with_response(cmd, 'stepper_position', self._oid)
|
params = self._mcu.send_with_response(cmd, 'stepper_position', self._oid)
|
||||||
pos = params['pos']
|
pos = params['pos']
|
||||||
|
@ -131,7 +134,8 @@ class MCU_stepper:
|
||||||
self._commanded_pos += count
|
self._commanded_pos += count
|
||||||
|
|
||||||
class MCU_endstop:
|
class MCU_endstop:
|
||||||
error = error
|
class TimeoutError(Exception):
|
||||||
|
pass
|
||||||
RETRY_QUERY = 1.000
|
RETRY_QUERY = 1.000
|
||||||
def __init__(self, mcu, pin_params):
|
def __init__(self, mcu, pin_params):
|
||||||
self._mcu = mcu
|
self._mcu = mcu
|
||||||
|
@ -142,7 +146,7 @@ class MCU_endstop:
|
||||||
self._cmd_queue = mcu.alloc_command_queue()
|
self._cmd_queue = mcu.alloc_command_queue()
|
||||||
self._oid = self._home_cmd = self._query_cmd = None
|
self._oid = self._home_cmd = self._query_cmd = None
|
||||||
self._homing = False
|
self._homing = False
|
||||||
self._min_query_time = self._next_query_time = self._home_timeout = 0.
|
self._min_query_time = self._next_query_time = 0.
|
||||||
self._last_state = {}
|
self._last_state = {}
|
||||||
def get_mcu(self):
|
def get_mcu(self):
|
||||||
return self._mcu
|
return self._mcu
|
||||||
|
@ -182,36 +186,33 @@ class MCU_endstop:
|
||||||
self._mcu.send(msg, reqclock=clock, cq=self._cmd_queue)
|
self._mcu.send(msg, reqclock=clock, cq=self._cmd_queue)
|
||||||
for s in self._steppers:
|
for s in self._steppers:
|
||||||
s.note_homing_start(clock)
|
s.note_homing_start(clock)
|
||||||
def home_finalize(self, print_time):
|
def home_wait(self, home_end_time):
|
||||||
for s in self._steppers:
|
|
||||||
s.note_homing_finalized()
|
|
||||||
self._home_timeout = print_time
|
|
||||||
def home_wait(self):
|
|
||||||
eventtime = self._mcu.monotonic()
|
eventtime = self._mcu.monotonic()
|
||||||
while self._check_busy(eventtime):
|
while self._check_busy(eventtime, home_end_time):
|
||||||
eventtime = self._mcu.pause(eventtime + 0.1)
|
eventtime = self._mcu.pause(eventtime + 0.1)
|
||||||
def _handle_end_stop_state(self, params):
|
def _handle_end_stop_state(self, params):
|
||||||
logging.debug("end_stop_state %s", params)
|
logging.debug("end_stop_state %s", params)
|
||||||
self._last_state = params
|
self._last_state = params
|
||||||
def _check_busy(self, eventtime):
|
def _check_busy(self, eventtime, home_end_time=0.):
|
||||||
# Check if need to send an end_stop_query command
|
# Check if need to send an end_stop_query command
|
||||||
if self._mcu.is_fileoutput():
|
|
||||||
return False
|
|
||||||
print_time = self._mcu.estimated_print_time(eventtime)
|
print_time = self._mcu.estimated_print_time(eventtime)
|
||||||
last_sent_time = self._last_state.get('#sent_time', -1.)
|
last_sent_time = self._last_state.get('#sent_time', -1.)
|
||||||
if last_sent_time >= self._min_query_time:
|
if last_sent_time >= self._min_query_time or self._mcu.is_fileoutput():
|
||||||
if not self._homing:
|
if not self._homing:
|
||||||
return False
|
return False
|
||||||
if not self._last_state.get('homing', 0):
|
if not self._last_state.get('homing', 0):
|
||||||
for s in self._steppers:
|
for s in self._steppers:
|
||||||
s.note_homing_triggered()
|
s.note_homing_end(did_trigger=True)
|
||||||
self._homing = False
|
self._homing = False
|
||||||
return False
|
return False
|
||||||
if print_time > self._home_timeout:
|
if print_time > home_end_time:
|
||||||
# Timeout - disable endstop checking
|
# Timeout - disable endstop checking
|
||||||
|
for s in self._steppers:
|
||||||
|
s.note_homing_end()
|
||||||
|
self._homing = False
|
||||||
msg = self._home_cmd.encode(self._oid, 0, 0, 0, 0, 0)
|
msg = self._home_cmd.encode(self._oid, 0, 0, 0, 0, 0)
|
||||||
self._mcu.send(msg, reqclock=0, cq=self._cmd_queue)
|
self._mcu.send(msg, reqclock=0, cq=self._cmd_queue)
|
||||||
raise error("Timeout during endstop homing")
|
raise self.TimeoutError("Timeout during endstop homing")
|
||||||
if self._mcu.is_shutdown():
|
if self._mcu.is_shutdown():
|
||||||
raise error("MCU is shutdown")
|
raise error("MCU is shutdown")
|
||||||
if print_time >= self._next_query_time:
|
if print_time >= self._next_query_time:
|
||||||
|
|
Loading…
Reference in New Issue