[Prusa style] Auto align dual Z-motor Y-axis on first home only once after power up

demo

Requirements:

  • Rigid couplers (use ball bearing for flexible)
  • Add extra 20mm in your Z limit configuration to allow stepper stalling
  • Physical limiter (e.g a screw in the extrusion on both sides with equal distances)
  • (optional) Software current control for low noise on stalls; using TMC in this example

Functions:

  • Aligns the two leadscrew-driven motors only once after powerup on the first G28 command until next power cycle.
  • Keeps Z motors on even with M84 by overriding the output pin and M84 command
  • Alignment is done by hitting the maximum hardware boundary in low current where the stepper stalls with low torque. Low current isn’t needed with rigid frames or non-software adjustable stepper drivers.
  • Again, issuing G28 after the first prompt will no longer align, motors stay on to prevent misalignments, subsequent prints and homing sequence will use the original G28 behavior, alignment happens on the first print only, power cycling the printer or restarting Klipper will force realignment when issuing G28.
  • To force original G28 on powerup use G28.1 (use it to force Z homing again)
  • To force Z motor power off use M84.1
  • Prior G28 will only home X and Y to prevent nozzle crash into print

Macro:
Replace < content > with your parameters

[gcode_macro  G28]
rename_existing: G28.1
variable_skew: 0
gcode:
  {% if skew < 1 %}
    M117 Aligning Y axis
    G28.1 Z
    SET_TMC_CURRENT STEPPER=stepper_z current=<Change to minimum torque>
    G1 Z<Change to max height + 20mm> F1500
    SET_TMC_CURRENT STEPPER=stepper_z current=<Change to your defaults>
    G28.1
    SET_GCODE_VARIABLE MACRO=G28 VARIABLE=skew VALUE=1
    M117 Ready
  {% else %}
    G28.1 X Y
  {% endif %}

[gcode_macro M84]
rename_existing: M84.1
gcode:
  SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0
  SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0
  SET_STEPPER_ENABLE STEPPER=extruder ENABLE=0

//Remove endstop_pin from your [stepper_z] parameters and add this in a new group parameter:
[output_pin z_always_on]
pin: <Replace with your enable pin for Z driver>
static_value: 1

1 Like