Skip to content

Commit

Permalink
Homing: support multi-motor sensorless homing
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Jan 5, 2024
1 parent 203d445 commit c755891
Showing 1 changed file with 96 additions and 20 deletions.
116 changes: 96 additions & 20 deletions homing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit c755891

Please sign in to comment.