Autonomous only running first few lines of code before completely stopping

Hi, our team is about to have competition this Saturday and our robot won’t run its autonomous. The driving works so its not technical. The robot would only run the rollers and the half of the driving code before stopping. This is in a competition template and I’m using it without the comp switch, although I don’t know if that information would help.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// rollers              motor_group   9, 12           
// DigitalOutH          digital_out   H               
// DigitalOutF          digital_out   F               
// Spnrs                motor_group   6, 7            
// R1                   motor         10              
// R2                   motor         20              
// R3                   motor         17              
// L1                   motor         3               
// L2                   motor         1               
// L3                   motor         11              
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here
  
  //drive (do tank drive)
void left_drive(void){
  L1.spin(forward, Controller1.Axis3.position(), velocityUnits::pct);
  L2.spin(forward, Controller1.Axis3.position(), velocityUnits::pct);
  L3.spin(forward, Controller1.Axis3.position(), velocityUnits::pct);

  }
void right_drive(void){
  R1.spin(forward, Controller1.Axis2.position(), velocityUnits::pct);
  R2.spin(forward, Controller1.Axis2.position(), velocityUnits::pct);
  R3.spin(forward, Controller1.Axis2.position(), velocityUnits::pct);

  
  
}
void spiny_thingys(void){
  Spnrs.spin(directionType::fwd, Controller1.ButtonR1.pressing(), percentUnits::pct);
  Spnrs.spin(directionType::rev, Controller1.ButtonR2.pressing(), percentUnits::pct);
}

  //ring launcher
int pneu() {
  return 0;
}

void out() { //wherever you write 'out' in the code, you are setting the solenoid to true and it will extend
  DigitalOutH.set(true);
  DigitalOutF.set(true); //this is the solenoid 
}

void retract() {
  DigitalOutH.set(false);
  DigitalOutF.set(false);
}


//rollers
void rollers_config(void){
  if(Controller1.ButtonUp.pressing()){
    rollers.spin(vex::directionType::fwd, 50, vex::velocityUnits::pct);
  }
 else if (Controller1.ButtonDown.pressing()){
    rollers.spin(directionType::rev, 50, velocityUnits::pct); //meaning it will reverse at 100 percent speed
  }
  else{
    rollers.stop(brakeType::hold);
  }
}




/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the V5 has been powered on and        */
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton(void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void autonomous(void) {


  //setVelocity
    R1.setVelocity(70, percentUnits::pct);
    R2.setVelocity(70, percentUnits::pct);
    R3.setVelocity(70, percentUnits::pct);
    L1.setVelocity(70, percentUnits::pct);
    L2.setVelocity(70, percentUnits::pct);
    L3.setVelocity(70, percentUnits::pct);
    rollers.setVelocity(60, percentUnits::pct);



// 1) Backup + Roll

  R1.spinFor(reverse, 1, turns, false);
  R2.spinFor(reverse, 1, turns, false);
  R3.spinFor(reverse, 1, turns, false);
  L1.spinFor(reverse, 1, turns, false);
  L2.spinFor(reverse, 1, turns, false);
  L3.spinFor(reverse, 1, turns);

  rollers.spinFor(fwd, 2, seconds);

// 2) Drive + Turn

  R1.spinFor(fwd, 1, turns, false);
  R2.spinFor(fwd, 1, turns, false);
  R3.spinFor(fwd, 1, turns, false);
  L1.spinFor(fwd, 1, turns, false);
  L2.spinFor(fwd, 1, turns, false);
  L3.spinFor(fwd, 1, turns);



  /*R1.spinFor(fwd, 1, turns, false);
  R2.spinFor(fwd, 1, turns, false);
  R3.spinFor(fwd, 1, turns, false);
  L1.spinFor(fwd, -2, turns, false);
  L2.spinFor(fwd, -2, turns, false);
  L3.spinFor(fwd, -2, turns);


// 3) Drive + Roll + Backup
  R1.spinFor(fwd, 3, turns, false); 
  R2.spinFor(fwd, 3, turns, false);
  R3.spinFor(fwd, 3, turns, false);
  L1.spinFor(fwd, 3, turns, false);
  L2.spinFor(fwd, 3, turns, false);
  L3.spinFor(fwd, 3, turns);

  rollers.spinFor(fwd, 2, seconds);

  R1.spinFor(reverse, 1, turns, false);
  R2.spinFor(reverse, 1, turns, false);
  R3.spinFor(reverse, 1, turns, false);
  L1.spinFor(reverse, 1, turns, false);
  L2.spinFor(reverse, 1, turns, false);
  L3.spinFor(reverse, 1, turns);


// 4) Turn + Drive
  R1.spinFor(reverse, 1, turns, false);
  R2.spinFor(reverse, 1, turns, false);
  R3.spinFor(reverse, 1, turns, false);
  L1.spinFor(fwd, 1, turns, false);
  L2.spinFor(fwd, 1, turns, false);
  L3.spinFor(fwd, 1, turns);

  R1.spinFor(fwd, 6, turns, false);
  R2.spinFor(fwd, 6, turns, false);
  R3.spinFor(fwd, 6, turns, false);
  L1.spinFor(fwd, 6, turns, false);
  L2.spinFor(fwd, 6, turns, false);
  L3.spinFor(fwd, 6, turns);


// 5) Turn + Drive
  R1.spinFor(reverse, 1, turns, false);
  R2.spinFor(reverse, 1, turns, false);
  R3.spinFor(reverse, 1, turns, false);
  L1.spinFor(fwd, 1, turns, false);
  L2.spinFor(fwd, 1, turns, false);
  L3.spinFor(fwd, 1, turns);

  R1.spinFor(fwd, 8, turns, false);
  R2.spinFor(fwd, 8, turns, false);
  R3.spinFor(fwd, 8, turns, false);
  L1.spinFor(fwd, 8, turns, false);
  L2.spinFor(fwd, 8, turns, false);
  L3.spinFor(fwd, 8, turns);

// 6) Turn + Backup + Roll
  R1.spinFor(reverse, 1, turns, false);
  R2.spinFor(reverse, 1, turns, false);
  R3.spinFor(reverse, 1, turns, false);
  L1.spinFor(fwd, 1, turns, false);
  L2.spinFor(fwd, 1, turns, false);
  L3.spinFor(fwd, 1, turns);

  R1.spinFor(reverse, 2, turns, false);
  R2.spinFor(reverse, 2, turns, false);
  R3.spinFor(reverse, 2, turns, false);
  L1.spinFor(reverse, 2, turns, false);
  L2.spinFor(reverse, 2, turns, false);
  L3.spinFor(reverse, 2, turns);

  rollers.spinFor(fwd, 2, seconds);

// 7) Drive + Turn
  R1.spinFor(fwd, 2, turns, false);
  R2.spinFor(fwd, 2, turns, false);
  R3.spinFor(fwd, 2, turns, false);
  L1.spinFor(fwd, 2, turns, false);
  L2.spinFor(fwd, 2, turns, false);
  L3.spinFor(fwd, 2, turns);

  R1.spinFor(fwd, 1, turns, false);
  R2.spinFor(fwd, 1, turns, false);
  R3.spinFor(fwd, 1, turns, false);
  L1.spinFor(reverse, 1, turns, false);
  L2.spinFor(reverse, 1, turns, false);
  L3.spinFor(reverse, 1, turns);

// 8) Drive + Roll + Backup
  R1.spinFor(fwd, 3, turns, false);
  R2.spinFor(fwd, 3, turns, false);
  R3.spinFor(fwd, 3, turns, false);
  L1.spinFor(fwd, 3, turns, false);
  L2.spinFor(fwd, 3, turns, false);
  L3.spinFor(fwd, 3, turns);

  rollers.spinFor(fwd, 2, seconds);

  R1.spinFor(reverse, 2, turns, false);
  R2.spinFor(reverse, 2, turns, false);
  R3.spinFor(reverse, 2, turns, false);
  L1.spinFor(reverse, 2, turns, false);
  L2.spinFor(reverse, 2, turns, false);
  L3.spinFor(reverse, 2, turns);*/
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
} 

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              User Control Task                            */
/*                                                                           */
/*  This task is used to control your robot during the user control phase of */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void usercontrol(void) {
  // User control code here, inside the loop
  while (1) {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
    // ........................................................................
    vexcodeInit();
  //set stopping hold
    R1.setStopping(brakeType::hold);
    R2.setStopping(brakeType::hold);
    R3.setStopping(brakeType::hold);
    L1.setStopping(brakeType::hold);
    L2.setStopping(brakeType::hold);
    L3.setStopping(brakeType::hold);
    //intake.setStopping(brakeType::hold);

  //set velocity
    R1.setVelocity(100, percentUnits::pct);
    R2.setVelocity(100, percentUnits::pct);
    R3.setVelocity(100, percentUnits::pct);
    L1.setVelocity(100, percentUnits::pct);
    L2.setVelocity(100, percentUnits::pct);
    L3.setVelocity(100, percentUnits::pct);
    rollers.setVelocity(45, percentUnits::pct);


  // drive config
    right_drive();
    left_drive();


  // intake config
    rollers_config();


  // ring launcher config
    Controller1.ButtonL1.pressed(out);
    Controller1.ButtonL2.pressed(retract);
    wait(15,msec);
    pneu();











    wait(20, msec); // Sleep the task for a short amount of time to
                    // prevent wasted resources.
  }
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

Just a tip for posting on the forum in the future, but if you put code, you should use a code block. To do this use three tick marks to open and close it like this:
```
Code Goes Inside Here
```

If done properly it looks like this:

std::cout << "Hello World!";

As for your issue with autonomous, I don’t immediately see what’s wrong, and I don’t have a robot in front of me to test with so someone else is going to have to help with that.

I edited the original post to add code tags now.

5 Likes

Hard to tell without being able to see the graphical configuration, often code (meaning drivetrain or other motors) assigned to the controller can interfere with autonomous functions, also

vexcodeInit();

you are calling that in a loop in usercontrol, don’t do that, probably not related but it’s not going to help. Be aware that usercontrol can run before you plug the robot into field control so you always need to take that into account.

6 Likes

I just ran the code without the usercontrol and commands that are set for driving and it still did the same thing, running the first line and stopping. The robot does make a sound like the motors are… buzzing? And then when I stop running the code, it jolts.

Could it be a problem with how I’m starting the code? I’m using the 3 2 1 countdown for “programming skills” without the comp switch so maybe there is another way that I don’t know

Try putting print statements to try and figure exactly where it fails

1 Like

What do you mean by this?

You make it so after every line or so it prints something to the controller or brain screen. Like the debug console. When they stop printing, you know where the error happened.

2 Likes

It may be your can not make one turn when back up since there is no enough distance to finish. Add timeout May solve this.

1 Like