Button Toggle

More
29 Sep 2024 18:21 #311037 by Project_Hopeless
Are Toggle and Toggle2inst separate independent functions?  Most of the examples I come across for toggling buttons use both. 

Is there a simple button toggle for a Mesa output using one or the other?

Please Log in or Create an account to join the conversation.

More
29 Sep 2024 21:31 #311044 by Benb
Replied by Benb on topic Button Toggle
Attached is a Function Block Diagram (FBD) and netlisting for toggling halui machine on/off. Since we are using FBD, signal names are insignificant in this case.  n.1 means net 1 ... etc. Hope this helps
 
#
# Load realtime Components and their counts
loadrt and2         count= 4
loadrt not            count= 4
loadrt or2            count= 2
loadrt toggle       count= 1
#
# Add functions to threads
addf and2.0                   servo-thread 
addf and2.1                   servo-thread 
addf and2.2                   servo-thread 
addf and2.3                   servo-thread 
addf not.0                      servo-thread 
addf not.1                      servo-thread 
addf not.2                      servo-thread 
addf not.3                      servo-thread 
addf or2.0                      servo-thread 
addf or2.1                      servo-thread 
addf toggle.0                 servo-thread 
#
# Set parameters
setp toggle.0.debounce                           5 
#
# Connect hal signals to hal component Pins
net gui.pb                     or2.1.in1  
net halui.mc.is-on         halui.machine.is-on  not.2.in  
net halui.mc.off             and2.3.out  halui.machine.off  
net halui.mc.on             and2.1.out  halui.machine.on  
net mc.pnl.pb                or2.0.in0  
net n.1                          or2.0.out  or2.1.in0  
net n.2                          toggle.0.in  and2.0.in0  and2.3.in1  or2.1.out  
net n.4                          toggle.0.out  not.0.in  
net n.5                          and2.2.in0  not.1.in  not.0.out  
net n.6                          not.3.in  not.2.out  and2.1.in1  
net n.7                          and2.0.in1  not.1.out  
net n.8                          not.3.out  and2.2.in1  
net n.9                          and2.0.out  and2.1.in0  
net n.10                        and2.2.out  and2.3.in0  
net pendant.pb             or2.0.in1  

 
Attachments:

Please Log in or Create an account to join the conversation.

More
30 Sep 2024 19:10 #311084 by Benb
Replied by Benb on topic Button Toggle
Actually in your case a simple single toggle component will do the trickt, just replace the hal signals input-togl and output-togld with your mesa input&output addresses:

loadrt toggle count= 1
addf toggle.0 servo-thread
setp toggle.0.debounce 5.0

net input-togl toggle.0.in
net output-togld toggle.0.out
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
30 Sep 2024 23:05 - 30 Sep 2024 23:32 #311098 by Project_Hopeless
Replied by Project_Hopeless on topic Button Toggle
I got a button to toggle but still not quite understanding how it works.

I followed this guide.

Big John T. Toggle

So my version that works
loadrt toggle count=1
addf toggle.0 servo-thread
net flood-toggle toggle.0.in <= pyvcp.drive-disable
net flood-control toggle.0.out => hm2_7i96s.0.ssr.00.out-01


I don't understand how flood-toggle and flood-control are linked.  Is there a simpler way to get button "drive-disable" to toggle ouput hm2_7i96s.0.ssr.00.out-01 ?
Last edit: 30 Sep 2024 23:32 by Project_Hopeless.

Please Log in or Create an account to join the conversation.

More
01 Oct 2024 01:45 #311106 by Benb
Replied by Benb on topic Button Toggle
The LinuxCNC Toggle component replicates a toggling pushbutton functionality. In the case of BJT example. The pyvcp is a push button widget on the screen that used to turn ON and OFF the flood valve.

So, initially the flood is OFF when you press the pyvcp widget the flood will turn ON if you press the same pyvcp widget button the flood will turn OFF and so forth.

In nut shell one push button is used to turn on and off the flood valve.

This is probably the simplest way to turn an output ON/OFF with only one push button (ui or hardwired). If you use hardwired push button add 20 ms debounce.

Please Log in or Create an account to join the conversation.

More
02 Oct 2024 01:55 #311136 by Project_Hopeless
Replied by Project_Hopeless on topic Button Toggle
My quest is more about understanding how the HAL structure works in this case.

I re-wrote the HAL below and changed to "generic-1" and "generic-2" and it still works.
loadrt toggle count=1
addf toggle.0 servo-thread
net generic-1 toggle.0.in <= pyvcp.drive-disable
net generic-2 toggle.0.out => hm2_7i96s.0.ssr.00.out-01

I thought I could write it in one line like so.    
pyvcp.drive-disable => toggle.0.out => hm2_7i96s.0.ssr.00.out-01

Trying to understand why "generic-1" and "generic-2" are necessary.
 

Please Log in or Create an account to join the conversation.

More
02 Oct 2024 02:24 #311138 by tommylight
Replied by tommylight on topic Button Toggle

Trying to understand why "generic-1" and "generic-2" are necessary.

Those can be "mom" and "dad", it does not matter, they are signal names that you freely assign to connections between hal pins
net generic-1 toggle.0.in <= pyvcp.drive-disable
can also be
net generic-1 toggle.0.in
net generic-1 pyvcp.drive-disable
and so can
net generic-2 toggle.0.out => hm2_7i96s.0.ssr.00.out-01
can be
net generic-2 toggle.0.out
net generic-2 hm2_7i96s.0.ssr.00.out-01
But your single line can not as you have it as there are two separate signals that have to be wired to 4 inputs/outputs.
Think of generic-1 (or mom or dad or) as a bus bar, toggle.0.in is one of the wires and pyvcp.drive-disable is the other wire tied together at the bus bar.
The following user(s) said Thank You: Benb, Project_Hopeless

Please Log in or Create an account to join the conversation.

More
02 Oct 2024 05:29 - 02 Oct 2024 05:30 #311153 by Benb
Replied by Benb on topic Button Toggle
It looks like you having problem distinguishing hal pin names from hal signal names. It's a common mistake by new linuxcnc hal users. further to Tom's explanation, I draw a block diagram, The dashed lines are your signal names generic-1 on the left and generic-2 on the right. If you connect them together you short circuit the input and output of the toggle component. 

 
Attachments:
Last edit: 02 Oct 2024 05:30 by Benb.
The following user(s) said Thank You: tommylight, Project_Hopeless

Please Log in or Create an account to join the conversation.

More
02 Oct 2024 21:47 - 02 Oct 2024 21:48 #311199 by Project_Hopeless
Replied by Project_Hopeless on topic Button Toggle

Benb post=311153 userid=20877It looks like you having problem distinguishing hal pin names from hal signal names. It's a common mistake by new linuxcnc hal users. further to Tom's explanation, I draw a block diagram, The dashed lines are your signal names generic-1 on the left and generic-2 on the right. If you connect them together you short circuit the input and output of the toggle component. 


 

Thank-you for taking the time to draw it out.  Its' more clear now!

I'm a jack (novice) of all code master of none.  HAL for some reason just ties me in knots! :)
 
Last edit: 02 Oct 2024 21:48 by Project_Hopeless.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
06 Oct 2024 01:33 - 06 Oct 2024 01:36 #311382 by Benb
Replied by Benb on topic Button Toggle
Here as another alteration of previous block diagram. This time we did away with the toggle componentOne thing you should learn is to draw block diagrams before you starting to write your hal netlisting. You will find as you start writing complex hal files block diagrams help tremulously in keeping you sane. I don’t know how to other members write their hal netlisting. In my case there is no way I can write hal without using block diagrams.

 If you look at the first block diagram to control halui machine on and off with one pushbutton. The reason the block diagram is complex because Hal which is real time program is communication with halui a user land non realtime program. The non realtime component timing is unpredictable and make RT comp communication with non realtime comp  difficult It requires trial and error intuition and luck to get to two to talk consistently no matter the jitter of the controllers.

I which someone could convert Halui to run in real time memory.
Attachments:
Last edit: 06 Oct 2024 01:36 by Benb.

Please Log in or Create an account to join the conversation.

Time to create page: 0.457 seconds
Powered by Kunena Forum