LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

case statements

I am trying to implement the following simple if statement using the case structure in LabVIEW.

if t < rt
v = v + rm
elseif t < rt + ft
v = max
elseif
etc...


I can't figure out how to define each case. I went through the documented examples and they always have the cases as TRUE/FALSE or a as a series of string inputs (such as in the function generator). How do I define them as mathematical conditions? Any references to sample code would be appreciated but unfortunately, I only have a demo version (6.01) and would likely not be able to run it, so a few simple words would be much more helpful.

Thanks very much.
0 Kudos
Message 1 of 6
(3,207 Views)
I'm a preety good LabVIEW programer, and I don't know of a way of defining calculations in your case statements.

Easiest way, is probably to use nested case statements. Check t
Another way is to do your comparisons before the case statement input, and bundle all the booleans into a boolean array. From their, use the Boolean array to number function. If you know how to interperate binary numbers you should know what the numerics mean:

0- no comparisons were true
1- first was true
2- second was true
3- first and second
4- third
.... so on and so forth
0 Kudos
Message 2 of 6
(3,207 Views)
tj robertson wrote in message news:<506500000005000000F5820000-1023576873000@exchange.ni.com>...
> I'm a preety good LabVIEW programer, and I don't know of a way of
> defining calculations in your case statements.
>
> Easiest way, is probably to use nested case statements. Check t> if so, do code, if not check t>
> Another way is to do your comparisons before the case statement input,
> and bundle all the booleans into a boolean array. From their, use the
> Boolean array to number function. If you know how to interperate
> binary numbers you should know what the numerics mean:
>
> 0- no comparisons were true
> 1- first was true
> 2- second was true
> 3- first and second
> 4- third
> ... so on and
so forth


Hi Lei,
the answer lies in the formula node. It can handle if else
statements

if (t < rt)
{
v = v + rm;
}
else {
if (t < rt + ft) {
v = MAX;
}
else {
if (v==MAX) {
v= 0 ;
}
}
}

The above is the equivalent of
if t < rt
v = v + rm
elseif t < rt + ft
v = max
elseif v==MAX
v= 0

Of course this can be a bit of a nightmare in terms of what brackets
go with what when you have a large if-else structure, but I hope this
helps. Just remember, each subsequence else embeds inside the previous
else, i.e. partners with the previous if.

Sash.
0 Kudos
Message 6 of 6
(3,207 Views)
I am sorry to say that such capability is not directly supported in the case
structure. The input to a case structure can only be a single value of type
numeric, boolean, string or enum. For each case you can specify a single
constant, range of constants, or group of constants. You will need to do
the conditional math upfront and then drive the case structure with booleans
or you can aggregate all the boolean conditions into an array and then use
boolean array to number or search 1d array index to drive the case
structure.

Mike Sachs
Intelligent Systems

"Lei Dai" wrote in message
news:506500000008000000914E0000-1023576873000@exchange.ni.com...
> I am trying to implement the following simple if statement using the
> case structure in LabVIEW.
>
> if
t < rt
> v = v + rm
> elseif t < rt + ft
> v = max
> elseif
> etc...
>
>
> I can't figure out how to define each case. I went through the
> documented examples and they always have the cases as TRUE/FALSE or a
> as a series of string inputs (such as in the function generator). How
> do I define them as mathematical conditions? Any references to sample
> code would be appreciated but unfortunately, I only have a demo
> version (6.01) and would likely not be able to run it, so a few simple
> words would be much more helpful.
>
> Thanks very much.
0 Kudos
Message 3 of 6
(3,207 Views)
It looks like you depend on a range of values to generate other values. The best way to do this in labview is filling an array with boundary values and use one of the array lookup vi's (interpolate or treshold) to calculate the index in the original array and have so either a second array that outputs the wanted value or a case statement indexed by the found value to generate a value.
I always forget which of the two array lookup vi's is best suited for the task.
greetings from the Netherlands
0 Kudos
Message 4 of 6
(3,206 Views)
Hi

Try using the "formula node" instead of the "case structure". You can perform conditional branching inside a formula node. Check the help in LV and this link:
http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/26f9ffcaeb9a97cb862568f900719f74?OpenDocument

Hope this helps

Luca P.
Application Engineer
National Instruments
Regards,
Luca
0 Kudos
Message 5 of 6
(3,206 Views)