View Single Post
  #7   Spotlight this post!  
Unread 08-03-2014, 18:59
AGPapa's Avatar
AGPapa AGPapa is offline
Registered User
AKA: Antonio Papa
FRC #5895
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Robbinsville, NJ
Posts: 323
AGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond reputeAGPapa has a reputation beyond repute
Re: Multi-Choice Autonomous

Quote:
Originally Posted by alexander.h View Post
I understand ... but if I use the digital inputs, what kind of structure do I connect each input to? I would be led to believe I would use a case structure, but I could be wrong.
The default code I showed before takes the array of booleans and splits it up into individual booleans. You can treat the outputs of the index array the same way you would treat the 8 individual button on the front panel.

Having separate case structures for each button and each autonomous mode would work, the first image I've attached shows how to do this.

This code will work fine if only one button is pressed at a time. If two or more buttons are pressed then each autonomous mode will run together at the same time. This is generally bad.


So for each case structure you should make sure that a certain button is pressed and all others aren't. There's a clever way to do this using "boolean array to number". This will turn the boolean array into an integer by treating the array like a boolean number. For example (four buttons):
0000=0
0001=1
0010=2
0100=4
1000=8
(Each button is represented by one digit)
Your cases for each mode will then be 1, 2, 4, 8, 16, etc.
Now if two buttons are pressed (ex: 0011=3) then it will enter the default case and not do anything!

Either approach will work, the second one will just make it impossible to execute two autonomous modes at the same time.
Attached Thumbnails
Click image for larger version

Name:	parallel case structures.JPG
Views:	54
Size:	125.9 KB
ID:	16509  Click image for larger version

Name:	booleanArrayToNumber.JPG
Views:	40
Size:	86.5 KB
ID:	16510  
__________________
Team 2590 Student [2011-2014]
Team 5684 Mentor [2015]
Team 5895 Mentor [2016-]
Reply With Quote