2018-01-22 20:33:25 +03:00
|
|
|
# Run user defined actions in place of a normal G28 homing command
|
|
|
|
#
|
|
|
|
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
class HomingOverride:
|
|
|
|
def __init__(self, config):
|
2018-01-17 02:58:41 +03:00
|
|
|
self.printer = config.get_printer()
|
|
|
|
self.start_pos = [config.getfloat('set_position_' + a, None)
|
|
|
|
for a in 'xyz']
|
2018-06-10 15:23:40 +03:00
|
|
|
self.axes = config.get('axes', 'XYZ').upper()
|
2020-05-05 21:10:30 +03:00
|
|
|
gcode_macro = self.printer.load_object(config, 'gcode_macro')
|
2019-04-03 05:09:37 +03:00
|
|
|
self.template = gcode_macro.load_template(config, 'gcode')
|
2018-01-22 20:33:25 +03:00
|
|
|
self.in_script = False
|
2020-08-17 07:05:41 +03:00
|
|
|
self.printer.load_object(config, 'gcode_move')
|
2018-01-17 02:58:41 +03:00
|
|
|
self.gcode = self.printer.lookup_object('gcode')
|
2020-02-13 04:19:18 +03:00
|
|
|
self.prev_G28 = self.gcode.register_command("G28", None)
|
2018-01-22 20:33:25 +03:00
|
|
|
self.gcode.register_command("G28", self.cmd_G28)
|
2020-04-25 05:38:25 +03:00
|
|
|
def cmd_G28(self, gcmd):
|
2018-01-22 20:33:25 +03:00
|
|
|
if self.in_script:
|
|
|
|
# Was called recursively - invoke the real G28 command
|
2020-04-25 05:38:25 +03:00
|
|
|
self.prev_G28(gcmd)
|
2018-01-22 20:33:25 +03:00
|
|
|
return
|
2018-06-10 15:23:40 +03:00
|
|
|
|
|
|
|
# if no axis is given as parameter we assume the override
|
|
|
|
no_axis = True
|
|
|
|
for axis in 'XYZ':
|
2020-04-25 05:38:25 +03:00
|
|
|
if gcmd.get(axis, None) is not None:
|
2018-06-10 15:23:40 +03:00
|
|
|
no_axis = False
|
|
|
|
break
|
|
|
|
|
|
|
|
if no_axis:
|
|
|
|
override = True
|
|
|
|
else:
|
2020-08-05 18:43:45 +03:00
|
|
|
# check if we home an axis which needs the override
|
2018-06-10 15:23:40 +03:00
|
|
|
override = False
|
|
|
|
for axis in self.axes:
|
2020-04-25 05:38:25 +03:00
|
|
|
if gcmd.get(axis, None) is not None:
|
2018-06-10 15:23:40 +03:00
|
|
|
override = True
|
|
|
|
|
|
|
|
if not override:
|
2020-08-05 18:43:45 +03:00
|
|
|
self.prev_G28(gcmd)
|
2018-06-10 15:23:40 +03:00
|
|
|
return
|
|
|
|
|
2018-01-17 02:58:41 +03:00
|
|
|
# Calculate forced position (if configured)
|
|
|
|
toolhead = self.printer.lookup_object('toolhead')
|
|
|
|
pos = toolhead.get_position()
|
|
|
|
homing_axes = []
|
|
|
|
for axis, loc in enumerate(self.start_pos):
|
|
|
|
if loc is not None:
|
|
|
|
pos[axis] = loc
|
|
|
|
homing_axes.append(axis)
|
|
|
|
toolhead.set_position(pos, homing_axes=homing_axes)
|
|
|
|
# Perform homing
|
2020-08-16 22:39:30 +03:00
|
|
|
context = self.template.create_template_context()
|
|
|
|
context['params'] = gcmd.get_command_parameters()
|
2018-01-22 20:33:25 +03:00
|
|
|
try:
|
|
|
|
self.in_script = True
|
2020-08-16 22:39:30 +03:00
|
|
|
self.template.run_gcode_from_command(context)
|
2018-01-22 20:33:25 +03:00
|
|
|
finally:
|
|
|
|
self.in_script = False
|
|
|
|
|
|
|
|
def load_config(config):
|
|
|
|
return HomingOverride(config)
|