Driving period is not working after the Autonomous period

My normal driving code isn’t working after my autonomous period. It makes our entire code slow down. This happens when I do a timed run. If I do a normal run, my code works perfectly fine, and that is because autonomous is not happening. Autonomous happened with timed run. I code in C++ with VEXcode V5

1 Like
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>


#include "vex.h"

using namespace vex;

// Brain should be defined by default
brain Brain;


// START V5 MACROS
#define waitUntil(condition)                                                   \
  do {                                                                         \
    wait(5, msec);                                                             \
  } while (!(condition))

#define repeat(iterations)                                                     \
  for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS


// Robot configuration code.
controller Controller1 = controller(primary);
motor Motor1 = motor(PORT9, ratio18_1, false);

motor Motor2 = motor(PORT10, ratio18_1, false);

motor Motor3 = motor(PORT8, ratio18_1, false);

motor Motor4 = motor(PORT3, ratio18_1, true);

motor Motor5 = motor(PORT5, ratio18_1, true);

motor Motor6 = motor(PORT2, ratio18_1, true);

motor intake = motor(PORT4, ratio6_1, false);

motor chain = motor(PORT1, ratio36_1, false);

motor shooter = motor(PORT6, ratio36_1, false);

digital_out wings = digital_out(Brain.ThreeWirePort.A);



// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
  printf("VEXPlaySound:%s\n", soundName);
  wait(5, msec);
}



// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool Controller1LeftShoulderControlMotorsStopped = true;
bool Controller1RightShoulderControlMotorsStopped = true;
bool Controller1XBButtonsControlMotorsStopped = true;

// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
  // process the controller input every 20 milliseconds
  // update the motors based on the input values
  while(true) {
    if(RemoteControlCodeEnabled) {
      // check the ButtonL1/ButtonL2 status to control chain
      if (Controller1.ButtonL1.pressing()) {
        chain.spin(forward);
        Controller1LeftShoulderControlMotorsStopped = false;
      } else if (Controller1.ButtonL2.pressing()) {
        chain.spin(reverse);
        Controller1LeftShoulderControlMotorsStopped = false;
      } else if (!Controller1LeftShoulderControlMotorsStopped) {
        chain.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1LeftShoulderControlMotorsStopped = true;
      }
      // check the ButtonR1/ButtonR2 status to control intake
      if (Controller1.ButtonR1.pressing()) {
        intake.spin(forward);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (Controller1.ButtonR2.pressing()) {
        intake.spin(reverse);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (!Controller1RightShoulderControlMotorsStopped) {
        intake.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1RightShoulderControlMotorsStopped = true;
      }
      // check the ButtonX/ButtonB status to control shooter
      if (Controller1.ButtonX.pressing()) {
        shooter.spin(forward);
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (Controller1.ButtonB.pressing()) {
        shooter.spin(reverse);
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (!Controller1XBButtonsControlMotorsStopped) {
        shooter.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1XBButtonsControlMotorsStopped = true;
      }
    }
    // wait before repeating the process
    wait(20, msec);
  }
  return 0;
}

task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);

#pragma endregion VEXcode Generated Robot Configuration

#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/*---------------------------------------------------------------------------*/
/*                          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!
  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...

}

void autoMove(int Motor12, int Motor22, int Motor32, int Motor42, int Motor52, int Motor62, int intake2, int chain2, int shooter2, double time){
Motor1.setVelocity(Motor12,percent);
Motor2.setVelocity(Motor22,percent);
Motor3.setVelocity(Motor32,percent);
Motor4.setVelocity(Motor42,percent);
Motor5.setVelocity(Motor52,percent);
Motor6.setVelocity(Motor62,percent);
intake.setVelocity(intake2,percent);
chain.setVelocity(chain2,percent);
shooter.setVelocity(shooter2,percent);
Motor1.spin(forward);
Motor2.spin(forward);
Motor3.spin(forward);
Motor4.spin(forward);
intake.spin(forward);
Motor5.spin(forward);
Motor6.spin(forward);
intake.spin(forward);
chain.spin(forward);
shooter.spin(forward);
wait(time,msec);
Motor1.setVelocity(0,percent);
Motor2.setVelocity(0,percent);
Motor3.setVelocity(0,percent);
Motor4.setVelocity(0,percent);
Motor5.setVelocity(0,percent);
Motor6.setVelocity(0,percent);
intake.setVelocity(0,percent);
chain.setVelocity(0,percent);
shooter.setVelocity(0,percent);
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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) {
autoMove(-127, -127, -127, -127, -127, -127, 0, 0, 0,250 );
autoMove(127, 127, 127, -127, -127, -127, 0, 0, 0,200 );


}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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) {
while (true) {
       
if (Controller1.Axis3.position(pct) != 0){
    Motor1.spin(forward,Controller1.Axis3.position(pct), pct);
    Motor2.spin(forward,Controller1.Axis3.position(pct), pct);
    Motor3.spin(forward,Controller1.Axis3.position(pct), pct);
    Motor4.spin(forward,Controller1.Axis3.position(pct), pct);
    Motor5.spin(forward,Controller1.Axis3.position(pct), pct);
    Motor6.spin(forward,Controller1.Axis3.position(pct), pct);
    }
  else if(Controller1.Axis1.position(pct) != 0){
        Motor1.spin(forward,Controller1.Axis1.position(pct), pct);
        Motor2.spin(forward,Controller1.Axis1.position(pct), pct);
        Motor3.spin(forward,Controller1.Axis1.position(pct), pct);
        Motor4.spin(reverse,Controller1.Axis1.position(pct), pct);
        Motor5.spin(reverse,Controller1.Axis1.position(pct), pct);
        Motor6.spin(reverse,Controller1.Axis1.position(pct), pct);
    }
    else{
      Motor1.stop();
      Motor2.stop();
      Motor3.stop();
      Motor4.stop();
      Motor5.stop();
      Motor6.stop();
    }
   
        if (Controller1.ButtonR1.pressing()) {
            intake.spin(forward, 127,pct);
        } 
        else if (Controller1.ButtonR2.pressing()) {
            intake.spin(reverse, 127,pct);
        } else {
            intake.stop();
        }

        if (Controller1.ButtonL1.pressing()) {
          chain.spin(forward, 127,pct);
        }
        else if (Controller1.ButtonL2.pressing()) {
          chain.spin(reverse, 127,pct);
        }
        else {
        chain.setStopping(brake);
        }
       
        if (Controller1.ButtonX.pressing()) {
          shooter.spin(forward, 127,pct);
        }
        else if (Controller1.ButtonB.pressing()) {
          shooter.spin(reverse, 127,pct);
        }
        else {
          shooter.stop();
        }

        if(Controller1.ButtonUp.pressing()){
          wings.set(true);
        }
        else if(Controller1.ButtonDown.pressing()){
          wings.set(false);
        }
  
  }
}
        
     // 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);
  }
}

Here is how my code is

Edit: code tags added by mods, please remember to use them so you code can be easily read.

could you please send us your main.cpp file and any other files you have modified?

For intake, chain and shooter, you have assigned to buttons to motors using graphical configuration but also have code trying to control them in usercontrol, pick one way or the other, don’t use both. If you stay with graphical, don’t set velocity to 0 for those motors at the end of auton, otherwise they will not move.

2 Likes