toggle2nist hangs when pressing an other button at the same time
- juergen-home
- Offline
- Junior Member
-
Less
More
- Posts: 38
- Thank you received: 10
28 Sep 2025 11:01 - 28 Sep 2025 11:17 #335504
by juergen-home
toggle2nist hangs when pressing an other button at the same time was created by juergen-home
I have this gamepad.hal as an example for my problem.
This is used with the button of a gamepad.I start a program by a button, then I can pause/resume it by another button.The third button is to stop the program.
The problem I have: If the program is started and I press pause/resume and stop at the same time, sometimes the toggle2nist_on get stucked in on state and the pause/resume will not work until I quit linuxcnc and start again. Is this a known behavior, or is something wrong in my gamepad.hal
This is used with the button of a gamepad.I start a program by a button, then I can pause/resume it by another button.The third button is to stop the program.
The problem I have: If the program is started and I press pause/resume and stop at the same time, sometimes the toggle2nist_on get stucked in on state and the pause/resume will not work until I quit linuxcnc and start again. Is this a known behavior, or is something wrong in my gamepad.hal
# test for linuxcnc 2.9 2025-09-28 work
# generic china Gamepad
loadusr -W hal_input -KRAL USB Gamepad
#---------------------
# Program Stop
#---------------------
#halui.program.stop (bit, in) - pin for stopping a program
net button13 input.0.btn-base5 => halui.program.stop
#---------------------
#---------------------
# Program Start
#---------------------
net button16 input.0.btn-base4 => halui.program.run
#---------------------
#---------------------
# Program Pause on/ Pause off
#---------------------
# known bugs: if you stop while in pause, than swich on and start program again, pause will not work.
# sometimes tog2nist_1.on stays on !
loadrt toggle names=tog_1
addf tog_1 servo-thread 1
loadrt toggle2nist names=tog2nist_1
addf tog2nist_1 servo-thread 2
net net-button-pause-trigger input.0.btn-base6 => tog_1.in # this is the pause button
net net-button-pause tog2nist_1.in <= tog_1.out
net net-pause-is-on tog2nist_1.is-on <= halui.program.is-paused
net net-pause-off tog2nist_1.off => halui.program.resume
net net-pause-on tog2nist_1.on => halui.program.pause
#---------------------
Attachments:
Last edit: 28 Sep 2025 11:17 by juergen-home.
The following user(s) said Thank You: COFHAL
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4506
- Thank you received: 2012
28 Sep 2025 13:44 #335505
by Aciera
Replied by Aciera on topic toggle2nist hangs when pressing an other button at the same time
'toggle2nist.comp' up to and including 2.9.x has issues:
github.com/LinuxCNC/linuxcnc/pull/3193
A new version is available in master:
github.com/LinuxCNC/linuxcnc/blob/0bc97e...nts/toggle2nist.comp
which you could install into your version by downloading the new version and using
(sudo) halcompile --install toggle2nist.comp
Note that 'halcompile' requires the 'linuxcnc-dev' package to be installed
Also note that people used to work around some of the problematic 'toggle2nist' behavior by adding hal components between the momentary switch and 'toggle2nist.in'. Looking at your .in pin signal in the halscope sreenshot makes me think that you might have done that. If you use the new version make sure to directly connect the momentary switch to the .in pin.
github.com/LinuxCNC/linuxcnc/pull/3193
A new version is available in master:
github.com/LinuxCNC/linuxcnc/blob/0bc97e...nts/toggle2nist.comp
which you could install into your version by downloading the new version and using
(sudo) halcompile --install toggle2nist.comp
Note that 'halcompile' requires the 'linuxcnc-dev' package to be installed
Also note that people used to work around some of the problematic 'toggle2nist' behavior by adding hal components between the momentary switch and 'toggle2nist.in'. Looking at your .in pin signal in the halscope sreenshot makes me think that you might have done that. If you use the new version make sure to directly connect the momentary switch to the .in pin.
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
Less
More
- Posts: 22336
- Thank you received: 4823
28 Sep 2025 17:36 #335512
by andypugh
Replied by andypugh on topic toggle2nist hangs when pressing an other button at the same time
Another possibility is that pressing two buttons means that the button-release event is not seen. So check the output pin from hal_input too.
Please Log in or Create an account to join the conversation.
- juergen-home
- Offline
- Junior Member
-
Less
More
- Posts: 38
- Thank you received: 10
28 Sep 2025 18:18 #335516
by juergen-home
Replied by juergen-home on topic toggle2nist hangs when pressing an other button at the same time
The Problem is the same as before.
@Aciera
So I did halcompile --install toggle2nist.comp.
I see a new pin toggle2nist_1.debounce so the update should be OK.
I also put the pause/resume signal direct to the toggle2nist without the toggle in front.
@andypugh
I dont understand "output pin from hal_input" my input pins from the gamepad are input.0.btn-base6 ...
@Aciera
So I did halcompile --install toggle2nist.comp.
I see a new pin toggle2nist_1.debounce so the update should be OK.
I also put the pause/resume signal direct to the toggle2nist without the toggle in front.
@andypugh
I dont understand "output pin from hal_input" my input pins from the gamepad are input.0.btn-base6 ...
Please Log in or Create an account to join the conversation.
- juergen-home
- Offline
- Junior Member
-
Less
More
- Posts: 38
- Thank you received: 10
05 Oct 2025 14:01 - 05 Oct 2025 14:05 #335860
by juergen-home
Replied by juergen-home on topic toggle2nist hangs when pressing an other button at the same time
To illustrate my issue with toggle2nist a bit more I have made a simple hal file.
The hal file makes no other sens as to show problem easily for testing yourself.
1. If I comment in
net net-mist-off => halui.program.stop
Linux runs as I expect. I can toggle the nist2 in halshow with set and clear.
If mist is switched off, a running program stops. I can start again and so on.
1. If I comment in
net net-mist-on => halui.program.stop
I can toggle the nist2 in halshow with set and clear only once.
If mist is switched on, a running program stops and the tog2nist.on LED is yellow all the time.
Is this working as expected?
The hal file makes no other sens as to show problem easily for testing yourself.
1. If I comment in
net net-mist-off => halui.program.stop
Linux runs as I expect. I can toggle the nist2 in halshow with set and clear.
If mist is switched off, a running program stops. I can start again and so on.
1. If I comment in
net net-mist-on => halui.program.stop
I can toggle the nist2 in halshow with set and clear only once.
If mist is switched on, a running program stops and the tog2nist.on LED is yellow all the time.
Is this working as expected?
# with this 2 lines each coolant shows a checkbox in the axis ui
# this is normaly part of the machine.hal / here only for test in the SIM-HAL-AXIS
#net coolant-mist <= iocontrol.0.coolant-mist
#net coolant-flood <= iocontrol.0.coolant-flood
# start and stop the coolant.
loadrt toggle2nist names=tog2nist0
addf tog2nist0 servo-thread
net net-mist.is-on tog2nist0.is-on <= halui.mist.is-on
net net-mist-off tog2nist0.off => halui.mist.off
net net-mist-on tog2nist0.on => halui.mist.on
#net net-mist-off => halui.program.stop
#net net-mist-on => halui.program.stop
Last edit: 05 Oct 2025 14:05 by juergen-home.
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4506
- Thank you received: 2012
05 Oct 2025 18:13 - 05 Oct 2025 18:50 #335873
by Aciera
Replied by Aciera on topic toggle2nist hangs when pressing an other button at the same time
The problem is that stopping a program will also switch off coolants (mist and flood). This is inbuilt behavior so by connecting 'halui.program.stop' in your hal example you are clearing 'tog2nist0.is-on' which upsets the logic.
When 'tog2nist0.in' goes true and 'tog2nist0.is-on' is false it sets 'tog2nist0.on' to true until 'tog2nist0.is-on' goes true. It then sets 'tog2nist0.on' to false. (So it basically produces a pulse on 'tog2nist0.on').
See the logic diagram in the manpage:
github.com/LinuxCNC/linuxcnc/blob/0bc97e...nts/toggle2nist.comp
In your case:
When 'tog2nist0.in' goes true it sets 'tog2nist0.on' to true which causes a program stop which forces 'tog2nist0.is-on' FALSE so the component waits forever with 'tog2nist0.on' True.
One way around this would be to change the component to have a maximum waiting time for 'tog2nist0.is-on' to change state.
[edit]
Attached is a modified component.
As an example set '.pulse_length' to 1000. Mind you it will only fix the lockup state not the flawed logic behind the hal construct.
When 'tog2nist0.in' goes true and 'tog2nist0.is-on' is false it sets 'tog2nist0.on' to true until 'tog2nist0.is-on' goes true. It then sets 'tog2nist0.on' to false. (So it basically produces a pulse on 'tog2nist0.on').
See the logic diagram in the manpage:
github.com/LinuxCNC/linuxcnc/blob/0bc97e...nts/toggle2nist.comp
In your case:
When 'tog2nist0.in' goes true it sets 'tog2nist0.on' to true which causes a program stop which forces 'tog2nist0.is-on' FALSE so the component waits forever with 'tog2nist0.on' True.
One way around this would be to change the component to have a maximum waiting time for 'tog2nist0.is-on' to change state.
[edit]
Attached is a modified component.
As an example set '.pulse_length' to 1000. Mind you it will only fix the lockup state not the flawed logic behind the hal construct.
Attachments:
Last edit: 05 Oct 2025 18:50 by Aciera.
The following user(s) said Thank You: juergen-home
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4506
- Thank you received: 2012
05 Oct 2025 19:01 #335875
by Aciera
Replied by Aciera on topic toggle2nist hangs when pressing an other button at the same time
To toggle program run/stop you would need to use :
loadrt toggle2nist names=tog2nist0
addf tog2nist0 servo-thread
net net-mist.is-on tog2nist0.is-on <= halui.program.is-running
net net-mist-off tog2nist0.off => halui.program.stop
net net-mist-on tog2nist0.on => halui.program.run
Please Log in or Create an account to join the conversation.
- juergen-home
- Offline
- Junior Member
-
Less
More
- Posts: 38
- Thank you received: 10
06 Oct 2025 17:51 #335929
by juergen-home
Replied by juergen-home on topic toggle2nist hangs when pressing an other button at the same time
Many thanks.
I compiled in your magic code in. With a puls-lenght of 50 my problems seem to be gone. This should become the standard toggle2nist.
Many thanks!
I compiled in your magic code in. With a puls-lenght of 50 my problems seem to be gone. This should become the standard toggle2nist.
Many thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.105 seconds