Vex C++ Exit Code 2

Hello, I have made a forum before this but no one is seeming to respond. I am not trying to be impatient but we are trying to get our programming done by the end of the year. We are having trouble compiling our program because it keeps coming up with “BUILDING ERROR” whenever we press the compile button at the top. And if that isn’t there then there is at the bottom of the compile in "output “exit code 2:” or something similar to those words. We would like to know if anyone could help us because our school year is about to end and we are trying super hard to get the programming done. If anyone could help that would be amazing and so much help to our ROBOTICS team at our school.

Note: This is an Unofficial Response
Please post your code, and make sure to surround your code on the post with [code] and [/code] to make it easier to read.

As for exit code meaning, you can see here. The error code is pretty vague other than its considered a “major error.” I think seeing the code may allow us to properly troubleshoot the problem.

1 Like

You have a build error! Post the code and we can help determine what it is.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\dscurry                                          */
/*    Created:      Mon Mar 08 2021                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller    21           
// Leftmotor            motor         20              
// Rightmotor           motor         19              
// ClawMotor            motor         17              
// ArmMotor             motor         18              
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include <cmath> // std::abs

using namespace vex;

// A global instance of competition
competition Competition;

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

/*--------------------------------------------------------------------------*/
/*                          Pre-Auonomus Functions                          */
/*                                                                          */
/* You may want to preform some actions before the competition starts.      */
/* Do then in the following function. You must return from this function    */ 
/* or the automus 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 activites that occur before the competition starts
  // Example: clearing encoders, setting servo positions, 
}

//Settings
double kP = 0.0;
double kI = 0.0;
double kD = 0.0;

//Autonomous Settings
int desiredValue = 200;

int error; //SensorValue - DesireValue : Position
int prevError = 0; //Position 20 milliseconds ago
int derivative;
int totalError;

//Variables modified for use
bool enableDrivePID = true;

int drivePID(){

  while(enableDrivePID){

    //Get the position of both motors
    int leftMotorPosition = Leftmotor.position(degrees);
    int rightMotorPosition = Rightmotor.position(degrees);

    ///////////////////////////////////
    //Lateral Movement PID
    //////////////////////////////////////////////////////
    //Get average of the two motors
    int averagePosition = (leftMotorPosition + rightMotorPosition)/2;

   // potential
    error = averagePosition - desiredValue;

  // derivative
    derivative = error - prevError;


    //code
    prevError = error;
    vex::task::sleep(20);

  }
    return 1; 

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

void autonomous(void) {

 vex::task billWiTheScienceFi(drivePID);


/////////////////////////////
//Drivetrain
//Settings
//////////////////////////////////////////////////////////////////////////////

//Driver Control

double turnImportance = 0.5;

while (1) {
/////////////////////////////
//Driver Control
//////////////////////////////////////////////////////////////////////////////

double turnVal = Controller1.Axis1.position(percent);

double forwardVal = Controller1.Axis3.position(percent);

double turnVolts = turnVal * 0.12;
double forwardVolts = forwardVal * 0.12 * (1 - std::abs (turnVolts)/12.0) * turnImportance;

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward,  forwardVolts + turnVolts, voltageUnits::volt);
Rightmotor.spin(forward,  forwardVolts - turnVolts, voltageUnits::volt);
////////////////////////////////////////////////////////////////////////////

/////////////////////////////
//Arm Control
////////////////////////////////////////////////////////////////////////////

bool topRightButton = Controller1.ButtonR1.pressing();
bool bottomRightButton = Controller1.ButtonR2.pressing();

if (topRightButton){
  ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomRightButton){
  ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
  ArmMotor.spin(forward, 0, voltageUnits::volt);

}
////////////////////////////////////////////////////////////////////////////

//Claw Control
////////////////////////////////////////////////////////////////////////////

bool topLeftButton = Controller1.ButtonL1.pressing();
bool bottomLeftButton = Controller1.ButtonL2.pressing();

if (topLeftButton){
  ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomLeftButton){
  ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
  ClawMotor.spin(forward, 0, voltageUnits::volt);

}

// This is the main execution loop for the user control program
// Each time through the loop your program must 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.
//.........................................................................

wait(20, msec); // sleep the task for a short amount of time to
                // prevent wasted sources
}
 #include "vex.h"
using namespace vex;


int main(void); {
  // Initializing Robot Configuration. DO NOT REMOVE! 
  vexcodeInit();
  Brain.Screen.print("Hello");


}


while (1)
wait(20,msec);
int num1 =1;
double num2 = 1.2;
char char1 = 'A';
bool bool1 = false;
num1 = (int)num2;
num2 = 3/2.0;   
char1 = 'B';
bool1 = false;
bool1 = true;

/*==

>=

>
<=
!-*/

while(1==1){
  // code
  num2 = 2.0;
}

double turnVal = Controller1.Axis1.position(percent);
double forwardVal = Controller1.Axis3.position(percent);
double turnVolts = turnVal *0.12;     
double forwardVolts = forwardVal *0.12; 

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward,  forwardVolts - turnVolts, voltageUnits::volt);
Rightmotor.spin(forward,  forwardVolts + turnVolts, voltageUnits::volt);

}

edit: code tags added by moderator

That is our coding. We made a new project to see if we could get the coding to work but we have more problems with duplicate coding words.