Duet3D Logo

    Duet3D

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Documentation
    • Order

    Solved Reading Input Pin States for Conditional GCode

    Gcode meta commands
    6
    15
    533
    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.
    • tenaja
      tenaja last edited by tenaja

      I have moved my question here, as I know a little more and it should be in this category.

      I have some hand-written gcode for a simple production task. I need it to accommodate the full tolerance of material. So, I would like it to run this pseudo-code:

      If e1stop = 1
        ;Run This GCode for large material
      elseif e0stop=1
        ;Run This GCode for Small material
      else
        ;Run this GCode for nominal material
      ; endif omited; indentation based.
      

      I have updated my Duet 2 Wifi to 3.3b2.

      I have tried a few things, but everything has given me an error. I've tried both of these methods for declaring my inputs:

      M950  J1 C"!^e1stop"
      M950  J0 C"!^e0stop"
      

      And everything I try to do to read them gives me an error. Clearly, I am missing the documentation that describes simple reading of the input value. Can someone point me to that?

      I've read this page:
      https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands
      and it discusses the commands, and not the inputs. I've read the pdf posted in this thread, and it does not cover gpio or inputs, either.
      https://forum.duet3d.com/topic/16495/conditional-g-code-introduction-tutorial-pdf
      (One of the links in there, to Object Model, even has this same question in the Comment section...unanswered.)

      I have found a thread looking at outputs, and their names with M409, but I have not found the place that describes the K value for inputs.

      I have searched the forum and the wiki, and must not be using the correct search terms. Do I have to declare it as a sensor?

      Thanks!

      OwenD dc42 2 Replies Last reply Reply Quote 0
      • OwenD
        OwenD @tenaja last edited by

        @tenaja
        You can't address the end stops directly in that manner.
        If you activate the object model browser plugin you can get an idea of how to do it.
        You need something lime

        if sensors.endstops[0].triggered=true
            ;do stuff here
        
        tenaja 1 Reply Last reply Reply Quote 1
        • tenaja
          tenaja @OwenD last edited by tenaja

          @OwenD thanks, I'll try that when I get back to my computer.

          Where is the end stop number lookup list?

          I don't actually have end stops... It's a 3pos switch. Is there a better way to declare them?

          ZipZap 1 Reply Last reply Reply Quote 0
          • ZipZap
            ZipZap @tenaja last edited by

            @tenaja
            The name of the endstop doesn't change, no matter what is connected to it.
            You can look all the (with the current config.g) addressable parameters and variables under

            • settings, then
            • general, then
            • Built-In-Plugins

            There you have to activate the object model browser plugin. After that, it appears under the settings-tab.

            /Julien

            Most important guide -> Triffid Hunter's Calibration Guide
            HyperCube EVO (derivate) in 250x250x300 - enclosed for ABS - Duet2WiFi - custom watercooling

            1 Reply Last reply Reply Quote 1
            • dc42
              dc42 administrators @tenaja last edited by

              @tenaja said in Reading Input Pin States for Conditional GCode:

              I have tried a few things, but everything has given me an error. I've tried both of these methods for declaring my inputs:

              M950  J1 C"!^e1stop" 
              M950  J0 C"!^e0stop" 
              

              And everything I try to do to read them gives me an error. Clearly, I am missing the documentation that describes simple reading of the input value. Can someone point me to that?

              Those lines are correct to set up those ports as general purpose inputs. They only need to be sent once, so they can go in config.g. To read them, use object model array sensors.gpIn. For example:

              if sensors.gpIn[1].value = 1
                ;Run This GCode for large material
              elif sensors.gpIn[0].value=1
                ;Run This GCode for Small material
              else
                ;Run this GCode for nominal material

              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

              tenaja 1 Reply Last reply Reply Quote 1
              • tenaja
                tenaja last edited by tenaja

                @ZipZap , your post gave me the information I needed to figure out, on my own, along with @OwenD help... basically what David handed me on a silver platter.

                Thanks to everyone for their help! This forum has always been excellent.

                1 Reply Last reply Reply Quote 2
                • tenaja
                  tenaja @dc42 last edited by

                  @dc42 ...for future readers, that gpIn is case sensitive! I tested it just to be sure, and sure enough, it fails with lower case.

                  Wherever I was reading about it, I could not tell if it was an i or an l, but it was neither... it turned out to be a capital I (capital i, not L). I had to do a ctrl-f search, and even then it was unclear.

                  1 Reply Last reply Reply Quote 0
                  • OwenD
                    OwenD last edited by

                    Yes, meta commands are case sensitive.

                    The wiki here states otherwise, but that was written before conditional code came along and needs review

                    Phaedrux 1 Reply Last reply Reply Quote 0
                    • Phaedrux
                      Phaedrux Moderator @OwenD last edited by Phaedrux

                      @OwenD Thanks for pointing that out. It is true for the average gcode that it's not case sensitive, but not so for the conditional gcode, correct?

                      Z-Bot CoreXY Build | Thingiverse Profile

                      fcwilt OwenD 2 Replies Last reply Reply Quote 0
                      • fcwilt
                        fcwilt @Phaedrux last edited by

                        I rather see the case sensitive nature eliminated.

                        I have seen many defend such behavior but imagine if that applied to the naming of things, like children for example.

                        Consider four sons named Frank, frank, franK, frAnk - a recipe for confusion to be sure.

                        😉

                        Frederick

                        Printers: A FT-5 with the 713 upgrade bits. A custom MarkForged style. A small Utilmaker style and a CoreXY from kits. Various hotends. Using Duets (2 and 3) running 3.4.1

                        OwenD 1 Reply Last reply Reply Quote 0
                        • OwenD
                          OwenD @Phaedrux last edited by

                          @Phaedrux
                          As far as I'm aware, the only thing that is case sensitive is object model names.
                          I don't think IF vs if makes a difference.
                          In a way the document is correct as these aren't "G Code" in the true sense, but as we are now referring to it as "conditional gcode" then confusing will arise.

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

                            @fcwilt said in Reading Input Pin States for Conditional GCode:

                            Consider four sons named Frank, frank, franK, frAnk - a recipe for confusion to be sure.

                            😉

                            Frederick

                            But of course only one of those names would be correct.

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

                              @OwenD said in Reading Input Pin States for Conditional GCode:

                              @fcwilt said in Reading Input Pin States for Conditional GCode:

                              Consider four sons named Frank, frank, franK, frAnk - a recipe for confusion to be sure.

                              😉

                              Frederick

                              But of course only one of those names would be correct.

                              How so? Four sons each with a different name if names were case sensitive.

                              Frederick

                              Printers: A FT-5 with the 713 upgrade bits. A custom MarkForged style. A small Utilmaker style and a CoreXY from kits. Various hotends. Using Duets (2 and 3) running 3.4.1

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

                                @fcwilt
                                I was mainly just throwing out a bait, but I'll answer.
                                It's simply because language has rules, be it English or a programming language.
                                A persons name must be represented with a capital letter.
                                Frank, is a name. "frank" is an adjective.

                                The use of uppercase letters in object names is for a good reason. Most programming languages have such conventions for readability among other things
                                .
                                I accept your point of view that being entirely case insensitive may seem attractive.
                                I just reject your example.

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

                                  @OwenD said in Reading Input Pin States for Conditional GCode:

                                  A persons name must be represented with a capital letter.

                                  But if case sensitive names had been the norm from the far past that "rule" you mention would not exist.

                                  I reject your rejection. 😉

                                  Frederick

                                  Printers: A FT-5 with the 713 upgrade bits. A custom MarkForged style. A small Utilmaker style and a CoreXY from kits. Various hotends. Using Duets (2 and 3) running 3.4.1

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