My autonomous buttons are useless... I need help

I have an autonomous button system. The button the bottom-most right of my brain is the alliance selector. The button to the left of it is the tile selector, either one or two. The button on the top right is the button that saves all of the variables to the program so that it runs the right autonomous. The idea is that you select the variables that will choose the auton (i.e. If you wanted to run the autonomous for Red side, tile one), then you click Save Variables and it runs the selected autonomous. But what is happening is every time I press a button to change a variable, it makes a single line of the “Blue side, Tile 1” auton run. I tried commenting it out, and when I did, the program did nothing. Here the auton code:

    void Autonomous(int color, int tile){ 
      //Save_Varibles = true;

     //4 Blocks in Goal Zone (Red Side, Tile 1)
     while (1) {
     if (color%2 == 0){

       if (tile%2 == 1) {
        
       autonstart();
        
       BarMotor.stop(brakeType::hold);
        
       LeftIntakeMotor.spin(directionType::fwd, 100, velocityUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, velocityUnits::pct);
       
       LeftMotorFront.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct,true);
       wait(211, msec);
       
       RightMotorFront.spin(directionType::rev,100, percentUnits::pct);
       LeftMotorFront.spin(directionType::fwd, 100, percentUnits::pct);
       RightMotorBack.spin(directionType::rev,100, percentUnits::pct);
       LeftMotorBack.spin(directionType::fwd, 100, percentUnits::pct);
       wait(1.475, sec);
        
       LeftMotorFront.resetRotation();
       RightMotorFront.resetRotation();
       LeftMotorBack.resetRotation();
      RightMotorBack.resetRotation();
        
       LeftMotorFront.rotateTo(convert(23), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(23), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(23), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(23), rotationUnits::rev, 50, velocityUnits::pct,true);
        
       LeftIntakeMotor.stop(brakeType::coast);
       RightIntakeMotor.stop(brakeType::coast);
        
       Deposit();
       
       LeftIntakeMotor.spin(directionType::fwd, 100, velocityUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, velocityUnits::pct);
        
       LeftMotorFront.rotateTo(convert(-5), rotationUnits::rev, 100, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(-5), rotationUnits::rev, 100, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(-5), rotationUnits::rev, 100, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(-5), rotationUnits::rev, 100, velocityUnits::pct,true);
        
       }

    // If All Else Fails... (Red Side, Tile 1)
        else if (tile%2 == 0) {
        
       autonstart();

       LeftMotorFront.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct,true);

       LeftMotorFront.rotateTo(convert(5), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(5), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(5), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(5), rotationUnits::rev, 50, velocityUnits::pct,true);
        
      }
      }

     //4 Blocks in Goal Zone (Blue Side, Tile 1)
     else if (color%2 == 1){

       if (tile%2 == 1) {
       
       autonstart();
        
       BarMotor.stop(brakeType::hold);
        
       LeftIntakeMotor.spin(directionType::rev, 100, velocityUnits::pct);
       RightIntakeMotor.spin(directionType::fwd, 100, velocityUnits::pct);
        
       LeftMotorFront.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(38), rotationUnits::rev, 50, velocityUnits::pct,true);
       wait(211, msec);
        
       RightMotorFront.spin(directionType::fwd,100, percentUnits::pct);
       LeftMotorFront.spin(directionType::rev, 100, percentUnits::pct);
       RightMotorBack.spin(directionType::fwd,100, percentUnits::pct);
       LeftMotorBack.spin(directionType::rev, 100, percentUnits::pct);
       wait(1.4, sec);
        
       LeftMotorFront.resetRotation();
       RightMotorFront.resetRotation();
       LeftMotorBack.resetRotation();
       RightMotorBack.resetRotation();
        
       LeftMotorFront.rotateTo(convert(23.2), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(23.2), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(23.2), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(23.2), rotationUnits::rev, 50, velocityUnits::pct,true);
        
       LeftIntakeMotor.stop(brakeType::coast);
       RightIntakeMotor.stop(brakeType::coast);

       Deposit();
       task::sleep(1000);
       
       LeftIntakeMotor.spin(directionType::fwd, 100 , percentUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, percentUnits::pct);
       task::sleep(100);
        
       LeftIntakeMotor.spin(directionType::fwd, 100 , percentUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, percentUnits::pct);
       task::sleep(100);
        
       LeftIntakeMotor.spin(directionType::fwd, 100 , percentUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, percentUnits::pct);
       task::sleep(100);
       
       LeftIntakeMotor.spin(directionType::fwd, 100, velocityUnits::pct);
       RightIntakeMotor.spin(directionType::rev, 100, velocityUnits::pct);
        
       LeftMotorFront.rotateTo(convert(-5), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(-5), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(-5), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(-5), rotationUnits::rev, 50, velocityUnits::pct,true);
        
       }

    //If All Else Fails... (Blue Side, Tile 2)
         else if (tile%2 == 0) {
        
       autonstart();
        
       LeftMotorFront.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorBack.rotateTo(convert(-7), rotationUnits::rev, 50, velocityUnits::pct,true);
        
       LeftMotorFront.rotateTo(convert(7), rotationUnits::rev, 50, velocityUnits::pct, false);
       RightMotorFront.rotateTo(convert(7), rotationUnits::rev, 50, velocityUnits::pct,false);
       LeftMotorBack.rotateTo(convert(7), rotationUnits::rev, 50, velocityUnits::pct, false);
     RightMotorBack.rotateTo(convert(7), rotationUnits::rev, 50, velocityUnits::pct,true);

      }
      }
      }
    }

And here is where I call the function:
Autonomous(color_value, text_value);

color_value and text_value are declared here:

int color_value = 1; int text_value = 1;

I tell color_value to change by 1 every time I press the alliance button. I tell text_value to change by 1 every time I press the tile button. As you could see from my autonomous code, the if statements check if the values are true. That’s what I got… I cannot seem to figure this one out.

are you sure you are using right competition template?

2 Likes

I’d say maybe try having autonstart() at the top, and have it check the selected value after.

Here is reference implementation of buttons from last season based on James Pearman’s button sector example in VCS:

The states you want to track should be global variables and visible to all parts of the program.

Good luck!

2 Likes