Macro Commands Out of Order
-
I have a printer that I have been building while in school that has a two-into-one extruder set up, running off of a Duet Maestro. I'm running fw version 3.4.1. I have added a purge bucket for filament swaps that is servo actuated. It's been working, but I've been tweaking things, and something I did messed things up.
Here is that macro:
; called from tfree#.g macros if state.currentTool == 0 || state.currentTool == 1; if a tool is active: set global.fan_speed = fans[0].requestedValue; store current fan speed (do this before tool change because PrusaSlicer emits the new fan speed command before actually changing tools) M106 S0; turn off fan M98 P"0:/macros/Tool Changing/Purge Bucket/Deploy"; move into position/deploy purge bucket G1 E30 F150; purge G1 E10 F270; fast purge M106 S255; turn on fan to cool blob G1 E-140 F840; immediately retract filament (140/840)*60 = 10 seconds cooling G1 X128 F60000000; scrape nozzle M106 S0; turn off fan set global.blob_detected = false; reset M98 P"0:/macros/Tool Changing/Purge Bucket/Retract"; retract purge bucket/dump blob else; if no tool is active: echo "cannot purge when no tool is selected"
Line 14 is being executed between lines 7 and 8.
Could this be caused by commands being added to the command buffer before the condition of the if statement is evaluated or something? Any help appreciated, and I can supply the other macros being called if needed.
Edit: messed up line numbers in original post
-
-
@lukrative Try inserting M400 before you call the macro, that will ensure that any queued movement commands have been executed.
-
@gloomyandy Yeah that seems to be working. I was playing around with putting M400 commands in various spots, and it seems that for them to be effective, they need to be right before the M280 command that moves the purge bucket.
Still, it seems weird that the printer is looking forward inside of another macro and executing an M280 command 10 or so lines early.
Anyway, thanks for your help!
-
@gloomyandy Also, do you know how if statements are handled by the command buffer? As in are commands inside of an if statement body queued from outside, or does the firmware hold off on queuing them until the condition of the if statement is evaluated?
-
@lukrative what commands within the macro file invoked by M98 are being executed too early?
The M98 may indeed be executed before the previous motion commands have completed, but most commands in it will be queued so as to synchronise with the motion, just as happens to the M106 command in the original file.
-
@lukrative said in Macro Commands Out of Order:
or does the firmware hold off on queuing them until the condition of the if statement is evaluated?
This is what happens.
-
@dc42 Here is the updated Retract macro from line 14 of my original post:
M400; clear the command buffer M280 P1 S{global.retract_angle} G4 P400; wait for purge bucket to fully retract
Before adding in the M400, the M280 P1 command was being executed between lines 7 and 8. I don't know if the dwell was being executed early.