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

    Conditional GCode and object model variables

    Scheduled Pinned Locked Moved
    Gcode meta commands
    32
    66
    7.5k
    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.
    • dc42undefined
      dc42 administrators
      last edited by

      The syntax has already been defined. It id described at https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands. We are constrained by the conventions and symbols that are already used in GCode.

      As GCode is a line-oriented language, the main decision that had to be taken was whether to denote block scopes using indentation (as in Haskell and Python) or using block end keywords (as in Algol 68, Ada and Fortran). I chose indentation.

      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 2
      • mwolterundefined
        mwolter
        last edited by

        Min and Max X and Y coordinates of the print.

        Would be very helpful if the min and max X and Y coordinates of the print could be read from the g code and used as a variable in an M557 which is saved before running G29. This would allow a custom probe grid to be used that only probes the area of the bed used for that particular print.

        Luke'sLaboratoryundefined 1 Reply Last reply Reply Quote 1
        • Luke'sLaboratoryundefined
          Luke'sLaboratory @mwolter
          last edited by

          @mwolter
          It would be pretty neat to have this built in to the printer instead of the slicer as I've been thinking about!

          Luke
          http://lukeslab.online

          1 Reply Last reply Reply Quote 0
          • A Former User?
            A Former User
            last edited by

            On the subject of Min/Max. Access to work dimensions as well as the specific job dimensions as mrwolter requets.

            dc42undefined 1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators @A Former User
              last edited by

              @bearer said in Conditional GCode and object model variables:

              On the subject of Min/Max. Access to work dimensions as well as the specific job dimensions as mrwolter requets.

              This is tricky, because GCode files do not contain information about the total dimensions of the part being printed/CNC'd/cut. But we can make a reasonable guess at it by scanning the entire GCode file. This assumes the the GCode file does not contain custom scripts for purge or prime towers, or similar operation that move to coordinates outside the model.

              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

              gtj0undefined A Former User? 2 Replies Last reply Reply Quote 0
              • fškundefined
                fšk
                last edited by fšk

                @jay_s_uk said in Conditional GCode and object model variables:

                The most useful thing for me would being able to detect a voltage on an input to identify which tool is fitted.
                E.g. tool 1 is 1V, tool 2 is 2V and so on.
                Then the machine would be aware of what tool is fitted and apply offsets accordingly etc.

                I would also find this very useful. Probably the only thing i would need conditional gcode for.
                Would need this to load a different config depending on what is connected on machine boot.

                1 Reply Last reply Reply Quote 0
                • HebigTundefined
                  HebigT
                  last edited by

                  The ability to call a macro using a "Layer_#" variable would be useful for my research. I'm planning to develop non-extrusion tools for tool-changing printers.

                  1 Reply Last reply Reply Quote 0
                  • Rievundefined
                    Riev @dc42
                    last edited by

                    @dc42 , I think The most useful things is :

                    1. The conditional block may consist "AND / OR" expression so we can combine two or more logic expression.

                    2. SELECT CASE Function as alternative conditional block after IF-ELIF

                    3. Attach "LABEL" name Function in any certain line and "JUMP TO LABEL / GOTO LABEL" Function so we can jump or loop to any line we desire. I think this is more flexible than "While" or other Loop function.

                    4. "WAIT" Function for any input signal or variable is triggered/changed, and make decision with conditional expression based on change of that input signal (Like wait for button is pressed)

                    5. Any variable / command to manipulate "Counter and Timer" Function.

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

                      @Riev said in Conditional GCode and object model variables:

                      @dc42 , I think The most useful things is :

                      1. The conditional block may consist "AND / OR" expression so we can combine two or more logic expression.

                      2. SELECT CASE Function as alternative conditional block after IF-ELIF

                      3. Attach "LABEL" name Function in any certain line and "JUMP TO LABEL / GOTO LABEL" Function so we can jump or loop to any line we desire. I think this is more flexible than "While" or other Loop function.

                      4. "WAIT" Function for any input signal or variable is triggered/changed, and make decision with conditional expression based on change of that input signal (Like wait for button is pressed)

                      5. Any variable / command to manipulate "Counter and Timer" Function.

                      Thanks for your suggestions. #1 is already implemented. #2 is complicated to do in a line-oriented language, also I don't envisage any common situations in which there would be many cases to choose from; so I won;t imllement it at least for now. For #3, 60 years of program language development have taught us GOTO is bad, so I won't be implementing it. #4 is interesting and I will consider it. Can you explain exactly what you mean by #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

                      garyd9undefined grizewaldundefined 2 Replies Last reply Reply Quote 0
                      • garyd9undefined
                        garyd9 @dc42
                        last edited by garyd9

                        @dc42 said in Conditional GCode and object model variables:

                        For #3, 60 years of program language development have taught us GOTO is bad, so I won't be implementing it.

                        Surely you knew when typing the above that you'd be starting a discussion on the merits of goto in programming, right?

                        Goto isn't the demon that it's made out to be. The problem is that it was massively abused. (Just like anything.) For things such as state machines, they are extremely useful. (Is conditional gcode a state machine?)

                        Keep in mind that all our languages are usually compiled to assembly. Show me any functional assembly that isn't littered with "goto" (jmp) instructions.

                        (I'm not suggesting that any type of 'goto' should exist. I was just making a silly point.)

                        "I'm not saying that you are wrong - I'm just trying to fit it into my real world simulated experience."

                        1 Reply Last reply Reply Quote 0
                        • grizewaldundefined
                          grizewald @dc42
                          last edited by

                          @dc42 said in Conditional GCode and object model variables:

                          60 years of program language development have taught us GOTO is bad, so I won't be implementing it.

                          I'm guessing you mean that GOTO is bad for those who don't know how to program. They should certainly be used very sparingly and can be misused to create spaghetti worse than any 3D printer, but they are not bad per-se.

                          In deeply nested decision blocks, a goto can be a life saver for code clarity. Even in those languages which don't provide a goto but give you a try, catch pattern instead, it still boils down to an absolute jump once it gets compiled.

                          infiniteloopundefined 1 Reply Last reply Reply Quote 0
                          • infiniteloopundefined
                            infiniteloop @grizewald
                            last edited by

                            @grizewald I’ve spent many years with GOTO, because the first incarnation of APL had nothing else to offer. This 'style' makes your code unreadable and difficult to debug, it’s a nightmare. Even with labels instead of line numbers: it’s easy to break the stack, to jump out of context… or think of someone who re-assigns a label by accident to something else. No, GOTO is nothing else than an invitation for bugs.

                            1 Reply Last reply Reply Quote 0
                            • JoergS5undefined
                              JoergS5
                              last edited by

                              C++ has goto and even Java has something similar with labels to jump out of a loop. I would prefer if it's available in a language and the developer can decide himself whether he wants to use it in extreme cases. I myself don't use it, but there may be specific cases.

                              wilrikerundefined 1 Reply Last reply Reply Quote 0
                              • wilrikerundefined
                                wilriker @JoergS5
                                last edited by

                                @JoergS5 said in Conditional GCode and object model variables:

                                even Java has something similar with labels to jump out of a loop

                                Java even has goto as a reserved word - it will lead to a compiler error when used. 😂

                                I don't actually want to chime in on the goto discussion. All I would have said is a mixture of the above.

                                @dc42 I was reading the language description wiki page and I was surprised that logical AND and logical OR are on the same precedence level. Most languages I know have a higher precedence for logical AND than for logical OR.

                                Manuel
                                Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                with probably always latest firmware/DWC (incl. betas or self-compiled)
                                My Tool Collection

                                A Former User? 1 Reply Last reply Reply Quote 0
                                • A Former User?
                                  A Former User @wilriker
                                  last edited by

                                  @wilriker said in Conditional GCode and object model variables:

                                  • it will lead to a compiler error when used

                                  Touché!

                                  But I guess we can put the whole discussion to bed with the following. All in favour of removing jmpinstruction raise their hand .. and having it doesn't mean you have to use it.

                                  OT aside, really looking forward to this beta!

                                  1 Reply Last reply Reply Quote 0
                                  • gtj0undefined
                                    gtj0 @dc42
                                    last edited by gtj0

                                    @dc42 said in Conditional GCode and object model variables:

                                    @bearer said in Conditional GCode and object model variables:

                                    On the subject of Min/Max. Access to work dimensions as well as the specific job dimensions as mrwolter requets.

                                    This is tricky, because GCode files do not contain information about the total dimensions of the part being printed/CNC'd/cut. But we can make a reasonable guess at it by scanning the entire GCode file. This assumes the the GCode file does not contain custom scripts for purge or prime towers, or similar operation that move to coordinates outside the model.

                                    This reminds me of a discussion we had a while back about having the DCS provide pre-processing hooks on files. The hook would provide the name of the file, the script would do whatever it needs to it, write it out to a temp file, then tell the DCS the new file name. This may already be possible with intercepts ( @chrishamm ? ).

                                    What RRF would need to do is allow statements to set variables in the print file that would later be accessible from macros.

                                    The original thought came up when we were talking about having multiple bed heaters creating zones on a large bed plate, then having the gcode only turn on the zones needed for the particular print. The thought was that the script would calculate the bounds and either override the bed heater commands in the input gcode or pass the bounds on to a macro with conditional gcode.

                                    1 Reply Last reply Reply Quote 0
                                    • gtj0undefined
                                      gtj0
                                      last edited by

                                      I kinda missed this thread but in reading it and the Meta Commands stuff it looks pretty good. Variables are the most important for me since I really want to make changes to things temporarily then set them back to the original value when I'm done.

                                      I also didn't see this in the discussion ( or I missed it ) but being able to get things set in config.g that aren't already in the object model is something I think we'd need. Kinda like a JSON output of M503 that we can reference in the macro.

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

                                        @gtj0 said in Conditional GCode and object model variables:

                                        I kinda missed this thread but in reading it and the Meta Commands stuff it looks pretty good. Variables are the most important for me since I really want to make changes to things temporarily then set them back to the original value when I'm done.

                                        Can you give me an example?

                                        If you need to restore everything to the values in config.g, you can do that by re-running config.g. To restore a subset of values, set those up in a macro that config.g calls.

                                        I also didn't see this in the discussion ( or I missed it ) but being able to get things set in config.g that aren't already in the object model is something I think we'd need. Kinda like a JSON output of M503 that we can reference in the macro.

                                        The plan is that everything you can configure (and some things you cannot) will be in the OM. Now that the OM framework is complete, it's mostly a matter of adding entries to tables and a few simple getter functions.

                                        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

                                        gtj0undefined 1 Reply Last reply Reply Quote 0
                                        • A Former User?
                                          A Former User @dc42
                                          last edited by

                                          @dc42 said in Conditional GCode and object model variables:

                                          @bearer said in Conditional GCode and object model variables:

                                          On the subject of Min/Max. Access to work dimensions as well as the specific job dimensions as mrwolter requets.

                                          This is tricky, because GCode files do not contain information about the total dimensions

                                          It can, many of us use post-processors for G-Code after it exits the slicer, and there many useful info can be embedded in the code... for e.g. there are some that embed %done, total amount of plastic, date, time etc etc... it's fairly easy to embed the size of the object, position... now, most of them embed this info in form of comment but when you implement the VAR xxx = yyy I assume that's it as then we can set in slicer/postprocessor to instead add this as comment, add these in form of VAR maxwhatever = 12345 ..

                                          tbh I expected this gcode addon to be also inside comments, to use some "special comments" like for e.g. bash uses #! or mysql /*! to be special comment ... so I expected something like ;! if blah blah .. so that G-Code works on other interpretters too (kinda) but I don't mind it like this 🙂

                                          1 Reply Last reply Reply Quote 0
                                          • gtj0undefined
                                            gtj0 @dc42
                                            last edited by

                                            @dc42 said in Conditional GCode and object model variables:

                                            @gtj0 said in Conditional GCode and object model variables:

                                            I kinda missed this thread but in reading it and the Meta Commands stuff it looks pretty good. Variables are the most important for me since I really want to make changes to things temporarily then set them back to the original value when I'm done.

                                            Can you give me an example?

                                            If you need to restore everything to the values in config.g, you can do that by re-running config.g. To restore a subset of values, set those up in a macro that config.g calls.

                                            I also didn't see this in the discussion ( or I missed it ) but being able to get things set in config.g that aren't already in the object model is something I think we'd need. Kinda like a JSON output of M503 that we can reference in the macro.

                                            The plan is that everything you can configure (and some things you cannot) will be in the OM. Now that the OM framework is complete, it's mostly a matter of adding entries to tables and a few simple getter functions.

                                            The one that sprang to mind immediately was defining the mesh grid
                                            M557 X0:460 Y0:450 S25

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