Problem with toggle2nist component

More
08 Nov 2020 18:18 #188678 by mwinterm
Hello,

I'm trying to implement a physical button to start/stop the spindle. To do so I try to use the toggle2nist component the following way:
# --- SPINDLE-BUTTON ---
net spindle-button toggle2nist.0.in <= hm2_7i76e.0.7i76.0.0.input-25
net spindle-enable => toggle2nist.0.is-on
net spindle-manual-start toggle2nist.0.on
net spindle-manual-stop toggle2nist.0.off

This does not work as supposed. The spindle is stopping as long as I keep the button pressed and starting again as soon as I release it. The following workaround where I delay the spindle-enable signal is providing the desired result.
# --- SPINDLE-BUTTON ---
net spindle-button toggle2nist.0.in <= hm2_7i76e.0.7i76.0.0.input-25
net spindle-enable => timedelay.0.in
net spindle-enable-delayed toggle2nist.0.is-on <= timedelay.0.out
net spindle-manual-start toggle2nist.0.on
net spindle-manual-stop toggle2nist.0.off

However I don't understand why this hack is needed. Could it be connected to the sequence the HAL execution?

Further, what would be the right way to initialize a toggle or toggle2nist component to be in a specific state on start-up?

Regards,

Marc

PS: spindle-enable has the following connections:
net spindle-enable        =>  pid.s.enable
net spindle-enable      => hm2_7i76e.0.7i76.0.0.spinena
net spindle-enable             <=  spindle.0.on

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

More
08 Nov 2020 18:33 #188679 by cmorley
What does spindle-manual-start/spindle-manual-stop connect to.

also what is the addf sequence for the components.
addf sets the sequence that components are evaluated and it can mean a component id evaluating old data.

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

More
08 Nov 2020 19:11 #188683 by mwinterm
net spindle-manual-stop   halui.spindle.0.stop
net spindle-manual-start  halui.spindle.0.start

and here the addf-statements:
addf hm2_7i76e.0.read          servo-thread
addf motion-command-handler   servo-thread
addf motion-controller        servo-thread
addf pid.x.do-pid-calcs       servo-thread
addf pid.y.do-pid-calcs       servo-thread
addf pid.z.do-pid-calcs       servo-thread
addf pid.s.do-pid-calcs       servo-thread
addf ratio_select             servo-thread
addf scale.gear               servo-thread
addf hm2_7i76e.0.write         servo-thread
setp hm2_7i76e.0.dpll.01.timer-us -50
setp hm2_7i76e.0.stepgen.timer-number 1
addf and2.0                   servo-thread
addf and2.1                   servo-thread
addf spindle-scale            servo-thread
addf conv-float-s32.0         servo-thread
addf feed-scale               servo-thread
addf conv-float-s32.1         servo-thread
addf rapid-scale              servo-thread
addf conv-float-s32.2         servo-thread
addf toggle.0                 servo-thread
addf toggle2nist.0            servo-thread
addf timedelay.0              servo-thread

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

More
08 Nov 2020 22:53 #188706 by cmorley
My guess is the servo thread updates faster then the HALUI component does.
HALUI is userspace so it's update is a little unpredictable but should be about 100ms IIRC.

Please describe completely what you are trying to do and maybe we can find a different way or just live with the time delay - it works !

Chris

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

More
11 Nov 2020 15:17 #189008 by mwinterm
Hello Chris,

this makes sense to me and knowing what the problem is I think I can live with my workaround for the moment.

However I'm facing another problem with toggle2nist: When I'm starting LinuxCNC toggle2nist immediately tries to do a switch-action (not sure if it is from on to off or other way around). As at start-up E-stop is still active this causes rightfully an error.

Here is the code from toggle2nist from that I found on GitHub:
component toggle2nist "toggle button to nist logic";

description
"""
toggle2nist can be used with a momentary push button connected to a
toggle component to control a device that has separate on and off inputs
and has an is-on output. 
If in changes states via the toggle output
  If is-on is true then on is false and off is true. 
  If is-on is false the on true and off is false.
""";

pin in  bit in;
pin in  bit is_on;
pin out bit on;
pin out bit off;
variable int old_in;
variable int to_state=0;
function _ nofp;
license "GPL";
;;
FUNCTION(_)  {
if (in!=old_in) /* a toggle has occurred */ {
    if (is_on) {   /* turn OFF if it's on */
        on=0;
        off=1;
        to_state=0;
    }
    else if (!is_on) { /* turn ON if it's off */
        on=1;
        off=0;
        to_state=1;
    }
}
else {
/* reset pins when we see the desired state */
    if (to_state==is_on) {
        on=0;
        off=0;
    }
}
old_in=in;
}
I'm pretty new to linuxcnc and have no experience in HAL component programming so far. However based on my general understanding of programming I think there could be a problem with
variable int old_in;
not being initialized on start-up and therefore having an arbitrary value most likely not being 0 or 1. With that when run the first time in the servo-thread it meets the first if-condition and therefore causes an immediate switch-action.
If my assumptions are correct a solution could be to add an additional initialization parameter that defines old_in when the HAL file is executed.

Does this make any sense?

Regards,

Marc

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

More
13 Nov 2020 22:57 #189267 by mwinterm
...no one with any feedback on this?

Regards,

Marc

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

More
13 Nov 2020 23:13 #189269 by tommylight
You can do some quick tests to check if it "misses", just load it in a sim config and check the sates with halshow or halscope or "show hal configuration" from the machine menu.

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

More
22 Nov 2020 03:51 #190021 by Benb
Attached is a cartoon showing similar hal file to toggle2nist with couple of interlocks to prevent signal racing. I have not tested this configuration, but its start.

File Attachment:

File Name: toggle1.hal
File Size:2 KB

This browser does not support PDFs. Please download the PDF to view it: Download PDF

Attachments:

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

More
22 Nov 2020 05:07 #190023 by cmorley
you could compile a new component and try your fix to see if it helps.
linuxcnc.org/docs/devel/html/hal/comp.ht...side_the_source_tree

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

More
26 Nov 2020 20:46 #190367 by mwinterm
@cmorley: Thanks for the link, that is exactly what I'm currently looking into (once I find a little more time again...)

@Benb: that is also very nice work, even though I try to keep the logical programming in the HAL file to a minimum (I'm more a higher level language coder... ;-). However you have made a very nice schemata. Do you have a tool to create this directly from the *.hal file?

Best regards,

Marc

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

Time to create page: 0.104 seconds
Powered by Kunena Forum