Run/Step Hold/Resume Buttons

30 Dec 2017 17:22 - 30 Dec 2017 18:19 #103861 by JackBerkhout
Thank you very much for this!!!

I added the Stop button, and the buttons have LED indicators, which I also use.
So we have:
'Run/Step' (Green)
'Pause/Resume' (Yellow)
'Stop' (Red)
Note I use a different MESA board...
And I used an AND in my 'home.hal', so here it counts from 1 instead of 0.

But Initially, when I pressed 'Stop', I got this error:
"can't do that (EMC_TRAJ_SET_TELEOP_ENABLE) in auto mode with interpreter idle"
But if I first pressed 'Pause', it worked without that error.
So to solved that, I added an OR (output to pause) and perform a pause, just before stop.

The code (my filename: 'run_step_pause_resume_stop.hal'):

# Run/Step Pause/Resume Stop Buttons
# This is how they function:
# Pressing Run/Step will begin executing a program.
# Pressing Pause/Resume while a program is running will pause the program.
# Pressing Run/Step while a program is paused will single step the program.
# Pressing Pause/Resume while a program is paused will return it to normal run mode.
# Pressing Stop while a program is running or paused will stop the program.

# TB6.00 = INPUT00 - Push-button 'Run/Step' (Green)
# TB6.01 = INPUT01 - Push-button 'Pause/Resume' (Yellow)
# TB6.02 = INPUT02 - Push-button 'Stop' (Red)
# TB6.00 = OUTPUT00 - LED Indicator Green 'Run' in 'Run/Step' push-button
# TB6.01 = OUTPUT01 - LED Indicator Yellow 'Paused' in 'Pause/Resume' push-button
# TB6.02 = OUTPUT02 - LED Indicator Red 'Stop' in 'Stop' push-button

#loadrt and2 count=4 (Only allowed in one place: done in home.hal)
loadrt or2 count=2
loadrt toggle count=1
loadrt toggle2nist count=1

addf and2.1 servo-thread
addf and2.2 servo-thread
addf and2.3 servo-thread
addf and2.4 servo-thread
addf or2.0 servo-thread
addf or2.1 servo-thread
addf toggle.0 servo-thread
addf toggle2nist.0 servo-thread

# External Program Pause/Resume, Run/Step, and Stop Buttons

# Run/Step Section
# This is your Run/Step input
# The contact is NO - Normally Open, the button is connected between Field Power and the input
#net run-step-btn and2.3.in0 and2.4.in0 <= hm2_7i76e.0.7i76.0.0.input-00-not
net run-step-btn and2.3.in0 and2.4.in0 <= hm2_7i76e.0.7i76.0.0.input-00
net idle-on and2.3.in1 <=
# net pause.on and 2.3.in1 <=
# and2.4.in1 was added in the net pause-on statement in Pause/Resume Section
net run-sig <= and2.3.out
net step-sig halui.program.step <= and2.4.out

# Pause/Resume Section
# This is your Pause/Resume input
# The contact is NO - Normally Open, the button is connected between Field Power and the input
#net pause-resume-btn and2.1.in0 and2.2.in0 <= hm2_7i76e.0.7i76.0.0.input-01-not
net pause-resume-btn and2.1.in0 and2.2.in0 <= hm2_7i76e.0.7i76.0.0.input-01
net pause-on and2.1.in1 and2.4.in1 <=
net run-on and2.2.in1 <=
net pause-sig or2.0.in0 <= and2.1.out
net resume-sig or2.0.in1 <= and2.2.out
net toggle-ok <= or2.0.out
net togglesig <= toggle.0.out
net toggleon or2.1.in0 <= toggle2nist.0.on
net toggleoff halui.program.resume <=

# Stop Section
# This is your Stop input
# The contact is NO - Normally Open, the button is connected between Field Power and the input
#net stop-btn <= hm2_7i76e.0.7i76.0.0.input-02-not
net stop-btn <= hm2_7i76e.0.7i76.0.0.input-02
net stop-btn => or2.1.in1
# I had to pause before stop, to avoid this error:
# can't do that (EMC_TRAJ_SET_TELEOP_ENABLE) in auto mode with interpreter idle'
# So I used an OR because halui.program.pause is activated from two places now, here and in rthe previous section
net program-pause or2.1.out => halui.program.pause
net stop-btn => halui.program.stop

# LED Indicator Section (LED indicators in the push-buttons)
# The LED indictors are connected bewteen outputs and GND
# Green LED Indicator in Run/Step push-button (
net run-on => hm2_7i76e.0.7i76.0.0.output-00
# Orange LED Indicator in Pause/Resume push-button (
net pause-on => hm2_7i76e.0.7i76.0.0.output-01
# Red LED Indicator in Stop push-button (
net idle-on => hm2_7i76e.0.7i76.0.0.output-02

I use several hal files, to separate things that belong together.
However instructions like 'loadrt and2 count=4' should only be done in one place it appears.
Maybe, I need to create a script for just those, like 'my_one_place_to_loadrt.hal'?
Anybody has a great solution for that?

Any comments are welcome.

Kind regards,
Last edit: 30 Dec 2017 18:19 by JackBerkhout.
The following user(s) said Thank You: DanMN
04 Dec 2018 00:22 #121788 by naborskid
if you don't mind i would like to add my code for cycle start and feed hold buttons.
it functions like fanuc control ,"cycle start" button starts program ,"feed hold" pauses program ,"cycle start" resumes program
maybe it will help someone with a basic parallel port setup

addf and2.10 servo-thread
addf and2.11 servo-thread

net remrun
net remrun and2.11.in0 and2.10.in1
net remidle and2.10.in0
net remgo and2.10.out
net remstop and2.11.in1
net remresume and2.11.out halui.program.resume
net remstart halui.program.pause <= halui.program.pause
net coolant-flood <=
net coolant-flood =>
06 Dec 2018 17:22 #121964 by andypugh
You might also like to look at LUT5, this is a HAL component that can define an output (boolean) for every possible state of 5 inputs. It is good for interlocks and such.
One thing that can make it even more useful is to feed the output back to one of the inputs. Then it can be used as a flip-flop. for example).

In your example you could wire cycle-start, halui.program-is-paused, door interlock, etc into a LUT5 and get a specific output for each combination.
Time to create page: 0.075 seconds
Powered by Kunena Forum