Control output from multiple inputs?
24 Nov 2023 05:02 #286382
by spumco
Control output from multiple inputs? was created by spumco
I've got a number of outputs I want to control from physical buttons as well as g-code. Collet closer(s), mist, part-loader cylinders, etc.
I thought this would be a relatively simple exercise with some or2's, toggles, and motion.digital-outs... But as I try to work out the logic I find myself going down in flames.
One of the likely causes is self-inflicted... I have one momentary button for each function and need some sort of toggle feature.
Example:
Bad: the two sources will compete
If I connect the button and a digital-out signal to an or2 and then a toggle, if I turn the mist on with a button while a program is running, an M107 later in the program will turn it off - not what I want.
Same problem if the mist is turned on by M107 and I turn it off with a button mid-program. An M108 later on will trigger the toggle and turn it on when the desire is to leave it off.
And if I use an xor2 to interlock the two inputs... it means I can't use the button mid-program to turn off the mist if it's already on from the M-code.
Thought about a toggle2nist, but there's no obvious pin to connect to the 'toggle2nist.N.is-on pin, nor am I perfectly clear how to work it out even if there was an is-on available.
Or am I going about this wrong way, and should be using Ladder or some other scheme?
I thought this would be a relatively simple exercise with some or2's, toggles, and motion.digital-outs... But as I try to work out the logic I find myself going down in flames.
One of the likely causes is self-inflicted... I have one momentary button for each function and need some sort of toggle feature.
Example:
- Secondary mist located on lathe tool-slide (normal M7 mist is fixed at the headstock).
- Mist on/off from both a button and with an M-code (perhaps M107-on, M108-off).
- M-code would be a simple bin/bash triggering motion.digital-out-NN.
Bad: the two sources will compete
If I connect the button and a digital-out signal to an or2 and then a toggle, if I turn the mist on with a button while a program is running, an M107 later in the program will turn it off - not what I want.
Same problem if the mist is turned on by M107 and I turn it off with a button mid-program. An M108 later on will trigger the toggle and turn it on when the desire is to leave it off.
And if I use an xor2 to interlock the two inputs... it means I can't use the button mid-program to turn off the mist if it's already on from the M-code.
Thought about a toggle2nist, but there's no obvious pin to connect to the 'toggle2nist.N.is-on pin, nor am I perfectly clear how to work it out even if there was an is-on available.
Or am I going about this wrong way, and should be using Ladder or some other scheme?
Please Log in or Create an account to join the conversation.
24 Nov 2023 07:35 #286387
by Aciera
Replied by Aciera on topic Control output from multiple inputs?
I have momentary push buttons on my machine panels say to toggle G90/G91, MDI/HAND or coolant. So basically the push button will toggle the state to the opposite of what it was.
IIRC it's like toggle2nist but with 'enable' and debounce.
For coolant my hal section looks like this:
Component is here:
Note that for this to work you need a source that tells the component what the current status of the function in question is which is sometimes, like for coolants, easily available as a hal pin. If it is not then you may have to use a helper component like this one I use to expose the state of G90/G91 as a hal pin:
The relevant hal section:
I've been using this for many years now but maybe there are better ways to do it.
IIRC it's like toggle2nist but with 'enable' and debounce.
For coolant my hal section looks like this:
#**********
# COOLANTS
#**********
# --- Toggle M7 on/off ---
net machine-is-on => paneltoggle.m7.enable
net m7-panel <= hm2_7i76e.0.7i73.0.1.input-02-not => paneltoggle.m7.input
net m7-is-on <= halui.mist.is-on => paneltoggle.m7.status => hm2_7i76e.0.7i73.0.1.output-09
net m7-is-on => hm2_7i76e.0.7i76.0.0.output-11
net m7-set <= paneltoggle.m7.set => halui.mist.on
net m7-reset <= paneltoggle.m7.reset => halui.mist.off
# --- Toggle M8 on/off ---
net machine-is-on => paneltoggle.m8.enable
net m8-panel <= hm2_7i76e.0.7i73.0.1.input-03-not => paneltoggle.m8.input
net m8-is-on <= halui.flood.is-on => paneltoggle.m8.status => hm2_7i76e.0.7i73.0.1.output-08
net m8-is-on => hm2_7i76e.0.7i76.0.0.output-08
net m8-set <= paneltoggle.m8.set => halui.flood.on
net m8-reset <= paneltoggle.m8.reset => halui.flood.off
Component is here:
Note that for this to work you need a source that tells the component what the current status of the function in question is which is sometimes, like for coolants, easily available as a hal pin. If it is not then you may have to use a helper component like this one I use to expose the state of G90/G91 as a hal pin:
Warning: Spoiler!
#!/usr/bin/env python
import sys
import hal
import linuxcnc
# Make a component and pins
h = hal.component("linuxcnc_status")
h.newpin("g90", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("g91", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
# test connection to linuxcnc
try:
s = linuxcnc.stat() # create a connection to the status channel
s.poll() # get current values
except linuxcnc.error, detail:
print "error ", detail
sys.exit(1)
# print all attributes and their current values
#for x in dir(s):
# if not x.startswith("_"):
# print x, getattr(s,x)
# loop
while 1:
# get current values
s.poll()
# Handle absolute / incremental (G90/G91) linuxcnc.stat.gcodes[6]
if s.gcodes[6] == 910:
h = 0
h = 1
elif s.gcodes[6] == 900:
h = 1
h = 0
else :
h = 0
h = 0
import sys
import hal
import linuxcnc
# Make a component and pins
h = hal.component("linuxcnc_status")
h.newpin("g90", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("g91", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
# test connection to linuxcnc
try:
s = linuxcnc.stat() # create a connection to the status channel
s.poll() # get current values
except linuxcnc.error, detail:
print "error ", detail
sys.exit(1)
# print all attributes and their current values
#for x in dir(s):
# if not x.startswith("_"):
# print x, getattr(s,x)
# loop
while 1:
# get current values
s.poll()
# Handle absolute / incremental (G90/G91) linuxcnc.stat.gcodes[6]
if s.gcodes[6] == 910:
h = 0
h = 1
elif s.gcodes[6] == 900:
h = 1
h = 0
else :
h = 0
h = 0
The relevant hal section:
#**************************************************************************************
# ----- Handle panel toggle buttons using Custom Python Component 'linuxcnc_status.py'
#**************************************************************************************
# --- Toggle G90/G91 ---
net machine-is-on => paneltoggle.g91.enable
net g91-panel <= hm2_7i76e.0.7i76.0.0.input-23-not => paneltoggle.g91.input
net g91-led <= linuxcnc_status.g91 => paneltoggle.g91.status => hm2_7i76e.0.7i73.0.1.output-14
net g91-set <= paneltoggle.g91.set => halui.mdi-command-04
net g91-reset <= paneltoggle.g91.reset => halui.mdi-command-05
I've been using this for many years now but maybe there are better ways to do it.
Attachments:
Please Log in or Create an account to join the conversation.
24 Nov 2023 12:43 - 24 Nov 2023 12:44 #286395
by timo
Replied by timo on topic Control output from multiple inputs?
Just because I started playing with it recently and I find nice to see what is going on. I suggest you look into Classic Ladder it is perfect for this type of input output things.
I like, that I can change it and see what happens very easy.
If I had understood earlier that it is relatively easy to setup, I would have given it more attention.
I found the video to be very efficient, explaining the first steps (the auto translation to English does a good enough job for the video to be usable)
Have fun, with the buttons!
I like, that I can change it and see what happens very easy.
If I had understood earlier that it is relatively easy to setup, I would have given it more attention.
I found the video to be very efficient, explaining the first steps (the auto translation to English does a good enough job for the video to be usable)
Have fun, with the buttons!
Last edit: 24 Nov 2023 12:44 by timo.
The following user(s) said Thank You: spumco
Please Log in or Create an account to join the conversation.
24 Nov 2023 16:55 #286414
by spumco
Replied by spumco on topic Control output from multiple inputs?
Thanks to both of you.
I started re-watching Feral Engineer's Ladder series again before I noticed your replies.
I think I'll wind up with a combination of Ladder for some inputs, and @Aciera's comp for others. Some functions need a simple flip-flop with some interlocks (collet closer), while others are a bit more complicated since I want to be able to trigger them while a program is running.
I started re-watching Feral Engineer's Ladder series again before I noticed your replies.
I think I'll wind up with a combination of Ladder for some inputs, and @Aciera's comp for others. Some functions need a simple flip-flop with some interlocks (collet closer), while others are a bit more complicated since I want to be able to trigger them while a program is running.
Please Log in or Create an account to join the conversation.
24 Nov 2023 19:49 - 24 Nov 2023 19:53 #286425
by beefy
Replied by beefy on topic Control output from multiple inputs?
I made myself a custom hal component with 3 inputs (0, 1, and 2) for something similar.
It ended up a combination of an OR gate and a toggle component.
Input 0 was a typical on/off input (for a typical on/off switch for example) so if say a switch/signal is on the output is always on, i.e. the other 2 inputs cannot turn off the output.
However, it input 0 is off, then inputs 1 and 2 can control the output.
Inputs 1 and 2 came from momentary inputs or pulses, just like what you get from a momentary push button.
Input 1 could turn the output on then input 2 could turn it off.
And visa versa, input 2 could turn the output on and input 1 could turn it off.
Or just basic operation, input 1 can turn the output on and off.
Or output 2 can turn the output on and off
I've attached the component if you can make use of it.
It ended up a combination of an OR gate and a toggle component.
Input 0 was a typical on/off input (for a typical on/off switch for example) so if say a switch/signal is on the output is always on, i.e. the other 2 inputs cannot turn off the output.
However, it input 0 is off, then inputs 1 and 2 can control the output.
Inputs 1 and 2 came from momentary inputs or pulses, just like what you get from a momentary push button.
Input 1 could turn the output on then input 2 could turn it off.
And visa versa, input 2 could turn the output on and input 1 could turn it off.
Or just basic operation, input 1 can turn the output on and off.
Or output 2 can turn the output on and off
I've attached the component if you can make use of it.
Attachments:
Last edit: 24 Nov 2023 19:53 by beefy.
The following user(s) said Thank You: spumco
Please Log in or Create an account to join the conversation.
Time to create page: 0.097 seconds