LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What do you guys think about my traffic lights code (see attached vi)?

Thank you very, Mr. Altenbach !!! Great information. I learned something new. This is why I like this forum!

0 Kudos
Message 11 of 19
(1,378 Views)

@altenbach wrote:

@GRCK5000 wrote:

How are you able to insert booleans (G, Y, R) in enum? How did you do that?


 

A radiobutton container (boolean palette) is similar to a cluster, but it can only contain booleans. Any style and number of booleans!!!!

 

Only exactly one (or also none of so configured) can be TRUE at any given time, As soon as another one turns true, all others turn false automatically. This is very useful and often dramatically simplifies your code.

 

In your case, you would place a radiobutton control from the palette, then drop your three LEDs in it. Now you can remove the two booleans that were originally in there. You can change the cluster order if needed. Of course you can make it a control (typical) or an indicator (as in this case).

 

The type is an enum with values for all element names in cluster order. The current value of the enum is the label of the element that is currently true, so make sure all elements have unique and clear labels, even if they don't show on the front panel.

 

( Also have a look at my description here and vote for it if you like. 😄 )


Very nice.

In the linked description you wrote "Of course a VI with an empty radio button control should probably be broken."  I would have worded it 'Of course a VI with an empty radio button control would have to be broken.'  I just can't imagine what value an empty radio buttons cluster would have (it would be like a enum with no items).

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 12 of 19
(1,349 Views)

@paul_cardinale wrote:
In the linked description you wrote "Of course a VI with an empty radio button control should probably be broken."  I would have worded it 'Of course a VI with an empty radio button control would have to be broken.'  I just can't imagine what value an empty radio buttons cluster would have (it would be like a enum with no items).

Well, that idea is way over 10 years old!

 

Maybe I should take that sentence back. An Enum placed freshly from the palette has no items and does not break the VI, so maybe an empty radiobutton control should not even break the VI. We just need to define how it should behave. 😄

 

altenbach_0-1668361751086.png

 

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png

 

0 Kudos
Message 13 of 19
(1,339 Views)

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png


I have used this in my code. I hope your not suggesting we change that 😁

 


@altenbach wrote:

@paul_cardinale wrote:
In the linked description you wrote "Of course a VI with an empty radio button control should probably be broken."  I would have worded it 'Of course a VI with an empty radio button control would have to be broken.'  I just can't imagine what value an empty radio buttons cluster would have (it would be like a enum with no items).

. An Enum placed freshly from the palette has no items and does not break the VI, so maybe an empty radiobutton control should not even break the VI. We just need to define how it should behave. 😄

 

 


 

Why does an empty cluster container break the VI if empty enums do not? 😕

 

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 14 of 19
(1,297 Views)

@Frozen wrote:

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png


I have used this in my code. I hope your not suggesting we change that 😁


No, the current behavior is correct, just not necessarily obvious to some.

 

Here's explicit code to do the same as "and array elements". If the array is empty, the number of iterations is zero and the TRUE is returned unchanged. 😄

 

altenbach_0-1668459900242.png

 

0 Kudos
Message 15 of 19
(1,291 Views)

@Frozen wrote:

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png


I have used this in my code. I hope your not suggesting we change that 😁

 


@altenbach wrote:

@paul_cardinale wrote:
In the linked description you wrote "Of course a VI with an empty radio button control should probably be broken."  I would have worded it 'Of course a VI with an empty radio button control would have to be broken.'  I just can't imagine what value an empty radio buttons cluster would have (it would be like a enum with no items).

. An Enum placed freshly from the palette has no items and does not break the VI, so maybe an empty radiobutton control should not even break the VI. We just need to define how it should behave. 😄

 

 


 

Why does an empty cluster container break the VI if empty enums do not? 😕

 

 


There's no such thing as an empty enum.  When you place a new one, it has one item (which is undeletable) that has an empty string as its name.

"If you weren't supposed to push it, it wouldn't be a button."
Message 16 of 19
(1,271 Views)

@Frozen wrote:

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png


I have used this in my code. I hope your not suggesting we change that 😁


There have been quite lengthy and heated discussions about this in the long ago past. And the mathematically educated consensus was that this IS the way it should be. There is a good reason for it, even if it is not very intuitive to the casual layperson. 😀

Rolf Kalbermatter
My Blog
0 Kudos
Message 17 of 19
(1,246 Views)

Similar the "AND array elements" of an empty boolean array is TRUE, even if that's not necessarily obvious to some people..

 

altenbach_1-1668361981721.png


Summary of my understanding of the rationale is tied to set theory:

 

In each case, the result of operating on an empty set is to produce the IDENTITY value for that operator.

  • for AND, the identity is True (X AND True results in X)
  • for OR, the identity is False (X OR False results in X)

 

This understanding carries over into the numerical operators for finding the sum or product of an array.  In the case of an empty array, you once again get the identity value for the operator.

  • for SUM, the identity is 0, so the sum of an empty array results in 0
  • for PRODUCT, the identity is 1, so the product of an empty array results in 1

 

The results for AND and PRODUCT are often unexpected.  AND in particular shows up "in the wild" with some regularity in code, PRODUCT seems to be needed less commonly.   Here's a simple workaround for the array AND situation with an empty array:

 

Kevin_Price_0-1668523128961.png

 

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 18 of 19
(1,211 Views)

Since the original discussion about traffic lights has run its course and we are now completely offtopic, there is an additional issue I have with AND/OR array elements:

 

While most boolean operations work in integers (bitwise!), these two array operations don't. Is there a fundamental explanation or is it just a glaring omission?

 

altenbach_0-1668526680442.png

 

I'll have to look in the ideas exchange if this has been mentioned. It would be relatively easy to do a vim that accepts any type of integer arrays with any number of dimensions.

 

0 Kudos
Message 19 of 19
(1,185 Views)