08-03-2023 04:25 PM
Hello,
I'm trying to write a program with a state machine. One of the state is the ''test'' state. In that state, I have 5 step : Heating, cooling, resistance measures, saving data and emergency stop (AU). Whenever there is a problem, I want to return to emergency stop. My problem is, for heating and cooling, it needs to be timed. I tried a ''wait'', and it works. The only problem is, if one of my emergency stop condition occurs while I'm in heating or cooling, I stay stuck in the state for the time value I put in the ''wait''. It's dangerous for my application, because I'm heating a cable and if the temperature is to high I really need to stop heating and go the emergency stop.
I also tried a Timed loop, but the only way I can stop it is with an event structure that only depends on controls (wich is good for a STOP HEAT button), but my other conditions are global variables that I measure physically and send to labview through a agilent and a labjack that goes into a producer-consumer vi.
Any ideas for me ?
Solved! Go to Solution.
08-03-2023 05:25 PM - edited 08-03-2023 05:27 PM
@cookie10 wrote:
Hello,
I'm trying to write a program with a state machine. One of the state is the ''test'' state. In that state, I have 5 step :
Any ideas for me ?
With out even looking at your code: Yes, each of the 5 steps in your "test state" should be a state.
Then instead of using a Wait have a "timer" state that can be aborted.
08-04-2023 07:39 AM
you have to add a condition that the emergency stop is monitored all the time so it triggers the EMERgency state, even during wait , heat, coolilng, and when it occur it overrides any other condition.
08-04-2023 11:42 AM
That's exactly what I'm trying to accomplish, but I'm struggling with finding out how, since my wait function forces the state I'm in to stay there until the heat time is over.
08-04-2023 11:52 AM
For something that is safety critical, I highly suggest you refactor your code. I have not looked at it in detail but there are a plethora of global/local variables that can lead to possible race conditions. All those values could be added to a cluster and put on a shift register for your loop, no globals or locals needed.
For your problem I suggest something like the JKI State Machine; your have an Event Structure in a loop. In your loop you can go to different states. For your "Wait Case", you could need to change the timeout of the Event Structure and go into an "Idle" State. If the event structure times out then you complete your test. If the time out of event structure is interrupted by an Event, like an Emergency Stop, you can go to that case. That is the beauty of using the timeout of an event structure it can be interrupted and stopped if needed.
08-04-2023 11:52 AM
Do you mean a timed loop with an ''abort'' event structure ? I tried, but it only works with a controlled button that the user has to press. I need it to also depend on 2 global variables that are EMERGY STOP BUTTON PUSHED and TMAX REACHED.
My application needs to run even when no user is around to press the stop heat button
08-04-2023 12:08 PM
@cookie10 wrote:
Do you mean a timed loop with an ''abort'' event structure ?
No. I mean an event structure.
@cookie10 wrote:
My application needs to run even when no user is around to press the stop heat button
A proper State machine can handle this no problem.
Below is a screenshot of the JKI State Machine, available on VIPM. Notice there is an Event Case in an "Idle State" to handle UI Interactions. The default timeout for the Event case is -1, but you can change that with a New State called Set Timeout and a Shift Register. Notice there is a shift register with a cluster that has all the data the State Machine Needs.
You can have a case and check the temperature, if TMax reached then shutdown.
08-04-2023 12:15 PM
In this case you can't use the Wait function because you will be stuck. One option is to implement a "Wait function using Tick Count, the while loop start and then read the tick count every iteration and compare with the first iteration to calculate elapsed time, it stops when the elapsed time is higher than the wait time, in the same loop you read the variable for Emergency (I guess it's called AU in your code) to stop the loop and get out of the wait.
this is a simple version
08-04-2023 12:38 PM
Do not rely on software to act as a safety mechanism for unattended high temperature control.
Also implement an independent hardware solution such as a temperature monitoring relay where you can set an upper temperature limit. If that limit is exceeded the relay can cut power to the heating element.
-AK2DM
08-04-2023 02:00 PM
Thank you so much! This works! now I can go to sleep lol