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

    G-Code Meta commands: Option unset (all) globals

    Scheduled Pinned Locked Moved
    Firmware wishlist
    7
    19
    1.1k
    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.
    • Stephen6309undefined
      Stephen6309 @oliof
      last edited by

      @oliof Wouldn't that be an ID10T error?

      1 Reply Last reply Reply Quote 0
      • oliofundefined
        oliof
        last edited by

        you can call it whatever you want but dc42 being a veteran c++ developer probably is well versed with the footgun analogy

        <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

        tfjieldundefined 1 Reply Last reply Reply Quote 0
        • tfjieldundefined
          tfjield @oliof
          last edited by

          This is an old thread, but I've just run into this issue and I wanted to share my workaround. I wanted to be able to keep my data neat and not have to have the same value on more than one line. (Because that provides an opportunity for errors, especially later when I'm changing something.)

          I thought of creating a script file to do it, but I couldn't figure out how to reference the contents of the parameters directly, so I wrote them to a file.

          I have all my globals in a file such as the following, and I set them using the "setglobal.g" script.

          ; globals.g
          ; called to initialize all global variables
          
          M98 P"setglobal.g" L"leveled" V"false"		; flag indicating whether the bed has been leveled
          M98 P"setglobal.g" L"xmin" V0			; x-axis minimum limit
          M98 P"setglobal.g" L"xmax" V620			; x-axis maximum limit
          M98 P"setglobal.g" L"ymin" V-28			; y-axis minimum limit
          M98 P"setglobal.g" L"ymax" V600			; y-axis maximum limit
          M98 P"setglobal.g" L"xprobeoffset" V5		; x-axis offset for probing z-axis datum
          M98 P"setglobal.g" L"yprobeoffset" V5		; y-axis offset for probing z-axis datum
          
          ;etc.
          

          The "setglobal.g" file writes the logic to check if the variable exists or not, and then executes it:

          ; setgobal.g
          ; Creates a global variable (if it doesn't already exist) and sets it to a value
          echo >"tempglobal.g" {"if !exists(global."^param.L^")"}
          echo >>"tempglobal.g" "    global "^param.L^" = "^param.V
          echo >>"tempglobal.g" "else"
          echo >>"tempglobal.g" "    set global."^param.L^" = "^param.V
          
          M98 P"tempglobal.g"
          

          Seems to work alright, and keeps my code fairly neat. There are probably limitations to this approach, but I don't know what they are, yet. lol

          fcwiltundefined 1 Reply Last reply Reply Quote 0
          • fcwiltundefined
            fcwilt @tfjield
            last edited by

            @tfjield

            Interesting but why?

            If you create all your global variables at print boot-up then you know they will succeed in being created.

            Frederick

            Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

            tfjieldundefined 1 Reply Last reply Reply Quote 0
            • tfjieldundefined
              tfjield @fcwilt
              last edited by

              @fcwilt Because not all variable changes are used in config.g. Some of the variables are used elsewhere, and for development I would like to update them without having to rerun config.g. And yes, I could change the value and update the globals.g file, but that's tedious. It's just so simple to rerun globals.g after I've made my changes and go on with testing. Of course, if the variables are used in config.g then I have to run it.

              Also, this gives me the flexibility of defining a global in another file and not in globals.g, and I don't have to check whether or not it already exists.

              Like most things, once everything is set up and working right, then it doesn't matter how you got there, how many lines of code, etc. But for development and iteration, I'm finding this helps.

              fcwiltundefined 1 Reply Last reply Reply Quote 0
              • fcwiltundefined
                fcwilt @tfjield
                last edited by

                @tfjield

                Thanks for the explanation.

                Frederick

                Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

                tfjieldundefined 1 Reply Last reply Reply Quote 0
                • tfjieldundefined
                  tfjield @dc42
                  last edited by

                  @dc42 How about automatically creating the global if it doesn't already exist when set it called, and allowing global to set an already existing variable? I'm thinking that would maintain backwards compatibility while going forward it would allow simplifying the scripts. I actually like variable declarations in code with strongly-typed languages, but not so much in scripting.

                  fcwiltundefined 1 Reply Last reply Reply Quote 0
                  • tfjieldundefined
                    tfjield @fcwilt
                    last edited by

                    @fcwilt For sure! 👍

                    1 Reply Last reply Reply Quote 0
                    • fcwiltundefined
                      fcwilt @tfjield
                      last edited by

                      @tfjield said in G-Code Meta commands: Option unset (all) globals:

                      How about automatically creating the global if it doesn't already exist when set it called

                      I want you to think long and hard about what you are proposing. 😉

                      I am prepared to forgot you ever suggested such a thing.

                      Frederick

                      Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

                      tfjieldundefined 1 Reply Last reply Reply Quote 0
                      • tfjieldundefined
                        tfjield @fcwilt
                        last edited by

                        @fcwilt 🤣

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