SET_GCODE_VARIABLE not working

I have a modified version of the klicky probe macro as below. However all the SET_GCODE_VARIABLE commands seem to have no effect and are not changed from their default values. However running SET_GCODE_VARIABLE in the console seems to work. What am I doing wrong?



[gcode_macro _Probe_Variables]
variable_probe_attached:            False
variable_probe_state:               False
variable_probe_lock:                False
variable_probe_z_homed:             False
variable_z_endstop_x:               0
variable_z_endstop_y:               0
gcode:



# Check to see if probe is where it is supposed to be after
# attaching/docking maneuver and set homing error or shutdown
[gcode_macro CheckProbe]
variable_probe_state: 0
gcode:
    Query_Probe
    _SetProbeState action={ params.ACTION }


# Due to how templates are evaluated, we have query endstops in one
# macro and call another macro to make decisions based on the result
[gcode_macro _SetProbeState]
gcode:
    {% set query_probe_triggered = printer.probe.last_query %}
    {% set action  = params.ACTION|default('') %}

    # If triggered (true), probe not attached
    {% if query_probe_triggered %}
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE=0
        RESPOND MSG='DOCKED'
        RESPOND MSG={printer["gcode_macro _Probe_Variables"].probe_attached}
    {% else %}
        # If not triggered (false), probe attached
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE=1
        RESPOND MSG='ATTACHED'
        RESPOND MSG={printer["gcode_macro _Probe_Variables"].probe_attached}
    {% endif %}

    {% if action == 'query' %}
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_state VALUE={ query_probe_triggered }
        RESPOND MSG='state'
        RESPOND MSG={printer["gcode_macro _Probe_Variables"].probe_state}

    {% endif %}

    # If probe fails to attach/detach

    # If not docked
    {% if not query_probe_triggered and action == 'dock' %}
        { action_raise_error("Probe dock failed!") }
    {% endif %}

    # If not attached
    {% if query_probe_triggered and action == 'attach' %}
        { action_raise_error("Probe attach failed!") }
    {% endif %}

SET_GCODE_VARIABLE is for storing values to reference in other (or future) macros, it cannot affect the current one (because the macro has already been templated before it runs.)

Since you already have two separate macros, you should be able to verify that it’s setting the expected variables pretty easily.

# Check to see if probe is where it is supposed to be after
# attaching/docking maneuver and set homing error or shutdown
[gcode_macro CheckProbe]
variable_probe_state: 0
gcode:
    Query_Probe
    _SetProbeState action={ params.ACTION }
    RESPOND MSG={printer["gcode_macro _Probe_Variables"]}


# Due to how templates are evaluated, we have query endstops in one
# macro and call another macro to make decisions based on the result
[gcode_macro _SetProbeState]
gcode:
    {% set query_probe_triggered = printer.probe.last_query %}
    {% set action  = params.ACTION|default('') %}

    # If triggered (true), probe not attached
    {% if query_probe_triggered %}
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE=0
        RESPOND MSG='DOCKED'
    {% else %}
        # If not triggered (false), probe attached
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_attached VALUE=1
        RESPOND MSG='ATTACHED'
    {% endif %}

    {% if action == 'query' %}
        SET_GCODE_VARIABLE MACRO=_Probe_Variables VARIABLE=probe_state VALUE={ query_probe_triggered }
        RESPOND MSG='state'
    {% endif %}

    # If probe fails to attach/detach

    # If not docked
    {% if not query_probe_triggered and action == 'dock' %}
        { action_raise_error("Probe dock failed!") }
    {% endif %}

    # If not attached
    {% if query_probe_triggered and action == 'attach' %}
        { action_raise_error("Probe attach failed!") }
    {% endif %}

Thanks, I forgot about that!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.