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

    while loop doesn't end

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    16
    818
    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.
    • mherundefined
      mher @OwenD
      last edited by

      Maybe @Phaedrux or @dc42 can comment about what the limit of the macros is, if there is such a thing and if that could be the cause of the while loop not exiting correctly.

      OwenDundefined 1 Reply Last reply Reply Quote 0
      • OwenDundefined
        OwenD @mher
        last edited by

        @mher
        What firmware version are you running?
        Someone else was having similar issues here
        https://forum.duet3d.com/topic/29070/weird-macro-behaviour?_=1668050444951

        mherundefined 1 Reply Last reply Reply Quote 0
        • mherundefined
          mher @OwenD
          last edited by

          @OwenD
          I'm running 3.4.0 currently so maybe there is a issue in there as well.
          For now I've worked around it by doing the if check in the while loop which works it's just not that clean.

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

            @mher that's odd, please try this and tell me if it works for you (it works for me):

            while iterations < 4
              echo iterations
              G4 S1
            

            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

            mherundefined 1 Reply Last reply Reply Quote 0
            • mherundefined
              mher @dc42
              last edited by

              @dc42
              Yeah I already created a macro like that to perform the same test and it was working as expected.

              Just did the same for the code you shared just to be sured and again it worked like expected.

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

                @OwenD said in while loop doesn't end:

                I suspect when the main calls your klicky macro, which in turn calls another, then the local variables in the original are lost.

                That shouldn't be the case, but of course there may be bugs in the implementation.

                @mher said in while loop doesn't end:

                Maybe @Phaedrux or @dc42 can comment about what the limit of the macros is, if there is such a thing and if that could be the cause of the while loop not exiting correctly.

                There is a limit of 10 nested stack pushes. A macro call (whether explicit or implicit) counts as a push, so does using M120. Within each stack push there is also a block nesting limit of 10, so while- and if-else bodies can't be nested more than 10 deep.

                @mher if you can identify what it is that you are doing in your macro that causes the while-loop to misbehave, I will look into it.

                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

                mherundefined 2 Replies Last reply Reply Quote 0
                • mherundefined
                  mher @dc42
                  last edited by

                  @dc42

                  As far as I can see really quickly i'm max nesting 5 pushes. However lets say i'm inside a while inside an if statement and I call a macro in this if statement and inside the macro itself there are additional if statements. Do they get counted towards the max bodies deep you can nest? If so that might be an issue

                  I'm also assuming that there isn't a max of how many macros you can call in 1 macro?
                  So if i would call M98 30 times in succession it should be fine?

                  1 Reply Last reply Reply Quote 0
                  • OwenDundefined
                    OwenD @mher
                    last edited by

                    @mher said in while loop doesn't end:

                    G1 X{var.centerX - sensors.probes[0].offsets[0]} Y{var.centerY - sensors.probes[0].offsets[1]} F99999

                    It may be unrelated but...
                    Just as a matter of interest, what happens when you send a command like G1 X100 Y100 F99999 ?
                    It will no doubt be restricted by the max speed you set with M203, but if that speed is causing an error condition it may be a factor.

                    I think you're going to have to heavily lace your code with echo commands so you can see where in the scheme of things your issue is appearing.

                    mherundefined 1 Reply Last reply Reply Quote 0
                    • mherundefined
                      mher @OwenD
                      last edited by

                      @OwenD As far as I understood it it will execute the command and the speed will be capped at the max you set in the firmware. So max speed for x is currently 10800 (for me atleast). So setting it to F999999 will make sure that when I share this in the vcore3 group (I'm running a vcore3) other people can use it with the speeds they have set on their setup.

                      I've been adding echo's the thing is that it just seems to fail on the "while iterations" check.
                      Because I've got it working now by just doing a check inside the while to break the code.

                      I even setup a testing file with a while loop and loading/unloading the probe which works as expected.

                      1 Reply Last reply Reply Quote 0
                      • mherundefined
                        mher @dc42
                        last edited by mher

                        @dc42
                        Alright it seems like i figured out what is causing the issue.

                        I created a new macro and started adding things one by one.
                        Everything went fine until I added this line:

                        G91 G1 H2 Z7 G90 ; Set to relative positioning, move Z up 5mm, change back to absolute positioning

                        after adding this the while loop kept on running. After removing it everything ran as expected again

                        EDIT:
                        just confirmed it by creating the following macro. This would just keep running the while loop infinite.

                        G91 G1 Z5 G90 ;Removed H2 to be sure this wasn't the cause
                        
                        while iterations < 4 
                        	echo "iteration: " ^ iterations
                        

                        Then I split the G91/G90 command from single line to multi line and it started working as expected. So it seems there is an issue with the single line implementation for relative/absolute.
                        Which I read here we should be able to do the way I did
                        https://forum.duet3d.com/topic/11662/treat-g90-g91-and-m82-m83-like-g53/3

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