Autonomous Part doesn't work PLEASE HELP

I’m in charge on developing the autonomous code for my team, and I’m having problems in running my autonomous part.
I used the sample from the VEX Programming site (Competition Template) as my base.

My code is the following:

#include "vex.h"

using namespace vex;

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

vex::motor MovementL = vex::motor(vex::PORT1, gearSetting::ratio18_1);                                                                                              //Declares Motor that controls the Left Movement of the robot | Assing Motor to Port 10 | Make the Gear Ratio 6 by 1 A.K.A. go Faster 
vex::motor MovementR = vex::motor(vex::PORT10, gearSetting::ratio18_1,  true);                                                                                        //Declares Motor that controls the Right Movement of the robot | Assing Motor to Port 1 | Make the Gear Ratio 6 by 1 A.K.A. go Faster
vex::motor FlippersL = vex::motor(vex::PORT5);                                                                                                                //Declares Motor that controls the Left Flipper Movement of the robot | Assing Motor to Port 5 
vex::motor FlippersR = vex::motor(vex::PORT6, true);                                                                                                                      //Declares Motor that controls the Right Flipper Movement of the robot | Assing Motor to Port 6
vex::motor ArmL = vex::motor(vex::PORT4, gearSetting::ratio36_1, true);                                                                                             //Declares Motor that controls the Left Arm Movement of the robot | Assing Motor to Port 8 | Make the Gear Ratio 36 by 1 A.K.A. go Slow but Stronger
vex::motor ArmR = vex::motor(vex::PORT7, gearSetting::ratio36_1);                                                                                                   //Declares Motor that controls the Right Arm Movement of the robot | Assing Motor to Port 3 | Make the Gear Ratio 36 by 1 A.K.A. go Slow but Stronger
vex::motor PlaneL = vex::motor(vex::PORT3, gearSetting::ratio36_1, true);                                                                                                 //Declares Motor that controls the Left Pusher Movement of the robot | Assing Motor to Port 2 | Make the Gear Ratio 36 by 1 A.K.A. go Slow but Stronger
vex::motor PlaneR = vex::motor(vex::PORT8, gearSetting::ratio36_1);                                                                                         //Declares Motor that controls the Right Pusher Movement of the robot | Assing Motor to Port 9 | Make the Gear Ratio 36 by 1 A.K.A. go Slow but Stronger

                                                                                                                               // A global instance of vex::competition
vex::controller Controller1 = vex::controller();                                                                                                            //A global instance of vex::Controller
vex::competition Competition;


//Autonomous Code
void autonomous(void) {
  int FlippersSpeed = 100;                                                                                                                                          
  
  //Set Velocity Speed
  MovementL.setVelocity( 50, vex::velocityUnits::pct );
  MovementR.setVelocity( 50, vex::velocityUnits::pct );

  //Robot moves foward for 2 seconds
  MovementL.spin( vex::directionType::fwd );
  MovementR.spin( vex::directionType::fwd );
  
  vex::task::sleep(2000);
  
  MovementL.stop();
  MovementR.stop();

  vex::task::sleep(500);

  //Robot use flippers to put the block for 1.5 seconds 
  FlippersL.spin(vex::directionType::fwd, FlippersSpeed, vex::velocityUnits::pct);                                                                              
  FlippersR.spin(vex::directionType::fwd, FlippersSpeed, vex::velocityUnits::pct);

  vex::task::sleep(1500);
  
  FlippersL.stop();                                                                                                                       
  FlippersR.stop();
  
  vex::task::sleep(500);
  
  //Robot moves backward for 2 seconds
  MovementL.spin( vex::directionType::rev);
  MovementR.spin( vex::directionType::rev);
  
  vex::task::sleep(2000);
  MovementL.stop();
  MovementR.stop();
}



//User Control
 void usercontrol() {
  int FlippersSpeed = 100;                                                                                                                                          //Integer Value that represents the force of the motor in the Flippers
  int ArmSpeed = 100;                                                                                                                                               //Integer Value that represents the force of the motor in the Arms
  int PlaneSpeed = 100;                                                                                                                                             //Integer Value of 1 that works kinda as boolean | Declares condition | Work in the Movement of Pushers

  while (1) {                                                                                                                                                       //Same as while(true) | Work as a infinite loop | Makes the control do forever the instructions in the code
    MovementL.spin(vex::directionType::fwd, Controller1.Axis3.position() + Controller1.Axis4.position(), vex::velocityUnits::pct);             //Makes the movement on the Left Side move back and foward depending on the movement of the Left joystick
    MovementR.spin(vex::directionType::fwd, Controller1.Axis3.position() - Controller1.Axis4.position(),  vex::velocityUnits::pct);            //Makes the movement on the Left Side move back and foward depending on the movement of the Left joystick

    if (Controller1.ButtonX.pressing()) {                                                                                                                           //If statement | When the X Button of the control is pressed
      FlippersL.spin(vex::directionType::fwd, FlippersSpeed, vex::velocityUnits::pct);                                                                              //Left Flipper spin foward with FlipperSpeed velocity                                                                
      FlippersR.spin(vex::directionType::fwd, FlippersSpeed, vex::velocityUnits::pct);                                                                              //Right Flipper spin foward with FlipperSpeed velocity
    } else if (Controller1.ButtonB.pressing()) {                                                                                                                    //Else If statement | If first conditions is not real | When the B Buttton of the control is pressed
      FlippersL.spin(vex::directionType::rev, FlippersSpeed, vex::velocityUnits::pct);                                                                              //Left Flipper spin backwards with FlipperSpeed velocity
      FlippersR.spin(vex::directionType::rev, FlippersSpeed, vex::velocityUnits::pct);                                                                              //Left Flipper spin backwards with FlipperSpeed velocity
    } else if (Controller1.ButtonA.pressing()) {                                                                                                                           //If statement | When the X Button of the control is pressed
      FlippersL.spin(vex::directionType::fwd, FlippersSpeed/2, vex::velocityUnits::pct);                                                                              //Left Flipper spin foward with FlipperSpeed velocity                                                                
      FlippersR.spin(vex::directionType::fwd, FlippersSpeed/2, vex::velocityUnits::pct);                                                                              //Right Flipper spin foward with FlipperSpeed velocity
    } else if (Controller1.ButtonY.pressing()) {                                                                                                                    //Else If statement | If first conditions is not real | When the B Buttton of the control is pressed
      FlippersL.spin(vex::directionType::rev, FlippersSpeed/2, vex::velocityUnits::pct);                                                                              //Left Flipper spin backwards with FlipperSpeed velocity
      FlippersR.spin(vex::directionType::rev, FlippersSpeed/2, vex::velocityUnits::pct);                                                                              //Left Flipper spin backwards with FlipperSpeed velocity
    } else {                                                                                                                                                        //Else statement | If the first two 'if' conditions are not been completed | When any buttons are not pressed
      FlippersL.stop(vex::brakeType::brake);                                                                                                                        //Left Flipper stop to move A.K.A. do not move
      FlippersR.stop(vex::brakeType::brake);                                                                                                                        //Right Flipper stop to move A.K.A. do not move
    }

    if (Controller1.ButtonR1.pressing()) {                                                                                                                          //If statement | When the R1 Button of the control is pressed
      ArmL.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);                                                                                        //Left Arm move up with ArmSpeed velocity 
      ArmR.spin(vex::directionType::fwd, ArmSpeed, vex::velocityUnits::pct);                                                                                        //Right Arm move up with ArmSpeed velocity 
    } else if (Controller1.ButtonR2.pressing()) {                                                                                                                   //Else If statement | If first conditions is not real | When the R2  Buttton of the control is pressed
      ArmL.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);                                                                                        //Left Arm move down with ArmSpeed velocity 
      ArmR.spin(vex::directionType::rev, ArmSpeed, vex::velocityUnits::pct);  
    } else if (Controller1.ButtonL1.pressing()) {
      Competition.autonomous( autonomous );
      Competition.drivercontrol( usercontrol );                                       
    } else {                                                                                                                                                        //Else statement | If the first three 'if' conditions are not been completed | When any buttons are not pressed
      ArmL.stop(vex::brakeType::brake);                                                                                                                             //Left Arm stop to move A.K.A. do not move
      ArmR.stop(vex::brakeType::brake);                                                                                                                             //Right Arm stop to move A.K.A. do not move
    }

    if (Controller1.ButtonUp.pressing()) {                                                                                                                          //If statement | When the Up Button of the control is pressed
      PlaneL.spin(vex::directionType::fwd, PlaneSpeed, vex::velocityUnits::pct);                                                                                    //Left Pusher move foward with PlaneSpeed velocity 
      PlaneR.spin(vex::directionType::fwd, PlaneSpeed, vex::velocityUnits::pct);                                                                                    //Right Pusher move foward with PlaneSpeed velocity 
    } else if (Controller1.ButtonDown.pressing()) {                                                                                                                 //Else If statement | If first conditions is not real | When the Down Buttton of the control is pressed
      PlaneL.spin(vex::directionType::rev, PlaneSpeed, vex::velocityUnits::pct);                                                                                    //Left Pusher move foward with PlaneSpeed velocity 
      PlaneR.spin(vex::directionType::rev, PlaneSpeed, vex::velocityUnits::pct);                                                                                    //Right Pusher move foward with PlaneSpeed velocity
    } else if (Controller1.ButtonRight.pressing()) {                                                                                                                 //Else If statement | If first conditions is not real | When the Down Buttton of the control is pressed
      PlaneL.spin(vex::directionType::fwd, PlaneSpeed/2, vex::velocityUnits::pct);                                                                                    //Left Pusher move foward with PlaneSpeed velocity 
      PlaneR.spin(vex::directionType::fwd, PlaneSpeed/2, vex::velocityUnits::pct);                                                                                    //Right Pusher move foward with PlaneSpeed velocity
    } else if (Controller1.ButtonLeft.pressing()) {                                                                                                                 //Else If statement | If first conditions is not real | When the Down Buttton of the control is pressed
      PlaneL.spin(vex::directionType::rev, PlaneSpeed/2, vex::velocityUnits::pct);                                                                                    //Left Pusher move foward with PlaneSpeed velocity 
      PlaneR.spin(vex::directionType::rev, PlaneSpeed/2, vex::velocityUnits::pct);                                                                                                                                                         //Right Pusher move foward with PlaneSpeed velocity
    } else {                                                                                                                                                        //Else statement | If the first three 'if' conditions are not been completed | When any buttons are not pressed
      PlaneL.stop(vex::brakeType::brake);                                                                                                                           //Left Pusher stop to move A.K.A. do not move
      PlaneR.stop(vex::brakeType::brake);                                                                                                                          //Right Pusher stop to move A.K.A. do not move
    }    
                                                                                                                                                               //Ending Brackets of 'else' statement
    vex::task::sleep(10);                                                                                                                                           //The time to response                                                                                                                                                                  //Ending Brackets of 'While' statement A.K.A. the loop
  }  
 }    

//Code start from here
 void pre_auton( void ) {                                                                                                                                   //Pre-Autonomous Part A.K.A. No idea to use it so just leave it in blank
    
 }

int main() {
    pre_auton();
    //Set up callbacks for autonomous and driver control periods
    Competition.autonomous(autonomous);
    Competition.drivercontrol( usercontrol );  
    //Run the pre-autonomous function.
    
    //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.
    }    
}

I think my problem is at initializing the autonomous function. If some one could help me I would be forever in debt with him. Thank you and hope this can be solved ASAP.

What exactly is the problem? Just not being able to run?

It runs but it doesn’t start the autonomous. It only start the control part.

That’s because you aren’t set up in competition. Autonomous only runs if it is told that the autonomous segment is occurring. If you don’t have a game switch I believe you can still go through the controller ‘match’ modes and find programming skills and run it that way.

2 Likes

Do I have to set the controller or the Brain in a Match setting? And how do it?

Turn on controller → Go to programs → Select your program → Go right and click on Match Play → Press A when you’re ready to run auton, there will be a 3 second countdown

1 Like

THANK DEICER AND THORSTENL312 FOR YOUR HELP!!! I APPRECIATE IT :smile::sob::smiley:

2 Likes