Skip to content

Conditional homing with Z lift #165

@netman74501

Description

@netman74501

First I'd like to say I have found your site very useful. I have used it for both Marlin and Klipper after recently acquiring an Ender 3 S1. So, thank you for keeping such a well structured resource alive!

Having said that, I was scouring the net for a drop in replacement of the G28 command that included Z lift and could be used for conditional homing, but alas... I never found such that satisfied me. So, what to do? Write my own. 😉

This uses the homing override, respond, and force move functions. They will need added to the printer configuration if not already there. Although the macro is mostly specific to my printer, I thought you might like to add it to your conditional homing section since it should work on any Cartesian style printer. (Force move won't work in certain situations on other printer types from what I understand -- as is discussed in this Discourse thread.)

Anyway, here it is, provided as-is with my notes and all:

Homing Override

[homing_override]
####
## PURPOSE:
##   - Conditional homing override with Z lift (i.e. home only when needed)
## REQUIRED:
##   - Ensure RESPOND is enabled (can test in the console), see https://www.klipper3d.org/Config_Reference.html#respond
##   - Ensure "enable_force_move: True" is present under "[force_move]" in printer.cfg, see https://www.klipper3d.org/G-Codes.html?h=tower#force_move
## EXAMPLE:
##
##   [respond]
##
##   [force_move]
##   enable_force_move: True
##
## WARNING:
##   - Steppers will skip and\or printer will incur damage if Z is at maximum when homing starts (should be rare)
## NOTE:
##   - This macro assumes a cartesian style printer with a bed size of 220x220 and a near zero offset mount for Y with center point probing
##   - Homing Z without first homing X and Y will result in all axes being homed (this means "G28" is the same as "G28 Z" when X and Y are not homed)
##   - You can set a mesh name in the first line below to always load a mesh when none is loaded (e.g. ...name|default('my_unique_name') %}...)
####
gcode:
    # Store any mesh name that is currently loaded
    {% set mesh_name = printer.bed_mesh.profile_name|default('') %}
    # Clear any bed mesh applied to avoid Z related move errors, see https://www.reddit.com/r/klippers/comments/10u5ve8/comment/mbh59mb/
    BED_MESH_CLEAR
    # Force lift Z when homing in case bed is too close
    {% if ("xyz" not in printer.toolhead.homed_axes and params.X is not defined and params.Y is not defined and params.Z is not defined) or ("x" not in printer.toolhead.homed_axes and params.X is defined) or ("y" not in printer.toolhead.homed_axes and params.Y is defined) or ("z" not in printer.toolhead.homed_axes and params.Z is defined) %}
        # Enable relative positioning
        G91
        # Set Z homed state
        SET_KINEMATIC_POSITION SET_HOMED=Z
        # Slowly lift Z
        G1 Z10 F600
        # Keep current X and Y homed state while clearing Z homed state, see https://www.klipper3d.org/G-Codes.html?h=tower#set_kinematic_position
        SET_KINEMATIC_POSITION SET_HOMED= CLEAR_HOMED=Z
    {% endif %}
    # Restore absolute positioning
    G90
    # Home all axes when parameters are missing and not already homed
    {% if "xyz" not in printer.toolhead.homed_axes and params.X is not defined and params.Y is not defined and params.Z is not defined %}
        RESPOND TYPE=command MSG="Homing all"
        G28 X
        G28 Y
        # Move to center point of bed
        G1 X157 Y110.25 F3000
        G28 Z
    {% endif %}
    # Home when X parameter is present and not already homed
    {% if "x" not in printer.toolhead.homed_axes and params.X is defined %}
        RESPOND TYPE=command MSG="Homing X"
        G28 X
    {% endif %}
    # Home when Y parameter is present and not already homed
    {% if "y" not in printer.toolhead.homed_axes and params.Y is defined %}
        RESPOND TYPE=command MSG="Homing Y"
        G28 Y
    {% endif %}
    # Home when Z parameter is present and not already homed
    {% if "z" not in printer.toolhead.homed_axes and params.Z is defined %}
        # Only home Z if X and Y are already homed, otherwise home all
        {% if "xy" in printer.toolhead.homed_axes or (params.X is defined and params.Y is defined) %}
            RESPOND TYPE=command MSG="Homing Z"
            # Move to center point of bed
            G1 X157 Y110.25 F3000
            G28 Z
        {% else %}
            RESPOND TYPE=command MSG="Homing X and Y before Z"
            G28 X
            G28 Y
            # Move to center point of bed
            G1 X157 Y110.25 F3000
            G28 Z
        {% endif %}
    {% endif %}
    # Restore any bed mesh that was loaded
    {% if mesh_name != '' %}
        BED_MESH_PROFILE LOAD={ mesh_name }
    {% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions