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