From c75589184d4302092b90ddc65fe9b7a790afd6d7 Mon Sep 17 00:00:00 2001 From: Mikkel Schmidt Date: Fri, 5 Jan 2024 09:17:52 +0100 Subject: [PATCH] Homing: support multi-motor sensorless homing --- homing.cfg | 116 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 20 deletions(-) diff --git a/homing.cfg b/homing.cfg index 41f3737f..cbd28c25 100644 --- a/homing.cfg +++ b/homing.cfg @@ -82,41 +82,117 @@ gcode: [gcode_macro HOME_X_SENSORLESS] gcode: - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} - {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} {% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %} {% if safe_home_x is not defined or safe_home_x|lower == 'middle' %} {% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %} {% endif %} - M204 S1000 # Set homing acceleration (important!) - SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} - SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} - G4 P300 # Wait for currents to settle + # Set homing acceleration (important!) + M204 S1000 + {% if printer["gcode_macro RatOS"].x_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].x_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} + {% endfor %} + {% else %} + {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} + SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} + {% endif %} + + {% if printer["gcode_macro RatOS"].y_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].y_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} + {% endfor %} + {% else %} + {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} + SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_x_current} + {% endif %} + # Wait for currents to settle + G4 P300 + # Home X G28 X - SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current} - SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current} - G4 P300 # Wait for currents to settle + # Restore current + {% if printer["gcode_macro RatOS"].x_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].x_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + {% set stepper_driver = printer["gcode_macro RatOS"].x_driver_types[loop.index0] ~ " " ~ stepper %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current} + {% endfor %} + {% else %} + {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} + SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current} + {% endif %} + + {% if printer["gcode_macro RatOS"].y_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].y_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + {% set stepper_driver = printer["gcode_macro RatOS"].y_driver_types[loop.index0] ~ " " ~ stepper %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current} + {% endfor %} + {% else %} + {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} + SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current} + {% endif %} + # Wait for currents to settle + G4 P300 # Restore acceleration M204 S{printer.configfile.config.printer.max_accel} [gcode_macro HOME_Y_SENSORLESS] gcode: {% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %} - {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} - {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} {% if safe_home_y is not defined or safe_home_y|lower == 'middle' %} {% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %} {% endif %} - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - M204 S1000 # Set homing acceleration (important!) - SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} - SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} - G4 P300 # Wait for currents to settle + # Set homing acceleration (important!) + M204 S1000 + {% if printer["gcode_macro RatOS"].x_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].x_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} + {% endfor %} + {% else %} + {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} + SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} + {% endif %} + + {% if printer["gcode_macro RatOS"].y_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].y_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} + {% endfor %} + {% else %} + {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} + SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer["gcode_macro RatOS"].sensorless_y_current} + {% endif %} + # Wait for currents to settle + G4 P300 + # Home Y G28 Y - SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current} - SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current} - G4 P300 # Wait for currents to settle + # Restore current + {% if printer["gcode_macro RatOS"].x_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].x_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + {% set stepper_driver = printer["gcode_macro RatOS"].x_driver_types[loop.index0] ~ " " ~ stepper %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current} + {% endfor %} + {% else %} + {% set x_driver = printer["gcode_macro RatOS"].driver_type_x|lower ~ " stepper_x" %} + SET_TMC_CURRENT STEPPER=stepper_x CURRENT={printer.configfile.config[x_driver].run_current} + {% endif %} + + {% if printer["gcode_macro RatOS"].y_axes is defined %} + {% for axis in printer["gcode_macro RatOS"].y_axes %} + {% set stepper = "stepper_" ~ axis|lower %} + {% set stepper_driver = printer["gcode_macro RatOS"].y_driver_types[loop.index0] ~ " " ~ stepper %} + SET_TMC_CURRENT STEPPER={stepper} CURRENT={printer.configfile.config[stepper_driver].run_current} + {% endfor %} + {% else %} + {% set y_driver = printer["gcode_macro RatOS"].driver_type_y|lower ~ " stepper_y" %} + SET_TMC_CURRENT STEPPER=stepper_y CURRENT={printer.configfile.config[y_driver].run_current} + {% endif %} + # Wait for currents to settle + G4 P300 # Restore acceleration M204 S{printer.configfile.config.printer.max_accel}