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

    Conditional Output status or Tool deselect script?

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    8
    425
    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.
    • mwwhitedundefined
      mwwhited
      last edited by mwwhited

      Re: Conditional Gcode and GPIO State
      Re: Tool deselect macro?

      Is it possible to write a conditional query to check that value currently sent to an output? I used M409 and can't find output or gpio status.

      On my duet3 I added a relay control board using io6.out, io7.out and io8.out. I want to be able to write code in the daemon.g that can compare the selected tool to these output states.

      Better still is there a gcode file that is execute when tool is deselected "T-1"? I'd prefer to not litter all of the tfreeX.g files with code to deenergize the relays.

      I saw another topic where someone suggested creating a fake tool "T99" and having that do the unload then set to -1. I'd prefer to not handle it this way.

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

        I don't think you can poll the state of outputs yet.
        I think the object model only has inputs at this point.
        That said it's probably a waste of cycle time to continually poll them in daemon.g
        You could create a single macro to do that and execute it from each of the tprX.g or tfreeX.g file(s).

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

          @OwenD said in Conditional Output status or Tool deselect script?:

          I don't think you can poll the state of outputs yet.

          You can read outputs in 3.01-RC10. Outputs are in array 'state.gpOut'.

          @mwwhited said in Conditional Output status or Tool deselect script?:

          Better still is there a gcode file that is execute when tool is deselected "T-1"? I'd prefer to not litter all of the tfreeX.g files with code to deenergize the relays.

          • You could write a macro to do what you need, and call that macro in every tfree file
          • The next 3.01RC will have an additional variable state.nextTool that will be available for use in tfree and tpre files. Is that helpful?

          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

          OwenDundefined mwwhitedundefined 2 Replies Last reply Reply Quote 0
          • Danalundefined
            Danal
            last edited by Danal

            @mwwhited said in Conditional Output status or Tool deselect script?:

            I'd prefer to not litter all of the tfreeX.g files with code to deenergize the relays.

            A balance point available today would be to put M98 P"/macros/checkRelays.g" in every tfree. That, at least, allows maintaining the code for the relays in one place.

            Delta / Kossel printer fanatic

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

              @dc42 said in Conditional Output status or Tool deselect script?:

              You can read outputs in 3.01-RC10. Outputs are in array 'state.gpOut'.

              Awesome.
              I missed that in the change-log ( I really do RTFM - promise !😀 )
              So it appears that you read the pwm property regardless of whether it's used as "standard" I/O?

              echo state.gpOut[5].pwm
              
              dc42undefined 1 Reply Last reply Reply Quote 0
              • dc42undefined
                dc42 administrators @OwenD
                last edited by dc42

                @OwenD said in Conditional Output status or Tool deselect script?:

                So it appears that you read the pwm property regardless of whether it's used as "standard" I/O?
                echo state.gpOut[5].pwm

                Yes. You will get a value between 0.0 and 1.0. This is a recent addition, so please check that it works properly for you.

                If the port is being used to drive a servo, then if you are using the default servo refresh frequency of 50Hz then the servo pulse width should be (pwm * 20000) microseconds.

                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 0
                • mwwhitedundefined
                  mwwhited @dc42
                  last edited by

                  @dc42 said in Conditional Output status or Tool deselect script?:

                  You could write a macro to do what you need, and call that macro in every tfree file

                  I know I could do this as I stated above but it has two issues. 1) It can cause an unneeded transition (could be solved by your state.nextTool.) But more importantly 2) it causes code duplication and as a software guy this drives me crazy. (this could be solved with a generic tfree.g that all tools could share.)

                  As for the state.gpOut[X].pwm ... that will work. (I swear I looked but it must have been before I updated to RC10, I think I only saw gpio when I did M490 K"state") I still think having more events would be better but I can make my own by checking the status of tool changes.

                  @dc42, is there a generic spot that I can store state or am I still waiting on variables.

                  @OwenD said in Conditional Output status or Tool deselect script?:

                  That said it's probably a waste of cycle time to continually poll them in daemon.g

                  I already have a polling loop in daemon.g every few seconds anyway to monitor the temperature and fan status in my power supply.

                  1 Reply Last reply Reply Quote 0
                  • mwwhitedundefined
                    mwwhited
                    last edited by

                    works great...

                    daemon.g

                    M98 P"0:/macros/Special Scripts/Check Relays"
                    

                    Special Scripts/Check Relays

                    if state.currentTool = -1
                    	if state.gpOut[0].pwm > 0 || state.gpOut[1].pwm > 0 || state.gpOut[2].pwm > 0
                    		M98 P"0:/macros/Special Scripts/All Relays Off"
                    

                    Special Scripts/All Relays Off

                    M18 E ;ensure steppers are off before changing relays
                    G4 P100
                    M42 P0 S0
                    M42 P1 S0
                    M42 P2 S0
                    G4 P100
                    
                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    Unless otherwise noted, all forum content is licensed under CC-BY-SA