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

    Store endstop status in a variable

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    3
    178
    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.
    • jan12345undefined
      jan12345
      last edited by

      Is it possible to store the status of an endstop in a variable?

      My goal is to write something like this:

      var endstop_status = M119 X
      if endstop_status = TRIGGERED
          G1 .....
      else
          G1 .....
      

      Is it possible to base a condition on the status of an endstop?

      Nightowlundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • Nightowlundefined
        Nightowl @jan12345
        last edited by Nightowl

        @jan12345
        As far as I understand it yes, but you'll (probably) need to reference it from the Object Model.

        You can define variables within the config.g file , like I do here:

        ; Variables definition
        global savedSpindleSpeed = 0
        global PausePress = false
        

        But the status of the variable need to be set within the macro that calls it, i.e. in my pause.g file:

        ; pause.g
        M42 P8 S0								; pause/resume LED off
        set global.PausePress = !global.PausePress				; toggle the value from whatever it was before
        set global.savedSpindleSpeed = spindles[0].active			; sets the global variable
        echo "Spindle speed saved at ", {global.savedSpindleSpeed}, "RPM"	; shows saved spindle speed in the Console
        G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)} F2400		; move the Z axis to a safe height		
        G0 X273.5 Y560								; move XY to a safe place
        M5							
        

        Sorry, I'm not a techie, but I hope this helps.

        Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
        I'm still on my learning curve, so take everything I say with caution!

        RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

          @jan12345 said in Store endstop status in a variable:

          Is it possible to base a condition on the status of an endstop?

          Yes:

          if sensors.endstops[0].triggered
              G1 ...
          else
              G1 ...
          

          No need to use a variable unless you want to save the triggered state to use later.

          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 1
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA