Competition autonomous does not work during competition, but does work on competition switch

Hello,

my match autonomous is supposed to shoot two discs in to our low zone, then drive forward turn and spin the roller on the far (right) side. When making this I created a save as from our left side and just changed the autonomous so everything should have worked. It does not, it basically just drive straight over the autonomous line and loses us the auton. I have created a new template to try and make this work, I had a mentor look over the code and even tested it through our field and it worked fine. But, when we went to a competition, the robot headed straight for the other side of the field. Just thought I would ask your guy’s thoughts.
Thanks




@jetdi

I recommend copying the text from this code into a Code Block in a reply in this thread. The community wll be able to parse through your code better in this format.

When making a post, highlight the text and select this button to place it in a block.

image

4 Likes
void autonomous(void) {
   //RIGHT ROLLER SHOOTING
  solenoid.set(true);
  int speed2 = 50;
     FrontLeftmotor.setVelocity( speed2, vex::percentUnits::pct);
  FrontRightmotor.setVelocity( speed2, vex::percentUnits::pct);
  BackLeftmotor.setVelocity( speed2, vex::percentUnits::pct);
  BackRightmotor.setVelocity( speed2, vex::percentUnits::pct);
elevatorMotor.setVelocity( speed2, vex::percentUnits::pct);

    flywheelMotor2.setVelocity( 40, vex::percentUnits::pct);
  flywheelMotor1.setVelocity(40, vex::percentUnits::pct);
  flywheelMotor1.rotateFor(vex::directionType::fwd,10000, vex::rotationUnits::deg, false);
  flywheelMotor2.rotateFor(vex::directionType::fwd,10000, vex::rotationUnits::deg,false);
  vex::task::sleep(3000);
       solenoid.set(false);
      vex::task::sleep(250);
      solenoid.set(true);
      vex::task::sleep(700);
      solenoid.set(false);
      vex::task::sleep(250);
      solenoid.set(true);
      flywheelMotor1.stop(vex::brakeType::coast);
      flywheelMotor2.stop(vex::brakeType::coast);
        vex::task::sleep(250);
   
    int fwd3 =685; 
  FrontLeftmotor.rotateFor(vex::directionType::fwd, fwd3, vex::rotationUnits::deg, false);
  FrontRightmotor.rotateFor(vex::directionType::fwd, fwd3, vex::rotationUnits::deg, false);
  BackLeftmotor.rotateFor(vex::directionType::fwd,fwd3, vex::rotationUnits::deg, false);
  BackRightmotor.rotateFor(vex::directionType::fwd,fwd3, vex::rotationUnits::deg);
       int TR1 =485; 
  FrontLeftmotor.rotateFor(vex::directionType::fwd, TR1, vex::rotationUnits::deg, false);
  FrontRightmotor.rotateFor(vex::directionType::rev, TR1, vex::rotationUnits::deg, false);
  BackLeftmotor.rotateFor(vex::directionType::fwd,TR1, vex::rotationUnits::deg, false);
  BackRightmotor.rotateFor(vex::directionType::rev,TR1, vex::rotationUnits::deg);
  int speed3 = 25;
     FrontLeftmotor.setVelocity( speed3, vex::percentUnits::pct);
  FrontRightmotor.setVelocity( speed3, vex::percentUnits::pct);
  BackLeftmotor.setVelocity( speed3, vex::percentUnits::pct);
  BackRightmotor.setVelocity( speed3, vex::percentUnits::pct);
    elevatorMotor.rotateFor(vex::directionType::rev,400, vex::rotationUnits::deg,false);
    int forwardd = 1500;
    FrontLeftmotor.spin(vex::directionType::fwd);
 FrontRightmotor.spin(vex::directionType::fwd);
 BackLeftmotor.spin(vex::directionType::fwd);
 BackRightmotor.rotateFor(vex::directionType::fwd, forwardd, vex::timeUnits::msec );
vex::task::sleep(100);
     int fwd2 =100; 
  FrontLeftmotor.rotateFor(vex::directionType::rev, fwd2, vex::rotationUnits::deg, false);
  FrontRightmotor.rotateFor(vex::directionType::rev, fwd2, vex::rotationUnits::deg, false);
  BackLeftmotor.rotateFor(vex::directionType::rev,fwd2, vex::rotationUnits::deg, false);
  BackRightmotor.rotateFor(vex::directionType::rev,fwd2, vex::rotationUnits::deg);

  


}
int main() {

  Competition.drivercontrol(usercontrol);

  Competition.autonomous(autonomous);

  //Prevent main from exiting with an infinite loop.                       
  while(1) {
    vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
  }  
  vexcodeInit();

}

Not directly related to your issue but it seems like it would simplify your code and benefit you if you learned how to use functions, such as for your drive so you don’t have to keep repeating the same code.

Competition autonomous does not work during competition, but does work on competition switch

usually this relates to code often entering the driver control section when first connected to a field.

3 Likes

Can you elaborate a bit further? I know our HS team is trying to figure out this issue as well.

What should they look for in their code that would lead to Driver control section?

Most likely if they start their program before connecting their controller to Field Control.

My understanding of the state machine is that:

  1. If Robot Brain thinks there is no Field Control, it starts Driver Control. This makes sense when one is testing a robot so one need not have Field Control/Competition Switch handy for testing.
  2. If Robot Brain detects Field Control, FC puts it thru the following state diagram:

A. Disabled (pre-match auton)
B. Auton (assuming not a skills run)
C. Disabled
D. Driver Control

It can be important to remember edge cases in state D. Your robot may “disconnect-reconnect” (or you may need to restart the program) in which case it will see Field Control is already in Driver Control and start that code. In edge cases, you may see your robot run Driver Control multiple times, not all of which would have 1:45 second run times

This last bit is important for EndGame this year, especially for teams that may have code that only allows their endgame mechanism to deploy after a certain number of seconds have elapsed.

3 Likes

@Mentor_355v gave a pretty good summary, it typically comes down to power up and connection order.

In addition, I’ll link a couple of topics that, although not necessarily directly related to this, are worth reading again.

4 Likes