• 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
    garethky
    last edited by 8 Feb 2021, 18:11

    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
    • undefined
      fcwilt @zapta
      last edited by 8 Feb 2021, 19:13

      @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 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 @theruttmeister
        last edited by 8 Feb 2021, 19:16

        @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 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
          BoA
          last edited by BoA 2 Aug 2021, 20:21 8 Feb 2021, 19:27

          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
          • undefined
            MJLew
            last edited by 8 Feb 2021, 20:02

            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
            • undefined
              MikeS @fcwilt
              last edited by 8 Feb 2021, 20:22

              @fcwilt +1 from me but at the moment {} brackets are used for putting variables from object model into gcode commands.

              Anyway i think that more similiar the conditional code is to c++ and less to python is for me a big yes....i have no problem with this type of language but i hate having indentation to determine the loop/function start/end.

              I would give a function its proper "ender" so for example "loop" for while loop and so on.

              1 Reply Last reply Reply Quote 1
              • undefined
                OwenD
                last edited by 8 Feb 2021, 20:28

                Having come from a Delphi programming background (based on pascal) I'd be inclined to lean towards a similar syntax
                Pascal was designed to be easy to read/teach.
                Blocks are typically surrounded by begin/end and use the keyword "do"
                Indentation is not required but usually used for clarity.

                while iterations < 10 do
                begin
                // do stuff
                end

                For if statements

                if move.axes[0].homed do
                begin
                echo "axis homed"
                end
                else
                begin
                echo "axis is not homed"
                end

                line ends are usually terminated with a semi colon ; except in nested begin/end blocks as if if else (the outer block must have a ; and the inner must not) but I don't think that is necessary here.
                Likewise the do keyword is purely for human readability.

                I would not allow mixing of indentation and whatever block format is chosen.

                1 Reply Last reply Reply Quote 2
                • undefined
                  bot
                  last edited by 8 Feb 2021, 22:52

                  I don't see the need for a begin keyword. If is the keyword that starts the block.

                  Perhaps if a keyword is required at the beginning, we could borrow some LUA parlance and use THEN, so that the parser knows when the conditional is over.

                  *not actually a robot

                  undefined 1 Reply Last reply 9 Feb 2021, 00:44 Reply Quote 0
                  • undefined
                    dbruce.ae05
                    last edited by 8 Feb 2021, 23:13

                    I’m going to break with the group. I like the Python style of programming and keeping the indentations. Python is widely used and when writing code on the SBC, most likely a raspberry pi, Python is the natural choice.

                    undefined 1 Reply Last reply 9 Feb 2021, 00:41 Reply Quote 0
                    • undefined
                      fcwilt @dbruce.ae05
                      last edited by 9 Feb 2021, 00:41

                      @dbruce-ae05 said in Feedback wanted: conditional GCode without indentation:

                      I’m going to break with the group. I like the Python style of programming and keeping the indentations. Python is widely used and when writing code on the SBC, most likely a raspberry pi, Python is the natural choice.

                      You're forgiven your errant ways. šŸ˜‰

                      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 9 Feb 2021, 01:06 Reply Quote 0
                      • undefined
                        fcwilt @bot
                        last edited by 9 Feb 2021, 00:44

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

                        I don't see the need for a begin keyword. If is the keyword that starts the block.

                        Perhaps if a keyword is required at the beginning, we could borrow some LUA parlance and use THEN, so that the parser knows when the conditional is over.

                        Well in Delphi if you only have one statement after the condition you don't need the begin/end pair. You use them when you have more than one statement.

                        I always thought that NOT always requiring begin/end even for one statement was a mistake.

                        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 2
                        • undefined
                          dbruce.ae05 @fcwilt
                          last edited by 9 Feb 2021, 01:06

                          @fcwilt šŸ™ƒ

                          1 Reply Last reply Reply Quote 0
                          • undefined
                            lord binky @DaveA
                            last edited by 9 Feb 2021, 16:44

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

                            What? But python style works great in editors like EMACS! Fancy IDE's highlighting { } groupings is for schmucks right? šŸ˜„

                            1 Reply Last reply Reply Quote 0
                            • undefined
                              wilriker
                              last edited by 9 Feb 2021, 17:23

                              My opinion: use a keyword to end blocks (end is fine for me, but honestly I don't care).

                              Do not allow mixing styles, use block end keywords exclusively (but allow indentation for style purposes).

                              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

                              undefined undefined 2 Replies Last reply 9 Feb 2021, 18:49 Reply Quote 1
                              • undefined
                                fcwilt @wilriker
                                last edited by 9 Feb 2021, 18:49

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

                                My opinion: use a keyword to end blocks (end is fine for me, but honestly I don't care).

                                So you would be ok with "ruvineckerned" or "footguratunnie"?

                                Just checking to be sure.

                                šŸ˜‰

                                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 1
                                • undefined
                                  garethky @wilriker
                                  last edited by 9 Feb 2021, 19:52

                                  @wilriker +1

                                  The target audience for this language is not skilled programmers. Its designers & makers that are trying to solve some problem with their printer. There is going to be a LOT of copy/paste code that mixes indentation types (tabs, spaces, number of spaces). Begin/end constructs survive this kind of abuse better than Python style strict indentation. Having just 1-way-to-do-it makes its safer/easier for newbies copying code.

                                  The few of us that are writing most of the code can use whatever construct you come up with.

                                  1 Reply Last reply Reply Quote 7
                                  • undefined
                                    DanS79
                                    last edited by 9 Feb 2021, 21:01

                                    I think php might be a good example here as it allows two types of syntax.

                                    For pure php

                                    <?php
                                    if ($a > $b) {
                                    // do somehting
                                    } else {
                                    // do somehting else
                                    }
                                    ?>

                                    For php mixed with large chunks of something else like html, JS etc.

                                    <?php if ($a > $b) : ?>
                                    // do somehting
                                    <?php else: ?>
                                    // do somehting else
                                    <?php endif; ?>

                                    All standard control structures have the second alternative syntax.

                                    The parser knows php is only contained between the opening and closing tags

                                    <?php  // some code here ?>
                                    

                                    The alternate control structures lets the parser know that logic spans multiple sets of opening and closing tags.

                                    Each control structure has it's own unique opening and closing tags.
                                    here is a quick little tutorial with examples.
                                    https://riptutorial.com/php/topic/1199/alternative-syntax-for-control-structures

                                    1 Reply Last reply Reply Quote 0
                                    • undefined
                                      OwenD
                                      last edited by 10 Feb 2021, 00:11

                                      One thought I guess as is how any start/end construct might be interpreted by common slicers if used in start gcode etc
                                      Prusa slicer uses if-endif so is definitely going to try to post process that. Whether it causes any issues probably depends on how PS handles things it doesn't understand

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        garyd9
                                        last edited by 10 Feb 2021, 00:28

                                        I agree that styles shouldn't be mixed and that RRF should either support one thing or another (and not both.) However, RRF 3 is a released product, so any change could be breaking a LOT of code, macros, etc.

                                        Even the initial "conditional gcode" stuff in RRF3 was done in such a way to not break any existing gcode.

                                        For that reason, I still think there are ways to solve the actual problem without breaking changes to the language. One idea I proposed above, though I don't know if that would actually work. Immediately after, someone else proposed something else that wouldn't break any existing gcode.

                                        Breaking an existing programming language for single special cases isn't a good practice. Even large functional changes should be careful to not break existing code. I still have old K&R style C code that still compiles with a modern C/C++ compiler!

                                        "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
                                          OwenD @dc42
                                          last edited by OwenD 2 Oct 2021, 03:37 10 Feb 2021, 03:35

                                          @dc42

                                          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.

                                          For this particular case, could it not be solved using a loop Gcode as in CNC or plasma cutting? In the case of Hypertherm controllers they use G97 & G98 to define the loop.
                                          In my day job I sell CNC plasma systems and the nesting program would output thusly if you used step and repeat.
                                          I would have thought that instead of stepping on Y, you'd just do Z?

                                          %
                                          G21
                                          G91
                                          G97 T10; loop 10 times
                                          N1
                                          M00
                                          G00X0.Y45.278
                                          (Seq 1 - square)
                                          G41
                                          M07 ; torch on
                                          G01Y4.722
                                          G01X50.
                                          G01Y-50.
                                          G01X-50.
                                          G01Y45.278
                                          M08 ; torch off
                                          G40
                                          G00X0.Y104.722 ; move to be ready for next part
                                          G98 ; Repeat at G97 point
                                          M30 ; end of program
                                          %
                                          deckingmanundefined 1 Reply Last reply 10 Feb 2021, 08:00 Reply Quote 0
                                          39 out of 54
                                          • First post
                                            39/54
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA