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
Time to create page: 0.055 seconds
Powered by Kunena Forum