probe: Create a probe:z_virtual_endstop pin

Create a virtual pin that may be used as the z endstop pin on
cartesian printers that use the probe in place of a z endstop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-01-23 12:47:28 -05:00
parent e38c7df064
commit 01bb4b291e
2 changed files with 20 additions and 2 deletions

View File

@ -2,11 +2,18 @@
# additional devices that may be configured on a printer. The snippets # additional devices that may be configured on a printer. The snippets
# in this file may be copied into the main printer.cfg file. See the # in this file may be copied into the main printer.cfg file. See the
# "example.cfg" file for description of common config parameters. # "example.cfg" file for description of common config parameters.
#
# Note, where an extra config section creates additional pins, the
# section defining the pins must be listed in the config file before
# any sections using those pins.
# Z height probe. One may define this section to enable Z height # Z height probe. One may define this section to enable Z height
# probing hardware. When this section is enabled, PROBE and # probing hardware. When this section is enabled, PROBE and
# QUERY_PROBE extended g-code commands become available. # QUERY_PROBE extended g-code commands become available. The probe
# section also creates a virtual probe:z_virtual_endstop pin. One may
# set the stepper_z endstop_pin to this virtual pin on cartesian style
# printers that use the probe in place of a z endstop.
#[probe] #[probe]
#pin: ar15 #pin: ar15
# Probe detection pin. This parameter must be provided. # Probe detection pin. This parameter must be provided.

View File

@ -4,13 +4,14 @@
# #
# 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 logging import logging
import homing import pins, homing
class PrinterProbe: class PrinterProbe:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
self.speed = config.getfloat('speed', 5.0) self.speed = config.getfloat('speed', 5.0)
self.z_position = config.getfloat('z_position', 0.) self.z_position = config.getfloat('z_position', 0.)
# Create an "endstop" object to handle the probe pin
ppins = self.printer.lookup_object('pins') ppins = self.printer.lookup_object('pins')
pin_params = ppins.lookup_pin('endstop', config.get('pin')) pin_params = ppins.lookup_pin('endstop', config.get('pin'))
mcu = pin_params['chip'] mcu = pin_params['chip']
@ -19,6 +20,9 @@ class PrinterProbe:
if (config.get('activate_gcode', None) is not None or if (config.get('activate_gcode', None) is not None or
config.get('deactivate_gcode', None) is not None): config.get('deactivate_gcode', None) is not None):
self.mcu_probe = ProbeEndstopWrapper(config, self.mcu_probe) self.mcu_probe = ProbeEndstopWrapper(config, self.mcu_probe)
# Create z_virtual_endstop pin
ppins.register_chip('probe', self)
# Register PROBE/QUERY_PROBE commands
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command( self.gcode.register_command(
'PROBE', self.cmd_PROBE, desc=self.cmd_PROBE_help) 'PROBE', self.cmd_PROBE, desc=self.cmd_PROBE_help)
@ -31,6 +35,13 @@ class PrinterProbe:
for mcu_endstop, name in s.get_endstops(): for mcu_endstop, name in s.get_endstops():
for mcu_stepper in mcu_endstop.get_steppers(): for mcu_stepper in mcu_endstop.get_steppers():
self.mcu_probe.add_stepper(mcu_stepper) self.mcu_probe.add_stepper(mcu_stepper)
def setup_pin(self, pin_params):
if (pin_params['pin'] != 'z_virtual_endstop'
or pin_params['type'] != 'endstop'):
raise pins.error("Probe virtual endstop only useful as endstop pin")
if pin_params['invert'] or pin_params['pullup']:
raise pins.error("Can not pullup/invert probe virtual endstop")
return self.mcu_probe
cmd_PROBE_help = "Probe Z-height at current XY position" cmd_PROBE_help = "Probe Z-height at current XY position"
def cmd_PROBE(self, params): def cmd_PROBE(self, params):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')