01-04-2018 07:46 AM
Hi
I have a simple reactor which has 4 basic steps, I can use a state machine or a flat sequence structure, the challenge which I have is in one of the steps a pump should run for 30 seconds or until it gets a signal from a level sensor then it moves to the next step, I didn't know how to combine these two conditions to the running time of the pump!! any suggestions are highly appreciated.
thanks in advance
Hatem
01-04-2018 07:57 AM
Hi Hatem,
in one of the steps a pump should run for 30 seconds or until it gets a signal from a level sensor then it moves to the next step … how to combine these two conditions
So you wrote your conditions and their relation ("or") - but you don't know how to program this?
Use an OR operation! 😄
01-04-2018 09:58 AM
You also answered your questions regarding whether to use a flat sequence or a state machine. Use the state machine. Your flow through the processing varies which lends itself perfectly to state machines. Flat sequence are rather unwieldy when you need to change the processing flow given specific conditions.
With that said, there are really only two use cases where I use flat sequences. The first is to impose data flow where none exists. For example, to make sure I read the stop button in a loop after all of the processing is complete rather than at the beginning of the loop. This prevents the loop from running an extra iteration. The second is when I am timing something. It is a simple three frame sequence with the start time in the first frame, the code I want to time in the middle frame and the end time in the last frame. Even these use cases can be implemented rather simply in a good state machine. Checking for a stop condition is almost always handled by the state machine. Timing operations are a good use of the sequence structure simply because it eliminates any other code overhead that could affect your measurement.
01-05-2018 02:54 AM
Hi GerdW,
Well, maybe this simple VI could explain more!
The first step LED 1 will be on for 5 seconds then it moves to second step where LED 2 will be on for 5 seconds then it moves to the last step LED 3 on for 5 seconds and so on....
what I want to do is keeping step 1 and step 3 as they are but step 2 should be for 5 seconds or until I get a signal from my sensor which could be in 2 or 3 seconds from the beginning of step 2
01-05-2018 03:35 AM - edited 01-05-2018 03:38 AM
Hi Hatema,
then create a state machine for your task!
(Hint: right-click the sequence frame and convert to stacked sequence. Then right-click the sequence again and convert to case structure. Now you're half-way to your state machine! :D)
State1, State2 and State3 will just set your LED as needed.
Then have one state to wait for 5s (maybe named "wait 5s") - and one more state to wait for your Level sensor OR 5s (named "wait 5s OR until level").
5 simple states in a simple state machine…
You need to go this order:
01-05-2018 03:41 AM
I am not sure I got what you mean by (( Then have one state to wait for 5s - and one more state to wait for your Level sensor OR 5s.))!!
01-05-2018 03:45 AM
Hi Hatema,
I am not sure I got what you mean by (( Then have one state to wait for 5s - and one more state to wait for your Level sensor OR 5s.))!!
You should create two different states:
- state "wait5s" will just wait for 5s
- state "wait5s OR until level" will wait upto 5s OR until your level sensor signals…
01-05-2018 05:34 AM
Hi Hatem
I think the issue is that you cannot simply wait in your State2 (for 5 seconds) as you have to be continually looking at your level sensor? If you are waiting you can't look at your sensor value. So your state machine needs to remain in a state up to a maximum time whilst making decisions based on the sensor level.
I put this together for you. It is not supposed to be a solution (or even be functional), that's down to you, but should give you some hints towards where I think you need to be.
NOTE: Constant values are convenient but you may want to avoid using them or at least comment them .
Steve
01-05-2018 05:45 AM
Hi Steve,
That is exactly what i mean, I have to look continually at the sensor.
thanks for your help, I will to use what I can from them, then I will be back here; hopefully with "SOLVED" 🙂
01-09-2018 03:03 AM
Hi again Steve.
I couldnt solve it unfortunately, maybe because i am still beginner in LabView!
I do not know how far you can help me!?
Regards
Hatem