05-23-2010 02:28 PM
Hi.
I have a process that runs through several stages in sequence. Each stage needs to wait for ~ 5 minutes before starting the next stage. There isn't really any "logic" involved; it just moves from one to the next until the end. However, I want to implement an Emergency Stop that will exit the current stage and perform some shutdown procesures. I am using a state machine inside a while loop to handle each step but I can't figure out how to exit immediately. When I press the "Stop" button, it continues through the current step, then next step and finally exits two steps later.
Here is a dummy example of my structure:
Any suggestions?
thanks,
jason
05-23-2010 07:41 PM
Very simple solution:
Use a notifier or a queue with the timeout
Code gets a bit messy because you need a producer consumer loop.
05-23-2010 07:44 PM
05-27-2010 07:13 AM
Jason,
Two things: If you need a real Emergency Stop, it should be implemented in hardware. The software should monitor the status of the stop and respond accordingly, but should not be relied upon to protect life or property.
One way to implement an "interruptible" wait is to use short waits and check to see if the total wait time has elapsed. A stop command will break out of the wait state after the short wait. In your example suppose a delay of one second in responding to the stop command is acceptable. When you enter the Wait state set a timeout value to be 300 = 60 seconds * 5 minutes. Set a current time value to zero. Wait 1 second. Add 1 to the current time. If current time >= timeout, then leave the wait state, else repeat from the Wait 1 second part.
Lynn
07-08-2010 05:53 PM
John,
Yes I have a big red obnoxious button that mechanically kills the whole system (loss of power => normally closed solenoids). I kind of want a "soft emergency" switch that will just allow the user to exit the loop so that the software doesn't keep running. I've found since posting initally, that any "Wait" command should be avoided at all cost. I am usually building VI's for one task and then adding to them as my coworkers need more features. Having to rework the initial timing can get real tricky if I need to be doing 10 things at once. I like Timmar's producer/consumer queue idea. I am using a similar setup to manage some motion commands so it will be easy to add a second P/C sequence.
07-09-2010 07:36 AM
If you are frequently adding features to your program, you definitely need to investigate the various flavors of state machines and producer/consumer architectures. The two are not mutually exclusive. In fact they work well together. Key advantages are robust performance and ease of modification. There are examples which ship with LV and many, many postings on the Forums about these topics.
For multiple independent timing I like to use a Timeout value for each task which needs timing. When the task starts, read the current tick count and add the timeout delay (or wait) value in milliseconds, and put the resulting Task[i] Timeout value (= tick count when task should stop) into a shift register. Each time through the loop the current tick count is compared to all of the Task[i] Timeout values. For any task where the tick count equals or exceeds the Timeout value, stop the task.
Any process which takes longer than the minimum resolution of the timing for ANY task needs to be put into a parallel loop or decomposed into small enough pieces to allow the interruption if a timeout occurs.
Lynn