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

    Feedback wanted: conditional GCode without indentation

    Scheduled Pinned Locked Moved
    Future Direction
    28
    54
    4.3k
    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.
    • fcwiltundefined
      fcwilt @zapta
      last edited by

      @zapta said in Feedback wanted: conditional GCode without indentation:

      One option is to annotate it with comments.

      END ; while xyz

      True but with specific keywords I'm forced to do the "right" thing. 😉

      Frederick

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

      1 Reply Last reply Reply Quote 0
      • alankilianundefined
        alankilian
        last edited by

        Here's one way to "DO" it. 🙂

        https://www.cnccookbook.com/cnc-g-code-macro-conditions-looping/

        SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

        1 Reply Last reply Reply Quote 1
        • garyd9undefined
          garyd9 @fcwilt
          last edited by

          @fcwilt said in Feedback wanted: conditional GCode without indentation:

          @garyd9 said in Feedback wanted: conditional GCode without indentation:

          Can you please give an example of a gcode sequence that would impractical with the current space delimiting blocks?

          The issue is gcode files as generated by a slicer - not the files you would create yourself on the duet.

          That doesn't answer the question. Without an example of the problem, it's difficult to give a reasonable opinion on a proposed solution.

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

          fcwiltundefined dc42undefined 2 Replies Last reply Reply Quote 0
          • botundefined
            bot
            last edited by

            I think removing all indentation/whitespace from the syntax is a good idea. I also think a single END keyword is best. Multiple end keywords is just unnecessary. Keep track of the ENDs the same way one keeps track of the }s.

            *not actually a robot

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

              @garyd9 said in Feedback wanted: conditional GCode without indentation:

              That doesn't answer the question. Without an example of the problem, it's difficult to give a reasonable opinion on a proposed solution.

              As dc42 said in his opening post:

              However, the need to indent the body of a conditional or loop makes it impractical to use a while-loop to create a looping GCode file, for example for a belt printer.

              That seems clear enough.

              Frederick

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

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

                @garyd9 said in Feedback wanted: conditional GCode without indentation:

                @fcwilt said in Feedback wanted: conditional GCode without indentation:

                @garyd9 said in Feedback wanted: conditional GCode without indentation:

                Can you please give an example of a gcode sequence that would impractical with the current space delimiting blocks?

                The issue is gcode files as generated by a slicer - not the files you would create yourself on the duet.

                That doesn't answer the question. Without an example of the problem, it's difficult to give a reasonable opinion on a proposed solution.

                Suppose you generate a GCode file using a slicer. But you have a belt printer and you want to print it 10 times, with a belt movement between each iteration.

                Using existing slicers, there is no way to use the slicer start and end scripts to achieve this.

                You could achieve it by editing the GCode file, but then you would have to indent almost the whole GCode file so that it became the body of the while-loop.

                If we offer the option to delimit if- and while-commands explicitly, then you could insert one line near the start of the file (the 'while' line), and one near the end (the 'end' line). You might even be able to put the 'while' line in your slicer start script, and the 'end' line in the end script, so that you don't need to edit the file at all.

                Does that make the reason for this proposal clearer?

                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 theruttmeisterundefined OwenDundefined 3 Replies Last reply Reply Quote 2
                • fcwiltundefined
                  fcwilt @bot
                  last edited by

                  @bot said in Feedback wanted: conditional GCode without indentation:

                  Keep track of the ENDs the same way one keeps track of the }s.

                  '}' symbols are evil incarnate.

                  😉

                  Frederick

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

                  botundefined zaptaundefined 2 Replies Last reply Reply Quote 0
                  • botundefined
                    bot @fcwilt
                    last edited by

                    @fcwilt } // they don't seem so bad to me

                    😛

                    *not actually a robot

                    1 Reply Last reply Reply Quote 1
                    • tekkydaveundefined
                      tekkydave @dc42
                      last edited by

                      @dc42 curly braces for me every time. I don't see the point of adding extra keywords that just take up space.

                      ~ tekkydave ~
                      D-Bot: 300x300mm | Duet WiFi + Duex2 | 3 independent z motors | X,Y & Z linear rails | E3D Titan Aero + V6 | Precision Piezo z-probe
                      FreeCAD, PrusaSlicer

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

                        @fcwilt I once used a language called pl/9 that had a repeat...until. I miss it from every other language I've used since.

                        ~ tekkydave ~
                        D-Bot: 300x300mm | Duet WiFi + Duex2 | 3 independent z motors | X,Y & Z linear rails | E3D Titan Aero + V6 | Precision Piezo z-probe
                        FreeCAD, PrusaSlicer

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

                          @tekkydave said in Feedback wanted: conditional GCode without indentation:

                          @fcwilt I once used a language called pl/9 that had a repeat...until. I miss it from every other language I've used since.

                          I never heard of PL/9 - I used PL/1 for a bit - it's looping syntax was flexible and consistent.

                          My programming language of choice is Delphi.

                          Frederick

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

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

                            @tekkydave said in Feedback wanted: conditional GCode without indentation:

                            @dc42 curly braces for me every time. I don't see the point of adding extra keywords that just take up space.

                            Keywords have a mnemonic value that isolated arbitrary symbols lack.

                            Frederick

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

                            1 Reply Last reply Reply Quote 0
                            • garyd9undefined
                              garyd9 @dc42
                              last edited by garyd9

                              @dc42 said in Feedback wanted: conditional GCode without indentation:

                              Does that make the reason for this proposal clearer?

                              Yes, much clearer. Thank you.

                              I'm not familiar with belt printers and how this might be used - which left (and still leaves) my understanding lacking.

                              That being said, can the problem be addressed using macros? Can a print job's gcode use M28/M29 to create new files?

                              ; ----- start gcode
                              ;
                              ; inital printer setup
                              ; 
                              M28 job.gcode ; cause the actual gcode to be written to job.gcode
                              ;
                              ; ------- actual print gcode generated by slicer
                              ;
                              ; --------- end gcode
                              M29  ; stop/save job.gcode
                              ;
                              ;  -- here would be the loop for running the print job
                              while (some_condition)
                                     ; belt movement
                                     M32 job.gcode
                              

                              <eof>

                              (I have no idea if a gcode file can use M28/m29 to create another gcode file, but if it can...)

                              "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
                              • theruttmeisterundefined
                                theruttmeister @dc42
                                last edited by

                                @dc42 said in Feedback wanted: conditional GCode without indentation:

                                @garyd9 said in Feedback wanted: conditional GCode without indentation:

                                @fcwilt said in Feedback wanted: conditional GCode without indentation:

                                @garyd9 said in Feedback wanted: conditional GCode without indentation:

                                Can you please give an example of a gcode sequence that would impractical with the current space delimiting blocks?

                                The issue is gcode files as generated by a slicer - not the files you would create yourself on the duet.

                                That doesn't answer the question. Without an example of the problem, it's difficult to give a reasonable opinion on a proposed solution.

                                Suppose you generate a GCode file using a slicer. But you have a belt printer and you want to print it 10 times, with a belt movement between each iteration.

                                Using existing slicers, there is no way to use the slicer start and end scripts to achieve this.

                                You could achieve it by editing the GCode file, but then you would have to indent almost the whole GCode file so that it became the body of the while-loop.

                                If we offer the option to delimit if- and while-commands explicitly, then you could insert one line near the start of the file (the 'while' line), and one near the end (the 'end' line). You might even be able to put the 'while' line in your slicer start script, and the 'end' line in the end script, so that you don't need to edit the file at all.

                                Does that make the reason for this proposal clearer?

                                That could be simplified down to a gcode command that executed a specific .gcode file multiple times:
                                Mxxx thisprintjob.gcode S10
                                For example.
                                That has the advantage of not needing anything like the complexity of conditionals.

                                I think the fact that it is a programming loop is making people think that the solution is to create the ability in g-code to code loops. Where as in fact for the described use case at least, its not really a loop, its just a way to not have the file be 10 times longer than it needs to be.

                                At there other things that actually are conditional and not just 'do x, y number of times'?

                                (in fact, all this could be done in DWC... which in some ways makes more sense).

                                Isolate, substitute, verify.

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

                                  @fcwilt said in Feedback wanted: conditional GCode without indentation:

                                  '}' symbols are evil incarnate.

                                  The Duet's firmware is full of them, don't bring it into your home. 😉

                                  https://github.com/Duet3D/RepRapFirmware/blob/dev/src/Movement/DriveMovement.cpp

                                  fcwiltundefined 1 Reply Last reply Reply Quote 0
                                  • garethkyundefined
                                    garethky
                                    last edited by

                                    1. end is fine
                                    2. I would pick just 1 way to do it, even if that way breaks existing code. Now is the time to make breaking changes. I don't want to imagine a) what tricky things users will think up to fool themselves b) what implementation bugs will arise due to the complexity of having 2 ways to do it.
                                    3. As a software engineer, this question makes my skin crawl. I really wouldn't do anything for whole files, just blocks. But if you really want to mix both styles, I would do this: require unintended blocks to have a begin and end keywords, on their own lines, to delimit the block. That way begin/end can be used with all of the existing block types without renaming them (the names are perfectly good as-is).
                                    if foo == bar
                                        begin  
                                    ; begin unruly slicer generated gcode
                                    G10
                                    G1 X50 Y50 F5000
                                    ; and so on ...
                                        end
                                    

                                    This is basically a friendlier versions of parens{<block>}. You could also postfix the if statement with python's : to indicate an unintended block start but this is so subtle and easy to miss that I think it is visiting an evil on the intended audience.

                                    Visual Basic has "OrElse" and "AndAlso", because they refused to re-define the meaning of "or" and "and". Don't be Visual Basic.

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

                                      @zapta said in Feedback wanted: conditional GCode without indentation:

                                      The Duet's firmware is full of them, don't bring it into your home. 😉

                                      That's why I perform a ritual "cleansing" of the boards before I use them in a printer.

                                      Better safe than sorry. 😉

                                      Frederick

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

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

                                        @theruttmeister said in Feedback wanted: conditional GCode without indentation:

                                        That could be simplified down to a gcode command that executed a specific .gcode file multiple times:
                                        Mxxx thisprintjob.gcode S10

                                        That would still require editing the slicer generated file to separate out the pre-print/post-print code from the main body of the code.

                                        With a While and End you add two lines to the file and your done.

                                        Frederick

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

                                        1 Reply Last reply Reply Quote 0
                                        • BoAundefined
                                          BoA
                                          last edited by BoA

                                          Should the keywork be 'end', or something else?
                                          I think I would use

                                          if condition
                                                     then
                                                                 if given condition true
                                                                 execute all commands up to else statement
                                                                 or to fi if there is no else statement
                                          
                                                     else
                                                                 if given condition false 
                                                                 execute all commands up to fi
                                                     fi
                                          

                                          and

                                          while condition
                                          do
                                             command1
                                             command2
                                             command3
                                          done
                                          

                                          Should it be permitted to mix keywork-delimiting and indentation-delimiting in the same file? If so, what problems might arise, and what restrictions should be enforced?

                                          IMO indentations should be allowed just to keep it more readable, but ignored in processing code

                                          How should the user indicate to the firmware that a loop or conditional is to be delimited by a keyword instead of by indentation? One option is to have a new command keyword (e.g. 'noblockindent') that means that for the remainder of the file, keywork-delimiting will be used. Using that keyword when already inside a block would probably have to be banned. Another option is to use different variations of 'if' and 'while' (e.g. a different keyword or some extra character) to indicate keywork delimiting for that command.

                                          I would drop indentations for indicating clode blocks

                                          1 Reply Last reply Reply Quote 1
                                          • MJLewundefined
                                            MJLew
                                            last edited by

                                            1. The coding language that I use most of the time (Livecode) uses "end repeat" to end a repeat loop, "end if" to end a conditional et cetera. It is very nice in that it does not depend on indents and it is entirely unambiguous. I commend it as a model to follow.

                                            2. No. Do not allow mixtures. They will be confusing.

                                            3. Ideally you would make the delimiting by keyword and do not support indentation. However, I'm guessing that indentation is already in use, and in that case your idea of something like 'noblockindent' would work rather like M82 and M83 (absolute and relative extruder). Perhaps it should have two keywords 'blockindent' and 'blockwords'.

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