diff --git a/Klipper_Files/Extra module/ercf.py b/Klipper_Files/Extra module/ercf.py index 3c848011..6458b073 100644 --- a/Klipper_Files/Extra module/ercf.py +++ b/Klipper_Files/Extra module/ercf.py @@ -3,13 +3,14 @@ # Copyright (C) 2021 Ette # # This file may be distributed under the terms of the GNU GPLv3 license. +import copy import logging import math -from random import randint -from . import pulse_counter -from . import force_move -import copy import time +from random import randint + +from . import force_move, pulse_counter + class EncoderCounter: @@ -104,6 +105,7 @@ def __init__(self, config): self.enable_clog_detection = config.getint('enable_clog_detection', 1) self.enable_endless_spool = config.getint('enable_endless_spool', 0) self.endless_spool_groups = config.getintlist('endless_spool_groups') + self.toolhead_use_stallguard = config.getint('toolhead_use_stallguard', 0) if self.enable_endless_spool == 1 and len(self.endless_spool_groups) != len(self.selector_offsets): raise config.error( @@ -212,6 +214,8 @@ def __init__(self, config): self.gcode.register_command('ERCF_SELECT_TOOL', self.cmd_ERCF_SELECT_TOOL, desc = self.cmd_ERCF_SELECT_TOOL_help) + self.gcode.register_command('_ERCF_HOME_FILAMENT_TO_EXTRUDER', + self.cmd__ERCF_HOME_FILAMENT_TO_EXTRUDER) def handle_connect(self): self.toolhead = self.printer.lookup_object('toolhead') @@ -959,6 +963,15 @@ def _load_to_end_of_bowden(self, length): return def _home_to_extruder(self, length, step): + if self.is_paused: + return + if not self.toolhead_use_stallguard: + return self._home_to_extruder_without_stallguard(length, step) + + return self._home_to_extruder_with_stallguard(length) + + + def _home_to_extruder_without_stallguard(self, length, step): self._servo_down() self._log_debug("Homing to extruder with %1.fmm moves" % (step)) @@ -979,6 +992,47 @@ def _home_to_extruder(self, length, step): self._log_info("Failed to reach extruder after moving %.1fmm, pausing" % length) self._pause() + def _home_to_extruder_with_stallguard(self, max_length): + self._servo_down() + self.toolhead.dwell(0.2) + self.toolhead.wait_moves() + + self._log_debug("Homing to extruder with stallguard, up to %.1fmm" % max_length) + + self.gear_stepper.do_set_position(0.) + + pre_move_position = self._counter.get_distance() + self.gear_stepper.do_homing_move(max_length, 5, self.gear_stepper_accel, True, True) + self.toolhead.dwell(0.2) + self.toolhead.wait_moves() + post_move_position = self._counter.get_distance() + distance_moved = post_move_position - pre_move_position + if distance_moved >= max_length: + self._log_info("Failed to reach extruder after moving %.1fmm, pausing" % distance_moved) + self._pause() + else: + self._log_debug("Extruder reached after %.1fmm" % distance_moved) + return post_move_position + + + def cmd__ERCF_HOME_FILAMENT_TO_EXTRUDER(self, params): + """Test command to home the filament to the extruder from + the end of the fast moves down the reverse bowden. + + Intended to be used for calibrating the stallguard threshold. + """ + return_after = params.get_int('RETURN_AFTER', 0, minval=0, maxval=1) + self.toolhead.wait_moves() + pre_home_position = self._counter.get_distance() + position = self._home_to_extruder(self.extruder_homing_max, self.extruder_homing_step) + dist_moved = position - pre_home_position + self._log_info("Filament homed to extruder, moved %.1fmm" % dist_moved) + if return_after: + self.gear_stepper.do_set_position(0.) + self.gear_stepper.do_move(-dist_moved, 5, self.gear_stepper_accel) + self._log_debug("Returning to original position after homing") + self._servo_up() + def _load_to_nozzle(self): if (self.is_paused): return diff --git a/Klipper_Files/ercf_hardware.cfg b/Klipper_Files/ercf_hardware.cfg index ed098929..c7fdebd8 100644 --- a/Klipper_Files/ercf_hardware.cfg +++ b/Klipper_Files/ercf_hardware.cfg @@ -3,6 +3,23 @@ [mcu ercf] serial: /dev/serial/by-id/usb-Klipper_samd21g18a_F6EE357D3432585020312E3545150FFF-if00 +[tmc2209 manual_stepper gear_stepper] +# Adapt accordingly to your setup and desires +# The default values are tested with the BOM NEMA14 motor +# Please adapt those values to the motor you are using +# Example : for NEMA17 motors, you'll usually set the stealthchop_threshold to 0 +# and use higher current +uart_pin: ercf:PA8 +uart_address: 0 +interpolate: True +run_current: 0.40 +hold_current: 0.3 +sense_resistor: 0.150 +stealthchop_threshold: 500 +# Uncomment the lines below if you want to use sensorless homing for the toolhead +# diag_pin: ^ercf:PA7 # Set to MCU pin connected to TMC DIAG pin +# driver_SGTHRS: 75 # 255 is most sensitive value, 0 is least sensitive. NEEDS TO BE TUNED. + # Carrot Feeder 5mm D-cut shaft # Example for an SKR 1.4 Board (E1 on the XY mcu) [manual_stepper gear_stepper] @@ -17,20 +34,8 @@ velocity: 35 accel: 150 #Right now no pin is used for the endstop, but we need to define one for klipper. So just use a random, not used pin endstop_pin: ^ercf:PA7 - -[tmc2209 manual_stepper gear_stepper] -# Adapt accordingly to your setup and desires -# The default values are tested with the BOM NEMA14 motor -# Please adapt those values to the motor you are using -# Example : for NEMA17 motors, you'll usually set the stealthchop_threshold to 0 -# and use higher current -uart_pin: ercf:PA8 -uart_address: 0 -interpolate: True -run_current: 0.40 -hold_current: 0.3 -sense_resistor: 0.150 -stealthchop_threshold: 500 +# comment the line above and uncomment the line below if using stallguard for homing to the extruder +# endstop_pin: tmc2209_gear_stepper:virtual_endstop # Carrot Feeder selector # Example for an SKR 1.4 Board (Z1 on the XY mcu) diff --git a/Klipper_Files/ercf_parameters.cfg b/Klipper_Files/ercf_parameters.cfg index b39acb81..7b0c04e7 100644 --- a/Klipper_Files/ercf_parameters.cfg +++ b/Klipper_Files/ercf_parameters.cfg @@ -54,6 +54,7 @@ num_moves: 2 # Number of moves to make when loading or unloading # Features sensorless_selector: 0 # 0 = use an endstop, 1 = use sensorless homing +toolhead_use_stallguard: 0 # 0 = use 'collision' homing, 1 = use stallguard for homing enable_clog_detection: 0 # 0 = do not use clog detection, 1 = use clog detection enable_endless_spool: 0 # 0 = do not use endless spool, 1 = use endless spool # if endless spool is turned on, you must define a list of EndlessSpool groups here, one entry for each tool in your ERCF