LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to design a switch/case structure that handles double/float values?

I am relatively new to LabVIEW and using version 8.5 SE, so please bear with me with the following.  I'm trying to implement the following "scaling" operation, I've looked into using a case structure but for some reason it is only allowing boolean "selects".

 

if (input voltage signal < 0.02), Force = (voltage * 0)

if (voltage < 0.1 and voltage > 0.02), Force = (voltage * 50)
if (voltage < 0.4 and > 0.1), Force = (voltage * 80)
if (voltage > 0.4), Force = (voltage * 54)

 

How would I implement this in LabVIEW without making multiple cascading if/select statements?  Thank you for your assistance.

0 Kudos
Message 1 of 8
(8,880 Views)

Hi amansari,

Unfortunately, a case structure can't handle floating point values, it is more suited to handling integers, text and boolean inputs. Suggest instead you use a formula node on your block diagram as this will allow you to enter an equation similar to the 'C' language in the format of If, Then, & Else statements.

 

Regards,

Andy

Message 2 of 8
(8,861 Views)

I think this may be a case where it is best to go back to a text based language to solve.  Execute the comparison and calculation in a formula node like attached.

 

I took your code and cleaned up the syntax so it would work in the formula node.

 

What happens if the voltage is exactly .02, .1 or .4?  Your case structure doesn't give a calculation for that.  Make sure you had an equality statement for that.  As it is right now, you have discontinuities in your calculations at those points.  I don't know if you want that to be the case or not.

Message 3 of 8
(8,859 Views)

Hi amansari,

      Having worked on the examples (attached) for while, I was about to say this sort of problem has many solutions - and formula-nodes are a nice way too. Smiley Wink

 

This example shows two ideas - including use of a case, though, the case is not very flexible as it requires editing the program if thresholds and scalers need to be "tweaked" later.

 

Another possibility might be to supply the thresholds and scalers at run time (attached.)

 

Cheers! 

 

P.S. Your original post left undefined "holes" for voltages of exactly 0.02, 0.1, and 0.4.  One way to close the holes is to include these values at the beginnig of a range, though, the attached examples assume them to mark the end of a range.

Message Edited by tbd on 12-03-2008 10:35 PM
Message Edited by tbd on 12-03-2008 10:35 PM
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 4 of 8
(8,855 Views)
Thank you all very much for your response!  I have tried the Formula Node method, however I am getting an error regarding "Array Indexing Expecting", saying that the error is located at the hash: "Error on line 2 is marked by a '#' character: "...Force; if (voltage <# 0.02) Force=0; if ".  I have attached my VI, it is taking continuously sampled voltages from a DAQ and converting them into a force.  Please only look at the "Sensor 1" signal.  Thank you once again for the guidance!
0 Kudos
Message 5 of 8
(8,836 Views)

Hi amansari,

>getting an error regarding "Array Indexing Expecting",

... that's because an array has been wired to the "voltage" input of the formula node! Smiley Surprised

 

Should the "Convert from Dynamic Data5" function ( the yellow bullet-shaped-thing to the left of the formula node) be configured to return a "Single scaler" instead of 1D array?

Just right-click on this function on your diagram and choose "Properties" - or see attached VI.

 

Cheers! 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 6 of 8
(8,790 Views)

You can try this method.  It basically determines what range it falls into the first array.  It gives a fractional index which is the interpolated value.  We round that down to a whole number to get the exxact index of the multiplier, then do your math.  It may not make sense when you first look at it, but it may be faster than using a formula node (I didn't benchmark it though).

 

 

Message Edited by Matthew Kelton on 12-04-2008 09:18 PM
Download All
Message 7 of 8
(8,779 Views)

Update to my VI, since we're not interpolating the second array, we only need to index it instead.

 

 

Message Edited by Matthew Kelton on 12-04-2008 09:54 PM
Download All
Message 8 of 8
(8,768 Views)