12-03-2008 08:24 PM
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.
12-03-2008 10:13 PM
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
12-03-2008 10:13 PM
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.
12-03-2008 10:26 PM - edited 12-03-2008 10:35 PM
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. ![]()
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.
12-03-2008 11:42 PM
12-04-2008 08:20 PM
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! ![]()
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!
12-04-2008 09:17 PM - edited 12-04-2008 09:18 PM
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).
12-04-2008 09:54 PM - edited 12-04-2008 09:54 PM
Update to my VI, since we're not interpolating the second array, we only need to index it instead.