bltouch: Add a BLTOUCH_DEBUG command

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-12-03 22:52:32 -05:00
parent aac92ffb91
commit e0b2d7c51d
3 changed files with 44 additions and 13 deletions

View File

@ -153,6 +153,14 @@ enabled:
- `QUERY_PROBE`: Report the current status of the probe ("triggered" - `QUERY_PROBE`: Report the current status of the probe ("triggered"
or "open"). or "open").
## BLTouch
The following command is available when a "bltouch" config section is
enabled:
- `BLTOUCH_DEBUG COMMAND=<command>`: This sends a command to the
BLTouch. It may be useful for debugging. Available commands are:
pin_down, touch_mode, pin_up, self_test, reset.
## Delta Calibration ## Delta Calibration
The following commands are available when the "delta_calibrate" config The following commands are available when the "delta_calibrate" config

View File

@ -3,6 +3,7 @@
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> # Copyright (C) 2018 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 logging
import homing, probe import homing, probe
SIGNAL_PERIOD = 0.025600 SIGNAL_PERIOD = 0.025600
@ -13,11 +14,10 @@ TEST_TIME = 5 * 60.
ENDSTOP_SAMPLE_TIME = .000015 ENDSTOP_SAMPLE_TIME = .000015
ENDSTOP_SAMPLE_COUNT = 4 ENDSTOP_SAMPLE_COUNT = 4
CMD_PIN_DOWN = 0.000700 Commands = {
CMD_PIN_UP = 0.001500 None: 0.0, 'pin_down': 0.000700, 'touch_mode': 0.001200,
CMD_SELF_TEST = 0.001800 'pin_up': 0.001500, 'self_test': 0.001800, 'reset': 0.002200,
CMD_RESET = 0.002200 }
CMD_TOUCH_MODE = 0.001200
# BLTouch "endstop" wrapper # BLTouch "endstop" wrapper
class BLTouchEndstopWrapper: class BLTouchEndstopWrapper:
@ -45,12 +45,16 @@ class BLTouchEndstopWrapper:
self.query_endstop = self.mcu_endstop.query_endstop self.query_endstop = self.mcu_endstop.query_endstop
self.query_endstop_wait = self.mcu_endstop.query_endstop_wait self.query_endstop_wait = self.mcu_endstop.query_endstop_wait
self.TimeoutError = self.mcu_endstop.TimeoutError self.TimeoutError = self.mcu_endstop.TimeoutError
# Register BLTOUCH_DEBUG command
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("BLTOUCH_DEBUG", self.cmd_BLTOUCH_DEBUG,
desc=self.cmd_BLTOUCH_DEBUG_help)
def _build_config(self): def _build_config(self):
kin = self.printer.lookup_object('toolhead').get_kinematics() kin = self.printer.lookup_object('toolhead').get_kinematics()
for stepper in kin.get_steppers('Z'): for stepper in kin.get_steppers('Z'):
stepper.add_to_endstop(self) stepper.add_to_endstop(self)
def send_cmd(self, print_time, cmd): def send_cmd(self, print_time, cmd):
self.mcu_pwm.set_pwm(print_time, cmd / SIGNAL_PERIOD) self.mcu_pwm.set_pwm(print_time, Commands[cmd] / SIGNAL_PERIOD)
def test_sensor(self): def test_sensor(self):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time() print_time = toolhead.get_last_move_time()
@ -58,10 +62,10 @@ class BLTouchEndstopWrapper:
self.next_test_time = print_time + TEST_TIME self.next_test_time = print_time + TEST_TIME
return return
# Raise the bltouch probe and test if probe is raised # Raise the bltouch probe and test if probe is raised
self.send_cmd(print_time, CMD_RESET) self.send_cmd(print_time, 'reset')
home_time = print_time + PIN_MOVE_TIME home_time = print_time + PIN_MOVE_TIME
self.send_cmd(home_time, CMD_TOUCH_MODE) self.send_cmd(home_time, 'touch_mode')
self.send_cmd(home_time + MIN_CMD_TIME, 0.) self.send_cmd(home_time + MIN_CMD_TIME, None)
# Perform endstop check to verify bltouch reports probe raised # Perform endstop check to verify bltouch reports probe raised
prev_positions = [s.get_commanded_position() prev_positions = [s.get_commanded_position()
for s in self.mcu_endstop.get_steppers()] for s in self.mcu_endstop.get_steppers()]
@ -80,19 +84,34 @@ class BLTouchEndstopWrapper:
self.test_sensor() self.test_sensor()
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time() print_time = toolhead.get_last_move_time()
self.send_cmd(print_time, CMD_PIN_DOWN) self.send_cmd(print_time, 'pin_down')
self.send_cmd(print_time + PIN_MOVE_TIME, CMD_TOUCH_MODE) self.send_cmd(print_time + PIN_MOVE_TIME, 'touch_mode')
toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME) toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME)
self.mcu_endstop.home_prepare() self.mcu_endstop.home_prepare()
def home_finalize(self): def home_finalize(self):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time() print_time = toolhead.get_last_move_time()
self.send_cmd(print_time, CMD_RESET) self.send_cmd(print_time, 'reset')
self.send_cmd(print_time + PIN_MOVE_TIME, 0.) self.send_cmd(print_time + PIN_MOVE_TIME, None)
toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME) toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME)
self.mcu_endstop.home_finalize() self.mcu_endstop.home_finalize()
def get_position_endstop(self): def get_position_endstop(self):
return self.position_endstop return self.position_endstop
cmd_BLTOUCH_DEBUG_help = "Send a command to the bltouch for debugging"
def cmd_BLTOUCH_DEBUG(self, params):
cmd = self.gcode.get_str('COMMAND', params, None)
if cmd is None or cmd not in Commands:
self.gcode.respond_info("BLTouch commands: %s" % (
", ".join(sorted([c for c in Commands if c is not None]))))
return
toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time()
msg = "Sending BLTOUCH_DEBUG COMMAND=%s" % (cmd,)
self.gcode.respond_info(msg)
logging.info(msg)
self.send_cmd(print_time, cmd)
self.send_cmd(print_time + PIN_MOVE_TIME, None)
toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME)
def load_config(config): def load_config(config):
blt = BLTouchEndstopWrapper(config) blt = BLTouchEndstopWrapper(config)

View File

@ -11,6 +11,10 @@ G1 Z1
G1 X1 G1 X1
G1 Y1 G1 Y1
# Run BLTOUCH_DEBUG
BLTOUCH_DEBUG
BLTOUCH_DEBUG COMMAND=reset
# Run bed_mesh_calibrate # Run bed_mesh_calibrate
BED_MESH_CALIBRATE BED_MESH_CALIBRATE