Vex v5 pro code help

I’m trying to make a autonomous event but for some reason there is an error please help
image

Also If I chage the C to a lowercase c the dot becomes an error

add the command

vex::competition Competition;

to the start of the file

2 Likes

Here’s the most simplistic competition template. You’ll need a loop inside of user control as well.

#include "vex.h"

using namespace vex;

competition Competition;

void pre_auton(void) {
}

void autonomous(void) {
}

void usercontrol(void) {
}

int main() {
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  pre_auton();

  while (true) {
wait(100, msec);
  }
}
6 Likes

With comments for those new to C++

// The #include "vex.h" tells the C++ "pre-processor" (a part of the compiling process) to read 
// the file called "vex.h" in the current directory and replace this line with the full contents 
// of that file.
#include "vex.h"

// This is a bit of a convenience statement so that the programmer doesn't have to
// prepend the "vex::" to things found in that namespace, which is a way to organize code
using namespace vex;

// This is declaring a variable called "Competition" which is of type "competition". In nearly
// all modern programming languages, the case of letters matters.  So "foo" is different than
// "FOO" is different than "Foo".  Because this is declared outside of any functions, this is
// known as a "Global Variable" and can be accessed in any "scope"
competition Competition;

// This defines a function. I don't recall if the declaration of "pre_auton" is done in "vex.h". If
// it is not, it is important that functions which are not declared in header files are defined
// before they are used.  If you were to move this function after the function "main", the
// compiler would complain.  You could then move it ahead of "main" or declare it, which is
// generally done in a header file, which would be "#include"-ed just like "vex.h"
void pre_auton(void) {
}

// Similar to pre_auton. Let's take a look at each component of this line.
// First, we see the first "void". This is the "return type" of the function. In this case, "void"
// indicates the function doesn't return a value.
// Second, we see "pre_auton" which is the name of the function.
// Third, we see the second "void" which indicates this function takes no arguments
// Combined, these 3 create the "function signature", which needs to be unique
void autonomous(void) {
}

void usercontrol(void) {
}

// For fun, we could create a new function:
// int doubleInput(int a) {
//   return a + a;
// }
// This function returns an "integer" (a number with no decimal places, so 1, 2, 3 or -1 or 0).
// This function takes 1 argument, which is also an integer.
// One could call this function in main by doing something like:
// int x = 1;
// int y = 0;
// y = doubleInput(x);  // The "value" of "x", in this case the integer 1, is passed into the function "doubleInput"'s first (and only) argument "a", so inside this call to "doubleInput", the value of "a" is 1

int main() {
  // This line tells the Competition object to call the function "autonomous" (the one between 
  // the ()) when the Competition switch indicates the autonomous part of the competition 
  // is active.  This does not actually run the autonomous() function at this time
  Competition.autonomous(autonomous);
  // If "Comptetition" had not been declared as a "Global Variable", the compiler would complain at this
  // point about not knowing what "Competition" was.
  Competition.drivercontrol(usercontrol);

  pre_auton();  // This runs whatever is in the pre_auton() function at this time

 // This is an infinite loop. 
 // This loop is necessary so that the Brain continues to run the program
  while (true) {  
  // This tells the Brain to go to sleep and let another task (such as the "autonomous" 
  // or "usercontrol" function to have the Brain's processor time for at least 100 milliseconds
    wait(100, msec);    
  }
}
7 Likes

i have had this problem before, and i fixed it by copying and pasting the code into a new document.

I’ve done this and it still doesn’t do anything when i start auton with the competition switch; I’ll send the code

#include “vex.h”
#include <vex_imu.h>
using namespace vex;
vex::competition Competition;
//drive foward function
void drivefoward(){

F_Left.spinFor(forward,1,degrees);
F_Right.spinFor(forward,1,degrees);
B_left.spinFor(forward,1,degrees);
B_Right.spinFor(forward,1,degrees);

}
//drive reverse function
void drivereverse(){

F_Left.spinFor(reverse,1,degrees);
F_Right.spinFor(reverse,1,degrees);
B_left.spinFor(reverse,1,degrees);
B_Right.spinFor(reverse,1,degrees);

}
//drive left function
void driveleft(){

F_Left.spinFor(reverse,1,degrees);
F_Right.spinFor(forward,1,degrees);
B_left.spinFor(forward,1,degrees);
B_Right.spinFor(reverse,1,degrees);

}
//drive right function
void driveright(){

F_Left.spinFor(forward,1,degrees);
F_Right.spinFor(reverse,1,degrees);
B_left.spinFor(reverse,1,degrees);
B_Right.spinFor(forward,1,degrees);

}

void score(){

forklift.spinToPosition(-300,degrees);

}

bool inertial_thing=true;

void turnon()
{
inertial_thing=true;
F_Left.setVelocity(100,percent);
F_Right.setVelocity(100,percent);
B_Right.setVelocity(100,percent);
B_left.setVelocity(100,percent);
}

void turnoff(){

inertial_thing=false;
Inertial21.setHeading(0,degrees);
F_Left.setVelocity(15,percent);
F_Right.setVelocity(15,percent);
B_left.setVelocity(15,percent);
B_Right.setVelocity(15,percent);

}
void usercontrol(void){

}
void pre_auton(){

}
//auton function
float i=0;

void autonomous(void){

intake.spin(forward);
//for(int i = 0; i < 100000; i++) {

// drivefoward();

// }
}

int main() {

vexcodeInit();

Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);

pre_auton();

//presets
intake.setVelocity(30,percent);
intake.setStopping(hold);

Inertial21.calibrate();

F_Left.setMaxTorque(100,percent);
B_left.setMaxTorque(100,percent);
F_Right.setMaxTorque(100,percent);
F_Left.setMaxTorque(100,percent);
F_Left.setStopping(brake);
F_Right.setStopping(brake);
B_Right.setStopping(brake);
B_left.setStopping(brake);

forklift.setVelocity(75,percent);
forklift.setStopping(hold);
forklift.setMaxTorque(10000000,percent);
forklift.setPosition(0,turns);

//driver mode
while (true){

Controller1.ButtonDown.pressed(turnon);
Controller1.ButtonUp.pressed(turnoff);
Controller1.ButtonY.pressed(score);

if (inertial_thing == (true)) { 

if (((forklift.position(turns)<=-.25)) && (Controller1.ButtonR1.pressing())){

  forklift.spin(forward);

} else if ((forklift.position(turns)>=-2.58) && (Controller1.ButtonR2.pressing())){

  forklift.spin(reverse);

}else{

  forklift.stop();

}

if (Controller1.ButtonX.pressing()){

  intake.spin(forward);

}else if (Controller1.ButtonB.pressing()){

  intake.spin(reverse);

}else {

  intake.stop();
}

  //drivetrain
  F_Right.spin(forward, Controller1.Axis3.value() - Controller1.Axis1.value() - Controller1.Axis4.value(), percent);
  B_Right.spin(forward, Controller1.Axis3.value() - Controller1.Axis1.value() + Controller1.Axis4.value(), percent);
  F_Left.spin(forward, Controller1.Axis3.value() + Controller1.Axis1.value() + Controller1.Axis4.value(), percent);
  B_left.spin(forward, Controller1.Axis3.value() + Controller1.Axis1.value() - Controller1.Axis4.value(), percent);

//auto balancing

if(inertial_thing==(false)){
  
  
  if ((Inertial21.heading(degrees)>=5) && (Inertial21.heading(degrees)<=180)){

    F_Left.spin(reverse);
    F_Right.spin(forward);
    B_Right.spin(forward);
    B_left.spin(reverse);

} else if ((Inertial21.heading(degrees)<=355) && (Inertial21.heading(degrees)>=180)){

  F_Left.spin(forward);
  F_Right.spin(reverse);
  B_Right.spin(reverse);
  B_left.spin(forward);

} else if (Inertial21.pitch(degrees)<=-15){

  F_Right.spin(forward);
  B_Right.spin(forward);
  F_Left.spin(forward);
  B_left.spin(forward);

} else if (Inertial21.pitch(degrees)>=15){

  F_Right.spin(reverse);
  B_Right.spin(reverse);
  F_Left.spin(reverse);
  B_left.spin(reverse);

} else {

  F_Right.stop();
  B_Right.stop();
  F_Left.stop();
  B_left.stop();     

}

}
wait(100, msec);
}
}
}
//it is very messy