VEXnet Competition Switch Glitching Autonomous

Hi everyone! I am having a issue with my competition switch. For a while now, I have been developing a really good auton, and it works great, but only if I start the program with the competition switch on ‘Enable Auton’. When I start the program on ‘Disable Auton’ and then switch it to ‘Enable Auton’, the robot goes completely mental and it smashes into walls and such. I have been programming for robotics for 5 years now and I have never seen this issue. This is very confusing because it seemed at first like it was a broken competition switch, but the fact that it works when start the program on "Enable Auton’ makes me think its a programming issue. I am worried about this because we have a competition on Saturday, and at a competition you start the program and the ref switches you to ‘Enable Auton’, which makes me think that the robot will go mental. Is this just a new glitch in V5? Please help!

P.S. I am using VEXcode Pro V5. Don’t know if this helps at all.

Can you post your code? If you are using the default competition template, no issues should occur.

Ok, here is my functions and auton.

/--------------------------------------------------------------------------/
/* /
/
Module: main.cpp /
/
Author: ProggrammingKid /
/
Created: Sun Sep 08 2019 /
/
Description: V5 project /
/
/
/
----------------------------------------------------------------------------*/
#include “vex.h”

/* ---- START VEXCODE CONFIGURED DEVICES ----
Robot Configuration:
[Name] [Type] [Port(s)]
Vision17 vision 17
FL motor 10
FR motor 2
BL motor 4
BR motor 3
---- END VEXCODE CONFIGURED DEVICES ----*/
using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen

// A global instance of vex::competition
vex::competition Competition;

//Function for going forward
void forward1(float distance, int speed){
FL.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
FR.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
BL.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
BR.rotateTo(distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct);

}
//Function to go backwards
//Check motor positions for - on the distance and for setting reversed motors
void backwards1(float distance, int speed){
FL.rotateTo(-distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
FR.rotateTo(-distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
BL.rotateTo(-distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct,false);
BR.rotateTo(-distance,vex::rotationUnits::rev,speed, vex::velocityUnits::pct);
}
//function for going left
void left1(float distance, int speed){
FL.rotateTo(-distance,rotationUnits::rev,speed, velocityUnits::pct,false);
FR.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BL.rotateTo(-distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BR.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct);
}
void left2(float distance, int speed){
FR.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BR.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct);
}
//funtion for right
void right1(float distance, int speed){
FL.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct,false);
FR.rotateTo(-distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BL.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BR.rotateTo(-distance,rotationUnits::rev,speed, velocityUnits::pct);
}
void right2(float distance, int speed){
FL.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct,false);
BL.rotateTo(distance,rotationUnits::rev,speed, velocityUnits::pct);
}
//Intake in function
void intIn( float distance, int speed){
IntL.rotateTo(distance, rotationUnits::rev,speed, velocityUnits::pct,false);
IntR.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct);
}
//Intake out function
void intOut( float distance, int speed){
IntL.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct,false);
IntR.rotateTo(distance, rotationUnits::rev,speed, velocityUnits::pct);
}
//center intake in function
void centerIn( float distance, int speed){
centerInt.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct);
}

void doBoth (float distance, int speed){
IntL.rotateTo(distance, rotationUnits::rev,speed, velocityUnits::pct,false);
IntR.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct,false);
centerInt.rotateTo(-distance, rotationUnits::rev,speed, velocityUnits::pct);
}

//reseting encoders function
void resetEncoders(){
BR.resetRotation();
FR.resetRotation();
BL.resetRotation();
FL.resetRotation();
}

//Sets stopping type
void setStop(){
BR.setStopping(brakeType::brake);
FR.setStopping(brakeType::brake);
BL.setStopping(brakeType::brake);
FL.setStopping(brakeType::brake);

}

//test 90

//a function to easly sleep
void bedtime(double ms){
task::sleep(ms);
}

/*----------------------------------------------------------------------
Pre-Autonomous Functions

---------------------------------------------------------------------------*/

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
resetEncoders();
setStop();

int speedy_boi;
speedy_boi = 100;
double power;
power = 100;
int twenteee;
twenteee = 25;
int fiftyee;
fiftyee = 50;

FL.setReversed(false);
FR.setReversed(true);
BL.setReversed(false);
BR.setReversed(true);

  //Sets max tourque for motors
FL.setMaxTorque(power,percentUnits::pct);
FR.setMaxTorque(power,percentUnits::pct);
BR.setMaxTorque(power,percentUnits::pct);
BL.setMaxTorque(power,percentUnits::pct); 

IntL.setMaxTorque(power,percentUnits::pct);
IntR.setMaxTorque(power,percentUnits::pct);
centerInt.setMaxTorque(power,percentUnits::pct);

IntL.setVelocity(speedy_boi, percentUnits::pct);
IntR.setVelocity(speedy_boi, percentUnits::pct);
centerInt.setVelocity(speedy_boi, percentUnits::pct);

}

/*---------------------------------------------------------------------------
Autonomous Task

---------------------------------------------------------------------------*/

void autonomous( void ) {

forward1(1.27, 60);

resetEncoders();

left2(2.8, 60);

resetEncoders();

forward1(1.21, 40);

resetEncoders();

intIn(2, 100);

resetEncoders();

doBoth(4.3, 100);

resetEncoders();

backwards1(1.42, 50);

resetEncoders();

left2(-1.08, 65);

resetEncoders();

backwards1(3.12,60);

resetEncoders();

left1(1.1,65);

resetEncoders();

forward1(0.5,50);

resetEncoders();

doBoth(8,100);

resetEncoders();

bedtime(90);

backwards1(1,100);

}

Try commenting out everything inside of the pre-auton function definition.

So you mean that I should get rid of all the // comments in the pre-auton?

No. For example say I had the preauton function:

void pre_auton(void){
    Brain.Screen.print(Pre-auton);
}

I would then do this;

void pre_auton(void){
    //Brain.Screen.print(Pre-auton);
}

If you don’t want to individually do it for every line, just put /* at the beginning and */ at the end.
In your case, it would look like this:

void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
/*resetEncoders();
setStop();

int speedy_boi;
speedy_boi = 100;
double power;
power = 100;
int twenteee;
twenteee = 25;
int fiftyee;
fiftyee = 50;

FL.setReversed(false);
FR.setReversed(true);
BL.setReversed(false);
BR.setReversed(true);

  //Sets max tourque for motors
FL.setMaxTorque(power,percentUnits::pct);
FR.setMaxTorque(power,percentUnits::pct);
BR.setMaxTorque(power,percentUnits::pct);
BL.setMaxTorque(power,percentUnits::pct); 
IntL.setMaxTorque(power,percentUnits::pct);
IntR.setMaxTorque(power,percentUnits::pct);
centerInt.setMaxTorque(power,percentUnits::pct);

IntL.setVelocity(speedy_boi, percentUnits::pct);
IntR.setVelocity(speedy_boi, percentUnits::pct);
centerInt.setVelocity(speedy_boi, percentUnits::pct);
*/
}
2 Likes

Alright, that’s what I did. I can’t test this right now though, im not in possession of our robot. Just out of curiosity though, how does making all of my pre-auton a comment solve my issue? I’m not saying you’re wrong, I just am wondering how this works.

I believe what is happening is that all of the stuff at the beginning of your program isn’t what usually runs when you go straight to autonomous. As a result, everything goes crazy. The only thing that I would recommend doing is to clear the encoders and reset the vision sensor. Everything else shouldn’t be in there.

For example, say when your running your auton directly, your torque is 40. But, if you have something before the auton(or when auton is disabled) like a function that turns torque to 100, suddenly the auton code will run under the 100 torque rather than the 40 torque.

You could also test this for yourself. For this first line of code in your autonomous, have a line that prints out the torque on the VEX Screen using this function:

Brain.Screen.print("Torque: %f", FL.torque());
2 Likes

Ok that makes sense. I’ll be able to test it out tomorrow and I’ll tell you how it goes. Thanks so much for the help!

1 Like

@ProgrammingKid did it work?

No. :(. ( it kinda messed up our auton (and somehow even our drive code) we hope it works at the competition tomorrow with the whole VEXnet setup… but… we’ll see. Thanks so much for the help though! I really appreciate it!