When HEAT_TEST is evaluated, the value of temp_down
is 0. So every time temp_down
appears in the macro, it will be replaced by 0 when the macro is executed. In the snippet you posted after height reaches 5mm you have this line:
SET_GCODE_VARIABLE MACRO=HEAT_TEST VARIABLE=temp_down VALUE={temp_down - 5}
Since temp_down
was 0 when the macro was evaluated, this command changes the value of the temp_down
variable to -5, which is what the TEMP_DOWN macro sees when it’s called, hence the error.
To address this, you can track the changing variable through the macro execution like this:
[gcode_macro HEAT_TEST]
description: Print to determine and the optimal Printtemperature @ 100mm/s
variable_temp_down: 0
gcode:
{% set TEMP = printer[“gcode_macro Calibration_Tool”].extr_temp %}
SET_GCODE_VARIABLE MACRO=HEAT_TEST VARIABLE=temp_down VALUE={TEMP}
START_TUNING_PRINT
;…
;Bunch of gcode till height reaches 5mm
;…
{% set TEMP = TEMP - 5 %}
SET_GCODE_VARIABLE MACRO=HEAT_TEST VARIABLE=temp_down VALUE={TEMP}
TEMP_DOWN
;…
;Bunch of gcode till height reaches 10mm
;…
{% set TEMP = TEMP - 5 %}
SET_GCODE_VARIABLE MACRO=HEAT_TEST VARIABLE=temp_down VALUE={TEMP}
TEMP_DOWN
;…
; This goes on till the Print is finished
; …
END_PRINT
This way when the macro is evaluated, the value of TEMP gets progressively updated as expected, then you can “store” that value in the macro variable so it can be accessed externally.
Of course, if this is your ultimate use case for this, you could probably skip using the variable_ and second macro altogether and simply do this:
[gcode_macro HEAT_TEST]
description: Print to determine and the optimal Printtemperature @ 100mm/s
gcode:
{% set TEMP = printer[“gcode_macro Calibration_Tool”].extr_temp %}
START_TUNING_PRINT
;…
;Bunch of gcode till height reaches 5mm
;…
{% set TEMP = TEMP - 5 %}
M104 S{TEMP|int}
;…
;Bunch of gcode till height reaches 10mm
;…
{% set TEMP = TEMP - 5 %}
M104 S{TEMP|int}
;…
; This goes on till the Print is finished
; …
END_PRINT