Go to Post we were sick and tired of compromises: "speed or torque", "traction or maneuverability", etc.; bump that, we want it all. all we had to compromise was simplicity. - RogerR [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2010, 18:42
RoboMaster's Avatar
RoboMaster RoboMaster is offline
Alum, former programmer&co-captain
FRC #2472 (The Centurions)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Minnesota, Twin Cities
Posts: 268
RoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant future
Best way to check multiple Boolean values?

In your program you need to check which button out of a couple of buttons, say, on a joystick, is currently pressed. Depending on which one it is you return a different value. So basically checking which of the multiple boolean values is true. What are some ways to do this, specifically in LabVIEW?

There's always the old "check one, if false, check the next, repeat." (a whole bunch of if...else statements in C). But in LabVIEW this means putting a lot of Case structures within themselves, which is a major pain especially if there are a lot of values/buttons to check.

Is there maybe a way to put all the button values into an array, search for a true or 1, and return which index it was? I don't think there's a "search array" VI.
__________________
My engineering blog: noeticbrainwaves.blogspot.com

I'm not slacking, my code's compiling
...and I'm using LabVIEW
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2010, 18:46
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: Best way to check multiple Boolean values?

In C++ you could do

Code:
if (joystick.GetRawButton(1) && joystick.GetRawButton(2)) {

}
Valid boolean operators are || (or) and && (and). I'm not sure how LabVIEW processes these but I'm sure there's a boolean conditional in LabView.
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2010, 21:59
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,533
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Best way to check multiple Boolean values?

I'm struggling to understand a situation where you have that many mutually exclusive buttons.

For instance - we have a button to reverse our front roller, that leads to a case statement that sets the motor speed. We have another case statement that fires the release on the catch.

The two have nothing to do with eachother, and the system works just fine if both are pressed or not pressed at the same time.

What is your situation, more specifically, where you have a bunch of buttons that affect eachother if they are pushed? (That is, if you can tell us without giving away your robot design). I've having trouble defining your problem statement in my head.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2010, 22:14
Luke Pike's Avatar
Luke Pike Luke Pike is offline
Programmer
FRC #1501 (THRUST)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Huntington
Posts: 114
Luke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to all
Re: Best way to check multiple Boolean values?

Put all of your boolean values in an array, then use the "Boolean Array to number" vi. This converts it from binary into a number. Wire that into a single case structure and create cases for the different values. For instance, "off off on" would be "1" and "off on off" would be "2".
__________________
Twitter Profile
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2010, 23:39
airnate airnate is offline
Registered User
FRC #0236 (Techno Ticks)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: southeastern CT
Posts: 93
airnate is a jewel in the roughairnate is a jewel in the roughairnate is a jewel in the rough
Re: Best way to check multiple Boolean values?

Quote:
Originally Posted by RoboMaster View Post
Is there maybe a way to put all the button values into an array, search for a true or 1, and return which index it was? I don't think there's a "search array" VI.
I think Luke already suggested an excellent way to do this, but to answer your question--yes you can do as you suggest and use Build Array to make an array of Booleans and then use Search 1D Array to search for a True (or False) value in the Boolean array. Both of these functions are found in the LabVIEW Array palette.
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2010, 10:19
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Best way to check multiple Boolean values?

Just to add a bit more to the excellent suggestions. If you have say six buttons, it is sometimes useful to see how many are on, or to see if one of the first two, one of the second two, and one of the last two are on.

For searching how many are on, another trick is to send the Boolean array to the Boolean to (0,1) conversion function. This will give you an array of integers with a 0 for falses and a 1 for trues. Then you can do things like Sum in the numeric palette to answer how many Booleans were true in the array.

To check for combinations, you can use Boolean operations directly on arrays, and sometimes that is nice. For example to And your buttons with a mask to see if specific ones are on. If you fine the arrays of Booleans difficult to read off, some people prefer to cast them to numbers and then do Boolean operations on the integers, for example MyInt AND Mask. In other words, the Boolean operations work on integers as well as Booleans.

Finally, to make the most self documenting code, it is often better to build clusters of the Booleans, or to convert the array to a cluster. The cluster allows you to name the individual Booleans, and of course you can use Boolean operations on the clusters too. So MyBooleanCluster AND Mask gives a very readable bit of code. It is often then useful afterwards to do quick conversions to integers to compare with 0 or to convert to array to search, etc. If you want to spend the time to make a typedef cluster of your Boolean cluster, you can make very readable code and cut out lots of logic debugging.

Greg McKaskle
Reply With Quote
  #7   Spotlight this post!  
Unread 31-01-2010, 21:55
RoboMaster's Avatar
RoboMaster RoboMaster is offline
Alum, former programmer&co-captain
FRC #2472 (The Centurions)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Minnesota, Twin Cities
Posts: 268
RoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant futureRoboMaster has a brilliant future
Re: Best way to check multiple Boolean values?

Thanks for the great replies! Now that I know that there is a "search array" VI, I think I like that idea best. But Greg Mckaskle gave some good points too.

One poster asked about my scenario more specifically. I tried to keep it general because this could be used for multiple instances, and I didn't just want help on my specific problem. But I can see how it could be confusing. So let me give an example, my current scenario. We have a ball kicker on our robot this year. We plan to program it to kick with various speeds depending on which "fire" button the operator pushes. So at one point in the programming we need to sense which button is pressed, if one is pressed at all. That's where I'm coming from.
__________________
My engineering blog: noeticbrainwaves.blogspot.com

I'm not slacking, my code's compiling
...and I'm using LabVIEW
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Way Of Scoring? KingBK General Forum 18 05-01-2009 21:08
Best way to detect a bot dpeterson3 Electrical 24 04-01-2009 14:56
Best Way to Get Points SSMike Rules/Strategy 54 09-01-2008 16:46
Best way to start Torboticsmember Programming 4 06-02-2007 12:27
Best way to make money! SPDEXL Fundraising 17 21-07-2003 01:19


All times are GMT -5. The time now is 22:42.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi