From e0b2d7c51d8077e3d516938b9053f9e058e57898 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 3 Dec 2018 22:52:32 -0500 Subject: [PATCH] bltouch: Add a BLTOUCH_DEBUG command Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 8 +++++++ klippy/extras/bltouch.py | 45 ++++++++++++++++++++++++++++------------ test/klippy/bltouch.test | 4 ++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index fd5291b4..a4e44ced 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -153,6 +153,14 @@ enabled: - `QUERY_PROBE`: Report the current status of the probe ("triggered" or "open"). +## BLTouch + +The following command is available when a "bltouch" config section is +enabled: +- `BLTOUCH_DEBUG 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 The following commands are available when the "delta_calibrate" config diff --git a/klippy/extras/bltouch.py b/klippy/extras/bltouch.py index 0cf07d79..3963adcb 100644 --- a/klippy/extras/bltouch.py +++ b/klippy/extras/bltouch.py @@ -3,6 +3,7 @@ # Copyright (C) 2018 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. +import logging import homing, probe SIGNAL_PERIOD = 0.025600 @@ -13,11 +14,10 @@ TEST_TIME = 5 * 60. ENDSTOP_SAMPLE_TIME = .000015 ENDSTOP_SAMPLE_COUNT = 4 -CMD_PIN_DOWN = 0.000700 -CMD_PIN_UP = 0.001500 -CMD_SELF_TEST = 0.001800 -CMD_RESET = 0.002200 -CMD_TOUCH_MODE = 0.001200 +Commands = { + None: 0.0, 'pin_down': 0.000700, 'touch_mode': 0.001200, + 'pin_up': 0.001500, 'self_test': 0.001800, 'reset': 0.002200, +} # BLTouch "endstop" wrapper class BLTouchEndstopWrapper: @@ -45,12 +45,16 @@ class BLTouchEndstopWrapper: self.query_endstop = self.mcu_endstop.query_endstop self.query_endstop_wait = self.mcu_endstop.query_endstop_wait 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): kin = self.printer.lookup_object('toolhead').get_kinematics() for stepper in kin.get_steppers('Z'): stepper.add_to_endstop(self) 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): toolhead = self.printer.lookup_object('toolhead') print_time = toolhead.get_last_move_time() @@ -58,10 +62,10 @@ class BLTouchEndstopWrapper: self.next_test_time = print_time + TEST_TIME return # 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 - self.send_cmd(home_time, CMD_TOUCH_MODE) - self.send_cmd(home_time + MIN_CMD_TIME, 0.) + self.send_cmd(home_time, 'touch_mode') + self.send_cmd(home_time + MIN_CMD_TIME, None) # Perform endstop check to verify bltouch reports probe raised prev_positions = [s.get_commanded_position() for s in self.mcu_endstop.get_steppers()] @@ -80,19 +84,34 @@ class BLTouchEndstopWrapper: self.test_sensor() toolhead = self.printer.lookup_object('toolhead') print_time = toolhead.get_last_move_time() - self.send_cmd(print_time, CMD_PIN_DOWN) - self.send_cmd(print_time + PIN_MOVE_TIME, CMD_TOUCH_MODE) + self.send_cmd(print_time, 'pin_down') + self.send_cmd(print_time + PIN_MOVE_TIME, 'touch_mode') toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME) self.mcu_endstop.home_prepare() def home_finalize(self): toolhead = self.printer.lookup_object('toolhead') print_time = toolhead.get_last_move_time() - self.send_cmd(print_time, CMD_RESET) - self.send_cmd(print_time + PIN_MOVE_TIME, 0.) + self.send_cmd(print_time, 'reset') + self.send_cmd(print_time + PIN_MOVE_TIME, None) toolhead.dwell(PIN_MOVE_TIME + MIN_CMD_TIME) self.mcu_endstop.home_finalize() def get_position_endstop(self): 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): blt = BLTouchEndstopWrapper(config) diff --git a/test/klippy/bltouch.test b/test/klippy/bltouch.test index b6b91738..bbfda377 100644 --- a/test/klippy/bltouch.test +++ b/test/klippy/bltouch.test @@ -11,6 +11,10 @@ G1 Z1 G1 X1 G1 Y1 +# Run BLTOUCH_DEBUG +BLTOUCH_DEBUG +BLTOUCH_DEBUG COMMAND=reset + # Run bed_mesh_calibrate BED_MESH_CALIBRATE