I can't figure out toggle

More
22 Oct 2020 06:24 - 22 Oct 2020 06:24 #186875 by kkuehn
I believe I am implementing it correctly (no errors on startup, everything functions correctly in my HAL file), but something isn't right because I'm not getting the expected output.

This is what I've been trying to do:
loadrt toggle count=1
net toggle-btn toggle.0.in parport.0.pin-12-in
net toggle-on toggle.0.out parport.0.pin-16-out

I've looked in HAL Meter and toggle.0.out does not change its value even when toggle.0.in does change.
Last edit: 22 Oct 2020 06:24 by kkuehn.

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

More
22 Oct 2020 07:26 - 22 Oct 2020 07:29 #186877 by BeagleBrainz
Did you add it to a thread ?

I think toggle works when on the rising edge of an input.

So at t=0 toggle-btn toggle.0.in = 0 toggle-btn toggle.0.out=0
So at t=1 toggle-btn toggle.0.in = 1 toggle-btn toggle.0.out=1
So at t=2 toggle-btn toggle.0.in = 0 toggle-btn toggle.0.out=1
So at t=3 toggle-btn toggle.0.in = 1 toggle-btn toggle.0.out=0
So at t=4 toggle-btn toggle.0.in = 0 toggle-btn toggle.0.out=0
So at t=5 toggle-btn toggle.0.in = 1 toggle-btn toggle.0.out=1

Which seems to be the behaviour when using halrun and using setp to toggle the input bit

This is a halrun session
halcmd: loadrt threads name1=test-thread period1=1000000
Note: Using POSIX realtime
halcmd: loadrt toggle count=1
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT             0  test-thread.time
     8  bit   IN          FALSE  toggle.0.in
     8  bit   I/O         FALSE  toggle.0.out
     8  s32   OUT             0  toggle.0.time

halcmd: addf toggle.0 test-thread
halcmd: start
halcmd: shwo pin
<stdin>:8: Unknown command 'shwo'
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT           288  test-thread.time
     8  bit   IN          FALSE  toggle.0.in
     8  bit   I/O         FALSE  toggle.0.out
     8  s32   OUT           288  toggle.0.time

halcmd: setp toggle.0.in 1
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT            80  test-thread.time
     8  bit   IN           TRUE  toggle.0.in
     8  bit   I/O          TRUE  toggle.0.out
     8  s32   OUT            80  toggle.0.time

halcmd: setp toggle.0.in 0
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT           340  test-thread.time
     8  bit   IN          FALSE  toggle.0.in
     8  bit   I/O          TRUE  toggle.0.out
     8  s32   OUT           340  toggle.0.time

halcmd: setp toggle.0.in 1
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT            44  test-thread.time
     8  bit   IN           TRUE  toggle.0.in
     8  bit   I/O         FALSE  toggle.0.out
     8  s32   OUT            44  toggle.0.time

halcmd: setp toggle.0.in 0
halcmd: setp toggle.0.in 1
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT           224  test-thread.time
     8  bit   IN           TRUE  toggle.0.in
     8  bit   I/O          TRUE  toggle.0.out
     8  s32   OUT           224  toggle.0.time

halcmd: setp toggle.0.in 0
halcmd: setp toggle.0.in 1
halcmd: show pin
Component Pins:
Owner   Type  Dir         Value  Name
     5  s32   OUT           100  test-thread.time
     8  bit   IN           TRUE  toggle.0.in
     8  bit   I/O         FALSE  toggle.0.out
     8  s32   OUT           100  toggle.0.time

halcmd: quit
Note: Using POSIX realtime
Last edit: 22 Oct 2020 07:29 by BeagleBrainz.
The following user(s) said Thank You: kkuehn

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

More
22 Oct 2020 17:27 - 22 Oct 2020 17:28 #186910 by bevins
Replied by bevins on topic I can't figure out toggle

I believe I am implementing it correctly (no errors on startup, everything functions correctly in my HAL file), but something isn't right because I'm not getting the expected output.

This is what I've been trying to do:
loadrt toggle count=1
net toggle-btn toggle.0.in parport.0.pin-12-in
net toggle-on toggle.0.out parport.0.pin-16-out

I've looked in HAL Meter and toggle.0.out does not change its value even when toggle.0.in does change.


This works. Have it and many others running on big machine.
change ion/outs are needed.
loadrt toggle count=6
addf toggle.0 servo-thread

net vaccum-pedal-LH toggle.0.in <= hm2_5i25.0.7i70.1.0.input-11
net vaccum-output-LH toggle.0.out => hm2_5i25.0.7i71.1.1.output-38

Looks like your just missing the servo.thread
Last edit: 22 Oct 2020 17:28 by bevins.
The following user(s) said Thank You: kkuehn

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

More
23 Oct 2020 03:31 - 23 Oct 2020 03:36 #186962 by kkuehn
Replied by kkuehn on topic I can't figure out toggle
Thank you very much for your help, indeed addf was what was missing. I'm a noob to HAL, but I'm picking it up quickly (I've only started working on programming my machine a few days ago).

If anyone is interested, I've programmed one of those red-yellow-green tower lights with the addition of an e-stop and a machine on button, it is working perfectly. (toggle2nist code stolen shamelessly from: www.forum.linuxcnc.org/24-hal-components...toggle-on-off-button)

My HAL file:
# Include your customized HAL commands here
# This file will not be overwritten when you run stepconf again

loadrt estop_latch
loadrt toggle2nist count=1
loadrt toggle count=1
addf estop-latch.0 servo-thread
addf toggle.0 servo-thread
addf toggle2nist.0 servo-thread

setp parport.0.pin-16-out-invert true
setp parport.1.pin-02-out-invert true
setp parport.1.pin-03-out-invert true
setp parport.1.pin-04-out-invert true

#estop-latch
net estop-loopout iocontrol.0.emc-enable-in <= estop-latch.0.ok-out
net estop-loopin iocontrol.0.user-enable-out => estop-latch.0.ok-in 
net estop-reset iocontrol.0.user-request-enable => estop-latch.0.reset
net remote-estop estop-latch.0.fault-in <=  parport.0.pin-10-in
net red-led estop-latch.0.fault-out parport.1.pin-02-out

#machine power on toggle button
net power-on-btn toggle.0.in parport.1.pin-12-in-not
net toggle-button toggle2nist.0.in toggle.0.out
net power-on-toggle toggle2nist.0.is-on halui.machine.is-on parport.1.pin-03-out
net power-on halui.machine.on toggle2nist.0.on
net power-off halui.machine.off toggle2nist.0.off

#machine program run
net green-led halui.program.is-running parport.1.pin-04-out
Last edit: 23 Oct 2020 03:36 by kkuehn.
The following user(s) said Thank You: BeagleBrainz

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

Time to create page: 0.101 seconds
Powered by Kunena Forum