- Posts: 142
- Thank you received: 33
Toggle On/Off Button
- 10K
- Offline
- Premium Member
-
Less
More
9 years 2 months ago #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:
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?
Code:
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.
- 10K
- Offline
- Premium Member
-
Less
More
- Posts: 142
- Thank you received: 33
9 years 2 months ago #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:
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.
Here's the working code:
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.
- julien83
- Offline
- New Member
-
Less
More
- Posts: 9
- Thank you received: 0
5 years 3 weeks ago #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 ??
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.
- chris@cnc
- Offline
- Platinum Member
-
Less
More
- Posts: 529
- Thank you received: 140
5 years 3 weeks ago #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.
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.
- 10K
- Offline
- Premium Member
-
Less
More
- Posts: 142
- Thank you received: 33
5 years 3 weeks ago #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..
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.
- julien83
- Offline
- New Member
-
Less
More
- Posts: 9
- Thank you received: 0
5 years 2 weeks ago #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
Best regard
When i check with halmetre i don't see any mistake.
In attached file my custom_postgui.hal
Best regard
Please Log in or Create an account to join the conversation.
Time to create page: 0.267 seconds