I have a project with several SFCs that are set to RunAlways. Each SFC has a corresponding tag to control its state, which can be “on” or “off”. Each SFC waits in a starting step until its state is set to “on”, then does some work, and finally sets its state back to “off” and returns to the start to wait for another “on” command.
My issue is that some processes cannot run simultaneously. So, if SFC 1 and SFC 2 cannot run simultaneously and SFC 1 is already running when SFC 2 is set to “on”, SFC 2 should wait until SFC 1 turns back off before it starts to do anything to the system. And vice versa.
I can have a transition near the beginning of each SFC that waits until the other is off before starting to do anything. However, there’s a race condition if SFC 1 and SFC 2 are both turned on simultaneously. Then each SFC will see that the other SFC is “on” and will wait, so the two SFC’s will wait forever and will never run. I know this is very improbable, but I’d much rather it be impossible than improbable. I’ve thought about other configurations of the SFCs and the state variable, but all seem to boil down to the need to check a value and then modify a value atomically, without letting another SFC access those values at the same time. A mutex seems like the standard way to do this. Does Ignition have a similar capability? Or is there another way that I should go about this?
Thanks,
Jack