Code:
void SelectAutonomousProgram(void)
{
if (autonomous_mode) //AUTONOMOUS MODE IS ACTIVE
{
if (automode_LED == 0)
{
automode_LED = 1; //Turn on the autonomous LED when autonomous mode first starts
DriveNeutral(); //Stop the drive motors.
//Do other initial autonomous initialization stuff.
}
}
else //MANUAL MODE IS ACTIVE
{
if (automode_LED == 1)
{
automode_LED = 0; //Turn off the autonomous LED
DriveNeutral(); //Stop the motors
}
//Store the status of the LR side select switch
sideselect = LRsideselect_sw;
//Store the status of the Auto Drive Disable switch
autodriveselect = smartdrivedisable_sw;
//Calculate the autonomous program number set by the BCD switch on the button box --> positions 0-7 are valid. 8-9 are not
autocode = (autoselect0 * 1) + (autoselect1 * 2) + (autoselect2 * 4);
}
} //End SelectAutonomousProgram
See the above code for reference - it's what I used last year. I call the SelectAutonomousProgram routine from Process_Data_From_Master_uP. To store any OI switch-driven settings I want to make available to the program once the match starts, I create variables (i.e. sideselect, autodriveselect, autocode) and write the status of the OI switches to them while the robot is in human control mode (which it is when it's powered on and disabled before match start). When autonomous mode starts, these variables are still available to the autonomous code while the OI switches, joysticks, etc. are being ignored. This routine also sets initial robot behavior when the bot first comes out of autonomous mode.
This year, we're using a 3-position toggle switch (wired to an analog input with the help of 22k and 47k resistors) and a BCD thumbwheel switch (8 distinct program options that consume three digital inputs) to yield 24 different autonomous program possibilities. The likelihood of me having the time to program our robot to do 24 different things in autonomous is almost nil, but that's beside the point.