Toggle On/Off Button

More
15 Aug 2017 21:38 #97533 by 10K
Toggle On/Off Button was created by 10K
I want to use a single button to toggle LinuxCNC on and off. I though I could do it like this:

net pwr-btn toggle2nist.0.in <= input.0.btn-pinkie
net pwr-on halui.machine.on <= toggle2nist.0.on
net pwr-off halui.machine.off <= toggle2nist.0.off

That turns the power on once, but not off. If I turn it off on the screen, the button won't do anything the second time. I was a little unclear reading the toggle2nist wiki, and it can be read that you need a regular toggle upstream of the toggle2nist. I tried adding it, but it still didn't work. There's another input pin that I didn't connect (toggle2nist.0.is-on)

I also considered using two and gates and a not gate along with the halui.machine.is-on signal, but I'm thinking that might oscillate.

Does anyone already have some code for this that works?

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

More
17 Aug 2017 00:05 #97602 by 10K
Replied by 10K on topic Toggle On/Off Button
I'll answer my own question. In hindsight, it's simple, but the documentation is confusing.

Here's the working code:
net btn-pwr toggle.0.in <= input.0.btn-pinkie
net pwr-btn toggle2nist.0.in <= toggle.0.out
net tog-on toggle2nist.0.is-on <=  halui.machine.is-on
net pwr-on halui.machine.on <= toggle2nist.0.on
net pwr-off halui.machine.off <= toggle2nist.0.off

In words:
Connect the button to a toggle2. Connect the toggle2 to a toggle2nist. You must have a toggle2 upstream of a toggle2nist. Connect the on, off, and is-on pins on the desired control to the pins with the same name on the toggle2nist.

Works great.
The following user(s) said Thank You: kkuehn

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

More
08 Oct 2021 14:25 #222554 by julien83
Replied by julien83 on topic Toggle On/Off Button
thanks for your example !!!!
i tried the same code for 3 button and 2 works fine but 1 dont work.

WORKS FINE
net joy-on-machine toggle.0.in <= input.0.btn-base
net pwr-btn toggle2nist.0.in <= toggle.0.out
net tog-on toggle2nist.0.is-on <= halui.machine.is-on
net pwr-on halui.machine.on <= toggle2nist.0.on
net pwr-off halui.machine.off <= toggle2nist.0.off

net joy-on-microlube toggle.1.in <= input.0.btn-trigger-happy17
net microlube-btn toggle2nist.1.in <= toggle.1.out
net microlube-tog-on toggle2nist.1.is-on <= halui.mist.is-on
net microlube-on halui.mist.on <= toggle2nist.1.on
net microlube-off halui.mist.off <= toggle2nist.1.off

DONT WORK
net joy-tog-laser toggle.2.in <= input.0.btn-trigger-happy18
net laser-btn toggle2nist.2.in <= toggle.2.out
net laser-tog-on toggle2nist.2.is-on <= halui.lube.is-on
net laser-on halui.lube.on <= toggle2nist.2.on
net laser-off halui.lube.off <= toggle2nist.2.off

i dont know why ??
have you an idea ??

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

More
08 Oct 2021 16:27 #222561 by chris@cnc
Replied by chris@cnc on topic Toggle On/Off Button
I guess you not enable the third button.
loadrt   toggle2nist    count=3
and 
addf   toogle2nist.2    servo-thread
should be in your *.hal.
If you unsure post your hal and we could correct together.

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

More
08 Oct 2021 22:02 #222589 by 10K
Replied by 10K on topic Toggle On/Off Button
Thanks for the reply, Chris. It's been a while since I wrote this, and I don't remember it very well any more!
Julien83, your code looks OK to me. Have you tried to look at each of the pin names using Halcmd or Halscope, and see which names are and are not working as you expect? This is how I debug things. If there are not enough instances of the logical pins declared as Chris mentioned, they won't show up there..

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

More
14 Oct 2021 07:47 #223063 by julien83
Replied by julien83 on topic Toggle On/Off Button
Thanks 10k and Chris sorry for my late answer.
When i check with halmetre i don't see any mistake.
In attached file my custom_postgui.hal

File Attachment:

File Name: custom_postgui.hal
File Size:4 KB


Best regard
Attachments:

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

More
14 Oct 2021 15:50 #223091 by andypugh
Replied by andypugh on topic Toggle On/Off Button
If halmeter shows that every signal is working as-expected, then what isn't working?

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

More
14 Oct 2021 17:46 #223101 by chris@cnc
Replied by chris@cnc on topic Toggle On/Off Button
I have had a bad experience using loadrt and addf in the postgui.hal. Write this lines in your top level hal. 
loadrt toggle count=3
loadrt toggle2nist count=3

addf toggle.0 servo-thread
addf toggle.1 servo-thread
addf toggle.2 servo-thread

addf toggle2nist.0 servo-thread
addf toggle2nist.1 servo-thread
addf toggle2nist.2 servo-thread

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

More
16 Oct 2021 06:20 #223280 by julien83
Replied by julien83 on topic Toggle On/Off Button
Sorry guys. I confused halui.lube and halui.flood. now it's works

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

Time to create page: 1.009 seconds
Powered by Kunena Forum