LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

flat sequence problem

Solved!
Go to solution

I had written a program, my problem is for the first iteration program is Ok, for the next iteration it goes to the last flat sequence and run its elapsed time, I want for each iteration of program, run first, second, third and finally forth flat sequence and dont go to the last flat sequence.

0 Kudos
Message 1 of 9
(3,363 Views)

Hi hsa,

 

don't use sequences, build a state machine instead!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,357 Views)
Solution
Accepted by topic author hsadegh

Gerd's recommendation is very good. In addition, reset your "Time has elapsed" VIs by using the "reset" input:image01.png

 

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 3 of 9
(3,335 Views)

Hi Jens,

 

that reset isn't needed as it is already set in the options of the ElapsedTime ExpressVIs… 😄

 

Hi hsa,

 

there is no wait function in your (while) loops: you don't need to spin them as fast as possible just to recalculate the very same expression again and again!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(3,313 Views)

Hi Jens,

 

don't mind my last comment: it still makes sense to reset the ElapsedTime at while loop start…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(3,304 Views)

I also recommend a state machine, but since this seems to be your very first program, here's some more advice.

 

  • Yes, as Gerd already said, learn about state machines. it will be infinitely scalable. Imagine your next program has 20 states. Do you really want a program that is 10 screens wide?
  • Except for the elapsed times, your indicators need to be updated only on the first iteration, because they never change.
  • All your math is constant folded, of course. I assume that your real code has more interesting calculations.
  • The first and second frame of the flat sequence can be combined because order is irrelevant. Both result indicators will update at about the same time. Same with the last two frames.
  • Your two while loops need a small wait (e.g. 50ms). There is no need to spin them as fast as the computer allows.
  • A typical program is surrounded by a while loop.
  • ...

I would recommend to try to convert the entire code to a simple state machine. The only structures you need is a single outer loop and a case structure. try it! :D.

 

Message 6 of 9
(3,293 Views)

And since everybody is recommending a state machine: Application Design Patterns: State Machines


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 9
(3,270 Views)

Hi, that is a good idea, it resets elapsed time and my program works correctly, in the other hands there are other ways to do that.

thanks jensG69 

0 Kudos
Message 8 of 9
(3,227 Views)

yes your completely wright, I dont know about a state machine, i would be a good idea, a very small and useful program better than a big, complex program.

thanks altenbach

0 Kudos
Message 9 of 9
(3,224 Views)