Skip to content

Instantly share code, notes, and snippets.

@acetousk
Created January 25, 2019 14:55
Show Gist options
  • Save acetousk/1cbab0b5e1570413af4e5e741a9ee5fe to your computer and use it in GitHub Desktop.
Save acetousk/1cbab0b5e1570413af4e5e741a9ee5fe to your computer and use it in GitHub Desktop.
auton code that is a massive if else tree that is a pain to write so this will make it easier probabally...
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
/** ------------------- 72832S variable definitions -----------------*/
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
int autonRun;
//auton cutoffs
int cutoffs[] = {-4096, -2048, 0, 2048, 4096};
//auton reading potentionmeters
int val1 = SensorValue[posPotent];
int val2 = SensorValue[progPotent];
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
/** ------------------- 72832S autonomous functions -----------------*/
/*********************************************************************/
/*********************************************************************/
/*********************************************************************/
void init(){
if (val1 >= cutoffs[0] && val1 < cutoffs[1]) {
if (val2 >= cutoffs[0] && val2 < cutoffs[1])
autonRun = 0;
else if (val2 >= cutoffs[1] && val2 < cutoffs[2])
autonRun = 1;
else if (val2 >= cutoffs[2] && val2 < cutoffs[3])
autonRun = 2;
else if (val2 >= cutoffs[3] && val2 < cutoffs[4])
autonRun = 3;
} else if (val1 >= cutoffs[1] && val1 < cutoffs[2]) {
if (val2 >= cutoffs[0] && val2 < cutoffs[1])
autonRun = 4;
else if (val2 >= cutoffs[1] && val2 < cutoffs[2])
autonRun = 5;
else if (val2 >= cutoffs[2] && val2 < cutoffs[3])
autonRun = 6;
else if (val2 >= cutoffs[3] && val2 < cutoffs[4])
autonRun = 7;
} else if (val1 >= cutoffs[2] && val1 < cutoffs[3]) {
if (val2 >= cutoffs[0] && val2 < cutoffs[1])
autonRun = 8;
else if (val2 >= cutoffs[1] && val2 < cutoffs[2])
autonRun = 9;
else if (val2 >= cutoffs[2] && val2 < cutoffs[3])
autonRun = 10;
else if (val2 >= cutoffs[3] && val2 < cutoffs[4])
autonRun = 11;
} else if (val1 >= cutoffs[3] && val1 < cutoffs[4]) {
if (val2 >= cutoffs[0] && val2 < cutoffs[1])
autonRun = 12;
else if (val2 >= cutoffs[1] && val2 < cutoffs[2])
autonRun = 13;
else if (val2 >= cutoffs[2] && val2 < cutoffs[3])
autonRun = 14;
else if (val2 >= cutoffs[3] && val2 < cutoffs[4])
autonRun = 15;
}else{
autonRun = -1;
}
}
task autonomous(){
if (autonRun == 0) {
auton0();
} else if (autonRun == 1) {
auton1();
} else if (autonRun == 2) {
auton2();
} else if (autonRun == 3) {
auton3();
} else if (autonRun == 4) {
auton4();
} else if (autonRun == 5) {
auton5();
} else if (autonRun == 6) {
auton6();
} else if (autonRun == 7) {
auton7();
} else if (autonRun == 8) {
auton8();
} else if (autonRun == 9) {
auton9();
} else if (autonRun == 10) {
auton10();
} else if (autonRun == 11) {
auton11();
} else if (autonRun == 12) {
auton12();
} else if (autonRun == 13) {
auton13();
} else if (autonRun == 14) {
auton14();
} else if (autonRun == 15) {
auton15();
} else {
auton_1();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment