How to wait for macro to finish first before going on?

Hi folks,

maybe I’m blind or dump but I do not find any information on how to wait for a macro to finish first before going on.

Currently I have a macro to run Z calibration like follows:

[gcode_macro Calibrate_Z_Probe]
#rename_existing: BASE_PROBE_CALIBRATE
gcode:
    Bauraumlicht
    {% if printer.toolhead.homed_axes != "xyz" %}
        G28                                                                     # home if not homed
    {% endif %}
    PROBE_CALIBRATE
    G90
    G0 Z10 F3600
    Bauraumlicht VALUE=0

It will run the PROBE_CALIBRATE macro and after this has finished raise Z again and turn off the light.
However it currently runs the PROBE_CALIBRATE macro and executes the following commands…
Is it somehow possible to wait for that whole calibration process?
A strange side effect is that when Z raises 10 mm the whole print head moves on X and Y as well. Maybe each axis for 10 mm as well… :confused:

Thanks in advance!

You could insert a M400 command:

https://reprap.org/wiki/G-code#M400:_Wait_for_current_moves_to_finish

Does not fix the issue. :frowning: But thanks for your reply.

However even when directly running PROBE_CALIBRATE the print head drifts away a few mm. Very strange.

AFAIK there is no direct way to wait for a long running process. You could time the seconds needed and use delayed_gcode
or find a printer variable that changes upon completion of PROBE_CALIBRATE and react upon this change (e.g. poll it every second and when changed, do something). I don’t know if there is a suitable one.

1 Like

Might be hard to set a duration for that process as it is not so static or deterministic.
Do you know where to change the original PROBE_CALIBRATE macro?
Seems to be internal and somehow hidden from us curious users… Maybe I can add some variables there and later analyze as you suggested.

PROBE_CALIBRATE moves the toolhead into a spot where you can use the “paper test” to verify the position of the toolhead. The following ACCEPT command continues the operation.

PROBE_CALIBRATE is not a macro - it is an internal command.

You may be able to make a new macro (eg, FINISH) that calls ACCEPT and turns the light off. You could potentially use that new macro in place of ACCEPT to accomplish your goal.

-Kevin

Thanks @koconnor for your reply.
So there is no option to hook on the internal PROBE_CALIBRATION command or that ACCEPT command that is only active when PROBE_CALIBRATION is running?

Especially with the later MainSail version there is a comfortable GUI for that routine.
As I’m often testing new print head designs or change nozzles and other parts I’ll appreciate to have some comfort during this calibration.

Alas, it’s not something I’ve tried or looked at, so I don’t know. It may or may not be possible to use some elaborate macros to override the behavior (or some other similar mechanism).

-Kevin