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

    More conditional gcode help required - SOLVED

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    8
    401
    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.
    • deckingmanundefined
      deckingman
      last edited by deckingman

      Can someone tell me how to read the state of an io pin please? Essentially, when the Z axis is a long way away from the nozzle, I want to move it up quickly until it is close (ish) to the nozzle. After that, homing will take place at "normal" speed. I have fitted a micro switch (normally closed) to an arm which pivots against a spring. When the bed gets to about 60 mm of the nozzle, the switch gets triggered and will remain triggered for the remainder of the Z axis travel. So, if I can read the switch state then if it's closed, I can do a fast 50mm move and repeat that move until the switch is triggered.

      The switch is connected to expansion board 3, io3 so I'm guessing I'll need to first create an io pin using M950 Jn C"^3.io3.in" or some such yes?

      Then something like:

      ; fast jog
      while Jn (switch is closed)
        G1 Z-50 F600 ; move 50mm up at 600mm/sec
        M400; wait for move to finish
      

      That should bring the nozzle somewhere within 10 to 60 mm of the bed in a series of 50mm moves at 600mm/sec, after which the switch will be triggered. I'm hoping I'll be able to push that speed a lot higher but we'll see what happens.

      But it's reading the state of the switch that I'm stuck with. I don't suppose for 1 minute that "while Jn" will work.

      Ian
      https://somei3deas.wordpress.com/
      https://www.youtube.com/@deckingman

      1 Reply Last reply Reply Quote 0
      • CR3Dundefined
        CR3D
        last edited by

        In my Thread I postet my solution for the Open Door IO:

        https://forum.duet3d.com/topic/17216/saftey-door-switches-for-big-printers/11?_=1594043918764

        Regards Christian (CR-3D)

        Christian from CR-3D
        Homepage:
        www.cr-3d.de

        Facebook:
        https://www.facebook.com/cr3d.official

        Our Discord Server
        https://discord.gg/SxRaPNuRdA

        Thingiverse Profile:
        https://www.thingiverse.com/cr-3d_official/about

        deckingmanundefined 1 Reply Last reply Reply Quote 1
        • A Former User?
          A Former User
          last edited by A Former User

          the sensor would then be sensors.gpIn[n].value where n is the same n as M950 Jn C"^3.io3.in"

          so something like

          while sensors.gpIn[n].value = 0
            G1 Z-50 F600
            M400
          

          edit: again, pretty close - just need to start poking the object model with M409 and you'll be unstoppable!
          (hm; maybe someone should make an interactive tool to poke the object model and show it in a tree structure nicely formatted)

          deckingmanundefined 1 Reply Last reply Reply Quote 1
          • deckingmanundefined
            deckingman @A Former User
            last edited by

            @bearer Cheers

            Actually, since my last feeble attempt, @OwenD sent me details of how to download, set up, and use RJ Text Ed. So I started with that, hoping that I could use the autocomplete feature to find what I was looking for. But I didn't consider that a gpio in would be considered as a sensor. It's kind of obvious when I think about it though.

            Ian
            https://somei3deas.wordpress.com/
            https://www.youtube.com/@deckingman

            1 Reply Last reply Reply Quote 0
            • deckingmanundefined
              deckingman @CR3D
              last edited by

              @CR3D Thanks. Had I seen that thread, the answer to my question would have been obvious.

              Ian
              https://somei3deas.wordpress.com/
              https://www.youtube.com/@deckingman

              1 Reply Last reply Reply Quote 0
              • deckingmanundefined
                deckingman
                last edited by

                That all works a treat with one minor addition. Strange things happen if one doesn't first use G91 to set relative movement before attempting a series of G1 moves. 🙂

                For completeness sake, here are the changes I made.

                Added this to config.g - M950 J2 C"^3.io3.in"

                and the macro is now this:

                ; Fast Jog Z
                M400; wait for any moves to finish
                G91; Set relative
                echo "Switch Closed
                while sensors.gpIn[2].value=0
                	G1 Z-50 F900; move Z 50mm @ 900mm/min
                	M400; wait for move to finish
                	
                echo "Switch open" 
                echo "Fast moves completed" 
                

                Ian
                https://somei3deas.wordpress.com/
                https://www.youtube.com/@deckingman

                A Former User? 1 Reply Last reply Reply Quote 0
                • A Former User?
                  A Former User @deckingman
                  last edited by

                  @deckingman said in More conditional gcode help required - SOLVED:

                  Strange things happen if one doesn't first use G91

                  ah, yes, alternatively you'd have to fetch the current z value and add 50 to it. i think dc42 has said something about each macro having its own state with respect to absolute/relative/mm/inch/etc. using G91 is by far the simplest approach 👍

                  1 Reply Last reply Reply Quote 0
                  • A Former User?
                    A Former User
                    last edited by

                    btw did you consider using https://duet3d.dozuki.com/Wiki/Gcode#Section_G38_2_to_G38_5_Straight_Probe and use conditional logic to remap the endtop before/after as needed?

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