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

    Macro Parameter Letters

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    5
    470
    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.
    • DonStaufferundefined
      DonStauffer
      last edited by

      This is a style question, but the answer may involve a feature I'm unaware of.

      If I want to call a macro with a pair of coordinates, I can do something like:

      M98 P"MacroFile" X{var.XCoord} Y{var.YCoord}

      Then in the macro, I just access them using param.X and param.Y.

      If I have ranges of coordinates, as in defining a bed area, I'm not aware of any way except choosing arbitrary letters:

      M98 P"MacroFile" X{var.XMin} A{var.XMax} Y{var.YMin} B{var.YMax}

      I could concatenate min and max as strings with a colon between them, but I know of no way to separate them again inside the macro.

      What's the best way to handle this?

      DonStaufferundefined 1 Reply Last reply Reply Quote 1
      • DonStaufferundefined
        DonStauffer @DonStauffer
        last edited by DonStauffer

        @donstauffer I did think of a way to "cheat": Multiply the Max value by 1,000 and add them together. But that's not all that much more readable than arbitrary letters. When arrays become available, if they can be passed as macro parameters, that might be somewhat better, although again, you'd have to know the "magic numbers" for what subscripts mean what. In either case you could define a variable inside the macro and assign to it, this giving a good name to each at the beginning of the macro. But overall, none of this is particularly syntactically "sugary."

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

          @donstauffer RRF doesn't yet support array-valued user variables and parameters. We may add this feature in RRF 3.5.

          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 1
          • Diamondbackundefined
            Diamondback
            last edited by

            I've recently run into the same issue (trying to pass used bed area from slicer to my mesh macro) and settled with the arbitrary letters as well.
            Really looking forward to user array support. 🙂

            DonStaufferundefined 1 Reply Last reply Reply Quote 0
            • DonStaufferundefined
              DonStauffer @Diamondback
              last edited by DonStauffer

              @diamondback Yes, arrays as parameters will be wonderful. I've written enough mini-compilers to know how hard the implementation of arrays will be though.

              For arbitrary letters, I wonder if it might be useful to establish some kind of convention for how to do common things like bed area. Say, use ABCD and dereference parameters into variables at the beginning of the macro:

              var XMin = param.A
              var XMax = param.B
              var YMin = param.C
              var YMax = param.D

              This has the disadvantage that if we're used to this usage those letters wouldn't be available for concepts that begin with them. But I don't know how to predict that. An alternative would be for X, Y & Z to be maximums and M, N and O. This choice has the disadvantage of using letters which can't be used in custom G-code or M-code commands, but starting with "M" is easily remembered as "Minimum". Or maybe, A, B and C would be better.

              Or, maybe:

              var XMax = floor(param.X / 1000)
              var XMin = param.X - var.XMax * 1000
              var YMax = floor(param.Y / 1000)
              var YMin = param.Y - var.YMax * 1000

              is a little more obscure but only uses X and Y. The call would look like:

              M98 P"MacroFile" X{var.XMin + var.XMax * 1000} Y{var.YMin + var.YMax * 1000)

              Or, maybe in preparation for retrofitting when array parameters become available, use variable names X0, X1, Y0 and Y1 (will array subscripts be zero based or 1 based?)

              I'm open to anything that makes sense to the most people.

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