Competition Template and switch

We have an autonomous program on the competition template and it runs when we are not plugged in to competition switch. When we plug into the competition switch, it will not run properly or much at all. Can anyone tell us what we may be doing to cause this? We have had a competition template autonomous at 2 tournaments this year and when we plug in, it will not work We bought a competition switch thinking we could figure out what is wrong and we are having the same issue. Thank you.

Are you using V5 or Cortex? If your auton is running when you are not plugged into a competition switch then I want to say your autonomous code is possibly in the driver control area??? Driver control code usually runs default without a competition switch. Make sure it is in autonomous. Other than that I don’t have any ideas.

2 Likes

We are indeed using the V5 Brain, our autonomous is located under the autonomous section in the competition template. I heard from another teacher that the autonomous shouldn’t even run at all when it is on the competition template but when it does, it runs how it is suppose to but when plugged into the competition switch it does random things.

What coding platform? It shouldn’t be running autonomous without a competition switch. Make sure you aren’t calling autonomous inside of driver control. Does what it do in a competition switch change every time or is it repeating the same things?

The coding platform we are using is C++, every time we plug it into the switch it changes every time

Sorry by coding platform I meant like PROS, or VCS, or Robotmesh. I’m not really sure what your problem is. The rest of the community could have some other suggestions.

Oh the coding platform we are using is Vex Coding Studio

Could you post your code? It’s much easier to catch these problems when the code can be read directly.

#include "robot-config.h"

vex::competition    competition;


void pre_auton( void ) {
}

void autonomous( void ) {
    
     Puncher.startRotateFor(500,rotationUnits::deg,50,velocityUnits::pct);
    Puncher2.startRotateFor(500,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(3000);
    
    Left1.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-290,rotationUnits::deg,30,velocityUnits::pct);
    Left2.startRotateFor(-290,rotationUnits::deg,30,velocityUnits::pct);
    Right1.startRotateFor(250,rotationUnits::deg,30,velocityUnits::pct);
    Right2.startRotateFor(250,rotationUnits::deg,30,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Left2.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Right1.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Right2.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    
     task::sleep(2000);
     
     Capper.startRotateFor(100,rotationUnits::deg,100,velocityUnits::pct);
  
     task::sleep(2000);
    
     
     Left1.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-60 ,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(200,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(200 ,rotationUnits::deg,50,velocityUnits::pct);
    
    task::sleep(2000);
    
  Left1.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Left2.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Right1.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Right2.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    
    task::sleep(2000);
    
     Left1.startRotateFor(260,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(260,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-250 ,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(1000);
    
    Left1.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Left2.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Right1.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Right2.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    
     task::sleep(3000);
}


void usercontrol( void ) {
  int capperSpeed  = 100;
  int intakeSpeed  = 70;
  int uptakeSpeed  = 80;
  int puncherSpeed = 70;
   while (1){
   
        if(Controller2.ButtonR1.pressing()) { 
            Capper.spin(vex::directionType::fwd, capperSpeed, vex::velocityUnits::pct);
        }
       else if(Controller2.ButtonR2.pressing()) {
            Capper.spin(vex::directionType::rev, capperSpeed, vex::velocityUnits::pct);
        }
        else { 
            Capper.stop(vex::brakeType::brake);
        }
        
        if(Controller1.ButtonL1.pressing()) { 
            Uptake.spin(vex::directionType::fwd, uptakeSpeed, vex::velocityUnits::pct);
        }
        else if(Controller1.ButtonL2.pressing()) { 
            Uptake.spin(vex::directionType::rev, uptakeSpeed, vex::velocityUnits::pct);
        }
        else { 
            Uptake.stop(vex::brakeType::brake);   Brain.Screen.setCursor(1,1);
        }
         if(Controller1.ButtonR1.pressing()) { 
            Puncher.spin(vex::directionType::fwd, puncherSpeed, vex::velocityUnits::pct);
        }
        else if(Controller1.ButtonR2.pressing()) { 
            Puncher.spin(vex::directionType::rev, puncherSpeed, vex::velocityUnits::pct);
        }
        else { 
            Puncher.stop(vex::brakeType::brake);        
        }
   }
         if(Controller1.ButtonR1.pressing()) { 
            Puncher2.spin(vex::directionType::fwd, puncherSpeed, vex::velocityUnits::pct);
        }
        else if(Controller1.ButtonR2.pressing()) { 
            Puncher2.spin(vex::directionType::rev, puncherSpeed, vex::velocityUnits::pct);
        }
        else { 
            Puncher2.stop(vex::brakeType::brake);        
        }
   
    vex::task::sleep(20); 
  }

int main() {
   
    pre_auton();
    autonomous();
    Brain.Screen.print("TitanX Activited, Controll Sequences Shall Begin Soon");
    Competition.autonomous( autonomous );
    Competition.drivercontrol( usercontrol );
                  
    while(1) {
  
        Left1.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
        Left2.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
        Right1.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
        Right2.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
        
      vex::task::sleep(100);    
}
}

remove the motor control from the while loop in main, that will conflict with your motor control in autonomous.

This part?

Left1.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Left2.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
Right1.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
Right2.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);

We have emailed Vex support and we are not hearing back from them. Can anyone help us with our situation? The code is posted above. We took out the part in the while loop and now it works every other time we run it. We need help, please!

You followed pre_auton(); with autonomous();. Normally the competition template has the following within main():

pre_auton();
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

So you’re calling autonomous directly, and then there is the callback for autonomous afterward. Try deleting that one line from main() and see if it behaves properly.

1 Like

yea, as @callen says, you are calling autonomous in main when that’s not needed. I tested this and it works ok.

usercontrol also had incorrect placed } and I added some debug print commands so you can see what’s happening.

void pre_auton( void ) {
}

void autonomous( void ) {
    Brain.Screen.printAt(10, 100, "Auton started");
    
    Puncher.startRotateFor(500,rotationUnits::deg,50,velocityUnits::pct);
    Puncher2.startRotateFor(500,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(3000);
    
    Left1.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(1000,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-350,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-290,rotationUnits::deg,30,velocityUnits::pct);
    Left2.startRotateFor(-290,rotationUnits::deg,30,velocityUnits::pct);
    Right1.startRotateFor(250,rotationUnits::deg,30,velocityUnits::pct);
    Right2.startRotateFor(250,rotationUnits::deg,30,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Left2.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Right1.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    Right2.startRotateFor(90,rotationUnits::deg,10,velocityUnits::pct);
    
     task::sleep(2000);
     
     Capper.startRotateFor(100,rotationUnits::deg,100,velocityUnits::pct);
  
     task::sleep(2000);
    
     
     Left1.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-60,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-60 ,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(2000);
    
     Left1.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(200,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(200 ,rotationUnits::deg,50,velocityUnits::pct);
    
    task::sleep(2000);
    
  Left1.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Left2.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Right1.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    Right2.startRotateFor(900,rotationUnits::deg,60,velocityUnits::pct);
    
    task::sleep(2000);
    
     Left1.startRotateFor(260,rotationUnits::deg,50,velocityUnits::pct);
    Left2.startRotateFor(260,rotationUnits::deg,50,velocityUnits::pct);
    Right1.startRotateFor(-250,rotationUnits::deg,50,velocityUnits::pct);
    Right2.startRotateFor(-250 ,rotationUnits::deg,50,velocityUnits::pct);
    
     task::sleep(1000);
    
    Left1.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Left2.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Right1.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    Right2.startRotateFor(1000,rotationUnits::deg,99,velocityUnits::pct);
    
     task::sleep(3000);
}


void usercontrol( void ) {
  int capperSpeed  = 100;
  int intakeSpeed  = 70;
  int uptakeSpeed  = 80;
  int puncherSpeed = 70;
  
  Brain.Screen.printAt(10, 100, "Driver started");

  while (1) {
  
      if(Controller2.ButtonR1.pressing()) { 
          Capper.spin(vex::directionType::fwd, capperSpeed, vex::velocityUnits::pct);
      }
      else if(Controller2.ButtonR2.pressing()) {
          Capper.spin(vex::directionType::rev, capperSpeed, vex::velocityUnits::pct);
      }
      else { 
          Capper.stop(vex::brakeType::brake);
      }
      
      if(Controller1.ButtonL1.pressing()) { 
          Uptake.spin(vex::directionType::fwd, uptakeSpeed, vex::velocityUnits::pct);
      }
      else if(Controller1.ButtonL2.pressing()) { 
          Uptake.spin(vex::directionType::rev, uptakeSpeed, vex::velocityUnits::pct);
      }
      else { 
          Uptake.stop(vex::brakeType::brake);   Brain.Screen.setCursor(1,1);
      }
        if(Controller1.ButtonR1.pressing()) { 
          Puncher.spin(vex::directionType::fwd, puncherSpeed, vex::velocityUnits::pct);
      }
      else if(Controller1.ButtonR2.pressing()) { 
          Puncher.spin(vex::directionType::rev, puncherSpeed, vex::velocityUnits::pct);
      }
      else { 
          Puncher.stop(vex::brakeType::brake);        
      }
        if(Controller1.ButtonR1.pressing()) { 
          Puncher2.spin(vex::directionType::fwd, puncherSpeed, vex::velocityUnits::pct);
      }
      else if(Controller1.ButtonR2.pressing()) { 
          Puncher2.spin(vex::directionType::rev, puncherSpeed, vex::velocityUnits::pct);
      }
      else { 
          Puncher2.stop(vex::brakeType::brake);        
      }
  
      vex::task::sleep(20); 
    }
  }

int main() {
   
    pre_auton();

    Brain.Screen.print("TitanX Activited, Controll Sequences Shall Begin Soon");

    Competition.autonomous( autonomous );
    Competition.drivercontrol( usercontrol );
                  
    while(1) {        
      vex::task::sleep(100);    
    }
}
1 Like

Ooof, the problem was simple yet I was so blind, omg thank you guys so much it all makes sense now. We just received our competition switch so we were just trying it out , it makes much more sense. Since we didn’t have the switch before I added autonomous(); to try to get it to activate but since we have the competition switch you just have to flip it for the autonomous to go which meant the line of code was conflicting each other, thank you guy so much for everything and sorry I bugged you all