LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to sequentially trigger events 1, 2, 3, and 4 in the Event Structure

Solved!
Go to solution

zubat18gmailcom_0-1692359174279.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I'm creating a program in LabVIEW where the traffic lights change according to the following pattern:

 

  1. North-South signal Green, East-West signal Red
  2. North-South signal Yellow, East-West signal Red
  3. North-South signal Red, East-West signal Green
  4. North-South signal Red, East-West signal Yellow
  5. Emergency
  6. STOP

The traffic lights will continue to change in this pattern.

 

I want to control the duration of the green light for North-South and East-West using two separate sliders.

 

I also want to control the duration of the yellow light, which will flash continuously.

 

If the emergency button is pressed, all the signals will turn off, and the yellow lights will flash in all directions.

 

If the stop button is pressed, all the signals will turn off. If the run button is pressed, the signals will start working again.

 

I initially used a sequence structure to control the traffic lights, but the flashing and stopping signals wouldn't activate until the sequence was finished. So, I'm switching to using an event structure.

I'm not sure what elements can trigger the next event in the event structure. Can you help?

 
 
 
 
0 Kudos
Message 1 of 8
(857 Views)

Hi zubat,

 


zubat18@gmail.com wrote:

I initially used a sequence structure to control the traffic lights, but the flashing and stopping signals wouldn't activate until the sequence was finished. So, I'm switching to using an event structure.

I'm not sure what elements can trigger the next event in the event structure. Can you help?


A sequence structure most often is the wrong tool.

An event structure should be used to handle user input…

 

Have you thought about using a statemachine?

You clearly described 6 distinctive states and some conditions to change states…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(833 Views)

20230819_123910.png

hanks for the response!

I followed your advice and set up a sequence using a state machine with a while loop, and it's working much better than before. However, there's still an issue.

When I press the Emergency button, the Amber LEDs start blinking. But, when I press the button again, the inner while loop for blinking keeps running and prevents the outer case structure from changing conditions. It should return to the original light sequence, but it doesn't. 

I believe the issue might be due to the location of the Emergency button. It's outside of the while loop, but I need to keep it that way since I'm using it for the outer case structure as well.

The inner structure seems to have higher priority than the outer structure...

 

Do you have any suggestions?

 
 
 
0 Kudos
Message 3 of 8
(792 Views)
Solution
Accepted by topic author zubat18@gmail.com

You still have some serious misconception about dataflow. For example your inner while loop can never stop because the stop button is not inside the loop. Don't use inner loops! The blinking is just another state of the state machine and the outer loop would be sufficient to spin it. (You could even create two states, one for blink-on and one for blink-off and alternate between them  depending of the controls.

You still have all indicator terminals disconnected. They belong right after the case structure wired to value from each state. No need for any local variables.

Instead of negating the boolean for the case structure, you could just swap the cases, right?

 

Unfortunately you failed to attach your VI, so our advice is limited. We cannot tell for example what's in the other cases, the mechanical action of the buttons, a control labeled "amber slide control" does not tell us anything about what its function is. etc. etc.

Message 4 of 8
(785 Views)

For example, you could study my old code here and easily expand it to four lights, adding maybe 10% more code. Adding the emergency state would be trivial.

Message 5 of 8
(779 Views)

I've updated the blinking loop to use the feedback and NOT gate for blinking, as you suggested.

That was a great answer, thank you!

It's working perfectly now!

I really appreciate your help! Have a great day!

 

 

 
0 Kudos
Message 6 of 8
(746 Views)
Solution
Accepted by topic author zubat18@gmail.com

For fun, I did a quick cleanup (and no, you don't need to focus on cosmetics such as the huge image that makes the VI over 6MB! You can worry about that once the logic is all worked out. My code is only 13kB or almost 500x smaller!!!)

 

altenbach_0-1692480587870.png

 

Hey, not a single local variable! Code fits on less than half a postcard! 😄

 

Note that this is a simplified version and you can easily add more features such that it would measure the time of the "emergency" and starts in a defined state once the emergency is over.

Message 7 of 8
(648 Views)

Thank you so much for your incredibly helpful and detailed response! I can't express how grateful I am for your assistance. Wishing you nothing but happiness and good fortune!

 
0 Kudos
Message 8 of 8
(503 Views)