From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

state machie

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 

0 Kudos
Message 1 of 16
(2,880 Views)

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! 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(2,874 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 16
(2,841 Views)

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

0 Kudos
Message 4 of 16
(2,818 Views)

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:

  • state1
  • wait5s
  • state2
  • wait5s OR until level
  • state3
  • wait5s
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 16
(2,811 Views)

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.))!!

0 Kudos
Message 6 of 16
(2,806 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 16
(2,800 Views)

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 Smiley Wink.

 

StateMachineDiscussionForums.png

 

Steve

0 Kudos
Message 8 of 16
(2,788 Views)

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" 🙂  

0 Kudos
Message 9 of 16
(2,784 Views)

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

0 Kudos
Message 10 of 16
(2,746 Views)