Code working normally but not during competition

The code i wrote works when i do run, and when i do a timed run both autonomous and regular code work. However when i plug in the controller during an actual match the autonomous works but after that only the drivetrain is accessible, the other motors etc dont work. This is incredibly urgent because i will be doing my last 2 matches tomorrow and any replies would be appreciated. Thanks in advance!

Please post your complete program, remembering to add triple backtics (```) before and after your code. Otherwise, it’s very difficult for us to debug code we can’t see.

1 Like

and perhaps export the project and attach the zip file

5 Likes

New users cant upload attachements :confused:

I’ll send it when i get home, im typing this on my phone and cant upload the zip of the project so ill type the files in about 2 hours. Thanks for the fast reply

main::

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

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Drivetrain           drivetrain    11, 1           
// Controller1          controller                    
// KolKaldirSag         motor         2               
// KolKaldirSol         motor         12              
// KolMotorSag          motor         3               
// KolMotorSol          motor         13              
// KuleDik              motor         7               
// ---- 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

/*---------------------------------------------------------------------------*/
/*                          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.                               */
/*---------------------------------------------------------------------------*/

int dikPozisyon = 30;
int egikPozisyon = 1;

float kolKaldirSure = 0.6f;
float tumKupSure = 3;

bool teamRed = false;
//KIRMIZIYSAK BUNU true YAP, MAVİYSEK DOKUNMA

void kollariKaldir()
{
    KolKaldirSag.spin(reverse);
    KolKaldirSol.spin(reverse);
}

void kollariIndir()
{
    KolKaldirSag.spin(forward);
    KolKaldirSol.spin(forward);
}

void kolDurdur()
{
    KolKaldirSag.stop();
    KolKaldirSol.stop();

}

void iceriKupAl()
{
    KolMotorSag.spin(forward);
    KolMotorSol.spin(forward);
}

void disariKupAt()
{
    KolMotorSag.spin(reverse);
    KolMotorSol.spin(reverse);
}

void icKolDurdur()
{
    KolMotorSag.stop();
    KolMotorSol.stop();
}


void kuleyiDik()
{
    KuleDik.spin(forward);
}

void doksanDereceEg()
{
    KuleDik.spin(reverse);
}

void retard()
{
    KuleDik.stop();
}

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

  KuleDik.setVelocity(40, rpm);
  KolKaldirSag.setVelocity(80, rpm);
  KolKaldirSol.setVelocity(80, rpm);
  KolMotorSag.setVelocity(200, rpm);
  KolMotorSol.setVelocity(200, rpm);

  Drivetrain.setDriveVelocity(200, rpm);
  // 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) {  

  //Drivetrain.driveFor(forward, 100, mm);
  ////Orta açılınca takılmasını engelle

  //kollariKaldir();
  //wait(kolKaldirSure, seconds);
  //kollariIndir();
  //wait(kolKaldirSure, seconds);
  //kolDurdur();
  ////Ortayı aç

  //Drivetrain.driveFor(forward, 242, mm);
  //iceriKupAl();
  //Drivetrain.drive(forward);
  //wait(tumKupSure, seconds);
  //Drivetrain.stop();
  //icKolDurdur();
  ////Küpleri al

  //Drivetrain.turnFor(right, 180, degrees);
  //Drivetrain.drive(forward);
  //wait(3, seconds);
  //Drivetrain.driveFor(reverse, 20, mm);
  ////Geri dön

  //if (teamRed == true) Drivetrain.turnFor(left, 90, degrees);
  //else Drivetrain.turnFor(right, 90, degrees);
  ////Kırmızı takımdaysak sola, Mavi takımdaysak sağa 90 derece dön

  //Drivetrain.driveFor(forward, 200, mm);
  ////Skor alanına kadar ileri git

  //kollariKaldir();
  //wait(kolKaldirSure, seconds);
  //kolDurdur();
  //kuleyiDik();
  ////Kuleyi dik hale getir.

  //Drivetrain.driveFor(reverse, 200, mm);
  ////Kuleyi bırak ve git


  Drivetrain.driveFor(reverse, 1500, mm);

  Drivetrain.driveFor(forward, 1500, mm);


  //if (teamRed == false) Drivetrain.turnFor(left, 90, degrees);
  //else Drivetrain.turnFor(right, 90, degrees);

  

}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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

  //Drivetrain.driveFor(reverse, 1500, mm);


  bool ControllerL1R1ButtonsControlMotorsStopped = true;
  bool ControllerABButtonsControlMotorsStopped = true;

  Drivetrain.driveFor(reverse, 180, mm);



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.

if (Controller1.ButtonL1.pressing()) {
    kollariKaldir();
    ControllerL1R1ButtonsControlMotorsStopped = false;
} 
else if (Controller1.ButtonR1.pressing()) {
    kollariIndir();
    ControllerL1R1ButtonsControlMotorsStopped = false;
} 
else if (!ControllerL1R1ButtonsControlMotorsStopped){
    kolDurdur();      
    ControllerL1R1ButtonsControlMotorsStopped = true;
}

if (Controller1.ButtonA.pressing()) {
    iceriKupAl();
    ControllerABButtonsControlMotorsStopped = false;
} 
else if (Controller1.ButtonB.pressing()) {
    disariKupAt();
    ControllerABButtonsControlMotorsStopped = false;
} 
else if (!ControllerABButtonsControlMotorsStopped){
    icKolDurdur();      
    ControllerABButtonsControlMotorsStopped = true;
}

//if (Controller1.ButtonY.pressing()) {
//    kuleyiDik();
//} 
//else if (Controller1.ButtonX.pressing()) {
//   doksanDereceEg();
//} 



    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
    // ........................................................................

    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);
  }
}

robot-config:

#include "vex.h"

using namespace vex;
using signature = vision::signature;
using code = vision::code;

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

// VEXcode device constructors
motor LeftDriveSmart = motor(PORT11, ratio18_1, true);
motor RightDriveSmart = motor(PORT1, ratio18_1, false);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 370, 244, mm, 2);
controller Controller1 = controller(primary);
motor KolKaldirSag = motor(PORT2, ratio36_1, false);
motor KolKaldirSol = motor(PORT12, ratio36_1, true);
motor KolMotorSag = motor(PORT3, ratio18_1, false);
motor KolMotorSol = motor(PORT13, ratio18_1, true);
motor KuleDik = motor(PORT7, ratio18_1, false);

// VEXcode generated functions
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool DrivetrainLNeedsToBeStopped_Controller1 = true;
bool DrivetrainRNeedsToBeStopped_Controller1 = true;

// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_callback_Controller1() {
  // process the controller input every 20 milliseconds
  // update the motors based on the input values
  while(true) {
    if(RemoteControlCodeEnabled) {
      // calculate the drivetrain motor velocities from the controller joystick axies
      // left = Axis3 + Axis1
      // right = Axis3 - Axis1
      int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();
      int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();
      // check if the value is inside of the deadband range
      if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
        // check if the left motor has already been stopped
        if (DrivetrainLNeedsToBeStopped_Controller1) {
          // stop the left drive motor
          LeftDriveSmart.stop();
          // tell the code that the left motor has been stopped
          DrivetrainLNeedsToBeStopped_Controller1 = false;
        }
      } else {
        // reset the toggle so that the deadband code knows to stop the left motor next time the input is in the deadband range
        DrivetrainLNeedsToBeStopped_Controller1 = true;
      }
      // check if the value is inside of the deadband range
      if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
        // check if the right motor has already been stopped
        if (DrivetrainRNeedsToBeStopped_Controller1) {
          // stop the right drive motor
          RightDriveSmart.stop();
          // tell the code that the right motor has been stopped
          DrivetrainRNeedsToBeStopped_Controller1 = false;
        }
      } else {
        // reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
        DrivetrainRNeedsToBeStopped_Controller1 = true;
      }
      // only tell the left drive motor to spin if the values are not in the deadband range
      if (DrivetrainLNeedsToBeStopped_Controller1) {
        LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
        LeftDriveSmart.spin(forward);
      }
      // only tell the right drive motor to spin if the values are not in the deadband range
      if (DrivetrainRNeedsToBeStopped_Controller1) {
        RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
        RightDriveSmart.spin(forward);
      }
    }
    // wait before repeating the process
    wait(20, msec);
  }
  return 0;
}

/**
 * Used to initialize code/tasks/devices added using tools in VEXcode Text.
 * 
 * This should be called at the start of your int main function.
 */
void vexcodeInit( void ) {
  task rc_auto_loop_task_Controller1(rc_auto_loop_callback_Controller1);
}

There’s a good chance this line of code at the beginning of user control could cause problems.

  Drivetrain.driveFor(reverse, 180, mm);

if the drive moves under joystick control for any reason before that completes, it will block.

Other than that, I tested on a competition switch and it seems ok.

4 Likes