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: 

My Solution for CLD Sample Exam (Traffic Light)

Hi there folks,
 
I was just preparing for my CLD exam and was going through the sample exam provided on ni.com.
I wanted to get any feedback for my solution. I looked at the solution and it seemed way to complex
to achieve a simple task! Then again, I am still learning.
 
 
ThanX in advance.
Download All
0 Kudos
Message 1 of 9
(5,121 Views)

nice!

i didnt look at Ni's solution, so idont know how complicated they make it.

yet, here are my 2Euro cents:

try avoiding local variable all together. use instead (if necessary), global variable (called also Action Engines, see Ben's nugget)

try also avoiding sequences. see Atenbach nugget

reasons: in your solution, the possibilities to expand your code, or use it in larger systems, is a bit limited.

good luck on your exam! Smiley Happy

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 2 of 9
(5,097 Views)
Forgot to attach the solution!
0 Kudos
Message 3 of 9
(5,072 Views)


try avoiding local variable all together. use instead (if necessary), global variable (called also Action Engines, see Ben's nugget)


oups! i meant Functional Global Smiley Tongue
 
looking at this solution one can learn several things, for example:queued state machine (very versatile solution once one get used to it), a single large cluster to handle all the data, a very fast update of the loop (useful to catch errors on the fly - no need to wait for end of wait).
 
and by the look at it: easy to read - no crowded space, no claustrophobic sequece structures...
 
thanks for sharing it! how much time is the exam? doesnt look like something one would do in an hour (well maybe the gurus...)
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 4 of 9
(5,055 Views)

exam is 4 hours.

I guess I have to learn as much as I can from the solution and then proceed to the next sample exam.

ThanX for all the feedback Gabi1

0 Kudos
Message 5 of 9
(5,050 Views)
You should study all of the examples given online.  Notice how they use a state machine, and that all controls are Type Defs (for scalability which is a requirement).  Also study the Labview Style Guideline, available on NI website (search on Labview style guideline).  It is important to know that about 1/3 of your grade is on functionality, 1/3 on style, and 1/3 on documentation.  So be sure to put comments, documentation in the VI Properties window, and put Description and Tip Strips on all front panel objects.  Use a state machine, use subvi's, avoid local variables (it is OK to have a couple when necessary), stay away from sequence structures.  These are just a few tips.
- tbob

Inventor of the WORM Global
Message 6 of 9
(5,039 Views)
Hi there folks,
 
I was just reviewing the solution once again & I finaly understood that the Queue Handlers VI are being used like shift registeres.
I actually replaced the Queue VIs with shift registers and the program runs fine.
I wanted to know if there is any particular advantage in using Queue VIs instead of shift registers for this particular application.
 
Thanks in advance once again.
 
 
0 Kudos
Message 7 of 9
(4,960 Views)
 
Download All
0 Kudos
Message 8 of 9
(4,959 Views)

About queues vs shift registers.  Queues allow you the ability to insert elements into either end of the queue.  You can also write code to insert several elements at one time.  With shift registers, only one new element can be carried over to the next loop at one time.

Lets say you have a state machine that always executes in the same order, no matter what the outcome, like State1 then State 2 then State 3.  A shift register works fine for this simple example.  However with queues, you can use a loop to insert the 3 states before the main state machine loop, then dequeue in the state machine.  This is really a matter of preference.

Next example.  Lets say you had a situation where you want to run 3 states, but if the second one fails, you want to run 2 other states before going to the third one.  You could use a shift register, and you would have to look at each state to see which is next.  A queue would allow you to insert the 2 extra states in between states 2 and 3.  Of if you want to exit on some failure during a state.  You can use the queue to insert the exit state at the opposite end so that it is the next to be dequeued.

Another situation is if you allow the user to call certain actions that require running several states.  When the user presses button A, you enqueue states 1,2,3.  If the user presses button C you enqueue states 7,8,9.  So now you have a state machine in which states are defined by some user action.  This would be more difficult to do with a shift register. 

There are many other situations where a queued state machine is better than just a simple shift register.  For the simplest of situations, I might use a shift register only.  But I like to make it a habit to always use queues because of their versatility, and for the fact that I can go back and upgrade a simple state machine to a more complex one easily if it is done with queues.  Be sure to use shift registers on the queue error in and error out so that errors can be propogated from one state to the next.  On each state, check the error status.  If one occures, enqueue a state at the other end to jump to your error handling state (or exit).

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 9
(4,929 Views)