Skip to content

Commit

Permalink
Sensorless homing improvements (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x authored Mar 27, 2023
1 parent f99b5e5 commit 38a9279
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/hardware/axis/XY/default_speed.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[stepper_x]
homing_speed: 60
homing_retract_dist: 5
homing_retract_dist: 0
homing_positive_dir: true

[stepper_y]
homing_speed: 60
homing_retract_dist: 5
homing_retract_dist: 0
homing_positive_dir: true
19 changes: 13 additions & 6 deletions config/software/sensorless_homing.cfg
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# This file add support for Sensorless homing using TMC2209 drivers
# To use it, be sure to place the corresponding jumpers correctly on your MCU!
[gcode_macro _USER_VARIABLES]
variable_sensorless_homing_enabled: True
gcode:


[stepper_x]
homing_speed: 40
endstop_pin: tmc2209_stepper_x:virtual_endstop

[tmc2209 stepper_x]
diag_pin: ^X_STOP
driver_SGTHRS: 255

[stepper_y]
homing_speed: 40
endstop_pin: tmc2209_stepper_y:virtual_endstop

[tmc2209 stepper_y]
diag_pin: ^Y_STOP
driver_SGTHRS: 255


# PLEASE READ THE FOLLOWING:
# 255 is the most sensitive value, 0 is the least sensitive. Here we set a default
# value of 255 to avoid any trouble or crash. Your axes should not move with this parameter!
## PLEASE READ THE FOLLOWING:
## 255 is the most sensitive value, 0 is the least sensitive. Here we set a default
## value of 255 to avoid any trouble or crash. Your axes should not move with this parameter!

## Follow the Klipper documentation here: https://www.klipper3d.org/TMC_Drivers.html#sensorless-homing
## to find the best suited SGTHRS value according to your machine. Then you can put it in your overrides
## file like that:

# Follow the Klipper documentation here: https://www.klipper3d.org/TMC_Drivers.html#sensorless-homing
# to find the best suited SGTHRS value according to your machine. Then you can put it in your overrides
# file like that:
# [tmc2209 stepper_x]
# driver_SGTHRS: new value for X

Expand Down
54 changes: 54 additions & 0 deletions macros/base/homing/homing_overide.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gcode:
{% set homing_zhop = printer["gcode_macro _USER_VARIABLES"].homing_zhop|float %}
{% set homing_travel_speed = printer["gcode_macro _USER_VARIABLES"].homing_travel_speed * 60 %}
{% set homing_travel_accel = printer["gcode_macro _USER_VARIABLES"].homing_travel_accel %}
{% set sensorless_homing_enabled = printer["gcode_macro _USER_VARIABLES"].sensorless_homing_enabled %}
{% set sensorless_current_factor = printer["gcode_macro _USER_VARIABLES"].sensorless_current_factor / 100 %}
{% set z_drop_speed = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}
{% set status_leds_enabled = printer["gcode_macro _USER_VARIABLES"].status_leds_enabled %}
{% set bed_mesh_enabled = printer["gcode_macro _USER_VARIABLES"].bed_mesh_enabled %}
Expand Down Expand Up @@ -100,31 +102,83 @@ gcode:
{% if verbose %}
{ action_respond_info("Homing X") }
{% endif %}
{% if sensorless_homing_enabled %}
{% set old_current_x = printer.configfile.config['tmc2209 stepper_x'].run_current %}
{% set old_current_y = printer.configfile.config['tmc2209 stepper_y'].run_current %}
{% set new_current_x = sensorless_current_factor * old_current_x %}
{% set new_current_y = sensorless_current_factor * old_current_y %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={new_current_y}
{% endif %}
G28 X0
G1 X{x_position_endstop + x_homing_backoff} F{homing_travel_speed}
{% if sensorless_homing_enabled %}
G4 P1000
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% endif %}
{% if Y %} # Home y
{% if verbose %}
{ action_respond_info("Homing Y") }
{% endif %}
{% if sensorless_homing_enabled %}
{% set old_current_x = printer.configfile.config['tmc2209 stepper_x'].run_current %}
{% set old_current_y = printer.configfile.config['tmc2209 stepper_y'].run_current %}
{% set new_current_x = sensorless_current_factor * old_current_x %}
{% set new_current_y = sensorless_current_factor * old_current_y %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={new_current_y}
{% endif %}
G28 Y0
G1 Y{y_position_endstop + y_homing_backoff} F{homing_travel_speed}
{% if sensorless_homing_enabled %}
G4 P1000
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% endif %}

{% elif homing_first == "Y" %}
{% if Y %} # Home y
{% if verbose %}
{ action_respond_info("Homing Y") }
{% endif %}
{% if sensorless_homing_enabled %}
{% set old_current_x = printer.configfile.config['tmc2209 stepper_x'].run_current %}
{% set old_current_y = printer.configfile.config['tmc2209 stepper_y'].run_current %}
{% set new_current_x = sensorless_current_factor * old_current_x %}
{% set new_current_y = sensorless_current_factor * old_current_y %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={new_current_y}
{% endif %}
G28 Y0
G1 Y{y_position_endstop + y_homing_backoff} F{homing_travel_speed}
{% if sensorless_homing_enabled %}
G4 P1000
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% endif %}
{% if X %} # Home x
{% if verbose %}
{ action_respond_info("Homing X") }
{% endif %}
{% if sensorless_homing_enabled %}
{% set old_current_x = printer.configfile.config['tmc2209 stepper_x'].run_current %}
{% set old_current_y = printer.configfile.config['tmc2209 stepper_y'].run_current %}
{% set new_current_x = sensorless_current_factor * old_current_x %}
{% set new_current_y = sensorless_current_factor * old_current_y %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={new_current_y}
{% endif %}
G28 X0
G1 X{x_position_endstop + x_homing_backoff} F{homing_travel_speed}
{% if sensorless_homing_enabled %}
G4 P1000
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% endif %}

{% else %}
Expand Down
3 changes: 3 additions & 0 deletions user_templates/variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ variable_homing_zhop: 5
variable_homing_first: "X" # can be set to "Y" first
variable_homing_backoff_distance_xy: -5, -5 # move 5mm in negative direction on both axis

## Percentage of run_current used while sensorless homing (if used)
variable_sensorless_current_factor: 75

## margin to avoid the probe dock when homing
variable_probe_dock_margin_xy: 0, 0

Expand Down

0 comments on commit 38a9279

Please sign in to comment.