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. When you are at a competition you connect your robot to the field controller that will start and stop your code based on timer and mode of the match.  If you code is not in this template it will not run properly.

A competition Template is available in the vex code IDE.  Choose File/Open Example. and you will get the above window, scroll to find the Competition Template then click next you will need to give it a unique project name.

Untitled

https://rollingrobots.com/sites/default/files/images/comp-example.png

Competition Template

Here is the code that is in main.cpp you can open a new project and copy paste this code to start or you cold find this code from the example codes that VexCode offers.

NOTE: The competition template has three sections that correspond to the three phases of a competition match: Pre Autonomous (robot setup), Autonomous period, and Driver Controlled Period.

In order for your code to work at a competition, you must:

  1. Leave the code below inside the main function in place.
  2. Add your code inside one of the three function (pre_autonautonomoususercontrol).

Main is the code that runs when you start the code

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

Using a Pre-auton Function for Any Setup Steps

https://kb.vex.com/hc/article_attachments/360043095292/file-ARGT3hAOCl.png