Conditional Output status or Tool deselect script?



  • 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.



  • 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).


  • administrators

    @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?


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



  • @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
    

  • administrators

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



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



  • 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
    

Log in to reply