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

Feedback wanted: conditional GCode without indentation

Scheduled Pinned Locked Moved
Future Direction
28
54
3.8k
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.
  • undefined
    fcwilt @garyd9
    last edited by 8 Feb 2021, 15:14

    @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.

    Frederick

    Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

    undefined 1 Reply Last reply 8 Feb 2021, 17:06 Reply Quote 1
    • undefined
      fcwilt @DaveA
      last edited by 8 Feb 2021, 15:16

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

      As a C & C++ programmer from around 1976 I'd love to see the Kernighan and Ritchie style with { } syntax. I hate Python indention style.
      Just my opinion since you asked.

      Ugh - no.

      C++ syntax was devised by sadists.

      😉

      Frederick

      Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

      undefined undefined 2 Replies Last reply 8 Feb 2021, 15:38 Reply Quote 1
      • undefined
        DaveA @fcwilt
        last edited by 8 Feb 2021, 15:38

        @fcwilt Yeah, I can agree with you on C++. I'd rather stick with straight C as most of my experience was with windows device drivers. In any case, it's better than Python. 🙂

        1 Reply Last reply Reply Quote 1
        • undefined
          zapta @fcwilt
          last edited by zapta 2 Aug 2021, 16:07 8 Feb 2021, 16:07

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

          END by itself is easy but if you don't see it in context you don't know what it is the end of. It might be better to have unique keywords - ENDWHILE, ENDIF or something along those lines.
          Frederick

          One option is to annotate it with comments.

          END ; while xyz

          BTW, I am also not a fan of white space indentation having semantic meaning. It's too fragile, event with language specific editors that support it.

          undefined 1 Reply Last reply 8 Feb 2021, 16:23 Reply Quote 2
          • undefined
            reghend79
            last edited by 8 Feb 2021, 16:13

            I think both keyword-delimiting and indentation-delimiting should be permitted in the same file to allow for flexibility and varying degrees of clarity. I'm working on analyzing print data in Matlab to create feedback control, and I am quite fond of using both indentations and "end" statements at the same time. The indentations are not normally required in Matlab, but they're done automatically to help visualize the blocks.

            undefined 1 Reply Last reply 8 Feb 2021, 16:20 Reply Quote 0
            • undefined
              zapta @reghend79
              last edited by zapta 2 Aug 2021, 16:21 8 Feb 2021, 16:20

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

              The indentations are not normally required in Matlab, but they're done automatically to help visualize the blocks.

              That's a good point, END should still allow indentation for code clarity, though the indentation would have no semantic impact. E.g. these code snippet should have the same meaning

              IF
              COMMAND1
              COMMAND2
              COMMAND3
              END
              IF
              COMMAND1
              COMMAND2
              END
              IF
              COMMAND1
              COMMAND2
              END
              IF
              COMMAND1
              COMMAND2
              END
              1 Reply Last reply Reply Quote 1
              • undefined
                fcwilt @zapta
                last edited by 8 Feb 2021, 16:23

                @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 small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                1 Reply Last reply Reply Quote 0
                • undefined
                  alankilian
                  last edited by 8 Feb 2021, 16:33

                  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
                  • undefined
                    garyd9 @fcwilt
                    last edited by 8 Feb 2021, 17:06

                    @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."

                    undefined undefined 2 Replies Last reply 8 Feb 2021, 17:20 Reply Quote 0
                    • undefined
                      bot
                      last edited by 8 Feb 2021, 17:12

                      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

                      undefined 1 Reply Last reply 8 Feb 2021, 17:21 Reply Quote 0
                      • undefined
                        fcwilt @garyd9
                        last edited by 8 Feb 2021, 17:20

                        @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 small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                        1 Reply Last reply Reply Quote 0
                        • undefined
                          dc42 administrators @garyd9
                          last edited by 8 Feb 2021, 17:21

                          @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

                          undefined undefined undefined 3 Replies Last reply 8 Feb 2021, 17:43 Reply Quote 2
                          • undefined
                            fcwilt @bot
                            last edited by 8 Feb 2021, 17:21

                            @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 small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                            undefined undefined 2 Replies Last reply 8 Feb 2021, 17:22 Reply Quote 0
                            • undefined
                              bot @fcwilt
                              last edited by 8 Feb 2021, 17:22

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

                              😛

                              *not actually a robot

                              1 Reply Last reply Reply Quote 1
                              • undefined
                                tekkydave @dc42
                                last edited by 8 Feb 2021, 17:28

                                @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

                                undefined 1 Reply Last reply 8 Feb 2021, 17:43 Reply Quote 0
                                • undefined
                                  tekkydave @fcwilt
                                  last edited by 8 Feb 2021, 17:35

                                  @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

                                  undefined 1 Reply Last reply 8 Feb 2021, 17:41 Reply Quote 0
                                  • undefined
                                    fcwilt @tekkydave
                                    last edited by 8 Feb 2021, 17:41

                                    @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 small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                                    1 Reply Last reply Reply Quote 0
                                    • undefined
                                      fcwilt @tekkydave
                                      last edited by 8 Feb 2021, 17:43

                                      @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 small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        garyd9 @dc42
                                        last edited by garyd9 2 Aug 2021, 17:44 8 Feb 2021, 17:43

                                        @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
                                        • undefined
                                          theruttmeister @dc42
                                          last edited by 8 Feb 2021, 17:45

                                          @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.

                                          undefined 1 Reply Last reply 8 Feb 2021, 19:16 Reply Quote 0
                                          18 out of 54
                                          • First post
                                            18/54
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA