homing: Move homing logic from manual_stepper.py to homing.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
38719c1359
commit
37a263c0b9
|
@ -195,10 +195,11 @@ class BLTouchEndstopWrapper:
|
|||
for s, mcu_pos in self.start_mcu_pos:
|
||||
if s.get_mcu_position() == mcu_pos:
|
||||
raise self.printer.command_error("BLTouch failed to deploy")
|
||||
def home_start(self, print_time, sample_time, sample_count, rest_time):
|
||||
def home_start(self, print_time, sample_time, sample_count, rest_time,
|
||||
triggered=True):
|
||||
rest_time = min(rest_time, ENDSTOP_REST_TIME)
|
||||
return self.mcu_endstop.home_start(print_time, sample_time,
|
||||
sample_count, rest_time)
|
||||
sample_count, rest_time, triggered)
|
||||
def get_position_endstop(self):
|
||||
return self.position_endstop
|
||||
def set_output_mode(self, mode):
|
||||
|
|
|
@ -18,9 +18,12 @@ def multi_complete(printer, completions):
|
|||
|
||||
# Implementation of homing/probing moves
|
||||
class HomingMove:
|
||||
def __init__(self, printer):
|
||||
def __init__(self, printer, endstops, toolhead=None):
|
||||
self.printer = printer
|
||||
self.toolhead = printer.lookup_object('toolhead')
|
||||
self.endstops = endstops
|
||||
if toolhead is None:
|
||||
toolhead = printer.lookup_object('toolhead')
|
||||
self.toolhead = toolhead
|
||||
self.end_mcu_pos = []
|
||||
def _calc_endstop_rate(self, mcu_endstop, movepos, speed):
|
||||
startpos = self.toolhead.get_position()
|
||||
|
@ -34,24 +37,27 @@ class HomingMove:
|
|||
if max_steps <= 0.:
|
||||
return .001
|
||||
return move_t / max_steps
|
||||
def homing_move(self, movepos, endstops, speed, probe_pos=False):
|
||||
def homing_move(self, movepos, speed, probe_pos=False,
|
||||
triggered=True, check_triggered=True):
|
||||
# Notify start of homing/probing move
|
||||
self.printer.send_event("homing:homing_move_begin",
|
||||
[es for es, name in endstops])
|
||||
[es for es, name in self.endstops])
|
||||
# Note start location
|
||||
self.toolhead.flush_step_generation()
|
||||
kin = self.toolhead.get_kinematics()
|
||||
for s in kin.get_steppers():
|
||||
s.set_tag_position(s.get_commanded_position())
|
||||
start_mcu_pos = [(s, name, s.get_mcu_position())
|
||||
for es, name in endstops for s in es.get_steppers()]
|
||||
for es, name in self.endstops
|
||||
for s in es.get_steppers()]
|
||||
# Start endstop checking
|
||||
print_time = self.toolhead.get_last_move_time()
|
||||
endstop_triggers = []
|
||||
for mcu_endstop, name in endstops:
|
||||
for mcu_endstop, name in self.endstops:
|
||||
rest_time = self._calc_endstop_rate(mcu_endstop, movepos, speed)
|
||||
wait = mcu_endstop.home_start(print_time, ENDSTOP_SAMPLE_TIME,
|
||||
ENDSTOP_SAMPLE_COUNT, rest_time)
|
||||
ENDSTOP_SAMPLE_COUNT, rest_time,
|
||||
triggered=triggered)
|
||||
endstop_triggers.append(wait)
|
||||
all_endstop_trigger = multi_complete(self.printer, endstop_triggers)
|
||||
self.toolhead.dwell(HOMING_START_DELAY)
|
||||
|
@ -63,9 +69,9 @@ class HomingMove:
|
|||
error = "Error during homing move: %s" % (str(e),)
|
||||
# Wait for endstops to trigger
|
||||
move_end_print_time = self.toolhead.get_last_move_time()
|
||||
for mcu_endstop, name in endstops:
|
||||
for mcu_endstop, name in self.endstops:
|
||||
did_trigger = mcu_endstop.home_wait(move_end_print_time)
|
||||
if not did_trigger and error is None:
|
||||
if not did_trigger and check_triggered and error is None:
|
||||
error = "Failed to home %s: Timeout during homing" % (name,)
|
||||
# Determine stepper halt positions
|
||||
self.toolhead.flush_step_generation()
|
||||
|
@ -80,7 +86,7 @@ class HomingMove:
|
|||
# Signal homing/probing move complete
|
||||
try:
|
||||
self.printer.send_event("homing:homing_move_end",
|
||||
[es for es, name in endstops])
|
||||
[es for es, name in self.endstops])
|
||||
except self.printer.command_error as e:
|
||||
if error is None:
|
||||
error = str(e)
|
||||
|
@ -125,8 +131,8 @@ class Homing:
|
|||
# Perform first home
|
||||
endstops = [es for rail in rails for es in rail.get_endstops()]
|
||||
hi = rails[0].get_homing_info()
|
||||
hmove = HomingMove(self.printer)
|
||||
hmove.homing_move(movepos, endstops, hi.speed)
|
||||
hmove = HomingMove(self.printer, endstops)
|
||||
hmove.homing_move(movepos, hi.speed)
|
||||
# Perform second home
|
||||
if hi.retract_dist:
|
||||
# Retract
|
||||
|
@ -140,8 +146,8 @@ class Homing:
|
|||
forcepos = [rp - ad * retract_r
|
||||
for rp, ad in zip(retractpos, axes_d)]
|
||||
self.toolhead.set_position(forcepos)
|
||||
hmove = HomingMove(self.printer)
|
||||
hmove.homing_move(movepos, endstops, hi.second_homing_speed)
|
||||
hmove = HomingMove(self.printer, endstops)
|
||||
hmove.homing_move(movepos, hi.second_homing_speed)
|
||||
if hmove.check_no_movement() is not None:
|
||||
raise self.printer.command_error(
|
||||
"Endstop %s still triggered after retract"
|
||||
|
@ -165,10 +171,15 @@ class PrinterHoming:
|
|||
# Register g-code commands
|
||||
gcode = self.printer.lookup_object('gcode')
|
||||
gcode.register_command('G28', self.cmd_G28)
|
||||
def manual_home(self, toolhead, endstops, pos, speed,
|
||||
triggered, check_triggered):
|
||||
hmove = HomingMove(self.printer, endstops, toolhead)
|
||||
hmove.homing_move(pos, speed, triggered=triggered,
|
||||
check_triggered=check_triggered)
|
||||
def probing_move(self, mcu_probe, pos, speed):
|
||||
hmove = HomingMove(self.printer)
|
||||
endstops = [(mcu_probe, "probe")]
|
||||
epos = hmove.homing_move(pos, endstops, speed, probe_pos=True)
|
||||
hmove = HomingMove(self.printer, endstops)
|
||||
epos = hmove.homing_move(pos, speed, probe_pos=True)
|
||||
if hmove.check_no_movement() is not None:
|
||||
raise self.printer.command_error(
|
||||
"Probe triggered prior to movement")
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
# Support for a manual controlled stepper
|
||||
#
|
||||
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2019-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import stepper, chelper
|
||||
from . import force_move
|
||||
|
||||
ENDSTOP_SAMPLE_TIME = .000015
|
||||
ENDSTOP_SAMPLE_COUNT = 4
|
||||
|
||||
class ManualStepper:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
|
@ -22,7 +19,7 @@ class ManualStepper:
|
|||
self.rail = stepper.PrinterStepper(config)
|
||||
self.steppers = [self.rail]
|
||||
self.velocity = config.getfloat('velocity', 5., above=0.)
|
||||
self.accel = config.getfloat('accel', 0., minval=0.)
|
||||
self.accel = self.homing_accel = config.getfloat('accel', 0., minval=0.)
|
||||
self.next_cmd_time = 0.
|
||||
# Setup iterative solver
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
|
@ -80,37 +77,12 @@ class ManualStepper:
|
|||
if not self.can_home:
|
||||
raise self.printer.command_error(
|
||||
"No endstop for this manual stepper")
|
||||
# Notify start of homing/probing move
|
||||
self.homing_accel = accel
|
||||
pos = [movepos, 0., 0., 0.]
|
||||
endstops = self.rail.get_endstops()
|
||||
self.printer.send_event("homing:homing_move_begin",
|
||||
[es for es, name in endstops])
|
||||
# Start endstop checking
|
||||
self.sync_print_time()
|
||||
endstops = self.rail.get_endstops()
|
||||
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(
|
||||
self.next_cmd_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
|
||||
min_step_dist / speed, triggered=triggered)
|
||||
# Issue move
|
||||
self.do_move(movepos, speed, accel)
|
||||
# Wait for endstops to trigger
|
||||
error = None
|
||||
for mcu_endstop, name in endstops:
|
||||
did_trigger = mcu_endstop.home_wait(self.next_cmd_time)
|
||||
if not did_trigger and check_trigger and error is None:
|
||||
error = "Failed to home %s: Timeout during homing" % (name,)
|
||||
# Signal homing/probing move complete
|
||||
try:
|
||||
self.printer.send_event("homing:homing_move_end",
|
||||
[es for es, name in endstops])
|
||||
except CommandError as e:
|
||||
if error is None:
|
||||
error = str(e)
|
||||
self.sync_print_time()
|
||||
if error is not None:
|
||||
raise self.printer.command_error(error)
|
||||
phoming = self.printer.lookup_object('homing')
|
||||
phoming.manual_home(self, endstops, pos, speed,
|
||||
triggered, check_trigger)
|
||||
cmd_MANUAL_STEPPER_help = "Command a manually configured stepper"
|
||||
def cmd_MANUAL_STEPPER(self, gcmd):
|
||||
enable = gcmd.get_int('ENABLE', None)
|
||||
|
@ -132,6 +104,24 @@ class ManualStepper:
|
|||
self.do_move(movepos, speed, accel, sync)
|
||||
elif gcmd.get_int('SYNC', 0):
|
||||
self.sync_print_time()
|
||||
# Toolhead wrappers to support homing
|
||||
def flush_step_generation(self):
|
||||
self.sync_print_time()
|
||||
def get_position(self):
|
||||
return [self.rail.get_commanded_position(), 0., 0., 0.]
|
||||
def set_position(self, newpos, homing_axes=()):
|
||||
self.do_set_position(newpos[0])
|
||||
def get_last_move_time(self):
|
||||
self.sync_print_time()
|
||||
return self.next_cmd_time
|
||||
def dwell(self, delay):
|
||||
self.next_cmd_time += max(0., delay)
|
||||
def drip_move(self, newpos, speed, drip_completion):
|
||||
self.do_move(newpos[0], speed, self.homing_accel)
|
||||
def get_kinematics(self):
|
||||
return self
|
||||
def get_steppers(self):
|
||||
return self.steppers
|
||||
|
||||
def load_config_prefix(config):
|
||||
return ManualStepper(config)
|
||||
|
|
Loading…
Reference in New Issue