Skip to main content

Competition Code

Formatting Code for the Vex Robotics Competition

A template with the function callbacks for autonomous and usercontrol mode is required to perform in a vex competition. rolling robots template can be downloaded from gitHub here: Rolling Robots Example Code. The folder CompetitionCode is a blank competition project. Download this as a start for your code, you should rename it to something specific to you and do not return it to the gitHub. Use your own gitHub once you have made any edits.

Competition Template

Here is the code that is in main.cpp you can open a new project and copy paste this code to start:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*    Update:  DK  6-11-2021                                                  */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
using namespace vex;

// A global instance of competition
competition Competition;

// define your global Variables here
float pi=3.14;


// Custom Functions


void pre_auton() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  // All activities that occur before the competition starts
  // Example: clearing encoders, setting initial positions, ...
}


void auton() {
  
}
void driver() {
  // User control code here, inside the loop
  while (true) {
    wait(10, msec); // Sleep the task for a short amount of time to prevent wasted resources.
  }
}
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(auton);
  Competition.drivercontrol(driver);
  // Run the pre-autonomous function.
  pre_auton();
  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}