View Single Post
  #2   Spotlight this post!  
Unread 13-03-2008, 13:00
whitetiger0990's Avatar
whitetiger0990 whitetiger0990 is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Earth
Posts: 157
whitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of lightwhitetiger0990 is a glorious beacon of light
Re: More than 1 autonomos...

Yup, we did this last year for FRC and just plain old C, but the logic should be the same, and it's good to understand the logic. We had a lot of digital ports opens, we wired up some pwms to a DIP switch and put it on the digital ports.
Code:
Auto_Mode=RC_dip_8;
Auto_Mode=(Auto_Mode << 1) | RC_dip_7;
Auto_Mode=(Auto_Mode << 1) | RC_dip_6;
Auto_Mode=(Auto_Mode << 1) | RC_dip_5;
Auto_Mode=(Auto_Mode << 1) | RC_dip_4;
Auto_Mode=(Auto_Mode << 1) | RC_dip_3;
Auto_Mode=(Auto_Mode << 1) | RC_dip_2; 
Auto_Mode=(Auto_Mode << 1) | RC_dip_1;
Basically with 8 switches, you could have 256 possibilities of autonomous modes. The << shifts all the bits in the number left one (basically multiplying the number by 2), and then ORing it with the next switch. In the end you have a char (a number which is 1 byte long, or 8 bits) and 8 switches, each one controlling one of the bits. So by having the switches flipped in different combinations, you have a range from 0 to 255. From that number you can switch statement or just if statements to control what the bot does.

We had no use for that many, but we had the space for it. The number of options you can have is 2 raise to the number of switches used. =)
__________________
print$q=chr(ord($q)+$1)while("7443-0201-8465130105-12-03135-82482113-06-7672-070208-0613-70"=~/(-?\d\d)/g);