aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/bltouch.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-12-03 22:52:32 -0500
committerKevin O'Connor <kevin@koconnor.net>2018-12-03 22:52:32 -0500
commite0b2d7c51d8077e3d516938b9053f9e058e57898 (patch)
tree841b7d849a6f931567dcd26c4cda66bba5819469 /klippy/extras/bltouch.py
parentaac92ffb916ccf74a9c6692ded671f4f25312b7e (diff)
downloadkutter-e0b2d7c51d8077e3d516938b9053f9e058e57898.tar.gz
kutter-e0b2d7c51d8077e3d516938b9053f9e058e57898.tar.xz
kutter-e0b2d7c51d8077e3d516938b9053f9e058e57898.zip
bltouch: Add a BLTOUCH_DEBUG command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/bltouch.py')
-rw-r--r--klippy/extras/bltouch.py45
1 files changed, 32 insertions, 13 deletions
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 <kevin@koconnor.net>
#
# 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)