Toggle a Program

I have a customer who wants to start a program with a push button. Once started they want to stop the program by pressing the same button. In a PLC, this logic is straight forward. (See attachment for reference). How would I go about implementing this logic into RMCTools?

I’ve also attached a user program that I think would mimic the logic, but I’m not able to test it currently.
Alwaysrun.rmcprog (1.55 KB)
Toggle PB.pdf (237 KB)

I would do this using the prescan table and 2 task. The first task starts with button push and task not running. This starts the motion. The second task starts with button push and task 1 running. This starts a program that stops task 1 and stops motion on any axis moving.
Toggle.rmcproj (15.8 KB)

CharlesM, Thank you for the response. The issue I was having with the push button was the length of time the input was true. Pressing and holding the push button caused the programs to alternate running and not running continuously.

I’ve attached a program showing the expression that I came up with after testing with Delta’s online unit. Input0 is the push button. It doesn’t matter how long one pushes the button, Bit_02 will change state (0 or 1) once per press/release.

Here is the expression in text for reference.:

(*With a push button tied to Input0, This expression can be used to toggle a program.
Bit_02 will toggle between 1 and 0, each press of a push button Input0.
It will = 1 on release and will = 0 on press. *)

IF ((Bit_03 = 0.0 OR Bit_04 = 1.0) AND( Input0=TRUE OR Bit_01=1.0)) AND Bit_02 = 0.0
THEN Bit_01:= 1.0; ELSEIF

((Bit_03 = 1.0 AND Bit_04 = 0.0) OR Input0 = FALSE OR Bit_02=1.0)
OR (Bit_00=0.0 AND (Bit_02 = 1.0 OR Bit_01=0.0))
THEN Bit_01:= 0.0; END_IF

IF (Bit_01 = 0.0 OR Bit_02=1.0) AND (Input0 = TRUE OR Bit_03 = 1.0) AND Bit_04 = 0.0
THEN Bit_03:=1.0;ELSEIF
((Bit_01 =1.0 AND Bit_02=0.0) OR Input0 = FALSE OR Bit_04=1.0)
OR (Bit_03 = 0.0 AND (Bit_04 = 1.0 OR Bit_03=0.0))
THEN Bit_03:=0.0; END_IF

IF (Bit_01=1.0 OR Bit_02 = 1.0) AND (Input0 = FALSE AND Bit_04 =0.0 AND Bit_03 = 0.0)
THEN Bit_02:=1.0; ELSEIF
(Bit_01=0.0 AND Bit_02 = 0.0) OR (Input0 = TRUE OR Bit_04 =1.0 OR Bit_03 = 1.0)
THEN Bit_02:=0.0; END_IF

IF (Bit_03 = 1.0 OR Bit_04 = 1.0) AND (Input0 = FALSE AND Bit_02 = 0.0)
THEN Bit_04:=1.0;ELSEIF
(Bit_03 = 0.0 AND Bit_04 = 0.0) OR (Input0 =TRUE OR Bit_02 = 1.0)
THEN Bit_04:=0.0; END_IF
Toggle in PRG.rmcproj (18 KB)

I think this is simpler.

Assming you will run your program on task 0, Set up your trigger table to run a watch program on task 1 like this:

Then Your watch program starts and stops the ProgramToRun on task 0 when the button is pressed like this: