Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Macro Commands Out of Order

    Scheduled Pinned Locked Moved Unsolved
    Gcode meta commands
    3
    7
    340
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Lukrativeundefined
      Lukrative
      last edited by Lukrative

      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

      gloomyandyundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • Lukrativeundefined Lukrative marked this topic as a question
      • gloomyandyundefined
        gloomyandy @Lukrative
        last edited by

        @lukrative Try inserting M400 before you call the macro, that will ensure that any queued movement commands have been executed.

        Lukrativeundefined 2 Replies Last reply Reply Quote 0
        • Lukrativeundefined
          Lukrative @gloomyandy
          last edited by

          @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!

          1 Reply Last reply Reply Quote 0
          • Lukrativeundefined
            Lukrative @gloomyandy
            last edited by

            @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?

            dc42undefined 1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators @Lukrative
              last edited by

              @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.

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              Lukrativeundefined 1 Reply Last reply Reply Quote 0
              • dc42undefined
                dc42 administrators @Lukrative
                last edited by

                @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.

                Duet WiFi hardware designer and firmware engineer
                Please do not ask me for Duet support via PM or email, use the forum
                http://www.escher3d.com, https://miscsolutions.wordpress.com

                1 Reply Last reply Reply Quote 0
                • Lukrativeundefined
                  Lukrative @dc42
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Unless otherwise noted, all forum content is licensed under CC-BY-SA