LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure inside case structure execute once

Solved!
Go to solution

Hello all,

 

I am making a controller using myRIO and labview where the program compares a sensor value to a preset and then chooses a case structure depending on what kind of air supply is required. What can be seen in the photo, for example, is case 0 where saturated air supply is required.

 

The event structure is used to send a step signal to stepper motors to open valves (closing is done further pretty much the same way). Anyway, the specific event turns my valves 90 degrees. I read from the sensor every one second, however, when the case remains unchanged, the case performs the event again resulting in my motors turning 90 degrees every second (basically continuously). What I am looking for is a way to send the step signal just once until a new case is selected.

 

It's not in the picture but the whole thing is inside the main while loop.

Apologies for any bad/cringeworthy coding, it's literally my first program ever using labview. I can post the full VI if you need it.

 

Any ideas would be much appreciated! Thanks

0 Kudos
Message 1 of 13
(6,215 Views)

Hi Simos,

 

please clean up your code: what's the purpose of all those Select functions?

 

Have you ever coded "IF TRUE THEN TRUE ELSE FALSE" in any other programming language? Several times in a function/VI? Seriously???

(Btw. "IF TRUE THEN FALSE ELSE TRUE" usually is named "Negate"…)

 

Why do you use an event structure at all? Why set this timeout to "-1" after the first iteration?

How do you determine the stop condition of the while loop around your event structure? Because of hidden wires we can only guess you compare to this FOR loop output…

And why do you use an autoindexing tunnel to output just the loop iterator in an array? Why do you want to compare with an array containing the numbers from zero to 199?

 

I can post the full VI if you need it.

It's always a good idea to post code instead of images. We cannot debug images with LabVIEW…

Best regards,
GerdW


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

Event Structures do not belong in embedded devices, like the myRIO.  So that is the first mistake.

 

GerdW already hit on a lot of other issues.  But that Event Structure is doing nothing for you.  Furthermore, neither is the While loop it is in.  And then the two Selects inside of the FOR loop can just be a simple NOT.

 


@simos wrote:

What I am looking for is a way to send the step signal just once until a new case is selected.


My recommendation is to use a Feedback Node so you can compare the current case that is to be called with the previous.  Pass the result into the case structure and then use another one inside that has your FOR loop so that the loop only runs when the call case changes.


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 3 of 13
(6,193 Views)

Hi GerdW and crossrulz,

 

Thank you for your swift replies. Just to ease your facepalming, I am not actually a programmer of any sorts, I'm just a mechanical engineering student with literally zero labview experience and a fairly ambitious task to complete. Also, I did not actually choose my hardware; someone told someone else that myRIO would be suitable and that someone else then gave me the RIO and told me to utilise it. 

 

I am sure there are multiple ways to do things better, however, I will try to answer your questions based on my understanding while writing the code:

-I use an event structure because that was the only way I could find to control the steps of my motor. PWM did not work. I set the timeout that way because I was looking for a way send that signal just once. Initially I had made a simple VI just with the event structure and that was the way I stopped the loop from repreating. (that was before the stop button comparison you see there.)

 

-I did not intentionally set up an autoindexing tunnel that was assigned with wiring. I needed a way to stop the while loop and thus stop my event structure from executing again and again. Because I need 200 iterations to turn my motor 90degrees I set it up to exit the loop when complete. 

 

I have cleaned up a bit and uploaded the VI for you to see. Thanks for teaching me the "negate".

 

crossrulz have you got a simple example by any chance that utilises the feedback node?

0 Kudos
Message 4 of 13
(6,172 Views)

Hi simos,

 

Thanks for teaching me the "negate".

Then why don't you use the NOT function in your VI?

Now I facepalm…

 

check.png

Removing the while loop and the event structure will make your FOR loop execute just once!

 

Btw. when you want a While loop to iterate just once you wire a TRUE constant to it's stop condition (set to "stop when TRUE"). No need to compare two arrays with 200 elements and to ArrayAND the result of the comparison… (Facepalm again… :D)

 

Why does your case structure has a case "4, default", when this case "4" isn't possible as you generate this number from just two boolean values???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 13
(6,157 Views)

@simos wrote:

Hi GerdW and crossrulz,

 

Thank you for your swift replies. Just to ease your facepalming, I am not actually a programmer of any sorts, I'm just a mechanical engineering student with literally zero labview experience and a fairly ambitious task to complete. Also, I did not actually choose my hardware; someone told someone else that myRIO would be suitable and that someone else then gave me the RIO and told me to utilise it. 

 

I am sure there are multiple ways to do things better, however, I will try to answer your questions based on my understanding while writing the code:

-I use an event structure because that was the only way I could find to control the steps of my motor. PWM did not work. I set the timeout that way because I was looking for a way send that signal just once. Initially I had made a simple VI just with the event structure and that was the way I stopped the loop from repreating. (that was before the stop button comparison you see there.)

 

-I did not intentionally set up an autoindexing tunnel that was assigned with wiring. I needed a way to stop the while loop and thus stop my event structure from executing again and again. Because I need 200 iterations to turn my motor 90degrees I set it up to exit the loop when complete. 

 

I have cleaned up a bit and uploaded the VI for you to see. Thanks for teaching me the "negate".

 

crossrulz have you got a simple example by any chance that utilises the feedback node?


What is the purpose of the event structure?

 

You say you needed it, but it doesn't do anything that wouldn't already happen if you just eliminated it.  It is set with a timeout of 0, so the timeout case will run instantly.  It resets the timeout to -1 so the timeout event will never run again.  But it will never run again if you set the while loop to run only once.

 

What is the purpose of the while loop?  You only want it to run one time.  So just eliminate it.

 

What is the purpose of the comparisons that are wired to the stop loop?  You are creating an array of the iteration values coming from the For Loop.  It will look like 0, 1, 2, 3, 4, .... 199.  Then you compare taht wtih an array that is 0, 1, 2, 3, 4, 5, 0, 0, 8, 9, 0, 0, ....., 0, 0, 199.  If any of those comparisons are True, then the while loop will stop.  Guess what.  The first 6 will always be true, the 8, 9, and 199 values will also be true.  You just made a very complicated True constant.   (But like I said, the while loop is not needed at all.)  More work went into this Rube Goldberg of a construction than I've seen in a long time.  Congratulations!  Smiley Wink

 

 

0 Kudos
Message 6 of 13
(6,137 Views)

This can't be serious, can it?

0 Kudos
Message 7 of 13
(6,117 Views)
Solution
Accepted by topic author simos

@simos wrote:

crossrulz have you got a simple example by any chance that utilises the feedback node?


See if this helps


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
Message 8 of 13
(6,097 Views)

GerdW,

 

Thanks for your suggestion. Unfortunately following your example does not seem to execute the For loop just once and then move on. Single stepping completes the loop, and then does not exit the case structure, it reruns the For loop.

 

 

About case 4 I know its not possible to generate it and I don't really require a default case. So should it matter if it's set on default or not?

0 Kudos
Message 9 of 13
(6,058 Views)

Hi simos,

 

Single stepping completes the loop, and then does not exit the case structure, it reruns the For loop.

That's not possible due to DATAFLOW. After executing the code inside the case structure it will exit that case!

 

About case 4 I know its not possible to generate it and I don't really require a default case. So should it matter if it's set on default or not?

 It's not the point you set this case "4" as default. It's the point of having that case "4" at all!
Why have code in the VI that NEVER executes? Why have code in a VI where other users don't know what it is good for?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 13
(6,052 Views)