View Full Version : More than 1 autonomos...
Jimmy_Team7011
13-03-2008, 11:24
It might be such a dumb question, but at the last competition here there were some teams with more than one autonomos programing , and then, they placed jumpers interrupts in the vex rc to change between these programs, is that possible to do , or were they just trying to make us fool?
If there is any way to do it, how?
whitetiger0990
13-03-2008, 13:00
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 (http://en.wikipedia.org/wiki/DIP_switch) and put it on the digital ports.
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 (http://en.wikipedia.org/wiki/Bit_shift#Bit_shifts) in the number left one (basically multiplying the number by 2), and then ORing (http://en.wikipedia.org/wiki/Bitwise_operation#OR) 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 (http://en.wikipedia.org/wiki/Switch_statement) or just if statements (http://en.wikipedia.org/wiki/Conditional_%28programming%29) 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. =)
thefro526
13-03-2008, 18:08
A real easy way to do it in EasyC is to use some code like this.
If Digital Input == 1
Do stuff
Else If Digital Input == 0
Do other stuff
and so on and so forth
Jimmy_Team7011
16-03-2008, 12:18
Oh...so its possible.....but i couldnt understand how to do it....could sb explain?
thanks
DonRotolo
16-03-2008, 13:55
Um, I think they just did.
Let's say that in Autonomous 1 you want the robot to turn left, and Autonomous 2 you want it to turn right.
If (Digital_input_1 = 1) then
[Code to turn left]
EndIf
If (Digital_input_2 = 1) then
[Code to turn right]
EndIf
Now, you need to think more about this, because what happens if there are jumpers on both inputs 1 and 2? (someone forgot and put both on). And a lot of IF statements might become impractical if you have 25 different autonomous modes.
Also, make sure there's always one choice for "do nothing".
Don
Also, make sure there's always one choice for "do nothing".
Don
THis is especially important cause otherwise youre robot will be stuck doing what ever it was supposed to do last.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.