LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Traffic Light with Walk Sign

Hello. I have been working on a fairly common VI. The traffic light but this one has a walk sign that flashes don't walk at the right times.

 

I thought I had the timing correct but when I run it, it does not complete. Something to do with how I am implementing the while loop within a while loop that does not let it progress.

 

This is probably basic, but can anyone explain how I might implement this better?

 

Right now it gets stuck on the "walk/don't walk" loops. I had hoped it would receive a command from my main traffic light code to prevent it from forever blinking and would just never get to that point because the timing was the same or less than the main code.

0 Kudos
Message 1 of 9
(2,979 Views)

You have a major data flow problem.  You have while loops inside of while loops, and the only way of ending those inner while loops is to hit all of those many extra Stop buttons you have.

 

Turn on Highlight execution and watch your block diagram while you run your VI.  You'll see the issue.

 

Your VI should only have 1 while loop.

 

I would recommend you learn more about LabVIEW from here. How to Learn LV

0 Kudos
Message 2 of 9
(2,940 Views)

Yes thank you. I did say that in my text though. How should I solve that?

0 Kudos
Message 3 of 9
(2,933 Views)

Look up state machine architecture for ideas.

 

Search for "traffic light" as this is a common exercise that others have done.

 

The idea is you have one while loop.  It will execute frequently.

In it you have shift register that keeps track of your current "state".  That means what mode of the traffic light you are in.  That should be a type defined enum.

 

The value of that enum drives a case structure that tells which lights are on and which are off.

 

For the lights that blink, you need to also tell when the light is "on", whether is has blinked on or off.

 

If you used an elapsed time express VI set for a second, you can use the "Has Elapsed" output to toggle a boolean to tell whether the Don't Walk sign is lit or unlit.

 

Here is an example for one piece of code for one Don't Walk Sign.

The while loop here is the master while loop, so other pieces of code would be inside the same while loop.

 

 

0 Kudos
Message 4 of 9
(2,923 Views)

Your VI is completely constipated with long inner delays preventing you big loop from spinning. As has been said, you need one toplevel loop that spins at regular intervals, a state machine architecture and something that keeps state time.

 

I actually recommend to stay away from the "elapsed time" express VI. It's too much for such a simple task.

 

Have a look at my old example and use it as a starting point. First try to fully understand it, then expand. All you need are more signals, durations, and states.  (You don't need more loops, more case structures, and more other stuff!). Blinking can be implemented as relatively rapid state changes, no need for properties.

 

altenbach_1-1588792751016.png

0 Kudos
Message 5 of 9
(2,914 Views)

I really am trying to see how this works but I just don't see it entirely yet.

 

My sign should have two modes "on and counting down to 52 seconds and then start blinking on a 0.5 second cycle for 8 seconds" and "off"

 

0 Kudos
Message 6 of 9
(2,869 Views)

Now you are adding requirements.

 

Start simple.  Get some basics working.  Don't start worrying about some more advanced stuff when you haven't even started with a working VI.

 

Once you have a viable state machine architecture, you'll find it will be easier to add additional states.

 

If you have a timer, then you can do all the things you want.

1.  Display remaining time.

2.  Display ON if the remaining time > 8 seconds.

3.  Display Blinking if the remaining time <= 8 seconds.

 

Altenbach is not in favor of the Elapsed Time Express VI.  While I try to avoid the Express VI's, they aren't all bad.  Express Time doesn't had that much overhead and things you want like time elapsed, boolean output for has elapsed, and the reset functions are all built in so you don't have to worry about building that functionality from scratch.

0 Kudos
Message 7 of 9
(2,864 Views)

I do really like this example. I understand most of it except I don't see how to add a don't walk sign into it. I don't want to scrap my current code.

 

I see my code got reorganized by mistake using clean up diagram so I am posting it again without my walk sign code.

 

Should I just scrap this and try to work from your code or is it possible to add a walk sign to this the way it is?

0 Kudos
Message 8 of 9
(2,860 Views)

Ok. I shall try some of this too 🙂

0 Kudos
Message 9 of 9
(2,859 Views)